refactor: tryGetDeviceTypeVal

This commit is contained in:
yangsy
2025-09-30 15:09:12 +08:00
parent 97bf9855c7
commit d0adb869da
11 changed files with 68 additions and 25 deletions

View File

@@ -1,11 +1,27 @@
import type { NdmDeviceResultVO } from '@/apis/models';
import type { LineDevices } from '@/composables/query';
import { tryGetDeviceTypeVal } from '@/enums/device-type';
import { defineStore } from 'pinia';
import { ref } from 'vue';
export const useLineDevicesStore = defineStore('ndm-line-devices-store', () => {
const lineDevices = ref<LineDevices>({});
const patch = (stationCode: string, device: NdmDeviceResultVO) => {
const deviceTypeVal = tryGetDeviceTypeVal(device.deviceType);
if (!!deviceTypeVal) {
if (lineDevices.value[stationCode]) {
const index = lineDevices.value[stationCode][deviceTypeVal].findIndex((d) => d.id === device.id);
if (index > -1) {
lineDevices.value[stationCode][deviceTypeVal][index] = device;
}
}
}
};
return {
lineDevices,
patch,
};
});