import { defineStore } from 'pinia' import { HandDetector, HandDetectorApi } from '@/api/gas/handdetector' import { Type, TypeApi } from '@/api/gas/gastype' import { Fence, FenceApi } from '@/api/gas/fence' import { AlarmType, AlarmTypeApi } from '@/api/gas/alarmtype' export const useHandDetectorStore = defineStore('handDetector', { state() { return { handDetectorList: [] as HandDetector[], gasTypes: [] as Type[], fences: [] as Fence[], alarmTypes: [] as AlarmType[] } }, getters: { getHandDetectorList(): HandDetector[] { return this.handDetectorList }, getGasTypes(): Type[] { return this.gasTypes }, getFences(): Fence[] { return this.fences }, getAlarmTypes(): AlarmType[] { return this.alarmTypes } }, actions: { async getAllHandDetector(refresh: boolean = false) { if (refresh || this.handDetectorList.length === 0) { const data = await HandDetectorApi.getListAll() this.handDetectorList = data return this.handDetectorList } else { return this.handDetectorList } }, async getAllFences(refresh: boolean = false) { if (refresh || this.fences.length === 0) { const data = await FenceApi.getListAll() this.fences = data return this.fences } else { return this.fences } }, async getAllGasTypes(refresh: boolean = false) { if (refresh || this.gasTypes.length === 0) { const data = await TypeApi.getTypePage({ pageNo: 1, pageSize: 100 }) this.gasTypes = data.list return this.gasTypes } else { return this.gasTypes } }, async getAllAlarmTypes(refresh: boolean = false) { if (refresh || this.alarmTypes.length === 0) { const data = await AlarmTypeApi.getAlarmTypePage({ pageNo: 1, pageSize: 100 }) this.alarmTypes = data.list return this.alarmTypes } else { return this.alarmTypes } } } })