From c35074e0e33054bb6c5ada22f8104422ae953b17 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期五, 21 二月 2025 17:19:04 +0800 Subject: [PATCH] 1. 新增默认加载时先判断各选项是否获取完成逻辑 --- src/components/search/OptionDevice.vue | 60 ++++++++++++++++++++++++++++++++++++------------------------ 1 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/components/search/OptionDevice.vue b/src/components/search/OptionDevice.vue index 6fc1b0a..0b56362 100644 --- a/src/components/search/OptionDevice.vue +++ b/src/components/search/OptionDevice.vue @@ -8,7 +8,7 @@ class="w-120" > <el-option - v-for="(s, i) in deviceList" + v-for="(s, i) in deviceOptions" :key="i" :label="s.label" :value="s.value" @@ -18,54 +18,66 @@ </template> <script> +// 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: { - deviceList() { - const t = this.type ? this.type : '0a'; - return [1, 2, 3].map((v) => { - const label = `${this.getDeviceType(t)}璁惧${v}鍙穈; - const value = `${t}000000000${v}`; + ...mapStores(useDeviceStore), + deviceOptions() { + return this.deviceStore.getDevice(this.type).map((v) => { return { - label: label, - value: value + label: v.deviceName, + value: v.deviceCode }; }); } }, watch: { - deviceList(nV, oV) { + // 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); - }, - getDeviceType(t) { - switch (t) { - case '0a': - return '杞﹁浇'; - case '0b': - return '鏃犱汉鏈�'; - case '0c': - return '鏃犱汉鑸�'; - default: - return '杞﹁浇'; - } } }, mounted() { - this.handleChange(this.deviceList[0].value); + if (this.deviceStore.deviceList.length == 0) { + this.fetchDevice(); + } else { + this.handleChange(this.deviceOptions[0].value); + } } }; </script> -- Gitblit v1.9.3