You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import { getDevices, getDevicesAll } from 'apis/index';
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
namespaced: true,
|
|
|
|
|
|
|
|
state: {
|
|
|
|
devices: [], // 站点列表 设备列表简版
|
|
|
|
devicesAll: null, // 设备列表完整版
|
|
|
|
currentDeviceId: '', // 当前正在编辑的设备deviceId
|
|
|
|
},
|
|
|
|
|
|
|
|
getters: {
|
|
|
|
// 当前正在编辑的设备的完整信息
|
|
|
|
current({ devicesAll, currentDeviceId }) {
|
|
|
|
try {
|
|
|
|
return devicesAll.data.find(device => device.deviceId === currentDeviceId);
|
|
|
|
} catch (error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
mutations: {
|
|
|
|
/**
|
|
|
|
* 设置devices数据
|
|
|
|
* @param {*} state
|
|
|
|
* @param {array} devices
|
|
|
|
*/
|
|
|
|
setDevices(state, devices) {
|
|
|
|
state.devices = devices;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 设置devicesAll的数据
|
|
|
|
* @param {*} state
|
|
|
|
* @param {array} devices
|
|
|
|
*/
|
|
|
|
setDevicesAll(state, devices) {
|
|
|
|
state.devicesAll = devices;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 设置正则编辑的设备deviceId
|
|
|
|
* @param {*} state
|
|
|
|
* @param {string} deviceId
|
|
|
|
*/
|
|
|
|
setCurrentDeviceId(state, deviceId) {
|
|
|
|
state.currentDeviceId = deviceId;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
// 获取设备列表(站点列表)
|
|
|
|
async getDevices({ commit }) {
|
|
|
|
try {
|
|
|
|
const data = await getDevices();
|
|
|
|
commit('setDevices', data || []);
|
|
|
|
return data;
|
|
|
|
} catch (error) {
|
|
|
|
throw new Error(error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// 获取设备列表(站点列表) 完整信息
|
|
|
|
async getDevicesAll({ commit }) {
|
|
|
|
try {
|
|
|
|
const data = await getDevicesAll();
|
|
|
|
commit('setDevicesAll', data || null);
|
|
|
|
return data;
|
|
|
|
} catch (error) {
|
|
|
|
throw new Error(error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default user;
|