From 2bb9a863e75312fe90869ea3deea137b46b1bb1e Mon Sep 17 00:00:00 2001 From: haoxuan <haoxuan> Date: 星期一, 06 十一月 2023 17:46:43 +0800 Subject: [PATCH] 拉代码 --- src/views/dashboard/components/DeviceCheckList.vue | 81 ++++++++++++++++++++++++++++------------ 1 files changed, 57 insertions(+), 24 deletions(-) diff --git a/src/views/dashboard/components/DeviceCheckList.vue b/src/views/dashboard/components/DeviceCheckList.vue index 3091543..b63dfe5 100644 --- a/src/views/dashboard/components/DeviceCheckList.vue +++ b/src/views/dashboard/components/DeviceCheckList.vue @@ -4,18 +4,18 @@ <template #title>璁惧閫夋嫨</template> <div class="device-box"> <el-scrollbar always class="scroller"> - <template v-if="devices?.length"> + <template v-if="deviceInfo?.deviceIDList?.length"> <div - v-for="(item, index) in devices" + v-for="(item, index) in deviceInfo?.deviceIDList" :key="index" - :class="item.checked ? 'device-item check-item' : 'device-item'" - @click="deviceClick(index)" + :class="selectedDevice === item ? 'device-item check-item' : 'device-item'" + @click="deviceClick(item)" > <div class="item-l"> - <span>{{ item.number }}</span> - {{ item.name }} + <span>{{ item }}</span> + <!-- {{ item }}--> </div> - <div v-if="item.checked" class="item-r"> + <div v-if="selectedDevice === item" class="item-r"> <el-icon class="item-icon" size="22" color="#00ff00"><CircleCheckFilled /></el-icon> </div> </div> @@ -35,7 +35,11 @@ import { useVModel } from '@vueuse/core' import { CircleCheckFilled } from '@element-plus/icons-vue' import BigButton from '@/views/dashboard/components/BigButton.vue' -import { ref } from 'vue' +import { useDevicesStore } from '@/stores/devices' +import { storeToRefs } from 'pinia' +import { ref, watch } from 'vue' +import { apiSetCurrentDevice } from '@/api' +import { ElMessage } from 'element-plus' export interface DeviceCheckListProps { modelValue: boolean } @@ -45,28 +49,57 @@ const emit = defineEmits<{ 'update:modelValue': [show: boolean] + shouldReload: [] }>() const modelData = useVModel(props, 'modelValue', emit) +const deviceStore = useDevicesStore() +const { deviceInfo } = storeToRefs(deviceStore) -const devices = ref([ - { - number: '111', - name: '璁惧A', - checked: true - }, - { - number: '222', - name: '璁惧b' +// 寮圭獥鎵撳紑鏃惰瀹氬綋鍓嶉�変腑鐨勮澶� +const selectedDevice = ref<string>('') +watch(modelData, () => { + if (modelData.value) { + selectedDevice.value = deviceInfo.value?.currentDeviceID ?? '' } -]) +}) + +function deviceClick(deviceId: string) { + selectedDevice.value = deviceId +} + +function saveModal() { + if (!selectedDevice.value) { + ElMessage({ + message: '璇峰厛閫変腑涓�涓澶�', + type: 'error', + duration: 3 * 1000 + }) + return + } + apiSetCurrentDevice({ currentDeviceID: selectedDevice.value }) + .then(() => { + ElMessage({ + message: '璁惧畾鎴愬姛', + type: 'success', + duration: 2 * 1000 + }) + modelData.value = false + emit('shouldReload') + }) + .catch((err) => { + console.error(err) + ElMessage({ + message: err.msg, + type: 'error', + duration: 3 * 1000 + }) + }) + .finally(() => { + deviceStore.startPollingDevice() + }) +} function closeModal() { modelData.value = false -} -function saveModal() {} -const deviceClick = (index) => { - devices.value.find((ele) => (ele.checked = false)) - - devices.value[index].checked = true } </script> <style scoped lang="scss"> -- Gitblit v1.8.0