From d205764a3ebe073b8302e8faf9345b74ae3350df Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 11 十一月 2024 17:12:35 +0800
Subject: [PATCH] 优化初始化进入界面时,默认监测因子选项为PM颗粒物等常用因子

---
 src/components/search/OptionDevice.vue |   37 +++++++++++++++++++++++++++++++++----
 1 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/components/search/OptionDevice.vue b/src/components/search/OptionDevice.vue
index 2ba1468..a6d3c47 100644
--- a/src/components/search/OptionDevice.vue
+++ b/src/components/search/OptionDevice.vue
@@ -18,7 +18,9 @@
 </template>
 
 <script>
-import { deviceList } from '@/constant/device-type';
+// import { deviceList } from '@/constant/device-type';
+import { mapStores } from 'pinia';
+import { useDeviceStore } from '@/stores/device';
 
 export default {
   props: {
@@ -30,24 +32,51 @@
     return {};
   },
   computed: {
+    ...mapStores(useDeviceStore),
     deviceOptions() {
-      return deviceList(this.type);
+      return this.deviceStore.getDevice(this.type).map((v) => {
+        return {
+          label: v.deviceName,
+          value: v.deviceCode
+        };
+      });
     }
   },
   watch: {
+    // type(nV, oV) {
+    //   if (nV != oV) {
+    //     this.refreshOptions();
+    //   }
+    // }
     deviceOptions(nV, oV) {
       if (nV != oV) {
-        this.handleChange(nV[0].value);
+        if (nV.length > 0) {
+          this.handleChange(nV[0].value);
+        }
       }
     }
   },
   methods: {
+    fetchDevice() {
+      this.deviceStore.fetchDevice().then((res) => {
+        if (res.success && res.data.length > 0) {
+          this.handleChange(this.deviceOptions[0].value);
+        }
+      });
+    },
+    // refreshOptions() {
+    //   this.deviceOptions =
+    // },
     handleChange(value) {
       this.$emit('update:modelValue', value);
     }
   },
   mounted() {
-    this.handleChange(this.deviceOptions[0].value);
+    if (this.deviceStore.deviceList.length == 0) {
+      this.fetchDevice();
+    } else {
+      this.handleChange(this.deviceOptions[0].value);
+    }
   }
 };
 </script>

--
Gitblit v1.9.3