Ming vor 4 Jahren
Ursprung
Commit
c67177dbc6
4 geänderte Dateien mit 75 neuen und 34 gelöschten Zeilen
  1. 37 4
      src/components/topHeader.vue
  2. 19 15
      src/pages/gasCard/gasCard.vue
  3. 10 12
      src/pages/index/index.vue
  4. 9 3
      src/store/index.js

+ 37 - 4
src/components/topHeader.vue

@@ -13,6 +13,7 @@
         >
           {{ item.StationName }}
         </option>
+        <option value="ss">ss</option>
         <!-- <option value="">站点一</option>
         <option value="">站点一</option> -->
       </select>
@@ -57,17 +58,37 @@ export default {
     "$store.state.wsInfo"(val) {
       this.messageHandle(val)
     },
+    StationID(val) {
+
+      console.log("watch时候的值");
+      console.log(val);
+
+      //监听testStationId是否发生了变化
+      // console.log('监听testStationId是否发生了变化');
+      this.$store.commit("changeStationID", val);
+
+      console.log("放入store的值");
+      console.log(this.getStationId);
+    },
+  
   },
   created() {
-    this.global.sendWs( { CMD: "getStationInfo" });
+   this.global.sendWs( { CMD: "getStationInfo" });
+
+this.StationID = this.getStationId;
+   
   },
   mounted() {
     this.navs();
   },
-  computed: {},
+  computed: {
+    getStationId(){
+      return this.$store.state.StationID
+    }
+  },
+    
 
 
-  onload() {},
   destroyed() {},
 
   methods: {
@@ -77,7 +98,19 @@ export default {
           // 初始化获取站点下拉数据
           if (redata.CMD == "getStationInfo") {
             this.siteList = redata.RESULT;
-            this.StationID = this.siteList[0].StationID;
+
+            //页面刚初始化时  获取下拉列表的第一个值 放入store里面
+            console.log("created函数里获取store的值=====" + this.getStationId);
+
+            if (!this.getStationId) {
+              console.log("created走没有的逻辑");
+              this.StationID = this.siteList[0].StationID;
+              this.$store.commit("changeStationID", this.StationId);
+            } else {
+              console.log("created走有的逻辑");
+            }
+            
+            
           }
           if (redata.CMD == "getStationDetail") {
             this.homeData = redata.RESULT.LIST;

+ 19 - 15
src/pages/gasCard/gasCard.vue

@@ -29,7 +29,7 @@
                   <th>告警状态</th>
                 </tr>
                 <tr>
-                  <td>{{getData.DeviceType}}</td>
+                  <td>{{ getData.DeviceType }}</td>
                   <td>位置BBBBBB</td>
                   <td>0.00%LEL</td>
                   <td>正常</td>
@@ -69,8 +69,9 @@ export default {
   data() {
     return {
       Inv: 0,
-      DeviceID:'',
-      getData:{}
+      DeviceID: "",
+      getData: {},
+      StationID: "",
     };
   },
   watch: {
@@ -78,30 +79,33 @@ export default {
       this.messageHandle(val);
     },
   },
+  computed: {
+  
+  },
 
   created() {
     this.DeviceID = this.$route.query.DeviceID;
+    this.StationID = this.$store.state.StationID;
+
     console.log("DeviceID");
     console.log(this.DeviceID);
+    this.global.sendWs({
+      CMD: "getDeviceDetail",
+      StationID: this.StationID,
+      // StationID: "7c9c30af-6132-43d1-98fb-020395183094",
+      DeviceID: this.DeviceID,
+    });
+
   },
   methods: {
     messageHandle(e) {
       if (e.data.search("{") != -1) {
         const redata = JSON.parse(e.data);
-        if (redata.CMD == "getStationInfo" && redata.RESULT) {
-          // 如果有站点选项,发送请求获取站点信息页数据
-          this.global.sendWs({
-            CMD: "getDeviceDetail",
-            StationID: "7c9c30af-6132-43d1-98fb-020395183094",
-            DeviceID:  this.DeviceID,
-          });
-        }
+
         if (redata.CMD == "getDeviceDetail") {
-     console.log('redata.RESULT')
-          console.log(redata.RESULT.Device)
+          console.log("redata.RESULT");
+          console.log(redata.RESULT.Device);
           this.getData = redata.RESULT.Device;
-
-        
         }
       }
     },

+ 10 - 12
src/pages/index/index.vue

@@ -63,26 +63,24 @@ export default {
       this.messageHandle(val);
     },
   },
-  created() {},
+  created() {
+
+    // 如果有站点选项,发送请求获取站点信息页数据
+           this.StationID = this.$store.state.StationID;
+          this.global.sendWs({
+            CMD: "getStationDetail",
+            StationID:  this.StationID,
+          });
+  },
   methods: {
     messageHandle(e) {
       if (e.data.search("{") != -1) {
    
         const redata = JSON.parse(e.data);
-        // this.StationID = redata.RESULT[0].StationID;
         
-        if (redata.CMD == "getStationInfo" && redata.RESULT) {
-          
-
-          // 如果有站点选项,发送请求获取站点信息页数据
-          this.global.sendWs({
-            CMD: "getStationDetail",
-            StationID: "7c9c30af-6132-43d1-98fb-020395183094",
-          });
-        }
         if (redata.CMD == "getStationDetail") {
           this.homeData = redata.RESULT.LIST;
-          // console.log('redata')
+          console.log('redata')
           // console.log(redata)
           console.log(this.homeData);
         }

+ 9 - 3
src/store/index.js

@@ -5,11 +5,17 @@ Vue.use(Vuex)
 
 export default new Vuex.Store({
     state: {
-        wsInfo: null
+        wsInfo: null,
+        StationID: ''
     },
     mutations: {
         wsInfoMiT(state, val) {
             state.wsInfo = val
-        }
-    }
+        },
+        changeStationID(state, val) {
+            state.StationID = val
+        },
+    },
+
+
 })