TongzhouTrafficMap.vue 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. <template>
  2. <div class="map-wrapper">
  3. <div ref="mapContainer" class="map-container"></div>
  4. <div class="map-legend" :style="privateStyle.legend" v-if="(!mode || mode === '路口')"
  5. :class="{ 'legend-hidden': !legendVisible }">
  6. <div class="legend-header">
  7. <div class="legend-title">图例</div>
  8. <div class="legend-close-btn" @click="toggleLegend">✕</div>
  9. </div>
  10. <div class="legend-list">
  11. <div class="legend-item all-select" @click="toggleAll">
  12. <div class="legend-dot"
  13. :style="{ backgroundColor: isAllSelected ? '#fff' : 'transparent', border: '1px solid #fff' }"></div>
  14. <div class="legend-label" style="font-weight: bold;">全选</div>
  15. </div>
  16. <div v-for="item in legendStatusConfig" class="legend-item" @click="toggleRouteVisible(item.name)" :key="item.name"
  17. :class="{ 'is-inactive': !activeLegends.includes(item.name) }">
  18. <div class="legend-dot"
  19. :style="{ backgroundColor: ['离线', '降级', '故障'].includes(item.name) ? 'transparent' : item.color }"
  20. :class="{ 'special-route': ['干线协调', '勤务路线'].includes(item.name), 'is-status-wrapper': ['离线', '降级', '故障'].includes(item.name) }">
  21. <span v-if="!['离线', '降级', '故障'].includes(item.name)">
  22. {{ item.name.charAt(0) }}
  23. </span>
  24. <img v-else
  25. :src="require(`@/assets/images/icon_${item.name === '离线' ? 'lixian' : item.name === '降级' ? 'jiangji' : 'guzhang'}.png`)"
  26. class="status-icon" />
  27. </div>
  28. <div class="legend-label">{{ item.name }}</div>
  29. </div>
  30. </div>
  31. </div>
  32. <div class="legend-show-btn" v-if="(!mode || mode === '路口') && !legendVisible" @click="toggleLegend" :style="legendShowBtnStyle">
  33. <div class="legend-show-icon">☰</div>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. import AMapLoader from '@amap/amap-jsapi-loader';
  39. export default {
  40. name: "TrafficMap",
  41. props: {
  42. amapKey: { type: String, default: '您的Key' },
  43. securityJsCode: { type: String, default: '您的安全密钥' },
  44. mode: { type: String, default: '', validator: (value) => ['', '路口', '干线', '特勤'].includes(value) }
  45. },
  46. data() {
  47. return {
  48. AMap: null,
  49. map: null,
  50. infoWindow: null,
  51. routeGroups: {},
  52. polylines: [],
  53. privateStyle: {
  54. legend: {}
  55. },
  56. legendVisible: true,
  57. activeLegends: ["中心计划", "干线协调", "勤务路线", "定周期控制", "感应控制", "自适应控制", "手动控制", "特殊控制", "离线", "降级", "故障"],
  58. // 核心修正:增加生命周期标识,防止组件销毁后异步回调继续执行
  59. isComponentDestroyed: false,
  60. drawSeq: 0,
  61. driving: null,
  62. infoCloseTimer: null,
  63. activeInfoWindowId: null,
  64. isInfoWindowHovered: false,
  65. // 状态类型配置
  66. statusConfig: [
  67. { name: "中心计划", color: "#004CDE", type: "normal" },
  68. { name: "干线协调", color: "#13C373", type: "route" },
  69. { name: "勤务路线", color: "#BC301D", type: "route" },
  70. { name: "定周期控制", color: "#3296FA", type: "normal" },
  71. { name: "感应控制", color: "#FF864C", type: "normal" },
  72. { name: "自适应控制", color: "#9F6EFE", type: "normal" },
  73. { name: "手动控制", color: "#EB9F36", type: "normal" },
  74. { name: "特殊控制", color: "#A26218", type: "normal" },
  75. { name: "离线", color: "#7A7A7A", type: "abnormal" },
  76. { name: "降级", color: "#D9C13B", type: "abnormal" },
  77. { name: "故障", color: "#FF3938", type: "abnormal" }
  78. ],
  79. // 真实路口数据
  80. intersectionData: [],
  81. // 按状态分类的路口数据
  82. statusIntersections: {},
  83. };
  84. },
  85. mounted() {
  86. this.isComponentDestroyed = false; // 重置标识
  87. this.loadMapData().then(() => {
  88. this.classifyIntersectionsByStatus();
  89. this.updateMapByMode();
  90. this.initAMap();
  91. });
  92. if (this.$route.path === '/home') {
  93. this.privateStyle.legend = { right: "25%" };
  94. }
  95. },
  96. watch: {
  97. mode: {
  98. handler() {
  99. this.updateMapByMode();
  100. this.updateMapDisplay();
  101. },
  102. immediate: false
  103. }
  104. },
  105. beforeDestroy() {
  106. // 1. 立即设置销毁状态
  107. this.isComponentDestroyed = true;
  108. this.drawSeq += 1;
  109. // 2. 关闭弹窗
  110. if (this.infoWindow) {
  111. try {
  112. this.infoWindow.close();
  113. } catch (e) {
  114. console.warn('关闭信息窗口时出错:', e);
  115. }
  116. this.infoWindow = null;
  117. }
  118. // 3. 清理覆盖物引用
  119. if (this.routeGroups) {
  120. Object.values(this.routeGroups).forEach(overlays => {
  121. if (Array.isArray(overlays)) {
  122. overlays.forEach(o => {
  123. try {
  124. if (o.setMap) o.setMap(null);
  125. } catch (e) {
  126. console.warn('清理覆盖物时出错:', e);
  127. }
  128. });
  129. }
  130. });
  131. this.routeGroups = {};
  132. }
  133. // 4. 销毁地图实例并清空引用
  134. if (this.map) {
  135. try {
  136. this.map.destroy();
  137. } catch (e) {
  138. console.warn('销毁地图实例时出错:', e);
  139. }
  140. this.map = null;
  141. }
  142. // 5. 清理其他引用
  143. this.AMap = null;
  144. this.driving = null;
  145. if (this.infoCloseTimer) {
  146. clearTimeout(this.infoCloseTimer);
  147. this.infoCloseTimer = null;
  148. }
  149. this.activeInfoWindowId = null;
  150. this.isInfoWindowHovered = false;
  151. },
  152. computed: {
  153. isAllSelected() {
  154. return this.activeLegends.length === this.statusConfig.length;
  155. },
  156. isHomePage() {
  157. return this.$route && this.$route.path === '/home';
  158. },
  159. legendShowBtnStyle() {
  160. if (!this.isHomePage) return {};
  161. const right = (this.privateStyle.legend && this.privateStyle.legend.right) ? this.privateStyle.legend.right : '25%';
  162. return { right, borderRadius: '6px' };
  163. },
  164. legendStatusConfig() {
  165. if (!this.mode) return this.statusConfig;
  166. if (this.mode === '路口') {
  167. return this.statusConfig.filter(item => !['干线协调', '勤务路线'].includes(item.name));
  168. }
  169. return [];
  170. }
  171. },
  172. methods: {
  173. // 动态加载地图数据
  174. async loadMapData() {
  175. try {
  176. const mapDataModule = await import('@/mock/map_data_gaode.json');
  177. this.intersectionData = mapDataModule.default || [];
  178. console.log('地图数据加载成功,共', this.intersectionData.length, '个路口');
  179. } catch (error) {
  180. console.error('地图数据加载失败:', error);
  181. this.intersectionData = [];
  182. }
  183. },
  184. // 检查地图环境是否安全可用
  185. isMapReady() {
  186. return !this.isComponentDestroyed && this.map && typeof this.map.add === 'function';
  187. },
  188. // 将真实路口数据按状态类型分类
  189. classifyIntersectionsByStatus() {
  190. const remainingData = this.intersectionData;
  191. const normalStatusCount = 6;
  192. const abnormalStatusCount = 3;
  193. const chunkSize = Math.floor(remainingData.length / (normalStatusCount + abnormalStatusCount));
  194. const maxAbnormalCount = 4;
  195. this.statusIntersections = {
  196. "中心计划": remainingData.slice(0, 20),
  197. "干线协调": [], // 清空,改为动态生成
  198. "勤务路线": [], // 清空,改为动态生成
  199. "定周期控制": remainingData.slice(chunkSize, chunkSize * 2),
  200. "感应控制": remainingData.slice(chunkSize * 2, chunkSize * 3),
  201. "自适应控制": remainingData.slice(chunkSize * 3, chunkSize * 4),
  202. "手动控制": remainingData.slice(chunkSize * 4, chunkSize * 5),
  203. "特殊控制": remainingData.slice(chunkSize * 5, chunkSize * 6),
  204. "离线": remainingData.slice(chunkSize * 6, Math.min(chunkSize * 7, chunkSize * 6 + maxAbnormalCount)),
  205. "降级": remainingData.slice(chunkSize * 7, Math.min(chunkSize * 8, chunkSize * 7 + maxAbnormalCount)),
  206. "故障": remainingData.slice(chunkSize * 8, Math.min(chunkSize * 9, chunkSize * 8 + maxAbnormalCount))
  207. };
  208. },
  209. updateMapByMode() {
  210. switch (this.mode) {
  211. case '路口':
  212. this.activeLegends = ["中心计划", "定周期控制", "感应控制", "自适应控制", "手动控制", "特殊控制", "离线", "降级", "故障"];
  213. break;
  214. case '干线':
  215. this.activeLegends = ["干线协调"];
  216. break;
  217. case '特勤':
  218. this.activeLegends = ["勤务路线"];
  219. break;
  220. default:
  221. this.activeLegends = this.statusConfig.map(item => item.name);
  222. }
  223. },
  224. updateMapDisplay() {
  225. if (this.infoWindow) this.infoWindow.close();
  226. if (!this.isMapReady()) return;
  227. Object.keys(this.routeGroups).forEach(name => {
  228. const overlays = this.routeGroups[name];
  229. if (overlays && overlays.length > 0) {
  230. if (this.activeLegends.includes(name)) {
  231. this.map.add(overlays);
  232. } else {
  233. this.map.remove(overlays);
  234. }
  235. }
  236. });
  237. },
  238. async initAMap() {
  239. if (this.isComponentDestroyed) return;
  240. // 确保在加载前注入
  241. window._AMapSecurityConfig = { securityJsCode: this.securityJsCode };
  242. try {
  243. const AMap = await AMapLoader.load({
  244. key: this.amapKey,
  245. version: "2.0",
  246. // 核心:确保 Driving 插件在此加载
  247. plugins: ['AMap.Driving']
  248. });
  249. if (this.isComponentDestroyed) return;
  250. this.AMap = AMap;
  251. this.map = new AMap.Map(this.$refs.mapContainer, {
  252. zoom: 15,
  253. mapStyle: "amap://styles/darkblue",
  254. center: [116.663, 39.905], // 通州区中心
  255. });
  256. this.driving = new AMap.Driving({ map: null, hideMarkers: true });
  257. // 建议在地图加载完成后再画线
  258. this.map.on('complete', () => {
  259. if (!this.isComponentDestroyed) {
  260. this.drawStaticRoutes();
  261. // 临时方案,实际项目中删除 按4:3:3比例提取故障、离线、降级坐标点并存储到localStorage
  262. this.storeStatusCoordsToLocalStorage();
  263. }
  264. });
  265. } catch (err) {
  266. console.error('地图加载失败:', err);
  267. }
  268. },
  269. // 绘制静态路线和标记
  270. // 对于普通状态,从 mock 数据加载路口标记
  271. // 对于路线类(干线协调和勤务路线),使用高德地图路线规划绘制路线和密集点位
  272. async drawStaticRoutes() {
  273. if (!this.isMapReady()) return;
  274. this.drawSeq += 1;
  275. const drawSeq = this.drawSeq;
  276. this.clearAllRouteOverlays();
  277. const realRouteConfigs = {
  278. "干线协调": [
  279. { start: [116.6421, 39.9272], end: [116.6825, 39.9272], color: "#13C373" },
  280. { start: [116.6426, 39.9221], end: [116.6830, 39.9221], color: "#13C373" },
  281. { start: [116.6432, 39.9171], end: [116.6833, 39.9171], color: "#13C373" },
  282. { start: [116.6438, 39.9123], end: [116.6841, 39.9123], color: "#13C373" },
  283. { start: [116.6445, 39.9075], end: [116.6846, 39.9075], color: "#13C373" }
  284. ],
  285. "勤务路线": [
  286. { start: [116.6900, 39.9225], end: [116.6900, 39.8971], color: "#BC301D" },
  287. { start: [116.6965, 39.9225], end: [116.6965, 39.8971], color: "#BC301D" },
  288. { start: [116.7021, 39.9225], end: [116.7021, 39.8971], color: "#BC301D" },
  289. { start: [116.7120, 39.9225], end: [116.7120, 39.8971], color: "#BC301D" },
  290. { start: [116.7234, 39.9225], end: [116.7234, 39.8971], color: "#BC301D" },
  291. { start: [116.7290, 39.9225], end: [116.7290, 39.8971], color: "#BC301D" },
  292. { start: [116.7350, 39.9170], end: [116.7350, 39.9000], color: "#BC301D" }
  293. ]
  294. };
  295. for (const config of this.statusConfig) {
  296. if (this.isComponentDestroyed || drawSeq !== this.drawSeq) return;
  297. // 1. 处理普通非路线状态(从 mock 数据加载)
  298. if (!realRouteConfigs[config.name]) {
  299. const intersections = this.statusIntersections[config.name] || [];
  300. const markers = intersections.map(item =>
  301. this.createTrafficLightMarker([item["位置-经度"], item["位置-纬度"]], {
  302. ...config,
  303. road: item["路口名称"] || '规划路口'
  304. })
  305. ).filter(Boolean);
  306. this.routeGroups[config.name] = markers;
  307. if (this.activeLegends.includes(config.name)) this.map.add(markers);
  308. continue;
  309. }
  310. // 2. 处理路线类(干线/特勤)
  311. this.routeGroups[config.name] = [];
  312. const lines = realRouteConfigs[config.name] || [];
  313. for (let lineIdx = 0; lineIdx < lines.length; lineIdx += 1) {
  314. if (this.isComponentDestroyed || drawSeq !== this.drawSeq) return;
  315. const line = lines[lineIdx];
  316. let path = null;
  317. try {
  318. path = await this.searchDrivingPathWithRetry(line.start, line.end);
  319. } catch (e) {
  320. path = null;
  321. }
  322. const overlays = this.buildRouteOverlaysFromPath({
  323. config,
  324. configName: config.name,
  325. line,
  326. lineIdx,
  327. path
  328. });
  329. if (this.isComponentDestroyed || drawSeq !== this.drawSeq) return;
  330. if (overlays.length > 0) {
  331. this.routeGroups[config.name].push(...overlays);
  332. if (this.activeLegends.includes(config.name)) this.map.add(overlays);
  333. }
  334. await this.sleep(80);
  335. }
  336. }
  337. },
  338. clearAllRouteOverlays() {
  339. if (!this.isMapReady()) return;
  340. try {
  341. if (this.infoWindow) this.infoWindow.close();
  342. } catch (e) {
  343. void e;
  344. }
  345. Object.values(this.routeGroups || {}).forEach(overlays => {
  346. if (!Array.isArray(overlays) || overlays.length === 0) return;
  347. try {
  348. this.map.remove(overlays);
  349. } catch (e) {
  350. void e;
  351. }
  352. overlays.forEach(o => {
  353. try {
  354. if (o && typeof o.setMap === 'function') o.setMap(null);
  355. } catch (e) {
  356. void e;
  357. }
  358. });
  359. });
  360. this.routeGroups = {};
  361. },
  362. sleep(ms) {
  363. return new Promise(resolve => setTimeout(resolve, ms));
  364. },
  365. async searchDrivingPathWithRetry(start, end) {
  366. if (!this.AMap || !this.driving || typeof this.driving.search !== 'function') {
  367. throw new Error('Driving not ready');
  368. }
  369. const maxAttempts = 3;
  370. let lastErr = null;
  371. for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
  372. try {
  373. return await this.withTimeout(this.searchDrivingPathOnce(start, end), 8000);
  374. } catch (e) {
  375. lastErr = e;
  376. await this.sleep(250 * attempt);
  377. }
  378. }
  379. throw lastErr || new Error('Driving search failed');
  380. },
  381. searchDrivingPathOnce(start, end) {
  382. return new Promise((resolve, reject) => {
  383. this.driving.search(start, end, (status, result) => {
  384. const route = result && result.routes && result.routes[0];
  385. if (status === 'complete' && route && Array.isArray(route.steps)) {
  386. const fullPath = [];
  387. route.steps.forEach(step => {
  388. if (step && Array.isArray(step.path)) fullPath.push(...step.path);
  389. });
  390. if (fullPath.length >= 2) resolve(fullPath);
  391. else reject(new Error('empty_path'));
  392. return;
  393. }
  394. reject(new Error(typeof status === 'string' ? status : 'driving_error'));
  395. });
  396. });
  397. },
  398. withTimeout(promise, timeoutMs) {
  399. return Promise.race([
  400. promise,
  401. new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeoutMs))
  402. ]);
  403. },
  404. buildRouteOverlaysFromPath({ config, configName, line, lineIdx, path }) {
  405. if (!this.AMap || !this.map) return [];
  406. let basePath = path;
  407. if (!Array.isArray(basePath) || basePath.length < 2) {
  408. basePath = this.buildFallbackLinePath(line.start, line.end, 30);
  409. }
  410. const segments = this.extractMainStraightSegments(basePath);
  411. const overlays = [];
  412. segments.forEach((segmentPath, segmentIdx) => {
  413. if (!Array.isArray(segmentPath) || segmentPath.length < 2) return;
  414. const polyline = new this.AMap.Polyline({
  415. path: segmentPath,
  416. strokeColor: line.color,
  417. strokeWeight: 6,
  418. strokeOpacity: 0.8,
  419. zIndex: 15
  420. });
  421. overlays.push(polyline);
  422. const totalPoints = segmentPath.length;
  423. const indices = this.pickEvenlySpacedIndices(totalPoints, 8);
  424. // 为第一个和最后一个圆点设置特殊类型
  425. for (let i = 0; i < indices.length; i++) {
  426. const idx = indices[i];
  427. const p = segmentPath[idx];
  428. const lng = p && typeof p.lng === 'number' ? p.lng : (Array.isArray(p) ? Number(p[0]) : NaN);
  429. const lat = p && typeof p.lat === 'number' ? p.lat : (Array.isArray(p) ? Number(p[1]) : NaN);
  430. if (Number.isNaN(lng) || Number.isNaN(lat)) continue;
  431. // 确定圆点类型:第一个为start,最后一个为end,其余为normal
  432. let markerType = 'normal';
  433. if (i === 0) {
  434. markerType = 'start';
  435. } else if (i === indices.length - 1) {
  436. markerType = 'end';
  437. }
  438. const marker = this.createTrafficLightMarker([lng, lat], {
  439. ...config,
  440. id: `MOCK-${configName.charAt(0)}-${lineIdx}-${segmentIdx}-${idx}`,
  441. road: `${configName}路口-${lineIdx}-${segmentIdx}-${idx}`
  442. }, markerType);
  443. if (marker) overlays.push(marker);
  444. }
  445. });
  446. return overlays;
  447. },
  448. pickEvenlySpacedIndices(totalPoints, count) {
  449. const total = Math.max(Number(totalPoints) || 0, 0);
  450. const target = Math.max(Number(count) || 0, 0);
  451. if (total <= 0) return [];
  452. if (target <= 0) return [];
  453. if (target >= total) return Array.from({ length: total }, (_, i) => i);
  454. if (target === 1) return [0];
  455. const set = new Set();
  456. const last = total - 1;
  457. for (let k = 0; k < target; k += 1) {
  458. const idx = Math.round((k * last) / (target - 1));
  459. set.add(idx);
  460. }
  461. return Array.from(set).sort((a, b) => a - b);
  462. },
  463. buildFallbackLinePath(start, end, pointCount) {
  464. const sLng = Number(start && start[0]);
  465. const sLat = Number(start && start[1]);
  466. const eLng = Number(end && end[0]);
  467. const eLat = Number(end && end[1]);
  468. const n = Math.max(Number(pointCount) || 2, 2);
  469. const path = [];
  470. if ([sLng, sLat, eLng, eLat].some(v => Number.isNaN(v))) return path;
  471. for (let i = 0; i < n; i += 1) {
  472. const t = n === 1 ? 0 : i / (n - 1);
  473. const lng = sLng + (eLng - sLng) * t;
  474. const lat = sLat + (eLat - sLat) * t;
  475. path.push({ lng, lat });
  476. }
  477. return path;
  478. },
  479. extractMainStraightSegments(path) {
  480. const points = (path || []).filter(p => p && typeof p.lng === 'number' && typeof p.lat === 'number');
  481. if (points.length < 2) return [];
  482. const thresholdDeg = 18;
  483. const segments = [];
  484. let curStart = 0;
  485. let curAngle = null;
  486. let curLen = 0;
  487. const pushSegment = (endIdx) => {
  488. if (endIdx <= curStart) return;
  489. segments.push({
  490. start: curStart,
  491. end: endIdx,
  492. len: curLen
  493. });
  494. };
  495. for (let i = 0; i < points.length - 1; i += 1) {
  496. const a = points[i];
  497. const b = points[i + 1];
  498. const len = this.calcApproxDistance(a, b);
  499. if (len <= 0) continue;
  500. const angle = this.calcBearingDeg(a, b);
  501. if (curAngle === null) {
  502. curStart = i;
  503. curAngle = angle;
  504. curLen = len;
  505. continue;
  506. }
  507. const diff = this.calcAngleDiffDeg(curAngle, angle);
  508. if (diff <= thresholdDeg) {
  509. curLen += len;
  510. } else {
  511. pushSegment(i);
  512. curStart = i;
  513. curAngle = angle;
  514. curLen = len;
  515. }
  516. }
  517. pushSegment(points.length - 2);
  518. if (segments.length === 0) return [points];
  519. segments.sort((s1, s2) => s2.len - s1.len);
  520. const maxLen = segments[0].len || 0;
  521. const filtered = segments.filter(s => s.len >= maxLen * 0.55).slice(0, 3);
  522. const finalSegments = filtered.map(s => points.slice(s.start, s.end + 2));
  523. return finalSegments.length > 0 ? finalSegments : [points];
  524. },
  525. calcBearingDeg(a, b) {
  526. const latRad = ((a.lat + b.lat) / 2) * Math.PI / 180;
  527. const dx = (b.lng - a.lng) * Math.cos(latRad);
  528. const dy = (b.lat - a.lat);
  529. let deg = Math.atan2(dy, dx) * 180 / Math.PI;
  530. if (deg < 0) deg += 360;
  531. return deg;
  532. },
  533. calcAngleDiffDeg(a, b) {
  534. let diff = Math.abs(a - b);
  535. if (diff > 180) diff = 360 - diff;
  536. return diff;
  537. },
  538. calcApproxDistance(a, b) {
  539. const latRad = ((a.lat + b.lat) / 2) * Math.PI / 180;
  540. const dx = (b.lng - a.lng) * Math.cos(latRad);
  541. const dy = (b.lat - a.lat);
  542. return Math.sqrt(dx * dx + dy * dy);
  543. },
  544. createTrafficLightMarker(position, config, type = 'normal') {
  545. if (!position || !config) return null;
  546. try {
  547. const lng = Number(position[0] || position.lng);
  548. const lat = Number(position[1] || position.lat);
  549. if (isNaN(lng) || isNaN(lat)) return null;
  550. // 状态文字:起、终、或者状态配置的首字母
  551. let displayText = config.name ? config.name.charAt(0) : '';
  552. if (type === 'start') displayText = '起';
  553. if (type === 'end') displayText = '终';
  554. const isAbnormal = ["离线", "降级", "故障"].includes(config.name);
  555. const isRoute = ["干线协调", "勤务路线"].includes(config.name);
  556. // 动态计算尺寸:起终点最大,异常点次之,普通点最小
  557. const size = (type === 'start' || type === 'end') ? '22px' : (isAbnormal ? '30px' : '14px');
  558. const sizeNumber = parseInt(size, 10);
  559. const paddingNumber = (isAbnormal || type === 'start' || type === 'end') ? 0 : 2;
  560. const outerSizeNumber = sizeNumber + paddingNumber * 2;
  561. // 边框样式:起终点用实白边框
  562. const borderStyle = (type === 'start' || type === 'end')
  563. ? '2px solid #fff'
  564. : '1.5px solid rgba(255,255,255,0.7)';
  565. // 生成异常状态的图标路径
  566. let markerContent = '';
  567. if (isAbnormal) {
  568. const iconName = config.name === '离线' ? 'lixian' : config.name === '降级' ? 'jiangji' : 'guzhang';
  569. markerContent = `
  570. <div class="pure-light-node ${isAbnormal ? 'breathe' : ''}"
  571. style="
  572. width: ${size};
  573. height: ${size};
  574. background: transparent;
  575. box-shadow: none;
  576. border: none;
  577. box-sizing: content-box;
  578. display: flex;
  579. justify-content: center;
  580. align-items: center;
  581. cursor: pointer;
  582. padding: ${paddingNumber}px;
  583. ">
  584. <img src="${require(`@/assets/images/icon_${iconName}.png`)}" style="width: 100%; height: 100%; object-fit: contain;" />
  585. </div>
  586. `;
  587. } else {
  588. markerContent = `
  589. <div class="pure-light-node ${isAbnormal ? 'breathe' : ''} ${isRoute ? 'route-node' : ''}"
  590. style="
  591. width: ${size};
  592. height: ${size};
  593. background: ${config.color || '#999'};
  594. box-shadow: ${isRoute ? 'none' : `0 0 8px ${config.color}`};
  595. border: ${isRoute ? 'none' : borderStyle};
  596. box-sizing: content-box;
  597. display: flex;
  598. justify-content: center;
  599. align-items: center;
  600. color: #fff;
  601. border-radius: 50%;
  602. cursor: pointer;
  603. padding: ${paddingNumber}px;
  604. ">
  605. <span style="transform: scale(0.8); font-weight: bold; font-size: 12px;">${displayText}</span>
  606. </div>
  607. `;
  608. }
  609. const marker = new this.AMap.Marker({
  610. position: [lng, lat],
  611. // 这里的 type 已经从参数拿到了,不会报错了
  612. zIndex: (type === 'start' || type === 'end') ? 120 : (isAbnormal ? 110 : 100),
  613. content: markerContent,
  614. offset: new this.AMap.Pixel(-Math.round(outerSizeNumber / 2), -Math.round(outerSizeNumber / 2)),
  615. extData: {
  616. ...config,
  617. position: [lng, lat],
  618. statusColor: config.color || '#999',
  619. statusLabel: config.name,
  620. road: config.road || '规划路口',
  621. timestamp: Date.now(),
  622. time: this.formatEventTime(Date.now())
  623. }
  624. });
  625. marker.on('click', (e) => {
  626. if (this.isComponentDestroyed) return;
  627. const extData = e.target.getExtData();
  628. if (this.isHomePage) {
  629. this.cancelCloseInfoWindow();
  630. this.openLightInfo(extData, e.lnglat);
  631. }
  632. // 获取像素坐标
  633. const pixel = this.map.lngLatToContainer(e.lnglat);
  634. this.$emit('map-crossing-click', extData, e.lnglat, pixel);
  635. });
  636. marker.on('mouseover', (e) => {
  637. if (this.isComponentDestroyed) return;
  638. if (!this.isHomePage) return;
  639. this.cancelCloseInfoWindow();
  640. this.openLightInfo(e.target.getExtData(), e.lnglat);
  641. // 获取像素坐标
  642. const pixel = this.map.lngLatToContainer(e.lnglat);
  643. // 传递路口鼠标滑入事件
  644. this.$emit('map-crossing-mouseover', e.target.getExtData(), e.lnglat, pixel);
  645. });
  646. marker.on('mouseout', (e) => {
  647. if (this.isComponentDestroyed) return;
  648. if (!this.isHomePage) return;
  649. this.scheduleCloseInfoWindow();
  650. // 传递路口鼠标滑出事件
  651. this.$emit('map-crossing-mouseout', e.target.getExtData());
  652. });
  653. return marker;
  654. } catch (e) {
  655. console.warn('创建标记时出错:', e);
  656. return null;
  657. }
  658. },
  659. openLightInfo(data, position) {
  660. if (!this.isMapReady()) return;
  661. const infoWindowId = `info-window-${Date.now()}`;
  662. this.activeInfoWindowId = infoWindowId;
  663. const isAbnormal = ["离线", "降级", "故障"].includes(data.name);
  664. const deviceStatusText = isAbnormal ? data.name : '正常';
  665. const alarmInfoText = isAbnormal ? this.getAlarmInfoText(data.name) : '';
  666. const eventTimeText = this.formatEventTime(data.timestamp || data.time);
  667. let statusDotContent = '';
  668. if (isAbnormal) {
  669. const iconName = data.name === '离线' ? 'lixian' : data.name === '降级' ? 'jiangji' : 'guzhang';
  670. statusDotContent = `<img src="${require(`@/assets/images/icon_${iconName}.png`)}" style="width: 100%; height: 100%; object-fit: contain;" />`;
  671. } else {
  672. statusDotContent = `<span>${data.name.charAt(0)}</span>`;
  673. }
  674. const content = `
  675. <div class="custom-info-card" id="${infoWindowId}">
  676. <div class="close-btn" data-id="${infoWindowId}">✕</div>
  677. <div class="card-header">
  678. <div class="status-dot ${isAbnormal ? 'breathe' : ''}" style="background: ${isAbnormal ? 'transparent' : data.statusColor}; border: ${isAbnormal ? 'none' : ''}">
  679. ${statusDotContent}
  680. </div>
  681. <span class="status-text">${data.statusLabel}</span>
  682. </div>
  683. <div class="card-body">
  684. ${isAbnormal
  685. ? `
  686. <div class="info-line"><span class="label">路口名称:</span><span class="value">${data.road}</span></div>
  687. <div class="info-line"><span class="label">设备状态:</span><span class="value digital">${deviceStatusText}</span></div>
  688. <div class="info-line"><span class="label">报警信息:</span><span class="value">${alarmInfoText}</span></div>
  689. <div class="info-line"><span class="label">发生时间:</span><span class="value digital">${eventTimeText}</span></div>
  690. `
  691. : `
  692. <div class="info-line"><span class="label">路口名称:</span><span class="value">${data.road}</span></div>
  693. <div class="info-line"><span class="label">设备状态:</span><span class="value digital">${deviceStatusText}</span></div>
  694. `
  695. }
  696. </div>
  697. </div>
  698. `;
  699. if (!this.infoWindow) {
  700. this.infoWindow = new this.AMap.InfoWindow({
  701. isCustom: true,
  702. offset: new this.AMap.Pixel(0, -20)
  703. });
  704. }
  705. this.infoWindow.setContent(content);
  706. this.infoWindow.open(this.map, position);
  707. setTimeout(() => {
  708. if (this.activeInfoWindowId !== infoWindowId) return;
  709. const closeBtn = document.querySelector(`#${infoWindowId} .close-btn`);
  710. if (closeBtn) {
  711. closeBtn.addEventListener('click', () => {
  712. if (this.infoWindow) this.infoWindow.close();
  713. });
  714. }
  715. const root = document.querySelector(`#${infoWindowId}`);
  716. if (root) {
  717. root.addEventListener('mouseenter', () => {
  718. if (this.activeInfoWindowId !== infoWindowId) return;
  719. this.isInfoWindowHovered = true;
  720. this.cancelCloseInfoWindow();
  721. });
  722. root.addEventListener('mouseleave', () => {
  723. if (this.activeInfoWindowId !== infoWindowId) return;
  724. this.isInfoWindowHovered = false;
  725. this.scheduleCloseInfoWindow();
  726. });
  727. }
  728. }, 100);
  729. },
  730. cancelCloseInfoWindow() {
  731. if (this.infoCloseTimer) {
  732. clearTimeout(this.infoCloseTimer);
  733. this.infoCloseTimer = null;
  734. }
  735. },
  736. scheduleCloseInfoWindow() {
  737. this.cancelCloseInfoWindow();
  738. this.infoCloseTimer = setTimeout(() => {
  739. if (this.isComponentDestroyed) return;
  740. if (this.isInfoWindowHovered) return;
  741. if (this.infoWindow) this.infoWindow.close();
  742. this.activeInfoWindowId = null;
  743. }, 160);
  744. },
  745. getAlarmInfoText(statusName) {
  746. if (statusName === '离线') return '通讯中断设备离线';
  747. if (statusName === '降级') return '降级定周期控制';
  748. if (statusName === '故障') return '东向左转信号灯红绿同亮';
  749. return '设备异常';
  750. },
  751. formatEventTime(input) {
  752. let d = null;
  753. if (input instanceof Date) d = input;
  754. else if (typeof input === 'number') d = new Date(input);
  755. else if (typeof input === 'string') {
  756. const t = Date.parse(input);
  757. if (!Number.isNaN(t)) d = new Date(t);
  758. }
  759. if (!d || Number.isNaN(d.getTime())) d = new Date();
  760. const y = d.getFullYear();
  761. const m = d.getMonth() + 1;
  762. const day = d.getDate();
  763. const hh = String(d.getHours()).padStart(2, '0');
  764. const mm = String(d.getMinutes()).padStart(2, '0');
  765. return `${y}.${m}.${day} ${hh}:${mm}`;
  766. },
  767. toggleAll() {
  768. const targetState = !this.isAllSelected;
  769. if (!this.isMapReady()) return;
  770. if (targetState) {
  771. this.activeLegends = this.statusConfig.map(item => item.name);
  772. Object.values(this.routeGroups).forEach(overlays => {
  773. if (overlays && overlays.length > 0) this.map.add(overlays);
  774. });
  775. } else {
  776. this.activeLegends = [];
  777. Object.values(this.routeGroups).forEach(overlays => {
  778. if (overlays && overlays.length > 0) this.map.remove(overlays);
  779. });
  780. if (this.infoWindow) this.infoWindow.close();
  781. }
  782. },
  783. toggleRouteVisible(name) {
  784. if (!this.isMapReady()) return;
  785. const overlays = this.routeGroups[name] || [];
  786. const index = this.activeLegends.indexOf(name);
  787. if (index > -1) {
  788. this.activeLegends.splice(index, 1);
  789. this.map.remove(overlays);
  790. if (this.infoWindow) this.infoWindow.close();
  791. } else {
  792. this.activeLegends.push(name);
  793. this.map.add(overlays);
  794. }
  795. },
  796. focusByLocation(targetPos) {
  797. if (!this.isMapReady() || !targetPos || targetPos.length !== 2) return;
  798. let foundMarker = null;
  799. Object.values(this.routeGroups).forEach(group => {
  800. const marker = group.find(item => {
  801. if (!(item instanceof this.AMap.Marker)) return false;
  802. const pos = item.getExtData().position;
  803. return Math.abs(pos[0] - targetPos[0]) < 0.0001 && Math.abs(pos[1] - targetPos[1]) < 0.0001;
  804. });
  805. if (marker) foundMarker = marker;
  806. });
  807. if (foundMarker) {
  808. const finalPos = foundMarker.getPosition();
  809. this.map.setZoomAndCenter(17, finalPos, false, 500);
  810. setTimeout(() => {
  811. if (!this.isComponentDestroyed) this.openLightInfo(foundMarker.getExtData(), finalPos);
  812. }, 600);
  813. }
  814. },
  815. toggleLegend() {
  816. this.legendVisible = !this.legendVisible;
  817. },
  818. // 按4:3:3比例提取故障、离线、降级坐标点并存储到localStorage
  819. storeStatusCoordsToLocalStorage() {
  820. // 故障、离线、降级坐标点(按4:3:3比例)
  821. const faultCoords = [
  822. [116.723317, 39.907606],
  823. [116.703624, 39.89801],
  824. [116.661252, 39.924948],
  825. [116.708958, 39.899609]
  826. ];
  827. const offlineCoords = [
  828. [116.677855, 39.895636],
  829. [116.656673, 39.856063],
  830. [116.656485, 39.90118]
  831. ];
  832. const degradedCoords = [
  833. [116.713356, 39.952856],
  834. [116.665391, 39.934546],
  835. [116.697784, 39.891312]
  836. ];
  837. // 组合成10个元素的数组
  838. const statusCoords = [...faultCoords, ...offlineCoords, ...degradedCoords];
  839. // 存储到localStorage
  840. statusCoords.forEach((coords, index) => {
  841. localStorage.setItem(`pos${index + 1}`, coords.join(','));
  842. });
  843. console.log('状态坐标已存储到localStorage');
  844. },
  845. // 公开方法:将经纬度转换为像素坐标
  846. lngLatToPixel(lng, lat) {
  847. if (!this.map) return null;
  848. return this.map.lngLatToContainer([lng, lat]);
  849. }
  850. }
  851. };
  852. </script>
  853. <style scoped>
  854. .map-wrapper {
  855. width: 100%;
  856. height: 100vh;
  857. position: relative;
  858. background: #010813;
  859. }
  860. .map-container {
  861. width: 100%;
  862. height: 100%;
  863. }
  864. ::v-deep .amap-logo,
  865. ::v-deep .amap-copyright,
  866. ::v-deep .amap-copyright-logo {
  867. display: none !important;
  868. }
  869. ::v-deep .pure-light-node.breathe {
  870. animation: light-breathe 2s infinite ease-in-out;
  871. }
  872. ::v-deep .pure-light-node span {
  873. display: flex;
  874. transform: scale(0.75);
  875. align-items: center;
  876. }
  877. ::v-deep .pure-light-node:hover {
  878. transform: scale(1.4);
  879. filter: brightness(1.2);
  880. }
  881. @keyframes light-breathe {
  882. 0% {
  883. transform: scale(0.9);
  884. opacity: 0.8;
  885. }
  886. 50% {
  887. transform: scale(1.1);
  888. opacity: 1;
  889. }
  890. 100% {
  891. transform: scale(0.9);
  892. opacity: 0.8;
  893. }
  894. }
  895. ::v-deep .close-btn {
  896. position: absolute;
  897. top: 10px;
  898. right: 12px;
  899. color: #8da6c7;
  900. cursor: pointer;
  901. font-size: 16px;
  902. transition: color 0.3s;
  903. line-height: 1;
  904. z-index: 10;
  905. }
  906. ::v-deep .close-btn:hover {
  907. color: #ffffff;
  908. }
  909. ::v-deep .custom-info-card {
  910. position: relative;
  911. background: rgba(10, 15, 24, 0.95);
  912. border-radius: 10px;
  913. padding: 12px 16px;
  914. min-width: 200px;
  915. border: 1px solid rgba(255, 255, 255, 0.1);
  916. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  917. color: #fff;
  918. }
  919. ::v-deep .card-header {
  920. display: flex;
  921. align-items: center;
  922. margin-bottom: 10px;
  923. }
  924. ::v-deep .status-dot {
  925. width: 30px;
  926. height: 30px;
  927. border-radius: 50%;
  928. display: flex;
  929. justify-content: center;
  930. align-items: center;
  931. margin-right: 8px;
  932. font-size: 14px;
  933. padding: 0;
  934. box-sizing: border-box;
  935. }
  936. ::v-deep .status-dot.breathe {
  937. animation: light-breathe 2s infinite ease-in-out;
  938. }
  939. ::v-deep .status-dot span {
  940. transform: scale(0.75);
  941. }
  942. ::v-deep .status-dot img {
  943. width: 100%;
  944. height: 100%;
  945. object-fit: contain;
  946. display: block;
  947. }
  948. ::v-deep .status-text {
  949. font-size: 15px;
  950. font-weight: bold;
  951. }
  952. ::v-deep .info-line {
  953. display: flex;
  954. margin-bottom: 6px;
  955. font-size: 13px;
  956. align-items: center;
  957. }
  958. ::v-deep .label {
  959. color: #8da6c7;
  960. white-space: nowrap;
  961. }
  962. ::v-deep .value {
  963. color: #ffffff;
  964. }
  965. ::v-deep .digital {
  966. font-family: 'Consolas', monospace;
  967. }
  968. .map-legend {
  969. position: absolute;
  970. bottom: 30px;
  971. right: 40px;
  972. background: rgba(5, 22, 45, 0.9);
  973. border: 1px solid #1e4d8e;
  974. padding: 15px;
  975. border-radius: 6px;
  976. z-index: 100;
  977. transition: all 0.3s ease-in-out;
  978. opacity: 1;
  979. max-width: 200px;
  980. overflow: hidden;
  981. }
  982. .map-legend.legend-hidden {
  983. opacity: 0;
  984. transform: translateX(calc(100% + 20px));
  985. pointer-events: none;
  986. }
  987. .legend-header {
  988. display: flex;
  989. justify-content: space-between;
  990. align-items: center;
  991. margin-bottom: 12px;
  992. border-bottom: 1px solid #1e4d8e;
  993. padding-bottom: 8px;
  994. }
  995. .legend-close-btn {
  996. color: #8da6c7;
  997. cursor: pointer;
  998. font-size: 16px;
  999. transition: color 0.3s;
  1000. line-height: 1;
  1001. }
  1002. .legend-close-btn:hover {
  1003. color: #ffffff;
  1004. }
  1005. .legend-show-btn {
  1006. position: absolute;
  1007. bottom: 30px;
  1008. right: 20px;
  1009. background: rgba(5, 22, 45, 0.9);
  1010. border: 1px solid #1e4d8e;
  1011. width: 40px;
  1012. height: 40px;
  1013. border-radius: 6px 0 0 6px;
  1014. display: flex;
  1015. justify-content: center;
  1016. align-items: center;
  1017. cursor: pointer;
  1018. z-index: 99;
  1019. transition: all 0.3s ease-in-out;
  1020. }
  1021. .legend-show-btn:hover {
  1022. background: rgba(10, 30, 60, 0.9);
  1023. border-color: #3a75c4;
  1024. }
  1025. .legend-show-icon {
  1026. color: #8da6c7;
  1027. font-size: 18px;
  1028. transition: color 0.3s;
  1029. }
  1030. .legend-show-btn:hover .legend-show-icon {
  1031. color: #ffffff;
  1032. }
  1033. .legend-title {
  1034. color: #fff;
  1035. font-size: 14px;
  1036. }
  1037. .legend-item {
  1038. display: flex;
  1039. align-items: center;
  1040. margin-bottom: 10px;
  1041. cursor: pointer;
  1042. transition: 0.3s;
  1043. }
  1044. .legend-item.is-inactive {
  1045. opacity: 0.2;
  1046. filter: grayscale(1);
  1047. }
  1048. .legend-dot {
  1049. margin-right: 10px;
  1050. display: flex;
  1051. justify-content: center;
  1052. align-items: center;
  1053. }
  1054. .legend-dot:not(.is-status-wrapper) {
  1055. width: 20px;
  1056. height: 20px;
  1057. border-radius: 50%;
  1058. }
  1059. .legend-dot span {
  1060. display: inline-block;
  1061. width: 20px;
  1062. height: 20px;
  1063. font-size: 12px;
  1064. color: #FFF;
  1065. text-align: center;
  1066. transform: scale(0.75);
  1067. line-height: 20px;
  1068. }
  1069. .legend-dot.special-route {
  1070. position: relative;
  1071. overflow: visible !important;
  1072. z-index: 1;
  1073. border: none !important;
  1074. border-radius: 50%;
  1075. }
  1076. .legend-dot.special-route span {
  1077. position: relative;
  1078. z-index: 3;
  1079. font-weight: bold;
  1080. }
  1081. .legend-dot.special-route::after {
  1082. content: "";
  1083. position: absolute;
  1084. top: 50%;
  1085. left: 50%;
  1086. width: 150%;
  1087. height: 3px;
  1088. background-color: inherit;
  1089. opacity: 0.8;
  1090. transform: translate(-50%, -50%) rotate(-45deg);
  1091. pointer-events: none;
  1092. z-index: 0;
  1093. }
  1094. .legend-dot.special-route::before {
  1095. content: "";
  1096. position: absolute;
  1097. top: 0;
  1098. left: 0;
  1099. width: 100%;
  1100. height: 100%;
  1101. border-radius: 50%;
  1102. z-index: 2;
  1103. background-color: inherit;
  1104. opacity: 1;
  1105. }
  1106. .legend-label {
  1107. flex: 1;
  1108. color: #d0d9e2;
  1109. font-size: 13px;
  1110. }
  1111. .legend-status {
  1112. font-size: 11px;
  1113. color: #5b7da8;
  1114. }
  1115. .all-select {
  1116. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  1117. padding-bottom: 12px;
  1118. margin-bottom: 12px !important;
  1119. }
  1120. .all-select .legend-dot {
  1121. border-radius: 2px;
  1122. transition: all 0.3s;
  1123. width: 10px;
  1124. height: 10px;
  1125. }
  1126. .legend-dot.is-status-wrapper {
  1127. width: 28px;
  1128. height: 28px;
  1129. background-color: transparent !important;
  1130. box-shadow: none !important;
  1131. border: none !important;
  1132. margin-right: 0;
  1133. transform: translateX(-15%);
  1134. }
  1135. .status-icon {
  1136. width: 100%;
  1137. height: 100%;
  1138. object-fit: contain;
  1139. display: block;
  1140. }
  1141. ::v-deep .pure-light-node {
  1142. width: 16px;
  1143. height: 16px;
  1144. border-radius: 50%;
  1145. border: 2px solid rgba(255, 255, 255, 0.8);
  1146. cursor: pointer;
  1147. transition: all 0.3s;
  1148. display: flex;
  1149. justify-content: center;
  1150. align-items: center;
  1151. color: #fff;
  1152. pointer-events: auto;
  1153. }
  1154. ::v-deep .pure-light-node.route-node {
  1155. position: relative;
  1156. overflow: visible;
  1157. }
  1158. ::v-deep .pure-light-node.route-node::after {
  1159. content: "";
  1160. position: absolute;
  1161. top: 50%;
  1162. left: 50%;
  1163. width: 150%;
  1164. height: 3px;
  1165. background-color: inherit;
  1166. opacity: 0.8;
  1167. transform: translate(-50%, -50%) rotate(-45deg);
  1168. pointer-events: none;
  1169. }
  1170. ::v-deep .pure-light-node.route-node span {
  1171. position: relative;
  1172. z-index: 1;
  1173. }
  1174. /* 异常状态增加稍微剧烈一点的呼吸感,但缩小范围 */
  1175. @keyframes light-breathe {
  1176. 0% {
  1177. transform: scale(0.9);
  1178. opacity: 0.8;
  1179. }
  1180. 50% {
  1181. transform: scale(1.1);
  1182. opacity: 1;
  1183. }
  1184. 100% {
  1185. transform: scale(0.9);
  1186. opacity: 0.8;
  1187. }
  1188. }
  1189. /* 首页展示时,如果觉得还是太密,可以给非异常节点降权 */
  1190. ::v-deep .pure-light-node:not(.abnormal-node) {
  1191. border: 1px solid rgba(255, 255, 255, 0.4);
  1192. }
  1193. </style>