StatusMonitoring.vue 35 KB

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