| | |
| | | |
| | | <script> |
| | | import { deviceList } from '@/constant/device-type'; |
| | | import { mapStores } from 'pinia'; |
| | | import { useDeviceStore } from '@/stores/device'; |
| | | |
| | | export default { |
| | | props: { |
| | |
| | | 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) { |
| | | 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() { |
| | | if (this.deviceStore.deviceList.length == 0) { |
| | | this.fetchDevice(); |
| | | } else { |
| | | this.handleChange(this.deviceOptions[0].value); |
| | | } |
| | | } |
| | | }; |
| | | </script> |
| | | <style scoped></style> |