api.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import {
  2. AlarmLevelInfo,
  3. SupportedAlarmStrategies
  4. } from '@/constant'
  5. import request from '@/utils/request'
  6. import {
  7. update,
  8. send,
  9. addTenant
  10. } from '@/api/base'
  11. export function getInformStrategy () {
  12. return send({
  13. url: '/tenant/informStrategy',
  14. method: 'GET',
  15. params: addTenant()
  16. }).then(({ data: { strategy } }) => Object.keys(strategy).sort().map(key => {
  17. return {
  18. level: key,
  19. name: AlarmLevelInfo[key],
  20. options: getStrategyOptions(strategy[key])
  21. }
  22. }))
  23. }
  24. function getStrategyOptions (strategy) {
  25. return SupportedAlarmStrategies.map(({ key, label }) => {
  26. return {
  27. key, label,
  28. value: strategy[key]
  29. }
  30. })
  31. }
  32. export function updateInformStrategy (strategy) {
  33. return update({
  34. url: '/tenant/informStrategy',
  35. method: 'POST',
  36. data: addTenant({ strategy })
  37. })
  38. }
  39. export const AUTORESTART = 'autorestart'
  40. export const UNATTEND = 'sensor_power'
  41. export const TEMPERATURE = 'Temperature'
  42. export const DEVIATION = 'Deviation'
  43. export const POWERTYPE = 'target_type'
  44. export function getTenantAttribute (key) {
  45. return send({
  46. url: '/tenant/attribute/query',
  47. method: 'GET',
  48. params: addTenant({ attributeKey: key })
  49. })
  50. }
  51. export function getTenantAttributeByBackground (key) {
  52. return request({
  53. url: '/tenant/attribute/query',
  54. method: 'GET',
  55. params: addTenant({ attributeKey: key })
  56. })
  57. }
  58. export function updateTenantAttribute (key, val) {
  59. return update({
  60. url: '/tenant/attribute/save',
  61. method: 'POST',
  62. data: addTenant({
  63. attributeKey: key,
  64. attributeValue: val
  65. })
  66. })
  67. }
  68. const REFRESH_KEY = 'refresh_online_seconds'
  69. export function getOnlineRefreshInterval () {
  70. return send({
  71. url: '/deviceOnlineInfoDetail/getExceptionOfflineConfig',
  72. method: 'GET'
  73. }).then(({ data }) => {
  74. return { data: data.find(({ paramKey }) => paramKey === REFRESH_KEY) }
  75. })
  76. }
  77. export function updateOnlineRefreshInterval (data) {
  78. return update({
  79. url: '/deviceOnlineInfoDetail/updateExceptionOfflineConfig',
  80. method: 'POST',
  81. data
  82. })
  83. }