Przeglądaj źródła

fix(layer): 修复地名显示和数值格式化问题

王杰 2 tygodni temu
rodzic
commit
34708629cb

+ 11 - 3
src/views/components/layerList/index.vue

@@ -96,8 +96,8 @@ export default {
                label: '支流入渭口',
                children: [
                  { id: '1-5-1', label: '黑河入渭口', meta: { type: 'point', url: '/sddnWeihe/geojson/黑河入口.geojson' } },
-                 { id: '1-5-2', label: '耿峪河入渭口', meta: { type: 'point', url: '/sddnWeihe/geojson/大耿峪河入口.geojson' } },
-                 { id: '1-5-3', label: '河入渭口', meta: { type: 'point', url: '/sddnWeihe/geojson/捞河入口.geojson' } }
+                 { id: '1-5-2', label: '耿峪河入渭口', meta: { type: 'point', url: '/sddnWeihe/geojson/大耿峪河入口.geojson' } },
+                 { id: '1-5-3', label: '河入渭口', meta: { type: 'point', url: '/sddnWeihe/geojson/捞河入口.geojson' } }
                ]
              }
           ]
@@ -348,12 +348,20 @@ export default {
         }
       } else if (name === '连霍高速G30与河堤路交接桥站' || name === '兴武排洪渠与河堤路交界站') {
         const ptStyle = this.getPointStyle(name)
+        // 根据站点名称映射对应的ID
+        let stationId = null
+        if (name === '连霍高速G30与河堤路交接桥站') {
+          stationId = 18
+        } else if (name === '兴武排洪渠与河堤路交界站') {
+          stationId = 19
+        }
         return {
           type: 'billboard',
           styleOptions: {
             image: require('./image/水文站.png'),
             ...ptStyle
-          }
+          },
+          stationId: stationId  // 添加站点ID
         }
       } else if (name.indexOf('排口') > -1) {
         const ptStyle = this.getPointStyle(name)

+ 0 - 3
src/views/hydrologic-info/right.vue

@@ -323,9 +323,6 @@ export default {
               {
                 type: 'value',
                 splitLine: { show: false },
-                min: 380,
-                interval: 10,
-                max: 420,
                 axisLine: {
                   lineStyle: {
                     color: '#374672',

+ 5 - 6
src/views/sand-monitor/right.vue

@@ -127,15 +127,14 @@ export default {
       return (Math.random() * 18 + 20).toFixed(1) + 'T';
     };
 
-    // 生成本周内的随机日期
+    // 生成当前日期前7天内的随机日期
     const generateDateInWeek = () => {
       const today = new Date();
-      const dayOfWeek = today.getDay();
-      const startDate = new Date(today);
-      startDate.setDate(today.getDate() - dayOfWeek);
 
-      const randomDate = new Date(startDate);
-      randomDate.setDate(startDate.getDate() + Math.floor(Math.random() * 7));
+      // 生成当前日期前7天内的随机日期(包括今天)
+      const randomDate = new Date();
+      const randomDaysAgo = Math.floor(Math.random() * 7);
+      randomDate.setDate(today.getDate() - randomDaysAgo);
 
       return randomDate.getFullYear() + '.' +
              String(randomDate.getMonth() + 1).padStart(2, '0') + '.' +

+ 75 - 27
src/views/water-station-popup/index.vue

@@ -16,21 +16,21 @@
               <el-col :span="8" class="label-col">
                 <div class="label">实时高程:</div>
                 <div class="value">
-                  <span>{{ swInfo.realTimeElevation }}</span
+                  <span>{{ swInfo.realTimeElevation !== undefined ? parseFloat(swInfo.realTimeElevation).toFixed(2) : '' }}</span
                   ><span>m</span>
                 </div>
               </el-col>
               <el-col :span="8" class="label-col">
                 <div class="label">昨日雨量:</div>
                 <div class="value">
-                  <span>{{ swInfo.precipitationYesterday }}</span
+                  <span>{{ swInfo.precipitationYesterday !== undefined ? parseFloat(swInfo.precipitationYesterday).toFixed(2) : '' }}</span
                   ><span>mm</span>
                 </div>
               </el-col>
               <el-col :span="8" class="label-col">
                 <div class="label">实时流量:</div>
                 <div class="value">
-                  <span>{{ swInfo.realTimeDischarge }}</span
+                  <span>{{ swInfo.realTimeDischarge !== undefined ? parseFloat(swInfo.realTimeDischarge).toFixed(2) : '' }}</span
                   ><span>m³/s</span>
                 </div>
               </el-col>
@@ -39,21 +39,21 @@
               <el-col :span="8" class="label-col">
                 <div class="label">昨日最高:</div>
                 <div class="value">
-                  <span>{{ swInfo.maxElevationYesterday }}</span
+                  <span>{{ swInfo.maxElevationYesterday !== undefined ? parseFloat(swInfo.maxElevationYesterday).toFixed(2) : '' }}</span
                   ><span>m</span>
                 </div>
               </el-col>
               <el-col :span="8" class="label-col">
                 <div class="label">当天雨量:</div>
                 <div class="value">
-                  <span>{{ swInfo.precipitationToday }}</span
+                  <span>{{ swInfo.precipitationToday !== undefined ? parseFloat(swInfo.precipitationToday).toFixed(2) : '' }}</span
                   ><span>mm</span>
                 </div>
               </el-col>
               <el-col :span="8" class="label-col">
                 <div class="label">实时流速:</div>
                 <div class="value">
-                  <span>{{ swInfo.realTimeVelocity }}</span
+                  <span>{{ swInfo.realTimeVelocity !== undefined ? parseFloat(swInfo.realTimeVelocity).toFixed(2) : '' }}</span
                   ><span>m³/s</span>
                 </div>
               </el-col>
@@ -151,19 +151,32 @@ export default {
     this.$globalEventBus.$on('clickWaterStation', (data) => {
       this.chartShow = false
       this.visible = true
-      if (data.layer.id == '2-2') {
-        this.getMonitoringStatistics(19)
+      // 从图层属性中获取站点ID,而不是硬编码
+      const stationId = data.layer.options.stationId
+      if (stationId) {
+        this.getMonitoringStatistics(stationId)
       } else {
-        this.getMonitoringStatistics(18)
+        // 如果没有找到站点ID,尝试从图层ID映射获取
+        let mappedId = null
+        if (data.layer.id == '2-2') {
+          mappedId = 19
+        } else if (data.layer.id == '2-1') {
+          mappedId = 18
+        }
+        if (mappedId) {
+          this.getMonitoringStatistics(mappedId)
+        }
       }
       this.stationGraphic = data.graphic
       this.title = data.layer.options.name
     })
   },
   destroyed() {
-    this.stopTimer()
+    this.stopTimer() // 停止所有定时器
     this.$globalEventBus.$off('clickWaterStation')
-    window.map.removeLayer(graphicsLayer)
+    if (graphicsLayer) {
+      window.map.removeLayer(graphicsLayer)
+    }
     this.graphicsLayer = null
   },
   methods: {
@@ -181,22 +194,49 @@ export default {
           this.chartShow = true
           if (res.data) {
             this.swInfo = res.data.info
+            // 格式化数值字段,保留2位小数
+            if (this.swInfo.realTimeElevation !== undefined) {
+              this.swInfo.realTimeElevation = parseFloat(this.swInfo.realTimeElevation).toFixed(2);
+            }
+            if (this.swInfo.realTimeDischarge !== undefined) {
+              this.swInfo.realTimeDischarge = parseFloat(this.swInfo.realTimeDischarge).toFixed(2);
+            }
+            if (this.swInfo.realTimeVelocity !== undefined) {
+              this.swInfo.realTimeVelocity = parseFloat(this.swInfo.realTimeVelocity).toFixed(2);
+            }
+            if (this.swInfo.precipitationYesterday !== undefined) {
+              this.swInfo.precipitationYesterday = parseFloat(this.swInfo.precipitationYesterday).toFixed(2);
+            }
+            if (this.swInfo.maxElevationYesterday !== undefined) {
+              this.swInfo.maxElevationYesterday = parseFloat(this.swInfo.maxElevationYesterday).toFixed(2);
+            }
+            if (this.swInfo.precipitationToday !== undefined) {
+              this.swInfo.precipitationToday = parseFloat(this.swInfo.precipitationToday).toFixed(2);
+            }
             this.startTimer('realTimeElevation',{
               value: this.swInfo.realTimeElevation,
               callback: (newValue, amount, isIncrement) => {
-                this.swInfo.realTimeElevation = newValue
+                this.swInfo.realTimeElevation = parseFloat(newValue).toFixed(2)
               }
             })
             this.startTimer('realTimeDischarge',{
               value: this.swInfo.realTimeDischarge,
               callback: (newValue, amount, isIncrement) => {
-                this.swInfo.realTimeDischarge = newValue
+                this.swInfo.realTimeDischarge = parseFloat(newValue).toFixed(2)
               }
             })
              this.startTimer('realTimeVelocity',{
-              value: this.swInfo.realTimeDischarge,
+              value: this.swInfo.realTimeVelocity,
               callback: (newValue, amount, isIncrement) => {
-                this.swInfo.realTimeVelocity = (this.swInfo.realTimeVelocity + Math.random() * 0.2).toFixed(2);
+                const increment = Math.random() > 0.5;
+                const changeAmount = Math.random() * 0.2;
+                let newVelocity;
+                if (increment) {
+                  newVelocity = parseFloat(this.swInfo.realTimeVelocity) + changeAmount;
+                } else {
+                  newVelocity = Math.max(0, parseFloat(this.swInfo.realTimeVelocity) - changeAmount); // 防止负数
+                }
+                this.swInfo.realTimeVelocity = newVelocity.toFixed(2);
               }
             })
             const option = {
@@ -252,9 +292,6 @@ export default {
                 {
                   type: 'value',
                   splitLine: { show: false },
-                  min: 380,
-                  interval: 10,
-                  max: 420,
                   axisLine: {
                     lineStyle: {
                       color: '#374672',
@@ -311,15 +348,16 @@ export default {
         } = config || {}
         this.timer[valueKey] = setInterval(() => {
           const increment = Math.random() > 0.5 
-          const amount = (Math.random() * 0.04).toFixed(2) + 0.01 
+          const amount = (Math.random() * 0.04 + 0.01).toFixed(2);
           let newValue = null
           if (increment) {
-            newValue = (parseFloat(value) + parseFloat(amount)).toFixed(2) 
+            newValue = (parseFloat(value) + parseFloat(amount)).toFixed(2);
           } else {
-            newValue = (parseFloat(value) - parseFloat(amount)).toFixed(2) 
+            // 确保值不会变成负数
+            newValue = Math.max(0, (parseFloat(value) - parseFloat(amount))).toFixed(2);
           }
           if (callback && typeof callback === 'function') {
-            callback(newValue, amount, increment)
+            callback(newValue, amount, increment);
           }
         }, 5000)
       }else{
@@ -327,10 +365,20 @@ export default {
       }
     },
     stopTimer(valueKey) {
-      if (this.timer[valueKey]) {
-        // 确保定时器已启动
-        clearInterval(this.timer[valueKey]) // 停止定时器
-        this.timer = null // 清除定时器引用
+      if (valueKey) {
+        // 停止特定的定时器
+        if (this.timer[valueKey]) {
+          clearInterval(this.timer[valueKey])
+          this.timer[valueKey] = null
+        }
+      } else {
+        // 停止所有定时器
+        Object.keys(this.timer).forEach(key => {
+          if (this.timer[key]) {
+            clearInterval(this.timer[key])
+          }
+        })
+        this.timer = {}
       }
     },
     getAroundAnalysisOwnList() {
@@ -369,7 +417,7 @@ export default {
       this.artShow = false
       this.flyToPoint(row)
        getVideoRealtimeUrl({
-              deviceCode: row.deviceCode,
+            deviceCode: row.deviceCode,
             channelCode: row.channelCode,
             netType: 2,
             protocolType:9,