device.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. import store from '@/store'
  2. import request, { tenantRequest } from '@/utils/request'
  3. import {
  4. add,
  5. update,
  6. del,
  7. confirm,
  8. messageSend,
  9. send,
  10. confirmAndSend,
  11. addTenant,
  12. addTenantOrOrg,
  13. addUser
  14. } from './base'
  15. import {
  16. AssetType,
  17. SupportedAlarmStrategies
  18. } from '@/constant'
  19. export function getRatiosWithUser () {
  20. return tenantRequest({
  21. url: '/device/resolutionRatio',
  22. method: 'GET',
  23. params: addTenantOrOrg({})
  24. }).then(({ data }) => {
  25. return {
  26. data: Object.keys(data).map(key => {
  27. return {
  28. value: key,
  29. label: `${key} ${data[key].slice(0, 3).map(device => device.name).join(', ')}`
  30. }
  31. })
  32. }
  33. })
  34. }
  35. export function getRatios () {
  36. return tenantRequest({
  37. url: '/device/resolutionRatio',
  38. method: 'GET',
  39. params: addTenant({})
  40. }).then(({ data }) => {
  41. return {
  42. data: Object.keys(data).map(key => {
  43. return {
  44. value: key,
  45. label: key
  46. }
  47. })
  48. }
  49. })
  50. }
  51. export function getTimeline (deviceId, options) {
  52. return request({
  53. url: `/content/deviceCalender/${deviceId}`,
  54. method: 'GET',
  55. ...options
  56. }).then(({ data }) => JSON.parse(data.eventDetail) || [])
  57. }
  58. export function getTimelineByRange (deviceId, startTime, endTime, options) {
  59. return request({
  60. url: `/content/deviceCalender/${deviceId}`,
  61. method: 'GET',
  62. params: {
  63. startTime,
  64. endTime
  65. },
  66. ...options
  67. }).then(({ data }) => JSON.parse(data.eventDetail) || [])
  68. }
  69. export function addDevice (data) {
  70. return add({
  71. url: '/device',
  72. method: 'POST',
  73. data
  74. })
  75. }
  76. export function updateDevice (data) {
  77. return update({
  78. url: '/device',
  79. method: 'PUT',
  80. data
  81. })
  82. }
  83. function deleteDeviceById (id) {
  84. return messageSend({
  85. url: `/device/${id}`,
  86. method: 'DELETE'
  87. }, '删除')
  88. }
  89. export function deleteDevice ({ id, name, masterId }) {
  90. if (__SUB_DEVICE__) {
  91. if (masterId) {
  92. return confirm(`删除备份设备【${name}】?`).then(() => deleteDeviceById(id))
  93. }
  94. return send({
  95. url: `/device/${id}/standbyDevice`,
  96. method: 'GET',
  97. params: { pageNum: 1, pageSize: 1 }
  98. }).then(({ data }) => confirm(
  99. data.length
  100. ? `删除主设备【${name}】后备份设备也将删除`
  101. : `删除设备【${name}】?`
  102. )).then(() => deleteDeviceById(id))
  103. }
  104. return confirm(`删除设备【${name}】?`).then(() => deleteDeviceById(id))
  105. }
  106. // isAttentionFlag 是否带关注标识位,开启值为1
  107. // attentionValue 过滤值,2为不过滤
  108. export function getDevices (query, options) {
  109. return getDevicesByQuery(addTenantOrOrg(query), options)
  110. }
  111. export function getDevicesByQuery (query, options) {
  112. const { tenant, org, ...params } = query
  113. if (tenant || org && org === store.getters.tenant) {
  114. return getDevicesByTenant(tenant || org, params, options)
  115. }
  116. return getDevicesByOrg(org, params, options)
  117. }
  118. export function getDevicesByTenant (tenant, query, options) {
  119. const { pageNum: pageIndex, pageSize, ...params } = query
  120. return tenantRequest({
  121. url: '/device/tenant/page',
  122. method: 'GET',
  123. params: {
  124. tenant,
  125. pageIndex,
  126. pageSize,
  127. ...params
  128. },
  129. ...options
  130. })
  131. }
  132. export function getDevicesByOrg (org, query, options) {
  133. const { pageNum: pageIndex, pageSize, ...params } = query
  134. return tenantRequest({
  135. url: '/device/relation/page',
  136. method: 'GET',
  137. params: {
  138. org,
  139. pageIndex,
  140. pageSize,
  141. ...params
  142. },
  143. ...options
  144. })
  145. }
  146. export function activateDevice ({ id, name }) {
  147. return confirmAndSend('激活', name, {
  148. url: '/device/batch/activate',
  149. method: 'PUT',
  150. data: [id]
  151. })
  152. }
  153. export function deactivateDevice ({ id, name }) {
  154. return confirmAndSend('停用', name, {
  155. url: '/device/batch/deactivate',
  156. method: 'PUT',
  157. data: [id]
  158. })
  159. }
  160. export function getDevice (id) {
  161. return request({
  162. url: `/device/${id}`,
  163. method: 'GET'
  164. })
  165. }
  166. export function getSubDevices (query) {
  167. const { id, pageNum: pageIndex, pageSize, ...params } = query
  168. return request({
  169. url: `/device/${id}/standbyDevice`,
  170. method: 'GET',
  171. params: {
  172. pageIndex, pageSize,
  173. ...params
  174. }
  175. })
  176. }
  177. export function addSubDevice ({ id }, data) {
  178. return add({
  179. url: `/device/${id}/addStandby`,
  180. method: 'POST',
  181. data
  182. })
  183. }
  184. export function addProductType (data) {
  185. return add({
  186. url: '/productType',
  187. method: 'POST',
  188. data
  189. })
  190. }
  191. export function updateProductType (data) {
  192. return update({
  193. url: '/productType',
  194. method: 'put',
  195. data
  196. })
  197. }
  198. export function deleteProductType ({ id, name }) {
  199. return del({
  200. url: `/productType/${id}`,
  201. method: 'DELETE'
  202. }, name)
  203. }
  204. export function getProductTypes (query) {
  205. const { pageNum: pageIndex, pageSize, ...params } = query
  206. return tenantRequest({
  207. url: '/productType/list',
  208. method: 'GET',
  209. params: addTenant({
  210. pageIndex, pageSize,
  211. ...params
  212. })
  213. })
  214. }
  215. export function addProduct (data) {
  216. return add({
  217. url: '/product',
  218. method: 'POST',
  219. data
  220. })
  221. }
  222. export function updateProduct (data) {
  223. return update({
  224. url: '/product',
  225. method: 'put',
  226. data
  227. })
  228. }
  229. export function deleteProduct ({ id, name }) {
  230. return del({
  231. url: `/product/${id}`,
  232. method: 'DELETE'
  233. }, name)
  234. }
  235. export function getProducts (query) {
  236. const { pageNum: pageIndex, pageSize, ...params } = query
  237. return tenantRequest({
  238. url: '/product/list',
  239. method: 'GET',
  240. params: addTenant({
  241. pageIndex, pageSize,
  242. ...params
  243. })
  244. })
  245. }
  246. export function addDeviceGroup (data) {
  247. return add({
  248. url: '/deviceGroup',
  249. method: 'POST',
  250. data
  251. })
  252. }
  253. export function updateDeviceGroup (data) {
  254. return update({
  255. url: '/deviceGroup',
  256. method: 'PUT',
  257. data
  258. })
  259. }
  260. export function deleteDeviceGroup ({ id, name }) {
  261. return del({
  262. url: `/deviceGroup/${id}`,
  263. method: 'DELETE'
  264. }, name)
  265. }
  266. export function getDeviceGroups (query) {
  267. const { pageNum: pageIndex, pageSize, ...params } = query
  268. return tenantRequest({
  269. url: '/deviceGroup/list',
  270. method: 'GET',
  271. params: addUser({
  272. pageIndex, pageSize,
  273. ...params
  274. })
  275. })
  276. }
  277. export function getDevicesByGroup (id) {
  278. return tenantRequest({
  279. url: `/deviceGroup/${id}/device`,
  280. method: 'GET',
  281. params: addTenantOrOrg({})
  282. })
  283. }
  284. export function getDeviceTree () {
  285. return tenantRequest({
  286. url: '/deviceGroup/deviceTree',
  287. method: 'GET',
  288. params: addUser(addTenantOrOrg({}))
  289. })
  290. }
  291. export function addDevicesToGroup (id, deviceIds) {
  292. return add({
  293. url: `/deviceGroup/${id}/device`,
  294. method: 'POST',
  295. data: deviceIds
  296. })
  297. }
  298. export function deleteDeviceFromGroup (id, { id: deviceId, name }) {
  299. return confirmAndSend('移除', name, {
  300. url: `/deviceGroup/${id}/device`,
  301. method: 'DELETE',
  302. params: { deviceId }
  303. })
  304. }
  305. export function getDeviceStatistics () {
  306. return getDeviceStatisticsByPath(store.getters.org)
  307. }
  308. export function getDeviceStatisticsByPath (path, options) {
  309. return tenantRequest({
  310. url: '/device/listDeviceTotal',
  311. method: 'GET',
  312. params: path === store.getters.tenant
  313. ? { tenant: path }
  314. : { org: path },
  315. ...options
  316. })
  317. }
  318. export function getDeviceAlarms (query) {
  319. const { pageNum: pageIndex, pageSize, ...params } = query
  320. return request({
  321. url: '/deviceException/list',
  322. method: 'GET',
  323. params: {
  324. pageIndex, pageSize,
  325. ...params
  326. }
  327. }).then(({ data, totalCount }) => {
  328. return {
  329. data: data.map(({ id, messageId, deviceName, level, pic, picUrl, type, handle, status, happenTime, bugMessage, ...item }) => {
  330. const alarm = {
  331. id, messageId, deviceName, level, happenTime,
  332. file: pic && picUrl
  333. ? {
  334. type: AssetType.IMAGE,
  335. url: picUrl,
  336. origin: true
  337. }
  338. : null,
  339. type: bugMessage || `预警码【${type}】`,
  340. handle: ['应用重启', '设备重启', '恢复出厂', '未干预'][handle] || '-',
  341. status: handle <= 2 && status <= 2
  342. ? {
  343. type: ['primary', 'success', 'danger'][status],
  344. label: ['处理中', '成功', '失败'][status]
  345. }
  346. : { label: '-' }
  347. }
  348. SupportedAlarmStrategies.forEach(({ key }) => {
  349. alarm[key] = getTag(item[key])
  350. })
  351. return alarm
  352. }),
  353. totalCount
  354. }
  355. })
  356. }
  357. function getTag (status) {
  358. switch (status) {
  359. case 0:
  360. return {
  361. type: 'primary',
  362. label: '待发送'
  363. }
  364. case 1:
  365. return {
  366. type: 'success',
  367. label: '已发送'
  368. }
  369. case 2:
  370. return {
  371. type: 'warning',
  372. label: '发送中'
  373. }
  374. case 3:
  375. return {
  376. type: 'danger',
  377. label: '失败'
  378. }
  379. case 4:
  380. return {
  381. type: 'danger',
  382. label: '无目标'
  383. }
  384. case 5:
  385. return {
  386. type: 'warning',
  387. label: '未开启'
  388. }
  389. default:
  390. return null
  391. }
  392. }
  393. export function getUsersByInform ({ messageId }) {
  394. return send({
  395. url: '/deviceException/user/list',
  396. method: 'GET',
  397. params: { messageId }
  398. })
  399. }
  400. export function getTasks (query) {
  401. const { pageNum: pageIndex, pageSize, ...params } = query
  402. return request({
  403. url: '/device/functionTask',
  404. method: 'GET',
  405. params: {
  406. pageIndex, pageSize,
  407. ...params
  408. }
  409. })
  410. }
  411. export function addTask (task) {
  412. return add({
  413. url: '/device/functionTask',
  414. method: 'POST',
  415. data: task
  416. })
  417. }
  418. export function updateTask (task) {
  419. return update({
  420. url: '/device/functionTask',
  421. method: 'PUT',
  422. data: task
  423. })
  424. }
  425. export function deleteTask ({ taskId }) {
  426. return del({
  427. url: `/device/functionTask/${taskId}`,
  428. method: 'DELETE'
  429. })
  430. }
  431. export function activateTask ({ taskId }) {
  432. return confirmAndSend('启用', null, {
  433. url: '/device/functionTask/resume',
  434. method: 'PUT',
  435. data: [taskId]
  436. })
  437. }
  438. export function deactivateTask ({ taskId }) {
  439. return confirmAndSend('停用', null, {
  440. url: '/device/functionTask/pause',
  441. method: 'PUT',
  442. data: [taskId]
  443. })
  444. }
  445. export function getShadow (deviceId) {
  446. return request({
  447. url: `/device/shadow/${deviceId}`,
  448. method: 'GET'
  449. })
  450. }
  451. export function getRecordConfig (deviceId, config) {
  452. return request({
  453. url: '/deviceStream/config',
  454. method: 'GET',
  455. params: { deviceId },
  456. ...config
  457. })
  458. }
  459. export function addRecordConfig (data, config) {
  460. return request({
  461. url: '/deviceStream/config',
  462. method: 'POST',
  463. data,
  464. ...config
  465. })
  466. }
  467. export function updateRecordConfig (data, config) {
  468. return request({
  469. url: '/deviceStream/config',
  470. method: 'PUT',
  471. data,
  472. ...config
  473. })
  474. }
  475. export function authCode (stream, options) {
  476. return request({
  477. url: `/deviceStream/${stream}/authCode`,
  478. method: 'GET',
  479. ...options
  480. })
  481. }
  482. export function addDeviceAttention (deviceId) {
  483. return update({
  484. url: `/device/attention/add/${deviceId}`,
  485. method: 'POST',
  486. data: { deviceId }
  487. }, '关注')
  488. }
  489. export function cancelDeviceAttention (deviceId) {
  490. return update({
  491. url: `/device/attention/cancel/${deviceId}`,
  492. method: 'DELETE'
  493. }, '取关')
  494. }
  495. export function getDeviceAttentionList (options) {
  496. return request({
  497. url: '/device/user/attention/list',
  498. method: 'GET',
  499. ...options
  500. })
  501. }
  502. export function getStatusReport (id, options) {
  503. return request({
  504. url: '/device/screenPower/latestStatusReport',
  505. method: 'POST',
  506. data: { deviceIds: id },
  507. ...options
  508. })
  509. }
  510. export function getDevicesWithPower (params) {
  511. return request({
  512. url: '/device/bond/multiFunction/list',
  513. method: 'GET',
  514. params
  515. })
  516. }
  517. export function getDepartmentDeviceTree (query) {
  518. return tenantRequest({
  519. url: '/admin/department/device/list',
  520. method: 'GET',
  521. params: query
  522. })
  523. }