yangys
2024-01-13 ea10117a46fbbe7dd831c3816217493d0da01bf9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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