device.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import ajax from '../../util/ajax'
  2. import api from '../../util/api'
  3. export default {
  4. namespaced: true,
  5. state: {
  6. deviceList: [],
  7. deviceInfo: {},
  8. },
  9. mutations: {
  10. updateList (state, payload) {
  11. state.deviceList = payload || []
  12. },
  13. updateInfo (state, payload) {
  14. state.deviceInfo = payload || {}
  15. },
  16. },
  17. actions: {
  18. bindKeyer ({ commit }, payload) {
  19. return new Promise((resolve, reject) => {
  20. ajax(api.caseManager.bindKey.url, {
  21. method: api.caseManager.bindKey.method,
  22. urlData: { ...payload },
  23. }).then(res => {
  24. resolve(res)
  25. }).catch(reject)
  26. })
  27. },
  28. getKeyList ({ commit }, payload) {
  29. return new Promise((resolve, reject) => {
  30. ajax(api.caseManager.getKeyListById.url, {
  31. method: api.caseManager.getKeyListById.method,
  32. queryData: { ...payload },
  33. }).then(res => {
  34. resolve(res)
  35. }).catch(reject)
  36. })
  37. },
  38. GetDeviceList ({ commit }, payload) {
  39. return new Promise((resolve, reject) => {
  40. ajax(api.device.list.url, {
  41. method: api.device.list.method,
  42. queryData: { ...payload }
  43. }).then(res => {
  44. commit('updateList', res)
  45. resolve(res)
  46. }).catch(reject)
  47. })
  48. },
  49. GetDeviceByID ({ commit }, { deviceid }) {
  50. ajax(api.device.info.url, {
  51. method: api.device.info.method,
  52. urlData: {
  53. id: deviceid,
  54. }
  55. }).then(res => {
  56. commit('updateInfo', res)
  57. })
  58. },
  59. AddDevice ({ commit }, payload) {
  60. return new Promise((resolve, reject) => {
  61. ajax(api.device.add.url, {
  62. method: api.device.add.method,
  63. data: {
  64. ...payload
  65. }
  66. }).then(res => {
  67. commit('updateInfo', res)
  68. resolve(res)
  69. }).catch(reject)
  70. })
  71. },
  72. UpdateDevice ({ commit }, payload) {
  73. return new Promise((resolve, reject) => {
  74. ajax(api.device.update.url, {
  75. method: api.device.update.method,
  76. data: {
  77. ...payload
  78. }
  79. }).then(res => {
  80. resolve(res)
  81. }).catch(reject)
  82. })
  83. },
  84. DelDevice ({ commit }, { id, callback }) {
  85. ajax(api.device.delete.url, {
  86. method: api.device.delete.method,
  87. urlData: {
  88. id: id,
  89. }
  90. }).then(res => {
  91. callback()
  92. })
  93. },
  94. SetDeviceNull ({ commit }) {
  95. commit('updateInfo', {})
  96. },
  97. UpdateInfo ({ commit }, info) {
  98. commit('updateInfo', info)
  99. },
  100. }
  101. }