Explorar el Código

新增showYSplitLine/showPhaseOffset/showScanLine/scanLineStart等配置参数;mock接口适配新组件roadSegments数据格式

画安 hace 1 semana
padre
commit
9cdd7ed27c
Se han modificado 2 ficheros con 16 adiciones y 25 borrados
  1. 3 2
      src/components/ui/TrafficTimeSpace.vue
  2. 13 23
      src/mock/api.js

+ 3 - 2
src/components/ui/TrafficTimeSpace.vue

@@ -35,7 +35,8 @@ export default {
     showYSplitLine: { type: Boolean, default: false },
     showPhaseOffset: { type: Boolean, default: true },
     showScanLine: { type: Boolean, default: true },
-    scanLineColor: { type: String, default: 'rgba(255, 60, 60, 0.8)' }
+    scanLineColor: { type: String, default: 'rgba(255, 60, 60, 0.8)' },
+    scanLineStart: { type: Number, default: 0 }
   },
   data() {
     return {
@@ -348,7 +349,7 @@ export default {
 
     startScanLine() {
       this.stopScanLine();
-      this.currentScanX = 0;
+      this.currentScanX = this.maxX * Math.min(1, Math.max(0, this.scanLineStart));
       const step = this.maxX / 100;
       this.scanLineTimer = setInterval(() => {
         this.currentScanX += step;

+ 13 - 23
src/mock/api.js

@@ -645,29 +645,19 @@ export async function apiGetKeyIntersections() {
 
 export async function apiGetTrafficTimeSpace(opts = {}) {
   await delay(300)
-  const { speed = 15, cycle = 120, band = 40, totalTime = 1800 } = opts
-  const intersections = opts.intersections || DB.timeSpaceData.intersections
-  const rawDistances = opts.distances || DB.timeSpaceData.distances
-  // 将不均匀的物理距离归一化为等间距,保证绿波带视觉对齐
-  const step = 500
-  const distances = rawDistances.map((_, i) => i * step)
-  const maxDist = distances[distances.length - 1]
-  const waveData = [], greenData = []
-
-  for (let t = 0; t <= totalTime; t += cycle) {
-    const upKmh = 45 + Math.random() * 10   // 45-55 km/h 随机
-    const downKmh = 45 + Math.random() * 10
-    const upSpd = upKmh / 3.6               // 转 m/s
-    const downSpd = downKmh / 3.6
-    const ds = t + cycle / 2
-    waveData.push({ yBottom: 0, yTop: maxDist, xBL: t, xBR: t + band, xTL: t + maxDist / upSpd, xTR: t + maxDist / upSpd + band, label: Math.round(upKmh) + 'km/h', direction: 'up', speed: Math.round(upKmh) })
-    waveData.push({ yBottom: maxDist, yTop: 0, xBL: ds, xBR: ds + band, xTL: ds + maxDist / downSpd, xTR: ds + maxDist / downSpd + band, label: Math.round(downKmh) + 'km/h', direction: 'down', speed: Math.round(downKmh) })
-    distances.forEach(y => {
-      greenData.push({ y, start: t + y / upSpd, end: t + y / upSpd + band })
-      greenData.push({ y, start: ds + (maxDist - y) / downSpd, end: ds + (maxDist - y) / downSpd + band })
-    })
-  }
-  return ok({ intersections, distances, waveData, greenData })
+  return ok({
+    roadSegments: [
+      { name: '交叉口A', distanceNext: 450, offset: 0 },
+      { name: '交叉口B', distanceNext: 669, offset: 50 },
+      { name: '交叉口C', distanceNext: 1050, offset: 0 },
+      { name: '交叉口D', distanceNext: 0, offset: 0 }
+    ],
+    speedKmh: 38.9,
+    cycle: 100,
+    greenDuration: 40,
+    bandwidth: 31.5,
+    scanLineStart: Math.round(Math.random() * 100) / 100
+  })
 }
 
 // ═══════════════════════════════════════════════════════════════════════