StatusMonitoring.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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
  16. amapKey="db2da7e3e248c3b2077d53fc809be63f"
  17. securityJsCode="a7413c674852c5eaf01d90813c5b7ef6"
  18. :mode="activeLeftTab === 'crossing' ? '路口' : activeLeftTab === 'trunkLine' ? '干线' : activeLeftTab === 'specialDuty' ? '特勤' : ''"
  19. @map-crossing-click="handleMapCrossingClick"
  20. />
  21. </template>
  22. <template #left>
  23. <!-- 左侧Tab菜单栏 -->
  24. <div class="left-sidebar-wrap" v-if="currentView !== 'list-mode'">
  25. <TechTabs v-model="activeLeftTab" type="underline" @tab-click="handleTabClick">
  26. <TechTabPane label="总览" name="overview" class="menu-scroll-view">
  27. <MenuItem theme="tech" v-for="item in menuData" :key="item.id" :node="item" :level="0"
  28. @node-click="handleMenuClick" />
  29. </TechTabPane>
  30. <TechTabPane label="路口" name="crossing" class="menu-scroll-view">
  31. <MenuItem theme="tech" v-for="item in menuData" :key="item.id" :node="item" :level="0"
  32. @node-click="handleMenuClick" />
  33. </TechTabPane>
  34. <TechTabPane label="干线" name="trunkLine" class="menu-scroll-view">
  35. <MenuItem v-for="item in menuData" :key="item.id" :node="item" :level="0"
  36. @node-click="handleMenuClick">
  37. <template #label="{ node }">
  38. <span v-if="node.children && node.children.length > 0">{{ node.label }}</span>
  39. <span v-else>{{ node.label }} 绿波带</span>
  40. </template>
  41. </MenuItem>
  42. </TechTabPane>
  43. <TechTabPane label="特勤" name="specialDuty">
  44. </TechTabPane>
  45. </TechTabs>
  46. </div>
  47. </template>
  48. <template #right>
  49. <!-- 模式切换按钮组 -->
  50. <div class="mode-switch" v-if="activeLeftTab === 'crossing'">
  51. <ButtonGroup v-model="currentView" :options="viewOptions" @select="onViewSelect" />
  52. </div>
  53. <!-- 特勤右上角表格 -->
  54. <TechTable ref="dutyTable" :columns="tableColumns" :data="tableData" class="duty-table" v-if="activeLeftTab === 'specialDuty'">
  55. <template #level="{ row }">
  56. <span :title="row.level" :style="{ color: row.level === '二级' ? '#FFDF0C' : '#F00' }">
  57. {{ row.level }}
  58. </span>
  59. </template>
  60. <template #status="{ row }">
  61. <span :title="row.status" :style="{ color: row.status === '进行中' ? '#FFDF0C' : '#F00' }">
  62. {{ row.status }}
  63. </span>
  64. </template>
  65. <template #action="{ row }">
  66. <span class="action-btn" @click="handleSpecialTaskView(row)">
  67. 查看
  68. </span>
  69. </template>
  70. </TechTable>
  71. </template>
  72. <template #center>
  73. </template>
  74. </DashboardLayout>
  75. </template>
  76. <script>
  77. import DashboardLayout from '@/layouts/DashboardLayout.vue';
  78. import DateTimeWidget from '@/components/ui/DateTimeWidget.vue';
  79. import TechTabs from '@/components/ui/TechTabs.vue';
  80. import TechTabPane from '@/components/ui/TechTabPane.vue';
  81. import TongzhouTrafficMap from '@/components/TongzhouTrafficMap.vue';
  82. import MenuItem from '@/components/ui/MenuItem.vue';
  83. import ButtonGroup from '@/components/ui/ButtonGroup.vue';
  84. import TechTable from '@/components/ui/TechTable.vue';
  85. import CrossingListPanel from '@/components/ui/CrossingListPanel.vue';
  86. import { apiGetTongzhouMenuTree, apiGetTasks, apiGetTrafficTimeSpace, apiGetCrossingTopCharts, apiGetSpecialTaskMonitorData, apiGetOverviewTopCharts } from '@/api';
  87. export default {
  88. name: "HomePage",
  89. components: {
  90. DashboardLayout,
  91. DateTimeWidget,
  92. TechTabs,
  93. TechTabPane,
  94. TongzhouTrafficMap,
  95. MenuItem,
  96. ButtonGroup,
  97. TechTable,
  98. CrossingListPanel
  99. },
  100. data() {
  101. return {
  102. // 左侧边栏数据
  103. activeLeftTab: 'overview',
  104. menuData: [],
  105. // 地图模式切换数据
  106. currentView: 'map-mode',
  107. viewOptions: [
  108. { label: '列表模式', value: 'list-mode' },
  109. { label: '地图模式', value: 'map-mode' },
  110. ],
  111. // 1. 表头
  112. tableColumns: [
  113. { label: '序号', key: 'id', width: '14%' },
  114. { label: '名称', key: 'name', width: '20%' },
  115. { label: '执行人', key: 'executor', width: '18%' },
  116. { label: '等级', key: 'level', width: '14%' },
  117. { label: '状态', key: 'status', width: '20%' },
  118. { label: '操作', key: 'action', width: '14%' }
  119. ],
  120. tableData: [],
  121. // 路口多选分屏
  122. crossingSelections: [],
  123. maxCrossingSlots: 4,
  124. };
  125. },
  126. watch: {
  127. // 监听路由参数变化(解决多次从首页点击不同数据跳转过来,页面不刷新的问题)
  128. '$route.query': {
  129. handler() {
  130. this.checkRouteParams();
  131. },
  132. deep: true
  133. }
  134. },
  135. created() {
  136. },
  137. async mounted() {
  138. // 加载菜单和任务数据
  139. const [menuData, taskData] = await Promise.all([
  140. apiGetTongzhouMenuTree(),
  141. apiGetTasks({ pageSize: 5 }),
  142. ]);
  143. this.menuData = menuData || [];
  144. this.tableData = taskData?.list || taskData || [];
  145. // 组件挂载时检查路由
  146. this.checkRouteParams();
  147. // 初始显示顶部图表(如果没有路由参数覆盖的话)
  148. if (Object.keys(this.$route.query).length === 0) {
  149. this.showTopChartDalogs();
  150. }
  151. },
  152. methods: {
  153. // 处理地图点击事件
  154. handleMapCrossingClick(mapData, lnglat) {
  155. console.log('父组件接收到了地图路口点击事件:', mapData, lnglat);
  156. // 组装模拟数据
  157. let nodeData = {
  158. id: Math.floor(Math.random()*5)+1,
  159. label: mapData.road,
  160. }
  161. console.log(nodeData);
  162. if (this.activeLeftTab === 'overview') { // 总览
  163. this.showOverviewDalogs(nodeData);
  164. } else if (this.activeLeftTab === 'crossing') { // 路口
  165. this.showCrossingDalogs(nodeData);
  166. } else if (this.activeLeftTab === 'trunkLine') { // 干线
  167. this.showTrunkLineDalogs(nodeData);
  168. } else if (this.activeLeftTab === 'specialDuty') { // 特勤
  169. this.showSpecialDutyDalogs(nodeData);
  170. }
  171. },
  172. // 模式切换
  173. onViewSelect(item) {
  174. console.log('你点击了:', item.label);
  175. this.currentView = item.value;
  176. this.$refs.layout.clearDialogs(); // 清空全部弹窗
  177. this.crossingSelections = [];
  178. // 列表模式弹窗
  179. if (this.currentView === 'list-mode') {
  180. // this.$refs.layout.openDialog({
  181. // id: 'crossing-list', // 这里的 ID 可以根据实际业务场景动态生成
  182. // title: '',
  183. // component: 'CrossingListPanel',
  184. // width: 1920,
  185. // height: 750,
  186. // center: false,
  187. // showClose: true,
  188. // noPadding: false,
  189. // enableDblclickExpand: false,
  190. // position: { x: 100, y: 150 },
  191. // data: {
  192. // onViewDetail: (rowData) => this.handleCrossingViewDetail(rowData)
  193. // }
  194. // });
  195. } else {
  196. this.showCrossingTopDialogs();
  197. }
  198. },
  199. // 处理tab点击
  200. handleTabClick(tabName) {
  201. console.log('父组件接收到了tab点击事件:', tabName);
  202. this.$refs.layout.clearDialogs(); // 清空全部弹窗
  203. this.crossingSelections = [];
  204. this.showTopChartDalogs(); // 根据当前Tab显示对应的顶部常驻图表
  205. },
  206. // 处理菜单点击
  207. handleMenuClick(nodeData) {
  208. console.log('父组件接收到了最底层路口点击事件:', nodeData);
  209. // 根据Tab来显示不同的弹窗内容
  210. if (this.activeLeftTab === 'overview') { // 总览
  211. this.showOverviewDalogs(nodeData);
  212. } else if (this.activeLeftTab === 'crossing') { // 路口
  213. this.showCrossingDalogs(nodeData);
  214. } else if (this.activeLeftTab === 'trunkLine') { // 干线
  215. this.showTrunkLineDalogs(nodeData);
  216. } else if (this.activeLeftTab === 'specialDuty') { // 特勤
  217. this.showSpecialDutyDalogs(nodeData);
  218. }
  219. },
  220. // 处理弹窗双击展开(通过 onExpand 回调从 Layout 传入)
  221. handleDoubleClickExpend(nodeData) {
  222. console.log('处理弹窗双击事件', nodeData);
  223. if (this.activeLeftTab === 'crossing' || this.activeLeftTab === 'overview') {
  224. this.showCrossingDetailDialogs(nodeData);
  225. }
  226. },
  227. // 显示顶部常驻图表(根据当前Tab状态)
  228. showTopChartDalogs() {
  229. if (this.activeLeftTab === 'overview') { // 总览
  230. this.showOverviewTopDialogs();
  231. } else if (this.activeLeftTab === 'crossing') { // 路口
  232. this.showCrossingTopDialogs();
  233. } else if (this.activeLeftTab === 'trunkLine') { // 干线
  234. // TODO: 干线Tab的顶部图表
  235. } else if (this.activeLeftTab === 'specialDuty') { // 特勤
  236. // this.openDutyDetailDialog({id: 'route_' + new Date().getTime(), label: '特勤路口'});
  237. }
  238. },
  239. // 显示总览弹窗组
  240. showOverviewDalogs(nodeData) {
  241. console.log('显示总览弹窗组', nodeData.id, nodeData.label);
  242. // 路口弹窗
  243. this.$refs.layout.openDialog({
  244. id: 'crossing3_' + nodeData.id, // 这里的 ID 可以根据实际业务场景动态生成
  245. title: nodeData.label,
  246. component: 'CrossingPanel',
  247. width: 260,
  248. height: 260,
  249. center: false,
  250. showClose: true,
  251. position: { x: 950, y: 430 },
  252. noPadding: false,
  253. data: {
  254. ...nodeData,
  255. onExpand: (data) => this.handleDoubleClickExpend(data)
  256. },
  257. onClose: () => {
  258. // this.$refs.layout.handleDialogClose('top-chart-crossing-1');
  259. // this.$refs.layout.handleDialogClose('top-chart-crossing-2');
  260. }
  261. });
  262. },
  263. async showOverviewTopDialogs() {
  264. this.$refs.layout.openDialog({
  265. id: 'top-chart-overview-1',
  266. title: '',
  267. component: 'OnlineStatusTabs',
  268. width: 300,
  269. height: 160,
  270. center: false,
  271. showClose: false,
  272. draggable: false,
  273. resizable: false,
  274. position: { x: 630, y: 130 },
  275. noPadding: true,
  276. data: {}
  277. });
  278. this.$refs.layout.openDialog({
  279. id: 'top-chart-overview-2',
  280. title: '',
  281. component: 'DeviceStatusTabs',
  282. width: 300,
  283. height: 160,
  284. center: false,
  285. showClose: false,
  286. draggable: false,
  287. resizable: false,
  288. position: { x: 980, y: 130 },
  289. noPadding: true,
  290. data: {}
  291. });
  292. },
  293. // 显示路口弹窗组(多选分屏)
  294. showCrossingDalogs(nodeData) {
  295. console.log('路口多选', nodeData.id, nodeData.label);
  296. // 1. 已选中 → 取消选中
  297. const existIndex = this.crossingSelections.findIndex(c => c.id === nodeData.id);
  298. if (existIndex !== -1) {
  299. this.crossingSelections.splice(existIndex, 1);
  300. if (this.crossingSelections.length === 0) {
  301. this.$refs.layout.handleDialogClose('crossing-multi-view');
  302. return;
  303. }
  304. this.openCrossingMultiView();
  305. return;
  306. }
  307. // 2. 已满 → 先进先出
  308. if (this.crossingSelections.length >= this.maxCrossingSlots) {
  309. this.crossingSelections.shift();
  310. }
  311. // 3. 追加选中
  312. this.crossingSelections.push({ ...nodeData });
  313. // 4. 打开或更新弹窗
  314. this.openCrossingMultiView();
  315. },
  316. openCrossingMultiView() {
  317. this.$refs.layout.openDialog({
  318. id: 'crossing-multi-view',
  319. title: '路口监控 (' + this.crossingSelections.length + '/' + this.maxCrossingSlots + ')',
  320. component: 'CrossingMultiView',
  321. width: 1400,
  322. height: 700,
  323. center: false,
  324. position: { x: 500, y: 150 },
  325. showClose: true,
  326. noPadding: true,
  327. enableDblclickExpand: false,
  328. data: {
  329. crossings: [...this.crossingSelections],
  330. maxSlots: this.maxCrossingSlots,
  331. onRemove: (id) => this.handleCrossingRemove(id),
  332. onReorder: (newOrder) => {
  333. this.crossingSelections = newOrder;
  334. }
  335. },
  336. onClose: () => {
  337. this.crossingSelections = [];
  338. }
  339. });
  340. },
  341. handleCrossingRemove(id) {
  342. this.crossingSelections = this.crossingSelections.filter(c => c.id !== id);
  343. if (this.crossingSelections.length === 0) {
  344. this.$refs.layout.handleDialogClose('crossing-multi-view');
  345. } else {
  346. this.openCrossingMultiView();
  347. }
  348. },
  349. // 单个路口详情弹窗(总览双击展开等场景使用)
  350. showCrossingDetailDialogs(nodeData) {
  351. console.log('显示路口详情弹窗组', nodeData.id, nodeData.label);
  352. this.$refs.layout.openDialog({
  353. id: 'crossing_detail' + nodeData.id,
  354. title: nodeData.label || nodeData.name,
  355. component: 'CrossingDetailPanel',
  356. width: 1315,
  357. height: 682,
  358. center: false,
  359. showClose: true,
  360. position: { x: 500, y: 170 },
  361. noPadding: false,
  362. enableDblclickExpand: false,
  363. data: nodeData
  364. });
  365. },
  366. async showCrossingTopDialogs() {
  367. const chartData = await apiGetCrossingTopCharts();
  368. const { onlineChart, faultChart } = chartData;
  369. this.$refs.layout.openDialog({
  370. id: 'top-chart-crossing-1',
  371. title: '',
  372. component: 'RingDonutChart',
  373. width: 228, height: 124, center: false, showClose: false,
  374. draggable: false, resizable: false,
  375. position: { x: 730, y: 130 }, noPadding: true,
  376. data: onlineChart
  377. });
  378. this.$refs.layout.openDialog({
  379. id: 'top-chart-crossing-2',
  380. title: '',
  381. component: 'RingDonutChart',
  382. width: 228, height: 124, center: false, showClose: false,
  383. draggable: false, resizable: false,
  384. position: { x: 980, y: 130 }, noPadding: true,
  385. data: faultChart
  386. });
  387. },
  388. // 路口列表模式下弹窗
  389. handleCrossingViewDetail(rowData) {
  390. console.log('显示路口列表查看', rowData);
  391. this.showCrossingDetailDialogs(rowData);
  392. },
  393. // 显示干线弹窗组
  394. async showTrunkLineDalogs(nodeData) {
  395. console.log('显示干线弹窗组', nodeData.id, nodeData.label);
  396. const tsData = await apiGetTrafficTimeSpace();
  397. this.$refs.layout.openDialog({
  398. id: nodeData.id,
  399. title: nodeData.label,
  400. component: 'TrafficTimeSpace',
  401. width: 1000,
  402. height: 500,
  403. center: true,
  404. showClose: true,
  405. data: tsData,
  406. });
  407. },
  408. // 显示特勤弹窗组
  409. showSpecialDutyDalogs(nodeData) {
  410. console.log('显示特勤弹窗组', nodeData.id, nodeData.label);
  411. this.openDutyDetailDialog(nodeData);
  412. },
  413. // === 解析路由参数并执行对应操作 ===
  414. checkRouteParams() {
  415. // 统一参数接收:特勤接收 id,路口接收 intersectionName 和 plan
  416. const { tab, action, id, } = this.$route.query;
  417. if (!tab) return; // 如果没有传递 tab 参数,说明是正常访问,不处理
  418. // 1. 处理“特勤线路”跳转
  419. if (tab === 'specialDuty') {
  420. this.activeLeftTab = 'specialDuty'; // 切换到左侧【特勤】Tab
  421. this.handleTabClick('specialDuty'); // 手动触发 Tab 切换事件,更新顶部图表
  422. // 这里判断的条件改为 id
  423. if (action === 'open-dialog' && id) {
  424. this.$nextTick(() => {
  425. this.openDutyDetailDialog({id: id, label: '特勤路口'}); // 打开特勤弹窗
  426. });
  427. }
  428. }
  429. // 2. 处理“关键路口”跳转
  430. else if (tab === 'crossing') {
  431. this.activeLeftTab = 'crossing'; // 切换到左侧【路口】Tab
  432. this.handleTabClick('crossing'); // 手动触发 Tab 切换事件,更新顶部图表
  433. if (action === 'open-dialog') {
  434. this.$nextTick(() => {
  435. // 构造一个假的 nodeData 传给详情弹窗方法
  436. this.showCrossingDetailDialogs({
  437. id: 'route_' + new Date().getTime(), // 动态生成一个ID防重复
  438. label: '路口详情',
  439. });
  440. });
  441. }
  442. }
  443. },
  444. // === 特勤详情弹窗 (你需要根据实际组件名替换) ===
  445. async openDutyDetailDialog(nodeData) {
  446. console.log('准备打开特勤线路详情:', nodeData);
  447. // 1. 获取数据
  448. const panelData = await apiGetSpecialTaskMonitorData(nodeData.id);
  449. const id = 'special-task-dialog' + new Date().getTime();
  450. // 2. 呼出弹窗
  451. this.$refs.layout.openDialog({
  452. id: id,
  453. title: ' ', // 留空以隐藏默认标题,使用自定义 Header
  454. width: 1400, // 弹窗宽一点,容纳 3 列
  455. height: 700,
  456. center: false,
  457. showClose: true,
  458. noPadding: true, // 去除默认内边距,让内部组件自己控制
  459. position: {x: 200, y: 150},
  460. // 挂载主体组件和数据
  461. component: 'SpecialTaskMonitorPanel',
  462. data: { panelData: panelData },
  463. // 挂载自定义 Header 和数据
  464. headerComponent: 'TaskMonitorHeader',
  465. headerProps: {
  466. taskData: panelData.taskInfo,
  467. onEndTask: () => {
  468. console.log('点击了结束任务');
  469. // this.$refs.layout.handleDialogClose(id);
  470. panelData.taskInfo.status = '已结束';
  471. }
  472. }
  473. });
  474. },
  475. handleSpecialTaskView(row) {
  476. console.log('查看特勤线路,当前数据:', row);
  477. this.openDutyDetailDialog(row);
  478. },
  479. }
  480. }
  481. </script>
  482. <style scoped>
  483. .mode-switch {
  484. display: flex;
  485. flex-direction: row;
  486. justify-content: flex-end;
  487. }
  488. .mode-switch>div {
  489. width: 200px;
  490. }
  491. .duty-table {
  492. margin-top: 10px;
  493. }
  494. ::v-deep .list-mode-panel {
  495. padding: 150px 30px 0 30px;
  496. }
  497. </style>