StatusMonitoring.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. <template>
  2. <DashboardLayout ref="layout" layoutClass="special-situation-monitoring">
  3. <template #header-left>
  4. </template>
  5. <template #header-right>
  6. <!-- 日期 -->
  7. <DateTimeWidget />
  8. </template>
  9. <template #map>
  10. <!-- 路口列表 -->
  11. <div v-if="currentView === 'list-mode' && activeLeftTab === 'crossing'" class="list-mode-panel">
  12. <CrossingListPanel :onViewDetail="handleCrossingViewDetail"/>
  13. </div>
  14. <!-- 地图 -->
  15. <TongzhouTrafficMap v-else ref="trafficMapRef"
  16. amapKey="db2da7e3e248c3b2077d53fc809be63f"
  17. securityJsCode="a7413c674852c5eaf01d90813c5b7ef6"
  18. :mode="activeLeftTab === 'crossing' ? '路口' : activeLeftTab === 'trunkLine' ? '干线' : activeLeftTab === 'specialDuty' ? '特勤' : ''"
  19. @map-crossing-click="handleMapCrossingClick"
  20. @map-crossing-mouseover="handleMapCrossingMouseover"
  21. @map-crossing-mouseout="handleMapCrossingMouseout"
  22. @bindTrunkMenuTree="handleTrunkMenuUpdate"
  23. />
  24. </template>
  25. <template #left>
  26. <!-- 左侧Tab菜单栏 -->
  27. <div class="left-sidebar-wrap" v-if="currentView !== 'list-mode'">
  28. <TechTabs v-model="activeLeftTab" type="underline" @tab-click="handleTabClick">
  29. <TechTabPane label="总览" name="overview" class="menu-scroll-view" :loading="menuData.length === 0">
  30. <MenuItem theme="tech" v-for="item in menuData" :key="item.id" :node="item" :level="0"
  31. @node-click="handleMenuClick" @folder-click="handleFolderClick"/>
  32. </TechTabPane>
  33. <TechTabPane label="路口" name="crossing" class="menu-scroll-view" :loading="menuData.length === 0">
  34. <MenuItem theme="tech" v-for="item in menuData" :key="item.id" :node="item" :level="0"
  35. @node-click="handleMenuClick" />
  36. </TechTabPane>
  37. <TechTabPane label="干线" name="trunkLine" class="menu-scroll-view" :loading="trunkLineMenuData.length === 0">
  38. <MenuItem v-for="item in trunkLineMenuData" :key="item.id" :node="item" :level="0"
  39. @node-click="handleTrunkLineClick">
  40. <template #label="{ node }">
  41. <span v-if="node.children && node.children.length > 0">{{ node.label }}</span>
  42. <span v-else>{{ node.label }} 绿波带</span>
  43. </template>
  44. </MenuItem>
  45. </TechTabPane>
  46. <TechTabPane label="特勤" name="specialDuty" class="menu-scroll-view">
  47. <TaskCardList :listData="tableData" class="special-duty-pane"
  48. @view="({ item }) => handleSpecialTaskView(item)"
  49. @start="({ item }) => handleSpecialTaskStart(item)"
  50. @end="({ item }) => handleSpecialTaskEnd(item)"
  51. @restart="({ item }) => handleSpecialTaskRestart(item)"
  52. />
  53. </TechTabPane>
  54. </TechTabs>
  55. </div>
  56. <div class="list-mode-tabs" v-else>
  57. <TechTabs v-model="activeLeftTab" type="underline" @tab-click="onListTabSelect">
  58. <TechTabPane label="总览" name="overview" />
  59. <TechTabPane label="路口" name="crossing" />
  60. <TechTabPane label="干线" name="trunkLine" />
  61. <TechTabPane label="特勤" name="specialDuty" />
  62. </TechTabs>
  63. </div>
  64. </template>
  65. <template #right>
  66. <!-- 模式切换按钮组 -->
  67. <div class="mode-switch" v-if="activeLeftTab === 'crossing'">
  68. <ButtonGroup v-model="currentView" :options="viewOptions" @select="onViewSelect" />
  69. </div>
  70. </template>
  71. <template #center>
  72. <!-- 顶部常驻图表区域(替代弹窗) -->
  73. <div class="top-charts-bar" v-if="currentView !== 'list-mode'">
  74. <!-- 总览Tab -->
  75. <template v-if="activeLeftTab === 'overview'">
  76. <div class="top-chart-box overview-chart-box">
  77. <OnlineStatusTabs />
  78. </div>
  79. <div class="top-chart-box overview-chart-box">
  80. <DeviceStatusTabs />
  81. </div>
  82. </template>
  83. <!-- 路口Tab -->
  84. <template v-if="activeLeftTab === 'crossing'">
  85. <div class="top-chart-box overview-chart-box">
  86. <OnlineStatusTabs />
  87. </div>
  88. <div class="top-chart-box overview-chart-box">
  89. <DeviceStatusTabs />
  90. </div>
  91. </template>
  92. </div>
  93. </template>
  94. </DashboardLayout>
  95. </template>
  96. <script>
  97. import DashboardLayout from '@/layouts/DashboardLayout.vue';
  98. import DateTimeWidget from '@/components/ui/DateTimeWidget.vue';
  99. import TechTabs from '@/components/ui/TechTabs.vue';
  100. import TechTabPane from '@/components/ui/TechTabPane.vue';
  101. import TongzhouTrafficMap from '@/components/TongzhouTrafficMap.vue';
  102. import MenuItem from '@/components/ui/MenuItem.vue';
  103. import ButtonGroup from '@/components/ui/ButtonGroup.vue';
  104. import TaskCardList from '@/components/ui/TaskCardList.vue';
  105. import CrossingListPanel from '@/components/ui/CrossingListPanel.vue';
  106. import OnlineStatusTabs from '@/components/ui/OnlineStatusTabs.vue';
  107. import DeviceStatusTabs from '@/components/ui/DeviceStatusTabs.vue';
  108. import { apiGetTongzhouMenuTree, apiGetTasks, apiGetTrafficTimeSpace, apiGetCrossingTopCharts, apiGetSpecialTaskMonitorData, apiGetCrossingDetailData } from '@/api';
  109. export default {
  110. name: "StatusMonitoring",
  111. components: {
  112. DashboardLayout,
  113. DateTimeWidget,
  114. TechTabs,
  115. TechTabPane,
  116. TongzhouTrafficMap,
  117. MenuItem,
  118. ButtonGroup,
  119. TaskCardList,
  120. CrossingListPanel,
  121. OnlineStatusTabs,
  122. DeviceStatusTabs,
  123. },
  124. data() {
  125. return {
  126. // 左侧边栏数据
  127. activeLeftTab: '',
  128. menuData: [],
  129. trunkLineMenuData: [],
  130. // 地图模式切换数据
  131. currentView: 'map-mode',
  132. viewOptions: [
  133. { label: '列表模式', value: 'list-mode' },
  134. { label: '地图模式', value: 'map-mode' },
  135. ],
  136. // 特勤表头
  137. tableColumns: [
  138. { label: '序号', key: 'id', width: '10%' },
  139. { label: '名称', key: 'name', width: '30%' },
  140. { label: '执行人', key: 'executor', width: '15%' },
  141. { label: '等级', key: 'level', width: '12%' },
  142. { label: '状态', key: 'status', width: '13%' },
  143. { label: '操作', key: 'action', width: '20%' }
  144. ],
  145. tableData: [],
  146. // 路口顶部图表数据
  147. crossingTopCharts: {},
  148. // 路口多选分屏
  149. crossingSelections: [],
  150. maxCrossingSlots: 4,
  151. };
  152. },
  153. watch: {
  154. // 监听路由参数变化(解决多次从首页点击不同数据跳转过来,页面不刷新的问题)
  155. '$route.query': {
  156. handler() {
  157. this.checkRouteParams();
  158. },
  159. deep: true
  160. }
  161. },
  162. created() {
  163. },
  164. async mounted() {
  165. // 加载菜单和任务数据
  166. const [menuData, taskData] = await Promise.all([
  167. apiGetTongzhouMenuTree(),
  168. apiGetTasks({ pageSize: 5 }),
  169. ]);
  170. this.menuData = menuData || [];
  171. this.trunkLineMenuData = [];
  172. this.tableData = taskData?.list || taskData || [];
  173. // 组件挂载时检查路由
  174. this.checkRouteParams();
  175. // 初始显示顶部图表(如果没有路由参数覆盖的话)
  176. if (Object.keys(this.$route.query).length === 0) {
  177. this.activeLeftTab = 'overview';
  178. this.showTopChartDalogs();
  179. }
  180. },
  181. methods: {
  182. // 处理地图鼠标滑入事件
  183. handleMapCrossingMouseover(mapData, lnglat, pixel) {
  184. console.log('父组件接收到了地图路口鼠标滑入事件:', mapData);
  185. // 组装模拟数据
  186. const scale = window.innerWidth / 1920;
  187. let nodeData = {
  188. id: mapData.position[0] + mapData.position[1],
  189. label: mapData.road,
  190. // 反算为设计稿坐标(SmartDialog 内部会再乘 scale)
  191. pixelX: pixel ? Math.round(pixel.x / scale) : 950,
  192. pixelY: pixel ? Math.round(pixel.y / scale) : 430,
  193. }
  194. console.log(nodeData);
  195. if (this.activeLeftTab === 'overview') { // 总览
  196. this.showOverviewDalogs(nodeData);
  197. } else if (this.activeLeftTab === 'crossing') { // 路口
  198. this.showOverviewDalogs(nodeData);
  199. }
  200. },
  201. // 处理地图鼠标滑出事件
  202. handleMapCrossingMouseout(mapData) {
  203. console.log('父组件接收到了地图路口鼠标滑出事件:', mapData);
  204. if (this.activeLeftTab === 'overview' && mapData) { // 总览
  205. const id = mapData.position[0] + mapData.position[1];
  206. this.$refs.layout.handleDialogClose('crossing3_' + id);
  207. } else if (this.activeLeftTab === 'crossing' && mapData) { // 路口
  208. const id = mapData.position[0] + mapData.position[1];
  209. this.$refs.layout.handleDialogClose('crossing3_' + id);
  210. }
  211. },
  212. // 处理地图点击事件
  213. handleMapCrossingClick(mapData, lnglat, pixel) {
  214. console.log('父组件接收到了地图路口点击事件:', mapData);
  215. console.log('父组件接收到了地图路口点击事件:', lnglat);
  216. console.log('父组件接收到了地图路口点击事件:', pixel);
  217. // 组装模拟数据
  218. const scale = window.innerWidth / 1920;
  219. let nodeData = {
  220. id: mapData.position[0] + mapData.position[1],
  221. label: mapData.road,
  222. // 反算为设计稿坐标(SmartDialog 内部会再乘 scale)
  223. pixelX: pixel ? Math.round(pixel.x / scale) : 950,
  224. pixelY: pixel ? Math.round(pixel.y / scale) : 430,
  225. }
  226. // 干线marker点击时,从菜单数据中匹配对应干线
  227. if (this.activeLeftTab === 'trunkLine' && mapData.id) {
  228. const matched = this.findTrunkMenuNode(mapData.id);
  229. if (matched) {
  230. nodeData.id = matched.id;
  231. nodeData.label = matched.label;
  232. nodeData.intersections = matched.intersections;
  233. nodeData.distances = matched.distances;
  234. }
  235. }
  236. console.log(nodeData);
  237. if (this.activeLeftTab === 'overview') { // 总览
  238. this.showCrossingDetailDialogs(nodeData);
  239. } else if (this.activeLeftTab === 'crossing') { // 路口
  240. this.showCrossingDalogs(nodeData);
  241. } else if (this.activeLeftTab === 'trunkLine') { // 干线
  242. this.showTrunkLineDalogs(nodeData);
  243. } else if (this.activeLeftTab === 'specialDuty') { // 特勤
  244. this.showSpecialDutyDalogs(nodeData);
  245. }
  246. },
  247. // 列表模式Tab切换
  248. onListTabSelect(tabName) {
  249. if (tabName !== 'crossing') {
  250. this.currentView = 'map-mode';
  251. }
  252. this.handleTabClick(tabName);
  253. },
  254. // 模式切换
  255. onViewSelect(item) {
  256. console.log('你点击了:', item.label);
  257. this.currentView = item.value;
  258. this.$refs.layout.clearDialogs(); // 清空全部弹窗
  259. this.crossingSelections = [];
  260. // 列表模式弹窗
  261. if (this.currentView === 'list-mode') {
  262. // this.$refs.layout.openDialog({
  263. // id: 'crossing-list', // 这里的 ID 可以根据实际业务场景动态生成
  264. // title: '',
  265. // component: 'CrossingListPanel',
  266. // width: 1920,
  267. // height: 750,
  268. // center: false,
  269. // showClose: true,
  270. // noPadding: false,
  271. // enableDblclickExpand: false,
  272. // position: { x: 100, y: 150 },
  273. // data: {
  274. // onViewDetail: (rowData) => this.handleCrossingViewDetail(rowData)
  275. // }
  276. // });
  277. } else {
  278. this.loadCrossingTopCharts();
  279. }
  280. },
  281. // 处理tab点击
  282. handleTabClick(tabName) {
  283. console.log('父组件接收到了tab点击事件:', tabName);
  284. this.$refs.layout.clearDialogs(); // 清空全部弹窗
  285. this.crossingSelections = [];
  286. this.showTopChartDalogs(); // 根据当前Tab显示对应的顶部常驻图表
  287. },
  288. // 处理菜单folder标题点击:计算子区路口中心坐标,移动地图
  289. handleFolderClick(nodeData) {
  290. console.log('父组件接收到了文件夹点击事件:', nodeData);
  291. const leaves = [];
  292. const collect = (nodes) => {
  293. if (!Array.isArray(nodes)) return;
  294. for (const n of nodes) {
  295. if (n.children) collect(n.children);
  296. else if (n.lng && n.lat) leaves.push(n);
  297. }
  298. };
  299. collect(nodeData.children || []);
  300. if (leaves.length === 0 || !this.$refs.trafficMapRef) return;
  301. const avgLng = leaves.reduce((s, n) => s + n.lng, 0) / leaves.length;
  302. const avgLat = leaves.reduce((s, n) => s + n.lat, 0) / leaves.length;
  303. const zoom = leaves.length <= 6 ? 15 : 14;
  304. const map = this.$refs.trafficMapRef.map;
  305. if (map) map.setZoomAndCenter(zoom, [avgLng, avgLat], false, 500);
  306. },
  307. // 处理菜单点击
  308. handleMenuClick(nodeData) {
  309. console.log('父组件接收到了最底层路口点击事件:', nodeData);
  310. const showDialog = () => {
  311. if (this.activeLeftTab === 'overview') {
  312. this.showOverviewDalogs(nodeData);
  313. } else if (this.activeLeftTab === 'crossing') {
  314. this.showCrossingDalogs(nodeData);
  315. } else if (this.activeLeftTab === 'trunkLine') {
  316. this.showTrunkLineDalogs(nodeData);
  317. } else if (this.activeLeftTab === 'specialDuty') {
  318. this.showSpecialDutyDalogs(nodeData);
  319. }
  320. };
  321. // 先关闭上一个总览弹窗
  322. if (this._lastOverviewDialogId) {
  323. this.$refs.layout.handleDialogClose(this._lastOverviewDialogId);
  324. this._lastOverviewDialogId = null;
  325. }
  326. // 通过路口编号定位地图 marker,动画完成后计算像素位置再弹窗
  327. if (this._menuClickTimer) {
  328. clearTimeout(this._menuClickTimer);
  329. this._menuClickTimer = null;
  330. }
  331. if (this.$refs.trafficMapRef) {
  332. const mapPos = this.$refs.trafficMapRef.focusById(nodeData.id);
  333. if (mapPos) {
  334. this._menuClickTimer = setTimeout(() => {
  335. this._menuClickTimer = null;
  336. // 地图已居中到标记点,直接用地图容器中心作为弹窗位置
  337. const mapEl = this.$refs.trafficMapRef.$el;
  338. const scale = window.innerWidth / 1920;
  339. if (mapEl) {
  340. const rect = mapEl.getBoundingClientRect();
  341. nodeData.pixelX = Math.round((rect.left + rect.width / 2) / scale) + 5;
  342. nodeData.pixelY = Math.round((rect.top + rect.height / 2) / scale);
  343. }
  344. showDialog();
  345. }, 600);
  346. return;
  347. }
  348. }
  349. // fallback: 没有地图或找不到 marker 时直接弹窗
  350. if (this.activeLeftTab === 'overview') { // 总览
  351. this.showOverviewDalogs(nodeData);
  352. } else if (this.activeLeftTab === 'crossing') { // 路口
  353. this.showCrossingDalogs(nodeData);
  354. } else if (this.activeLeftTab === 'trunkLine') { // 干线
  355. this.showTrunkLineDalogs(nodeData);
  356. } else if (this.activeLeftTab === 'specialDuty') { // 特勤
  357. this.showSpecialDutyDalogs(nodeData);
  358. }
  359. },
  360. // 处理弹窗双击展开(通过 onExpand 回调从 Layout 传入)
  361. handleDoubleClickExpend(nodeData) {
  362. console.log('处理弹窗双击事件', nodeData);
  363. if (this.activeLeftTab === 'crossing' || this.activeLeftTab === 'overview') {
  364. this.showCrossingDetailDialogs(nodeData);
  365. }
  366. },
  367. // 显示顶部常驻图表(根据当前Tab状态)
  368. showTopChartDalogs() {
  369. if (this.activeLeftTab === 'crossing') {
  370. this.loadCrossingTopCharts();
  371. }
  372. },
  373. // 显示总览弹窗组
  374. showOverviewDalogs(nodeData) {
  375. console.log('显示总览弹窗组', nodeData.id, nodeData.label);
  376. const dialogId = 'crossing3_' + nodeData.id;
  377. this._lastOverviewDialogId = dialogId;
  378. // 路口弹窗
  379. this.$refs.layout.openDialog({
  380. id: dialogId, // 这里的 ID 可以根据实际业务场景动态生成
  381. title: nodeData.label,
  382. component: 'CrossingPanel',
  383. width: 260,
  384. height: 260,
  385. center: false,
  386. showClose: true,
  387. position: { x: (nodeData.pixelX || 950) + 10, y: nodeData.pixelY || 430 },
  388. noPadding: false,
  389. data: {
  390. ...nodeData,
  391. onExpand: (data) => this.handleDoubleClickExpend(data)
  392. },
  393. onClose: () => {
  394. // this.$refs.layout.handleDialogClose('top-chart-crossing-1');
  395. // this.$refs.layout.handleDialogClose('top-chart-crossing-2');
  396. }
  397. });
  398. },
  399. async loadCrossingTopCharts() {
  400. try {
  401. this.crossingTopCharts = await apiGetCrossingTopCharts();
  402. } catch (e) { /* ignore */ }
  403. },
  404. // 显示路口弹窗组(多选分屏)
  405. async showCrossingDalogs(nodeData) {
  406. console.log('路口多选', nodeData.id, nodeData.label);
  407. // 0. 离线检查
  408. const detailData = await apiGetCrossingDetailData(nodeData.id, { iconMode: 'simple' });
  409. if (detailData?.intersectionData?.status !== '在线') {
  410. this.$msg({
  411. title: '提示',
  412. message: `路口「${nodeData.label || nodeData.id}」设备离线,无法查看详情`,
  413. duration: 3000,
  414. });
  415. return;
  416. }
  417. // 1. 已选中 → 不重复操作
  418. const existIndex = this.crossingSelections.findIndex(c => c.id === nodeData.id);
  419. if (existIndex !== -1) {
  420. return;
  421. }
  422. // 2. 已满 → 先进先出
  423. if (this.crossingSelections.length >= this.maxCrossingSlots) {
  424. this.crossingSelections.shift();
  425. }
  426. // 3. 追加选中,带上预加载数据避免重复请求
  427. this.crossingSelections.push({ ...nodeData, _preloadedData: detailData });
  428. // 4. 打开或更新弹窗
  429. this.openCrossingMultiView();
  430. },
  431. openCrossingMultiView() {
  432. this.$refs.layout.openDialog({
  433. id: 'crossing-multi-view',
  434. title: '',
  435. component: 'CrossingMultiView',
  436. width: 1400,
  437. height: 700,
  438. center: false,
  439. position: { x: 500, y: 150 },
  440. showClose: false,
  441. noPadding: true,
  442. enableDblclickExpand: false,
  443. draggable: false,
  444. data: {
  445. crossings: [...this.crossingSelections],
  446. maxSlots: this.maxCrossingSlots,
  447. onRemove: (id) => this.handleCrossingRemove(id),
  448. onReorder: (newOrder) => {
  449. this.crossingSelections = newOrder;
  450. }
  451. },
  452. onClose: () => {
  453. this.crossingSelections = [];
  454. }
  455. });
  456. },
  457. handleCrossingRemove(id) {
  458. this.crossingSelections = this.crossingSelections.filter(c => c.id !== id);
  459. if (this.crossingSelections.length === 0) {
  460. this.$refs.layout.handleDialogClose('crossing-multi-view');
  461. } else {
  462. this.openCrossingMultiView();
  463. }
  464. },
  465. // 单个路口详情弹窗(总览双击展开等场景使用)
  466. async showCrossingDetailDialogs(nodeData) {
  467. console.log('显示路口详情弹窗组', nodeData.id, nodeData.label);
  468. const detailData = await apiGetCrossingDetailData(nodeData.id, { iconMode: 'simple' });
  469. if (detailData?.intersectionData?.status !== '在线') {
  470. this.$msg({
  471. title: '提示',
  472. message: `路口「${nodeData.label || nodeData.id}」设备离线,无法查看详情`,
  473. duration: 3000,
  474. });
  475. return;
  476. }
  477. const dialogId = 'crossing_detail' + nodeData.id;
  478. this.$refs.layout.openDialog({
  479. id: dialogId,
  480. title: ' ',
  481. component: 'CrossingDetailPanel',
  482. width: 1315,
  483. height: 682,
  484. center: false,
  485. showClose: true,
  486. position: { x: 500, y: 170 },
  487. noPadding: false,
  488. enableDblclickExpand: false,
  489. data: { ...nodeData, preloadedData: detailData },
  490. headerComponent: 'CrossingDetailHeader',
  491. headerProps: {
  492. currentRoute: detailData?.currentRoute || {},
  493. intersectionData: detailData?.intersectionData || {},
  494. cycleLength: detailData?.cycleLength || 0,
  495. }
  496. });
  497. },
  498. // 路口列表模式下弹窗
  499. handleCrossingViewDetail(rowData) {
  500. console.log('显示路口列表查看', rowData);
  501. this.showCrossingDetailDialogs(rowData);
  502. },
  503. // 显示干线弹窗组
  504. // 干线菜单叶子节点点击
  505. handleTrunkLineClick(nodeData) {
  506. console.log('干线菜单点击:', nodeData);
  507. this.showTrunkLineDalogs(nodeData);
  508. },
  509. findTrunkMenuNode(markerId) {
  510. // 从 marker ID(如 trunk_1_point_3)提取干线编号(trunk_1)
  511. const trunkId = String(markerId).replace(/_point_\d+$/, '');
  512. const leaves = [];
  513. const walk = (nodes) => {
  514. if (!Array.isArray(nodes)) return;
  515. for (const n of nodes) {
  516. if (n.children && n.children.length > 0) walk(n.children);
  517. else leaves.push(n);
  518. }
  519. };
  520. walk(this.trunkLineMenuData);
  521. return leaves.find(n => n.id === trunkId) || null;
  522. },
  523. handleTrunkMenuUpdate(segments) {
  524. this.trunkLineMenuData = [{
  525. id: 'trunk_root',
  526. label: '主控中心',
  527. icon: 'icon-control',
  528. isOpen: true,
  529. children: [{
  530. id: 'trunk_beijing',
  531. label: '北京市交警总队',
  532. icon: 'icon-police',
  533. isOpen: true,
  534. children: [{
  535. id: 'trunk_tongzhou',
  536. label: '通州区',
  537. icon: 'icon-district',
  538. isOpen: true,
  539. children: (() => {
  540. const list = segments.slice(0, 6);
  541. if (list[5]) list[5] = { ...list[5], label: '张台路与湖亦路路口' };
  542. return list;
  543. })()
  544. }]
  545. }]
  546. }];
  547. },
  548. async showTrunkLineDalogs(nodeData) {
  549. console.log('显示干线弹窗组', nodeData.id, nodeData.label);
  550. // 优先使用菜单节点自带的路口和距离数据
  551. let tsData;
  552. if (nodeData.intersections && nodeData.distances) {
  553. tsData = await apiGetTrafficTimeSpace({
  554. intersections: nodeData.intersections,
  555. distances: nodeData.distances,
  556. });
  557. } else {
  558. tsData = await apiGetTrafficTimeSpace();
  559. }
  560. this.$refs.layout.openDialog({
  561. id: nodeData.id,
  562. title: nodeData.label + ' 绿波带',
  563. component: 'TrafficTimeSpace',
  564. width: 1000,
  565. height: 500,
  566. center: true,
  567. showClose: true,
  568. noPadding: false,
  569. data: tsData,
  570. });
  571. },
  572. // 显示特勤弹窗组
  573. showSpecialDutyDalogs(nodeData) {
  574. console.log('显示特勤弹窗组', nodeData.id, nodeData.label);
  575. this.openDutyDetailDialog(nodeData);
  576. },
  577. // === 解析路由参数并执行对应操作 ===
  578. checkRouteParams() {
  579. // 统一参数接收:特勤接收 id,路口接收 intersectionName 和 plan
  580. const { tab, action, id, } = this.$route.query;
  581. if (!tab) return; // 如果没有传递 tab 参数,说明是正常访问,不处理
  582. // 1. 处理“特勤线路”跳转
  583. if (tab === 'specialDuty') {
  584. this.activeLeftTab = 'specialDuty'; // 切换到左侧【特勤】Tab
  585. this.handleTabClick('specialDuty'); // 手动触发 Tab 切换事件,更新顶部图表
  586. // 这里判断的条件改为 id
  587. if (action === 'open-dialog' && id) {
  588. this.$nextTick(() => {
  589. this.openDutyDetailDialog({id: id, label: '特勤路口'}); // 打开特勤弹窗
  590. });
  591. }
  592. }
  593. // 2. 处理“关键路口”跳转
  594. else if (tab === 'crossing') {
  595. this.activeLeftTab = 'crossing'; // 切换到左侧【路口】Tab
  596. this.handleTabClick('crossing'); // 手动触发 Tab 切换事件,更新顶部图表
  597. if (action === 'open-dialog') {
  598. this.$nextTick(() => {
  599. // 构造一个假的 nodeData 传给详情弹窗方法
  600. this.showCrossingDetailDialogs({
  601. id: 'route_' + new Date().getTime(), // 动态生成一个ID防重复
  602. label: '路口详情',
  603. });
  604. });
  605. }
  606. }
  607. },
  608. // === 特勤详情弹窗 (你需要根据实际组件名替换) ===
  609. async openDutyDetailDialog(nodeData) {
  610. console.log('准备打开特勤线路详情:', nodeData);
  611. // 1. 获取数据
  612. const panelData = await apiGetSpecialTaskMonitorData(nodeData.id);
  613. const id = 'special-task-dialog' + new Date().getTime();
  614. // 2. 呼出弹窗
  615. this.$refs.layout.openDialog({
  616. id: id,
  617. title: ' ', // 留空以隐藏默认标题,使用自定义 Header
  618. width: 1400, // 弹窗宽一点,容纳 3 列
  619. height: 700,
  620. center: false,
  621. showClose: true,
  622. noPadding: true, // 去除默认内边距,让内部组件自己控制
  623. position: {x: 200, y: 150},
  624. // 挂载主体组件和数据
  625. component: 'SpecialTaskMonitorPanel',
  626. data: { panelData: panelData },
  627. // 挂载自定义 Header 和数据
  628. headerComponent: 'TaskMonitorHeader',
  629. headerProps: {
  630. taskData: panelData.taskInfo,
  631. onStartTask: () => {
  632. console.log('点击了立即执行');
  633. panelData.taskInfo.status = '进行中';
  634. const tableRow = this.tableData.find(r => r.id === nodeData.id);
  635. if (tableRow) tableRow.status = '进行中';
  636. },
  637. onEndTask: () => {
  638. console.log('点击了立即结束');
  639. panelData.taskInfo.status = '已完成';
  640. const tableRow = this.tableData.find(r => r.id === nodeData.id);
  641. if (tableRow) tableRow.status = '已完成';
  642. }
  643. }
  644. });
  645. return panelData;
  646. },
  647. handleSpecialTaskView(row) {
  648. console.log('查看特勤线路,当前数据:', row);
  649. this.openDutyDetailDialog(row);
  650. },
  651. async handleSpecialTaskStart(row) {
  652. console.log('立即执行特勤任务:', row);
  653. const panelData = await this.openDutyDetailDialog(row);
  654. this.$msg({
  655. title: '操作确认',
  656. message: `确认立即执行任务「${row.name}」?`,
  657. duration: 0,
  658. showConfirm: true,
  659. showCancel: true,
  660. confirmText: '确认执行',
  661. noBackdrop: true,
  662. onConfirm: () => { row.status = '进行中'; panelData.taskInfo.status = '进行中'; }
  663. });
  664. },
  665. async handleSpecialTaskEnd(row) {
  666. console.log('立即结束特勤任务:', row);
  667. const panelData = await this.openDutyDetailDialog(row);
  668. this.$msg({
  669. title: '操作确认',
  670. message: `确认立即结束任务「${row.name}」?`,
  671. duration: 0,
  672. showConfirm: true,
  673. showCancel: true,
  674. confirmText: '确认结束',
  675. noBackdrop: true,
  676. onConfirm: () => { row.status = '已完成'; panelData.taskInfo.status = '已完成'; }
  677. });
  678. },
  679. async handleSpecialTaskRestart(row) {
  680. console.log('重新开始特勤任务:', row);
  681. const panelData = await this.openDutyDetailDialog(row);
  682. this.$msg({
  683. title: '操作确认',
  684. message: `确认重新开始任务「${row.name}」?`,
  685. duration: 0,
  686. showConfirm: true,
  687. showCancel: true,
  688. confirmText: '确认开始',
  689. noBackdrop: true,
  690. onConfirm: () => { row.status = '进行中'; panelData.taskInfo.status = '进行中'; }
  691. });
  692. },
  693. }
  694. }
  695. </script>
  696. <style scoped>
  697. .mode-switch {
  698. display: flex;
  699. flex-direction: row;
  700. justify-content: flex-end;
  701. }
  702. .mode-switch>div {
  703. width: 200px;
  704. }
  705. .duty-table {
  706. margin-top: 10px;
  707. }
  708. .action-btn {
  709. cursor: pointer;
  710. color: #4da8ff;
  711. margin-right: 10px;
  712. }
  713. .action-btn:hover {
  714. text-decoration: underline;
  715. }
  716. .action-start {
  717. color: #67c23a;
  718. }
  719. .action-end {
  720. color: #f56c6c;
  721. }
  722. .top-charts-bar {
  723. display: flex;
  724. justify-content: center;
  725. gap: clamp(10px, 1.04vw, 20px);
  726. pointer-events: none;
  727. }
  728. .top-chart-box {
  729. pointer-events: auto;
  730. flex-shrink: 0;
  731. background: radial-gradient(circle at 20% 0%, rgba(40,120,200,0.5) 0%, rgba(20,60,130,0.7) 70%);
  732. box-shadow: inset 0px 0px 0.625rem 0px rgba(88, 146, 255, 0.4), inset 1.25rem 0px 1.875rem -0.625rem rgba(88, 146, 255, 0.15);
  733. border: 1px solid rgba(255, 255, 255, 0.15);
  734. border-radius: clamp(6px, 0.625vw, 12px);
  735. overflow: hidden;
  736. }
  737. /* --- 总览Tab图表尺寸适配 (原 300x160) --- */
  738. .overview-chart-box {
  739. /* clamp(最小值, 理想值(1920下比例), 最大值) */
  740. width: clamp(200px, 15.625vw, 300px);
  741. height: clamp(106px, 8.333vw, 160px);
  742. }
  743. /* --- 路口Tab图表尺寸适配 (原 228x124) --- */
  744. .crossing-chart-box {
  745. width: clamp(152px, 11.875vw, 228px);
  746. height: clamp(82px, 6.458vw, 124px);
  747. }
  748. ::v-deep .list-mode-panel {
  749. position: absolute;
  750. inset: 0;
  751. padding: 150px 30px 30px 30px;
  752. box-sizing: border-box;
  753. display: flex;
  754. flex-direction: column;
  755. overflow: hidden;
  756. }
  757. .list-mode-tabs {
  758. flex-shrink: 0;
  759. max-width: 400px;
  760. }
  761. .duty-name {
  762. display: inline-block;
  763. max-width: 8em;
  764. overflow: hidden;
  765. text-overflow: ellipsis;
  766. white-space: nowrap;
  767. vertical-align: middle;
  768. }
  769. /* 针对特勤 Tab 单独剥离背景和边框 */
  770. ::v-deep .special-duty-pane {
  771. padding: 10px 20px;
  772. }
  773. </style>