StatusMonitoring.vue 40 KB

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