import { getMachineStatusByWorkshopId } from '../../api/MdcApi'
|
import Vue from 'vue'
|
|
const workshopDevice = {
|
state: {
|
deviceList: []
|
},
|
getters: {
|
},
|
mutations: {
|
/**
|
* 房间内设备状态信息
|
* @param state
|
* @param params { type,index,value } type - 设备类型 index - 设备数组角标 value - 数据
|
* @constructor
|
*/
|
SET_ROOM_DEVICE_STATUS(state, params) {
|
// 复制数据状态到 state
|
// console.log(params)
|
const temp = params || {}
|
const tempList = []
|
for (const prop in state) {
|
if (state.hasOwnProperty(prop)) {
|
Vue.delete(state, prop)
|
}
|
}
|
for (const prop in temp) {
|
if (temp.hasOwnProperty(prop)) {
|
// state[prop] = temp[prop]
|
Vue.set(state, prop, temp[prop])
|
}
|
// 创建设备列表
|
for (let i = 0; i < temp[prop].length; i++) {
|
const item = temp[prop][i]
|
item.type = prop
|
tempList.push(item)
|
}
|
}
|
Vue.set(state, 'deviceList', tempList)
|
}
|
},
|
actions: {
|
/**
|
* 获取指定车间内的机床状态
|
* @param commit
|
* @param workshopId
|
* @return {Promise<any>}
|
* @constructor
|
*/
|
GetMachineStatusByWorkshopId({ commit }, workshopId) {
|
return new Promise((resolve, reject) => {
|
getMachineStatusByWorkshopId(workshopId).then(res => {
|
commit('SET_ROOM_DEVICE_STATUS', res)
|
}).catch(error => {
|
reject(error)
|
})
|
})
|
}
|
}
|
}
|
export default workshopDevice
|