TongzhouTrafficMap.vue 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  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["位置-纬度"]], config)
  302. ).filter(Boolean);
  303. this.routeGroups[config.name] = markers;
  304. if (this.activeLegends.includes(config.name)) this.map.add(markers);
  305. continue;
  306. }
  307. // 2. 处理路线类(干线/特勤)
  308. this.routeGroups[config.name] = [];
  309. const lines = realRouteConfigs[config.name] || [];
  310. for (let lineIdx = 0; lineIdx < lines.length; lineIdx += 1) {
  311. if (this.isComponentDestroyed || drawSeq !== this.drawSeq) return;
  312. const line = lines[lineIdx];
  313. let path = null;
  314. try {
  315. path = await this.searchDrivingPathWithRetry(line.start, line.end);
  316. } catch (e) {
  317. path = null;
  318. }
  319. const overlays = this.buildRouteOverlaysFromPath({
  320. config,
  321. configName: config.name,
  322. line,
  323. lineIdx,
  324. path
  325. });
  326. if (this.isComponentDestroyed || drawSeq !== this.drawSeq) return;
  327. if (overlays.length > 0) {
  328. this.routeGroups[config.name].push(...overlays);
  329. if (this.activeLegends.includes(config.name)) this.map.add(overlays);
  330. }
  331. await this.sleep(80);
  332. }
  333. }
  334. },
  335. clearAllRouteOverlays() {
  336. if (!this.isMapReady()) return;
  337. try {
  338. if (this.infoWindow) this.infoWindow.close();
  339. } catch (e) {
  340. void e;
  341. }
  342. Object.values(this.routeGroups || {}).forEach(overlays => {
  343. if (!Array.isArray(overlays) || overlays.length === 0) return;
  344. try {
  345. this.map.remove(overlays);
  346. } catch (e) {
  347. void e;
  348. }
  349. overlays.forEach(o => {
  350. try {
  351. if (o && typeof o.setMap === 'function') o.setMap(null);
  352. } catch (e) {
  353. void e;
  354. }
  355. });
  356. });
  357. this.routeGroups = {};
  358. },
  359. sleep(ms) {
  360. return new Promise(resolve => setTimeout(resolve, ms));
  361. },
  362. async searchDrivingPathWithRetry(start, end) {
  363. if (!this.AMap || !this.driving || typeof this.driving.search !== 'function') {
  364. throw new Error('Driving not ready');
  365. }
  366. const maxAttempts = 3;
  367. let lastErr = null;
  368. for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
  369. try {
  370. return await this.withTimeout(this.searchDrivingPathOnce(start, end), 8000);
  371. } catch (e) {
  372. lastErr = e;
  373. await this.sleep(250 * attempt);
  374. }
  375. }
  376. throw lastErr || new Error('Driving search failed');
  377. },
  378. searchDrivingPathOnce(start, end) {
  379. return new Promise((resolve, reject) => {
  380. this.driving.search(start, end, (status, result) => {
  381. const route = result && result.routes && result.routes[0];
  382. if (status === 'complete' && route && Array.isArray(route.steps)) {
  383. const fullPath = [];
  384. route.steps.forEach(step => {
  385. if (step && Array.isArray(step.path)) fullPath.push(...step.path);
  386. });
  387. if (fullPath.length >= 2) resolve(fullPath);
  388. else reject(new Error('empty_path'));
  389. return;
  390. }
  391. reject(new Error(typeof status === 'string' ? status : 'driving_error'));
  392. });
  393. });
  394. },
  395. withTimeout(promise, timeoutMs) {
  396. return Promise.race([
  397. promise,
  398. new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeoutMs))
  399. ]);
  400. },
  401. buildRouteOverlaysFromPath({ config, configName, line, lineIdx, path }) {
  402. if (!this.AMap || !this.map) return [];
  403. let basePath = path;
  404. if (!Array.isArray(basePath) || basePath.length < 2) {
  405. basePath = this.buildFallbackLinePath(line.start, line.end, 30);
  406. }
  407. const segments = this.extractMainStraightSegments(basePath);
  408. const overlays = [];
  409. segments.forEach((segmentPath, segmentIdx) => {
  410. if (!Array.isArray(segmentPath) || segmentPath.length < 2) return;
  411. const polyline = new this.AMap.Polyline({
  412. path: segmentPath,
  413. strokeColor: line.color,
  414. strokeWeight: 6,
  415. strokeOpacity: 0.8,
  416. zIndex: 15
  417. });
  418. overlays.push(polyline);
  419. const totalPoints = segmentPath.length;
  420. const indices = this.pickEvenlySpacedIndices(totalPoints, 8);
  421. // 为第一个和最后一个圆点设置特殊类型
  422. for (let i = 0; i < indices.length; i++) {
  423. const idx = indices[i];
  424. const p = segmentPath[idx];
  425. const lng = p && typeof p.lng === 'number' ? p.lng : (Array.isArray(p) ? Number(p[0]) : NaN);
  426. const lat = p && typeof p.lat === 'number' ? p.lat : (Array.isArray(p) ? Number(p[1]) : NaN);
  427. if (Number.isNaN(lng) || Number.isNaN(lat)) continue;
  428. // 确定圆点类型:第一个为start,最后一个为end,其余为normal
  429. let markerType = 'normal';
  430. if (i === 0) {
  431. markerType = 'start';
  432. } else if (i === indices.length - 1) {
  433. markerType = 'end';
  434. }
  435. const marker = this.createTrafficLightMarker([lng, lat], {
  436. ...config,
  437. id: `MOCK-${configName.charAt(0)}-${lineIdx}-${segmentIdx}-${idx}`,
  438. road: `${configName}路口-${lineIdx}-${segmentIdx}-${idx}`
  439. }, markerType);
  440. if (marker) overlays.push(marker);
  441. }
  442. });
  443. return overlays;
  444. },
  445. pickEvenlySpacedIndices(totalPoints, count) {
  446. const total = Math.max(Number(totalPoints) || 0, 0);
  447. const target = Math.max(Number(count) || 0, 0);
  448. if (total <= 0) return [];
  449. if (target <= 0) return [];
  450. if (target >= total) return Array.from({ length: total }, (_, i) => i);
  451. if (target === 1) return [0];
  452. const set = new Set();
  453. const last = total - 1;
  454. for (let k = 0; k < target; k += 1) {
  455. const idx = Math.round((k * last) / (target - 1));
  456. set.add(idx);
  457. }
  458. return Array.from(set).sort((a, b) => a - b);
  459. },
  460. buildFallbackLinePath(start, end, pointCount) {
  461. const sLng = Number(start && start[0]);
  462. const sLat = Number(start && start[1]);
  463. const eLng = Number(end && end[0]);
  464. const eLat = Number(end && end[1]);
  465. const n = Math.max(Number(pointCount) || 2, 2);
  466. const path = [];
  467. if ([sLng, sLat, eLng, eLat].some(v => Number.isNaN(v))) return path;
  468. for (let i = 0; i < n; i += 1) {
  469. const t = n === 1 ? 0 : i / (n - 1);
  470. const lng = sLng + (eLng - sLng) * t;
  471. const lat = sLat + (eLat - sLat) * t;
  472. path.push({ lng, lat });
  473. }
  474. return path;
  475. },
  476. extractMainStraightSegments(path) {
  477. const points = (path || []).filter(p => p && typeof p.lng === 'number' && typeof p.lat === 'number');
  478. if (points.length < 2) return [];
  479. const thresholdDeg = 18;
  480. const segments = [];
  481. let curStart = 0;
  482. let curAngle = null;
  483. let curLen = 0;
  484. const pushSegment = (endIdx) => {
  485. if (endIdx <= curStart) return;
  486. segments.push({
  487. start: curStart,
  488. end: endIdx,
  489. len: curLen
  490. });
  491. };
  492. for (let i = 0; i < points.length - 1; i += 1) {
  493. const a = points[i];
  494. const b = points[i + 1];
  495. const len = this.calcApproxDistance(a, b);
  496. if (len <= 0) continue;
  497. const angle = this.calcBearingDeg(a, b);
  498. if (curAngle === null) {
  499. curStart = i;
  500. curAngle = angle;
  501. curLen = len;
  502. continue;
  503. }
  504. const diff = this.calcAngleDiffDeg(curAngle, angle);
  505. if (diff <= thresholdDeg) {
  506. curLen += len;
  507. } else {
  508. pushSegment(i);
  509. curStart = i;
  510. curAngle = angle;
  511. curLen = len;
  512. }
  513. }
  514. pushSegment(points.length - 2);
  515. if (segments.length === 0) return [points];
  516. segments.sort((s1, s2) => s2.len - s1.len);
  517. const maxLen = segments[0].len || 0;
  518. const filtered = segments.filter(s => s.len >= maxLen * 0.55).slice(0, 3);
  519. const finalSegments = filtered.map(s => points.slice(s.start, s.end + 2));
  520. return finalSegments.length > 0 ? finalSegments : [points];
  521. },
  522. calcBearingDeg(a, b) {
  523. const latRad = ((a.lat + b.lat) / 2) * Math.PI / 180;
  524. const dx = (b.lng - a.lng) * Math.cos(latRad);
  525. const dy = (b.lat - a.lat);
  526. let deg = Math.atan2(dy, dx) * 180 / Math.PI;
  527. if (deg < 0) deg += 360;
  528. return deg;
  529. },
  530. calcAngleDiffDeg(a, b) {
  531. let diff = Math.abs(a - b);
  532. if (diff > 180) diff = 360 - diff;
  533. return diff;
  534. },
  535. calcApproxDistance(a, b) {
  536. const latRad = ((a.lat + b.lat) / 2) * Math.PI / 180;
  537. const dx = (b.lng - a.lng) * Math.cos(latRad);
  538. const dy = (b.lat - a.lat);
  539. return Math.sqrt(dx * dx + dy * dy);
  540. },
  541. createTrafficLightMarker(position, config, type = 'normal') {
  542. if (!position || !config) return null;
  543. try {
  544. const lng = Number(position[0] || position.lng);
  545. const lat = Number(position[1] || position.lat);
  546. if (isNaN(lng) || isNaN(lat)) return null;
  547. // 状态文字:起、终、或者状态配置的首字母
  548. let displayText = config.name ? config.name.charAt(0) : '';
  549. if (type === 'start') displayText = '起';
  550. if (type === 'end') displayText = '终';
  551. const isAbnormal = ["离线", "降级", "故障"].includes(config.name);
  552. const isRoute = ["干线协调", "勤务路线"].includes(config.name);
  553. // 动态计算尺寸:起终点最大,异常点次之,普通点最小
  554. const size = (type === 'start' || type === 'end') ? '22px' : (isAbnormal ? '30px' : '14px');
  555. const sizeNumber = parseInt(size, 10);
  556. const paddingNumber = (isAbnormal || type === 'start' || type === 'end') ? 0 : 2;
  557. const outerSizeNumber = sizeNumber + paddingNumber * 2;
  558. // 边框样式:起终点用实白边框
  559. const borderStyle = (type === 'start' || type === 'end')
  560. ? '2px solid #fff'
  561. : '1.5px solid rgba(255,255,255,0.7)';
  562. // 生成异常状态的图标路径
  563. let markerContent = '';
  564. if (isAbnormal) {
  565. const iconName = config.name === '离线' ? 'lixian' : config.name === '降级' ? 'jiangji' : 'guzhang';
  566. markerContent = `
  567. <div class="pure-light-node ${isAbnormal ? 'breathe' : ''}"
  568. style="
  569. width: ${size};
  570. height: ${size};
  571. background: transparent;
  572. box-shadow: none;
  573. border: none;
  574. box-sizing: content-box;
  575. display: flex;
  576. justify-content: center;
  577. align-items: center;
  578. cursor: pointer;
  579. padding: ${paddingNumber}px;
  580. ">
  581. <img src="${require(`@/assets/images/icon_${iconName}.png`)}" style="width: 100%; height: 100%; object-fit: contain;" />
  582. </div>
  583. `;
  584. } else {
  585. markerContent = `
  586. <div class="pure-light-node ${isAbnormal ? 'breathe' : ''} ${isRoute ? 'route-node' : ''}"
  587. style="
  588. width: ${size};
  589. height: ${size};
  590. background: ${config.color || '#999'};
  591. box-shadow: ${isRoute ? 'none' : `0 0 8px ${config.color}`};
  592. border: ${isRoute ? 'none' : borderStyle};
  593. box-sizing: content-box;
  594. display: flex;
  595. justify-content: center;
  596. align-items: center;
  597. color: #fff;
  598. border-radius: 50%;
  599. cursor: pointer;
  600. padding: ${paddingNumber}px;
  601. ">
  602. <span style="transform: scale(0.8); font-weight: bold; font-size: 12px;">${displayText}</span>
  603. </div>
  604. `;
  605. }
  606. const marker = new this.AMap.Marker({
  607. position: [lng, lat],
  608. // 这里的 type 已经从参数拿到了,不会报错了
  609. zIndex: (type === 'start' || type === 'end') ? 120 : (isAbnormal ? 110 : 100),
  610. content: markerContent,
  611. offset: new this.AMap.Pixel(-Math.round(outerSizeNumber / 2), -Math.round(outerSizeNumber / 2)),
  612. extData: {
  613. ...config,
  614. position: [lng, lat],
  615. statusColor: config.color || '#999',
  616. statusLabel: config.name,
  617. road: config.road || '规划路口',
  618. timestamp: Date.now(),
  619. time: this.formatEventTime(Date.now())
  620. }
  621. });
  622. marker.on('click', (e) => {
  623. if (this.isComponentDestroyed) return;
  624. const extData = e.target.getExtData();
  625. if (this.isHomePage) {
  626. this.cancelCloseInfoWindow();
  627. this.openLightInfo(extData, e.lnglat);
  628. }
  629. // 获取像素坐标
  630. const pixel = this.map.lngLatToContainer(e.lnglat);
  631. this.$emit('map-crossing-click', extData, e.lnglat, pixel);
  632. });
  633. marker.on('mouseover', (e) => {
  634. if (this.isComponentDestroyed) return;
  635. if (this.isHomePage) return;
  636. this.cancelCloseInfoWindow();
  637. this.openLightInfo(e.target.getExtData(), e.lnglat);
  638. // 获取像素坐标
  639. const pixel = this.map.lngLatToContainer(e.lnglat);
  640. // 传递路口鼠标滑入事件
  641. this.$emit('map-crossing-mouseover', e.target.getExtData(), e.lnglat, pixel);
  642. });
  643. marker.on('mouseout', (e) => {
  644. if (this.isComponentDestroyed) return;
  645. if (this.isHomePage) return;
  646. this.scheduleCloseInfoWindow();
  647. // 传递路口鼠标滑出事件
  648. this.$emit('map-crossing-mouseout', e.target.getExtData());
  649. });
  650. return marker;
  651. } catch (e) {
  652. console.warn('创建标记时出错:', e);
  653. return null;
  654. }
  655. },
  656. openLightInfo(data, position) {
  657. if (!this.isMapReady()) return;
  658. const infoWindowId = `info-window-${Date.now()}`;
  659. this.activeInfoWindowId = infoWindowId;
  660. const isAbnormal = ["离线", "降级", "故障"].includes(data.name);
  661. const deviceStatusText = isAbnormal ? data.name : '正常';
  662. const alarmInfoText = isAbnormal ? this.getAlarmInfoText(data.name) : '';
  663. const eventTimeText = this.formatEventTime(data.timestamp || data.time);
  664. let statusDotContent = '';
  665. if (isAbnormal) {
  666. const iconName = data.name === '离线' ? 'lixian' : data.name === '降级' ? 'jiangji' : 'guzhang';
  667. statusDotContent = `<img src="${require(`@/assets/images/icon_${iconName}.png`)}" style="width: 100%; height: 100%; object-fit: contain;" />`;
  668. } else {
  669. statusDotContent = `<span>${data.name.charAt(0)}</span>`;
  670. }
  671. const content = `
  672. <div class="custom-info-card" id="${infoWindowId}">
  673. <div class="close-btn" data-id="${infoWindowId}">✕</div>
  674. <div class="card-header">
  675. <div class="status-dot ${isAbnormal ? 'breathe' : ''}" style="background: ${isAbnormal ? 'transparent' : data.statusColor}; border: ${isAbnormal ? 'none' : ''}">
  676. ${statusDotContent}
  677. </div>
  678. <span class="status-text">${data.statusLabel}</span>
  679. </div>
  680. <div class="card-body">
  681. ${isAbnormal
  682. ? `
  683. <div class="info-line"><span class="label">路口名称:</span><span class="value">${data.road}</span></div>
  684. <div class="info-line"><span class="label">设备状态:</span><span class="value digital">${deviceStatusText}</span></div>
  685. <div class="info-line"><span class="label">报警信息:</span><span class="value">${alarmInfoText}</span></div>
  686. <div class="info-line"><span class="label">发生时间:</span><span class="value digital">${eventTimeText}</span></div>
  687. `
  688. : `
  689. <div class="info-line"><span class="label">路口名称:</span><span class="value">${data.road}</span></div>
  690. <div class="info-line"><span class="label">设备状态:</span><span class="value digital">${deviceStatusText}</span></div>
  691. `
  692. }
  693. </div>
  694. </div>
  695. `;
  696. if (!this.infoWindow) {
  697. this.infoWindow = new this.AMap.InfoWindow({
  698. isCustom: true,
  699. offset: new this.AMap.Pixel(0, -20)
  700. });
  701. }
  702. this.infoWindow.setContent(content);
  703. this.infoWindow.open(this.map, position);
  704. setTimeout(() => {
  705. if (this.activeInfoWindowId !== infoWindowId) return;
  706. const closeBtn = document.querySelector(`#${infoWindowId} .close-btn`);
  707. if (closeBtn) {
  708. closeBtn.addEventListener('click', () => {
  709. if (this.infoWindow) this.infoWindow.close();
  710. });
  711. }
  712. const root = document.querySelector(`#${infoWindowId}`);
  713. if (root) {
  714. root.addEventListener('mouseenter', () => {
  715. if (this.activeInfoWindowId !== infoWindowId) return;
  716. this.isInfoWindowHovered = true;
  717. this.cancelCloseInfoWindow();
  718. });
  719. root.addEventListener('mouseleave', () => {
  720. if (this.activeInfoWindowId !== infoWindowId) return;
  721. this.isInfoWindowHovered = false;
  722. this.scheduleCloseInfoWindow();
  723. });
  724. }
  725. }, 100);
  726. },
  727. cancelCloseInfoWindow() {
  728. if (this.infoCloseTimer) {
  729. clearTimeout(this.infoCloseTimer);
  730. this.infoCloseTimer = null;
  731. }
  732. },
  733. scheduleCloseInfoWindow() {
  734. this.cancelCloseInfoWindow();
  735. this.infoCloseTimer = setTimeout(() => {
  736. if (this.isComponentDestroyed) return;
  737. if (this.isInfoWindowHovered) return;
  738. if (this.infoWindow) this.infoWindow.close();
  739. this.activeInfoWindowId = null;
  740. }, 160);
  741. },
  742. getAlarmInfoText(statusName) {
  743. if (statusName === '离线') return '通讯中断设备离线';
  744. if (statusName === '降级') return '降级定周期控制';
  745. if (statusName === '故障') return '东向左转信号灯红绿同亮';
  746. return '设备异常';
  747. },
  748. formatEventTime(input) {
  749. let d = null;
  750. if (input instanceof Date) d = input;
  751. else if (typeof input === 'number') d = new Date(input);
  752. else if (typeof input === 'string') {
  753. const t = Date.parse(input);
  754. if (!Number.isNaN(t)) d = new Date(t);
  755. }
  756. if (!d || Number.isNaN(d.getTime())) d = new Date();
  757. const y = d.getFullYear();
  758. const m = d.getMonth() + 1;
  759. const day = d.getDate();
  760. const hh = String(d.getHours()).padStart(2, '0');
  761. const mm = String(d.getMinutes()).padStart(2, '0');
  762. return `${y}.${m}.${day} ${hh}:${mm}`;
  763. },
  764. toggleAll() {
  765. const targetState = !this.isAllSelected;
  766. if (!this.isMapReady()) return;
  767. if (targetState) {
  768. this.activeLegends = this.statusConfig.map(item => item.name);
  769. Object.values(this.routeGroups).forEach(overlays => {
  770. if (overlays && overlays.length > 0) this.map.add(overlays);
  771. });
  772. } else {
  773. this.activeLegends = [];
  774. Object.values(this.routeGroups).forEach(overlays => {
  775. if (overlays && overlays.length > 0) this.map.remove(overlays);
  776. });
  777. if (this.infoWindow) this.infoWindow.close();
  778. }
  779. },
  780. toggleRouteVisible(name) {
  781. if (!this.isMapReady()) return;
  782. const overlays = this.routeGroups[name] || [];
  783. const index = this.activeLegends.indexOf(name);
  784. if (index > -1) {
  785. this.activeLegends.splice(index, 1);
  786. this.map.remove(overlays);
  787. if (this.infoWindow) this.infoWindow.close();
  788. } else {
  789. this.activeLegends.push(name);
  790. this.map.add(overlays);
  791. }
  792. },
  793. focusByLocation(targetPos) {
  794. if (!this.isMapReady() || !targetPos || targetPos.length !== 2) return;
  795. let foundMarker = null;
  796. Object.values(this.routeGroups).forEach(group => {
  797. const marker = group.find(item => {
  798. if (!(item instanceof this.AMap.Marker)) return false;
  799. const pos = item.getExtData().position;
  800. return Math.abs(pos[0] - targetPos[0]) < 0.0001 && Math.abs(pos[1] - targetPos[1]) < 0.0001;
  801. });
  802. if (marker) foundMarker = marker;
  803. });
  804. if (foundMarker) {
  805. const finalPos = foundMarker.getPosition();
  806. this.map.setZoomAndCenter(17, finalPos, false, 500);
  807. setTimeout(() => {
  808. if (!this.isComponentDestroyed) this.openLightInfo(foundMarker.getExtData(), finalPos);
  809. }, 600);
  810. }
  811. },
  812. toggleLegend() {
  813. this.legendVisible = !this.legendVisible;
  814. },
  815. // 按4:3:3比例提取故障、离线、降级坐标点并存储到localStorage
  816. storeStatusCoordsToLocalStorage() {
  817. // 故障、离线、降级坐标点(按4:3:3比例)
  818. const faultCoords = [
  819. [116.723317, 39.907606],
  820. [116.703624, 39.89801],
  821. [116.661252, 39.924948],
  822. [116.708958, 39.899609]
  823. ];
  824. const offlineCoords = [
  825. [116.677855, 39.895636],
  826. [116.656673, 39.856063],
  827. [116.656485, 39.90118]
  828. ];
  829. const degradedCoords = [
  830. [116.713356, 39.952856],
  831. [116.665391, 39.934546],
  832. [116.697784, 39.891312]
  833. ];
  834. // 组合成10个元素的数组
  835. const statusCoords = [...faultCoords, ...offlineCoords, ...degradedCoords];
  836. // 存储到localStorage
  837. statusCoords.forEach((coords, index) => {
  838. localStorage.setItem(`pos${index + 1}`, coords.join(','));
  839. });
  840. console.log('状态坐标已存储到localStorage');
  841. },
  842. // 公开方法:将经纬度转换为像素坐标
  843. lngLatToPixel(lng, lat) {
  844. if (!this.map) return null;
  845. return this.map.lngLatToContainer([lng, lat]);
  846. }
  847. }
  848. };
  849. </script>
  850. <style scoped>
  851. .map-wrapper {
  852. width: 100%;
  853. height: 100vh;
  854. position: relative;
  855. background: #010813;
  856. }
  857. .map-container {
  858. width: 100%;
  859. height: 100%;
  860. }
  861. ::v-deep .amap-logo,
  862. ::v-deep .amap-copyright,
  863. ::v-deep .amap-copyright-logo {
  864. display: none !important;
  865. }
  866. ::v-deep .pure-light-node.breathe {
  867. animation: light-breathe 2s infinite ease-in-out;
  868. }
  869. ::v-deep .pure-light-node span {
  870. display: flex;
  871. transform: scale(0.75);
  872. align-items: center;
  873. }
  874. ::v-deep .pure-light-node:hover {
  875. transform: scale(1.4);
  876. filter: brightness(1.2);
  877. }
  878. @keyframes light-breathe {
  879. 0% {
  880. transform: scale(0.9);
  881. opacity: 0.8;
  882. }
  883. 50% {
  884. transform: scale(1.1);
  885. opacity: 1;
  886. }
  887. 100% {
  888. transform: scale(0.9);
  889. opacity: 0.8;
  890. }
  891. }
  892. ::v-deep .close-btn {
  893. position: absolute;
  894. top: 10px;
  895. right: 12px;
  896. color: #8da6c7;
  897. cursor: pointer;
  898. font-size: 16px;
  899. transition: color 0.3s;
  900. line-height: 1;
  901. z-index: 10;
  902. }
  903. ::v-deep .close-btn:hover {
  904. color: #ffffff;
  905. }
  906. ::v-deep .custom-info-card {
  907. position: relative;
  908. background: rgba(10, 15, 24, 0.95);
  909. border-radius: 10px;
  910. padding: 12px 16px;
  911. min-width: 200px;
  912. border: 1px solid rgba(255, 255, 255, 0.1);
  913. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  914. color: #fff;
  915. }
  916. ::v-deep .card-header {
  917. display: flex;
  918. align-items: center;
  919. margin-bottom: 10px;
  920. }
  921. ::v-deep .status-dot {
  922. width: 30px;
  923. height: 30px;
  924. border-radius: 50%;
  925. display: flex;
  926. justify-content: center;
  927. align-items: center;
  928. margin-right: 8px;
  929. font-size: 14px;
  930. padding: 0;
  931. box-sizing: border-box;
  932. }
  933. ::v-deep .status-dot.breathe {
  934. animation: light-breathe 2s infinite ease-in-out;
  935. }
  936. ::v-deep .status-dot span {
  937. transform: scale(0.75);
  938. }
  939. ::v-deep .status-dot img {
  940. width: 100%;
  941. height: 100%;
  942. object-fit: contain;
  943. display: block;
  944. }
  945. ::v-deep .status-text {
  946. font-size: 15px;
  947. font-weight: bold;
  948. }
  949. ::v-deep .info-line {
  950. display: flex;
  951. margin-bottom: 6px;
  952. font-size: 13px;
  953. align-items: center;
  954. }
  955. ::v-deep .label {
  956. color: #8da6c7;
  957. white-space: nowrap;
  958. }
  959. ::v-deep .value {
  960. color: #ffffff;
  961. }
  962. ::v-deep .digital {
  963. font-family: 'Consolas', monospace;
  964. }
  965. .map-legend {
  966. position: absolute;
  967. bottom: 30px;
  968. right: 40px;
  969. background: rgba(5, 22, 45, 0.9);
  970. border: 1px solid #1e4d8e;
  971. padding: 15px;
  972. border-radius: 6px;
  973. z-index: 100;
  974. transition: all 0.3s ease-in-out;
  975. opacity: 1;
  976. max-width: 200px;
  977. overflow: hidden;
  978. }
  979. .map-legend.legend-hidden {
  980. opacity: 0;
  981. transform: translateX(calc(100% + 20px));
  982. pointer-events: none;
  983. }
  984. .legend-header {
  985. display: flex;
  986. justify-content: space-between;
  987. align-items: center;
  988. margin-bottom: 12px;
  989. border-bottom: 1px solid #1e4d8e;
  990. padding-bottom: 8px;
  991. }
  992. .legend-close-btn {
  993. color: #8da6c7;
  994. cursor: pointer;
  995. font-size: 16px;
  996. transition: color 0.3s;
  997. line-height: 1;
  998. }
  999. .legend-close-btn:hover {
  1000. color: #ffffff;
  1001. }
  1002. .legend-show-btn {
  1003. position: absolute;
  1004. bottom: 30px;
  1005. right: 20px;
  1006. background: rgba(5, 22, 45, 0.9);
  1007. border: 1px solid #1e4d8e;
  1008. width: 40px;
  1009. height: 40px;
  1010. border-radius: 6px 0 0 6px;
  1011. display: flex;
  1012. justify-content: center;
  1013. align-items: center;
  1014. cursor: pointer;
  1015. z-index: 99;
  1016. transition: all 0.3s ease-in-out;
  1017. }
  1018. .legend-show-btn:hover {
  1019. background: rgba(10, 30, 60, 0.9);
  1020. border-color: #3a75c4;
  1021. }
  1022. .legend-show-icon {
  1023. color: #8da6c7;
  1024. font-size: 18px;
  1025. transition: color 0.3s;
  1026. }
  1027. .legend-show-btn:hover .legend-show-icon {
  1028. color: #ffffff;
  1029. }
  1030. .legend-title {
  1031. color: #fff;
  1032. font-size: 14px;
  1033. }
  1034. .legend-item {
  1035. display: flex;
  1036. align-items: center;
  1037. margin-bottom: 10px;
  1038. cursor: pointer;
  1039. transition: 0.3s;
  1040. }
  1041. .legend-item.is-inactive {
  1042. opacity: 0.2;
  1043. filter: grayscale(1);
  1044. }
  1045. .legend-dot {
  1046. margin-right: 10px;
  1047. display: flex;
  1048. justify-content: center;
  1049. align-items: center;
  1050. }
  1051. .legend-dot:not(.is-status-wrapper) {
  1052. width: 20px;
  1053. height: 20px;
  1054. border-radius: 50%;
  1055. }
  1056. .legend-dot span {
  1057. display: inline-block;
  1058. width: 20px;
  1059. height: 20px;
  1060. font-size: 12px;
  1061. color: #FFF;
  1062. text-align: center;
  1063. transform: scale(0.75);
  1064. line-height: 20px;
  1065. }
  1066. .legend-dot.special-route {
  1067. position: relative;
  1068. overflow: visible !important;
  1069. z-index: 1;
  1070. border: none !important;
  1071. border-radius: 50%;
  1072. }
  1073. .legend-dot.special-route span {
  1074. position: relative;
  1075. z-index: 3;
  1076. font-weight: bold;
  1077. }
  1078. .legend-dot.special-route::after {
  1079. content: "";
  1080. position: absolute;
  1081. top: 50%;
  1082. left: 50%;
  1083. width: 150%;
  1084. height: 3px;
  1085. background-color: inherit;
  1086. opacity: 0.8;
  1087. transform: translate(-50%, -50%) rotate(-45deg);
  1088. pointer-events: none;
  1089. z-index: 0;
  1090. }
  1091. .legend-dot.special-route::before {
  1092. content: "";
  1093. position: absolute;
  1094. top: 0;
  1095. left: 0;
  1096. width: 100%;
  1097. height: 100%;
  1098. border-radius: 50%;
  1099. z-index: 2;
  1100. background-color: inherit;
  1101. opacity: 1;
  1102. }
  1103. .legend-label {
  1104. flex: 1;
  1105. color: #d0d9e2;
  1106. font-size: 13px;
  1107. }
  1108. .legend-status {
  1109. font-size: 11px;
  1110. color: #5b7da8;
  1111. }
  1112. .all-select {
  1113. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  1114. padding-bottom: 12px;
  1115. margin-bottom: 12px !important;
  1116. }
  1117. .all-select .legend-dot {
  1118. border-radius: 2px;
  1119. transition: all 0.3s;
  1120. width: 10px;
  1121. height: 10px;
  1122. }
  1123. .legend-dot.is-status-wrapper {
  1124. width: 28px;
  1125. height: 28px;
  1126. background-color: transparent !important;
  1127. box-shadow: none !important;
  1128. border: none !important;
  1129. margin-right: 0;
  1130. transform: translateX(-15%);
  1131. }
  1132. .status-icon {
  1133. width: 100%;
  1134. height: 100%;
  1135. object-fit: contain;
  1136. display: block;
  1137. }
  1138. ::v-deep .pure-light-node {
  1139. width: 16px;
  1140. height: 16px;
  1141. border-radius: 50%;
  1142. border: 2px solid rgba(255, 255, 255, 0.8);
  1143. cursor: pointer;
  1144. transition: all 0.3s;
  1145. display: flex;
  1146. justify-content: center;
  1147. align-items: center;
  1148. color: #fff;
  1149. pointer-events: auto;
  1150. }
  1151. ::v-deep .pure-light-node.route-node {
  1152. position: relative;
  1153. overflow: visible;
  1154. }
  1155. ::v-deep .pure-light-node.route-node::after {
  1156. content: "";
  1157. position: absolute;
  1158. top: 50%;
  1159. left: 50%;
  1160. width: 150%;
  1161. height: 3px;
  1162. background-color: inherit;
  1163. opacity: 0.8;
  1164. transform: translate(-50%, -50%) rotate(-45deg);
  1165. pointer-events: none;
  1166. }
  1167. ::v-deep .pure-light-node.route-node span {
  1168. position: relative;
  1169. z-index: 1;
  1170. }
  1171. /* 异常状态增加稍微剧烈一点的呼吸感,但缩小范围 */
  1172. @keyframes light-breathe {
  1173. 0% {
  1174. transform: scale(0.9);
  1175. opacity: 0.8;
  1176. }
  1177. 50% {
  1178. transform: scale(1.1);
  1179. opacity: 1;
  1180. }
  1181. 100% {
  1182. transform: scale(0.9);
  1183. opacity: 0.8;
  1184. }
  1185. }
  1186. /* 首页展示时,如果觉得还是太密,可以给非异常节点降权 */
  1187. ::v-deep .pure-light-node:not(.abnormal-node) {
  1188. border: 1px solid rgba(255, 255, 255, 0.4);
  1189. }
  1190. </style>