From 306ef09707d6bcf9ffa67de55f86ab6f4362deee Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 18 七月 2025 10:04:01 +0800
Subject: [PATCH] 2025.7.18 动态溯源-测试版本

---
 src/components/search/OptionDevice.vue |   41 ++++++++++++++++++++++++++++++++++++-----
 1 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/src/components/search/OptionDevice.vue b/src/components/search/OptionDevice.vue
index 2ba1468..093e7b8 100644
--- a/src/components/search/OptionDevice.vue
+++ b/src/components/search/OptionDevice.vue
@@ -18,36 +18,67 @@
 </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: {
     type: String,
     modelValue: String
   },
-  emits: ['update:modelValue'],
+  emits: ['update:modelValue', 'initOver'],
   data() {
     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);
+          this.$emit('initOver');
+        }
+      });
+    },
+    // 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);
+      this.$emit('initOver');
+    }
   }
 };
 </script>

--
Gitblit v1.9.3