device.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import request from '@/utils/request'
  2. import {
  3. add,
  4. update,
  5. del,
  6. confirm,
  7. messageSend,
  8. send,
  9. confirmAndSend
  10. } from './base'
  11. export function getRatios () {
  12. return request({
  13. url: '/device/resolutionRatio',
  14. method: 'GET'
  15. }).then(({ data }) => {
  16. return {
  17. data: Object.keys(data).map(key => {
  18. return {
  19. value: key,
  20. label: key,
  21. devices: data[key].map(device => device.name).join(', ')
  22. }
  23. })
  24. }
  25. })
  26. }
  27. export function addDevice (data) {
  28. return add({
  29. url: '/device',
  30. method: 'POST',
  31. data
  32. })
  33. }
  34. export function updateDevice (data) {
  35. return update({
  36. url: '/device',
  37. method: 'put',
  38. data
  39. })
  40. }
  41. export function deleteDevice ({ id, name }) {
  42. return send({
  43. url: `/device/${id}/standbyDevice`,
  44. method: 'GET',
  45. params: { pageNum: 1, pageSize: 1 }
  46. }).then(({ data }) => {
  47. return confirm(data.length
  48. ? `删除主设备 ${name} 后备份设备也将删除,确定删除?`
  49. : `确定删除 ${name}?`
  50. ).then(() => messageSend({
  51. url: `/device/${id}`,
  52. method: 'DELETE'
  53. }, '删除'))
  54. })
  55. }
  56. export function getDevices (query) {
  57. const { pageNum: pageIndex, pageSize, ...params } = query
  58. return request({
  59. url: '/device/list',
  60. method: 'GET',
  61. params: {
  62. pageIndex, pageSize,
  63. ...params
  64. }
  65. })
  66. }
  67. export function activateDevice ({ id, name }) {
  68. return confirmAndSend('激活', name, {
  69. url: '/device/batch/activate',
  70. method: 'put',
  71. data: [id]
  72. })
  73. }
  74. export function deactivateDevice ({ id, name }) {
  75. return confirmAndSend('停用', name, {
  76. url: '/device/batch/deactivate',
  77. method: 'put',
  78. data: [id]
  79. })
  80. }
  81. export function getDevice (id) {
  82. return request({
  83. url: `/device/${id}`,
  84. method: 'GET'
  85. })
  86. }
  87. export function getSubDevices (query) {
  88. const { id, pageNum: pageIndex, pageSize, ...params } = query
  89. return request({
  90. url: `/device/${id}/standbyDevice`,
  91. method: 'GET',
  92. params: {
  93. pageIndex, pageSize,
  94. ...params
  95. }
  96. })
  97. }
  98. export function addSubDevice ({ id }, data) {
  99. return add({
  100. url: `/device/${id}/addStandby`,
  101. method: 'POST',
  102. data
  103. })
  104. }
  105. export function addProductType (data) {
  106. return add({
  107. url: '/productType',
  108. method: 'POST',
  109. data
  110. })
  111. }
  112. export function updateProductType (data) {
  113. return update({
  114. url: '/productType',
  115. method: 'put',
  116. data
  117. })
  118. }
  119. export function deleteProductType ({ id, name }) {
  120. return del({
  121. url: `/productType/${id}`,
  122. method: 'DELETE'
  123. }, name)
  124. }
  125. export function getProductTypes (query) {
  126. const { pageNum: pageIndex, pageSize, ...params } = query
  127. return request({
  128. url: '/productType/list',
  129. method: 'GET',
  130. params: {
  131. pageIndex, pageSize,
  132. ...params
  133. }
  134. })
  135. }
  136. export function addProduct (data) {
  137. return add({
  138. url: '/product',
  139. method: 'POST',
  140. data
  141. })
  142. }
  143. export function updateProduct (data) {
  144. return update({
  145. url: '/product',
  146. method: 'put',
  147. data
  148. })
  149. }
  150. export function deleteProduct ({ id, name }) {
  151. return del({
  152. url: `/product/${id}`,
  153. method: 'DELETE'
  154. }, name)
  155. }
  156. export function getProducts (query) {
  157. const { pageNum: pageIndex, pageSize, ...params } = query
  158. return request({
  159. url: '/product/list',
  160. method: 'GET',
  161. params: {
  162. pageIndex, pageSize,
  163. ...params
  164. }
  165. })
  166. }
  167. export function addDeviceGroup (data) {
  168. return add({
  169. url: '/deviceGroup',
  170. method: 'POST',
  171. data
  172. })
  173. }
  174. export function updateDeviceGroup (data) {
  175. return update({
  176. url: '/deviceGroup',
  177. method: 'put',
  178. data
  179. })
  180. }
  181. export function deleteDeviceGroup ({ id, name }) {
  182. return del({
  183. url: `/deviceGroup/${id}`,
  184. method: 'DELETE'
  185. }, name)
  186. }
  187. export function getDeviceGroups (query) {
  188. const { pageNum: pageIndex, pageSize, ...params } = query
  189. return request({
  190. url: '/deviceGroup/list',
  191. method: 'GET',
  192. params: {
  193. pageIndex, pageSize,
  194. ...params
  195. }
  196. })
  197. }
  198. export function getDevicesByGroup (id) {
  199. return request({
  200. url: `/deviceGroup/${id}/device`,
  201. method: 'GET'
  202. })
  203. }
  204. export function getDeviceTree () {
  205. return request({
  206. url: '/deviceGroup/deviceTree',
  207. method: 'GET'
  208. })
  209. }
  210. export function addDeviceToGroup (id, deviceId) {
  211. return add({
  212. url: `/deviceGroup/${id}/device`,
  213. method: 'POST',
  214. data: [].concat(deviceId)
  215. })
  216. }
  217. export function deleteDeviceFromGroup (id, { id: deviceId, name }) {
  218. return confirmAndSend('移除', name, {
  219. url: `/deviceGroup/${id}/device`,
  220. method: 'DELETE',
  221. params: { deviceId }
  222. })
  223. }
  224. export function getDeviceStatistics (productId) {
  225. return request({
  226. url: '/device/listDeviceTotal',
  227. method: 'GET',
  228. params: { productId }
  229. })
  230. }
  231. export function getDeviceAlarms (query) {
  232. const { pageNum: pageIndex, pageSize, ...params } = query
  233. return request({
  234. url: '/deviceException/list',
  235. method: 'GET',
  236. params: {
  237. pageIndex, pageSize,
  238. ...params
  239. }
  240. })
  241. }