57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
|
|
import { deviceInfo } from '#/api/device/device';
|
|
|
|
export const useDeviceStore = defineStore('device', {
|
|
state: () => ({
|
|
currentDevice: {} as any,
|
|
tabActiveKey: 'BasicInfo',
|
|
deviceCount: 0,
|
|
}),
|
|
|
|
getters: {
|
|
getCurrentDevice: (state) => state.currentDevice,
|
|
getTabActiveKey: (state) => state.tabActiveKey,
|
|
getDeviceCount: (state) => state.deviceCount,
|
|
},
|
|
|
|
actions: {
|
|
setCurrent(device: any) {
|
|
this.currentDevice = device;
|
|
},
|
|
|
|
setTabActiveKey(key: string) {
|
|
this.tabActiveKey = key;
|
|
},
|
|
|
|
setDeviceCount(count: number) {
|
|
this.deviceCount = count;
|
|
},
|
|
|
|
updateDeviceStatus(state: string) {
|
|
this.currentDevice.deviceState = state;
|
|
},
|
|
|
|
async getDetail(id: string) {
|
|
try {
|
|
const res = await deviceInfo(id);
|
|
if (res?.productObj?.productParam) {
|
|
res.productParamArray = JSON.parse(res.productObj.productParam) || [];
|
|
}
|
|
this.currentDevice = res;
|
|
|
|
return res;
|
|
} catch (error) {
|
|
console.error('获取设备详情失败:', error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
reset() {
|
|
this.currentDevice = {};
|
|
this.tabActiveKey = 'BasicInfo';
|
|
this.deviceCount = 0;
|
|
},
|
|
},
|
|
});
|