refactor: tryGetDeviceTypeVal
This commit is contained in:
@@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user