Browse Source

feat(alarm): support department bubble and custom events

Casper Dai 2 years ago
parent
commit
adb5920a55
4 changed files with 146 additions and 72 deletions
  1. 19 33
      src/api/device.js
  2. 14 5
      src/api/user.js
  3. 33 12
      src/views/device/detail/components/DeviceAlarm.vue
  4. 80 22
      src/views/realm/user/Account.vue

+ 19 - 33
src/api/device.js

@@ -362,13 +362,13 @@ export function getDeviceAlarms (query) {
     }
   }).then(({ data, totalCount }) => {
     return {
-      data: data.map(({ id, deviceName, level, pic, picUrl, type, handle, status, happenTime, bugMessage, ...item }) => {
+      data: data.map(({ id, messageId, deviceName, level, pic, picUrl, type, handle, status, happenTime, bugMessage, ...item }) => {
         const alarm = {
-          id, deviceName, level, happenTime,
+          id, messageId, deviceName, level, happenTime,
           file: pic && picUrl
             ? {
               type: AssetType.IMAGE,
-              url: /exception-pic\/.+\/.+/.test(picUrl) ? picUrl.replace('exception-pic/', '') : picUrl,
+              url: picUrl,
               origin: true
             }
             : null,
@@ -382,7 +382,7 @@ export function getDeviceAlarms (query) {
             : { label: '-' }
         }
         SupportedAlarmStrategies.forEach(({ key }) => {
-          alarm[key] = getTag(key, item[key], item[`${key}Address`])
+          alarm[key] = getTag(item[key])
         })
         return alarm
       }),
@@ -391,65 +391,51 @@ export function getDeviceAlarms (query) {
   })
 }
 
-function getTag (key, status, address) {
-  const ignore = !address || address.length === 0
-  const msg = ignore ? null : `目标${address.length}人`
+function getTag (status) {
   switch (status) {
     case 0:
       return {
         type: 'primary',
-        label: '待发送',
-        key,
-        msg,
-        address,
-        ignore
+        label: '待发送'
       }
     case 1:
       return {
         type: 'success',
-        label: '已发送',
-        key,
-        msg,
-        address,
-        ignore
+        label: '已发送'
       }
     case 2:
       return {
         type: 'warning',
-        label: '发送中',
-        key,
-        msg,
-        address,
-        ignore
+        label: '发送中'
       }
     case 3:
       return {
         type: 'danger',
-        label: '失败',
-        key,
-        msg,
-        address,
-        ignore
+        label: '失败'
       }
     case 4:
       return {
         type: 'danger',
-        label: '无目标',
-        key,
-        ignore: true
+        label: '无目标'
       }
     case 5:
       return {
         type: 'warning',
-        label: '未开启',
-        key,
-        ignore: true
+        label: '未开启'
       }
     default:
       return null
   }
 }
 
+export function getUsersByInform ({ messageId }) {
+  return send({
+    url: '/deviceException/user/list',
+    method: 'GET',
+    params: { messageId }
+  })
+}
+
 export function getTasks (query) {
   const { pageNum: pageIndex, pageSize, ...params } = query
   return request({

+ 14 - 5
src/api/user.js

@@ -397,14 +397,14 @@ export function updateUserName (userId, name) {
   }, null, tenantRequest)
 }
 
-export function updateUserInformLevel ({ userId, userName }, informLevel) {
+export function updateUserInformLevel ({ userId, userName }, informLevel, informType = []) {
   let informName = '未知'
   switch (true) {
-    case informLevel >= 1000:
-      informName = `所有${AlarmLevelInfo[informLevel - 1000]}`
+    case informLevel === 9999:
+      informName = '自定义'
       break
     case informLevel >= 0:
-      informName = `部门${AlarmLevelInfo[informLevel - 1000]}`
+      informName = AlarmLevelInfo[informLevel]
       break
     case informLevel === -1:
       informName = '不预警'
@@ -419,11 +419,20 @@ export function updateUserInformLevel ({ userId, userName }, informLevel) {
       userId,
       userName,
       informLevel,
-      informName
+      informName,
+      informType
     })
   }, null, tenantRequest)
 }
 
+export function getUserInforms ({ userId }) {
+  return send({
+    url: '/admin/user/custom',
+    method: 'GET',
+    params: { userId }
+  })
+}
+
 export function migrateUser (data) {
   return tenantRequest({
     url: '/admin/users/temporary/migration',

+ 33 - 12
src/views/device/detail/components/DeviceAlarm.vue

@@ -5,12 +5,11 @@
     :schema="schema"
   >
     <preview-dialog ref="previewDialog" />
-    <c-dialog
-      ref="accountDIalog"
+    <table-dialog
+      ref="accountDialog"
       title="推送目标"
-    >
-      {{ accounts }}
-    </c-dialog>
+      :schema="accountSchema"
+    />
   </schema-table>
 </template>
 
@@ -20,7 +19,10 @@ import {
   SupportedAlarmStrategies
 } from '@/constant'
 import { createListOptions } from '@/utils'
-import { getDeviceAlarms } from '@/api/device'
+import {
+  getDeviceAlarms,
+  getUsersByInform
+} from '@/api/device'
 
 const DeviceAlarmTypes = [
   { value: 1, label: '播控器上下线' },
@@ -50,6 +52,9 @@ export default {
     return {
       options: createListOptions({ deviceId: this.device.id }),
       schema: {
+        listeners: {
+          'row-click': this.showAccounts
+        },
         list: this.getDeviceAlarms,
         filters: [
           { key: 'type', type: 'select', placeholder: '预警类型', options: [
@@ -82,13 +87,26 @@ export default {
             return {
               prop: key,
               label: `${label}通知`,
-              type: 'tag',
-              on: this.showAccounts
+              type: 'tag'
             }
           })
         ]
       },
-      accounts: ''
+      accountSchema: {
+        nonPagination: true,
+        list: this.getUsersByInform,
+        cols: [
+          { prop: 'userName', label: '账号' },
+          ...SupportedAlarmStrategies.map(({ key, label }) => {
+            return {
+              label,
+              type: 'tag',
+              render: ({ [key]: val }) => val ? { type: 'success', label: '已绑定', msg: val } : { type: 'danger', label: '未绑定' },
+              width: null
+            }
+          })
+        ]
+      }
     }
   },
   methods: {
@@ -101,9 +119,12 @@ export default {
     onView ({ file }) {
       this.$refs.previewDialog.show(file)
     },
-    showAccounts (val, { address }) {
-      this.accounts = address?.join(', ')
-      this.$refs.accountDIalog.show()
+    getUsersByInform () {
+      return getUsersByInform(this.$inform)
+    },
+    showAccounts (inform) {
+      this.$inform = inform
+      this.$refs.accountDialog.show()
     }
   }
 }

+ 80 - 22
src/views/realm/user/Account.vue

@@ -65,6 +65,24 @@
         />
       </template>
     </c-dialog>
+    <confirm-dialog
+      ref="eventDialog"
+      title="自定义事件"
+      @confirm="onConfirmEvents"
+    >
+      <el-checkbox-group
+        v-model="selectedEvents"
+        class="l-grid--info mini"
+      >
+        <el-checkbox
+          v-for="item in events"
+          :key="item.id"
+          :label="item.id"
+        >
+          {{ item.label }}
+        </el-checkbox>
+      </el-checkbox-group>
+    </confirm-dialog>
   </schema-table>
 </template>
 
@@ -76,10 +94,39 @@ import {
   addUser,
   updateUserName,
   toggleUser,
-  updateUserInformLevel
+  updateUserInformLevel,
+  getUserInforms
 } from '@/api/user'
 import Settings from './Settings'
 
+const CustomEvents = Object.freeze([
+  { id: 1, level: 0, label: '播控器离线' },
+  { id: 17, level: 2, label: '播控器工作时段离线' },
+  { id: 15, level: 2, label: '播控器人为离线' },
+  { id: 9, level: 0, label: '播控器上线' },
+  { id: 32, level: 2, label: '播控器非工作时段上线' },
+  { id: 40, level: 2, label: '播控器上线失败' },
+  { id: 35, level: 0, label: '接收卡提示性预警' },
+  { id: 2, level: 2, label: '接收卡紧急预警' },
+  { id: 36, level: 2, label: '关闭电源' },
+  { id: 37, level: 2, label: '开启电源' },
+  { id: 0, level: 1, label: '屏幕疑似黑屏' },
+  { id: 13, level: 2, label: '屏幕黑屏' },
+  { id: 10, level: 2, label: '屏幕内容疑似不合规' },
+  // { id: 3, level: 2, label: '屏幕内容不合规(拼接器)' },
+  { id: 11, level: 2, label: '屏幕内容不合规' },
+  { id: 18, level: 0, label: '温度传感器提示告警' },
+  { id: 19, level: 0, label: '温度传感器一级告警' },
+  { id: 20, level: 0, label: '温度传感器二级告警' },
+  { id: 21, level: 1, label: '温度传感器三级告警' },
+  { id: 22, level: 2, label: '温度传感器四级告警' },
+  { id: 23, level: 2, label: '位移传感器报警' },
+  { id: 7, level: 2, label: '屏幕监控摄像头离线' },
+  { id: 8, level: 2, label: '人流监测摄像头离线' },
+  { id: 33, level: 0, label: '屏幕监控摄像头上线' },
+  { id: 34, level: 0, label: '人流监测摄像头上线' }
+])
+
 export default {
   name: 'Account',
   components: {
@@ -124,6 +171,17 @@ export default {
               change: val => this.updateInformLevel(val, data)
             }
           }, [
+            data.informLevel === 9999 && h('i', {
+              slot: 'prefix',
+              staticClass: 'l-flex--row center el-icon-edit u-font-size--md has-active',
+              staticStyle: {
+                height: '100%'
+              },
+              on: { click: e => {
+                e.stopPropagation()
+                this.onEditEvents(data)
+              } }
+            }),
             h('el-option', {
               key: 'none',
               props: {
@@ -135,42 +193,28 @@ export default {
               key: 'info',
               props: {
                 value: 0,
-                label: `部门${AlarmLevelInfo[0]}`
+                label: `${AlarmLevelInfo[0]}及以上`
               }
             }),
             h('el-option', {
               key: 'warning',
               props: {
                 value: 1,
-                label: `部门${AlarmLevelInfo[1]}`
+                label: `${AlarmLevelInfo[1]}及以上`
               }
             }),
             h('el-option', {
               key: 'error',
               props: {
                 value: 2,
-                label: `部门${AlarmLevelInfo[2]}`
-              }
-            }),
-            h('el-option', {
-              key: 'tinfo',
-              props: {
-                value: 1000,
-                label: `所有${AlarmLevelInfo[0]}`
-              }
-            }),
-            h('el-option', {
-              key: 'twarning',
-              props: {
-                value: 1001,
-                label: `所有${AlarmLevelInfo[1]}`
+                label: AlarmLevelInfo[2]
               }
             }),
             h('el-option', {
               key: 'terror',
               props: {
-                value: 1002,
-                label: `所有${AlarmLevelInfo[2]}`
+                value: 9999,
+                label: AlarmLevelInfo[9999]
               }
             })
           ]) },
@@ -186,7 +230,9 @@ export default {
         ]
       },
       user: {},
-      treeProps: { label: 'name', children: 'children' }
+      treeProps: { label: 'name', children: 'children' },
+      events: CustomEvents,
+      selectedEvents: []
     }
   },
   computed: {
@@ -247,7 +293,6 @@ export default {
         username: '',
         name: ''
       }
-      console.log(this.group)
       this.$department = { id: this.group.id, path: this.group.path, name: this.group.name }
       this.$refs.editDialog.show()
     },
@@ -316,7 +361,20 @@ export default {
     updateInformLevel (val, user) {
       updateUserInformLevel(user, val).then(() => {
         user.informLevel = val
+        if (val === 9999) {
+          this.onEditEvents(user)
+        }
+      })
+    },
+    onEditEvents (user) {
+      this.$user = user
+      getUserInforms(user).then(({ data }) => {
+        this.selectedEvents = data
+        this.$refs.eventDialog.show()
       })
+    },
+    onConfirmEvents (done) {
+      updateUserInformLevel(this.$user, 9999, this.selectedEvents).then(done)
     }
   }
 }