浏览代码

feat(alarm): support target informartion and push status

Casper Dai 2 年之前
父节点
当前提交
1d1a10b4dd
共有 3 个文件被更改,包括 124 次插入11 次删除
  1. 43 7
      src/api/device.js
  2. 14 2
      src/views/device/detail/components/DeviceAlarm.vue
  3. 67 2
      src/views/realm/user/Account.vue

+ 43 - 7
src/api/device.js

@@ -380,7 +380,7 @@ export function getDeviceAlarms (query) {
             : { label: '-' }
         }
         SupportedAlarmStrategies.forEach(({ key }) => {
-          alarm[key] = getTag(item[key])
+          alarm[key] = getTag(key, item[key], item[`${key}Address`])
         })
         return alarm
       }),
@@ -389,20 +389,56 @@ export function getDeviceAlarms (query) {
   })
 }
 
-function getTag (value) {
-  switch (value) {
+function getTag (key, status, address) {
+  const ignore = !address || address.length === 0
+  const msg = ignore ? null : `目标${address.length}人`
+  switch (status) {
     case 0:
       return {
-        type: 'danger',
-        label: '否'
+        type: 'primary',
+        label: '待发送',
+        msg,
+        address,
+        ignore
       }
     case 1:
       return {
         type: 'success',
-        label: '是'
+        label: '成功',
+        msg,
+        address,
+        ignore
+      }
+    case 2:
+      return {
+        type: 'warning',
+        label: '发送中',
+        msg,
+        address,
+        ignore
+      }
+    case 3:
+      return {
+        type: 'danger',
+        label: '失败',
+        msg,
+        address,
+        ignore
+      }
+    case 4:
+      return {
+        type: 'danger',
+        label: '无目标',
+        ignore: true
+      }
+    case 5:
+      return {
+        type: 'warning',
+        label: '未开启',
+        ignore: true
       }
     default:
-      return { label: '-' }
+      return null
   }
 }
 

+ 14 - 2
src/views/device/detail/components/DeviceAlarm.vue

@@ -5,6 +5,12 @@
     :schema="schema"
   >
     <preview-dialog ref="previewDialog" />
+    <c-dialog
+      ref="accountDIalog"
+      title="推送目标"
+    >
+      {{ accounts }}
+    </c-dialog>
   </schema-table>
 </template>
 
@@ -44,16 +50,22 @@ export default {
             return {
               prop: key,
               label: `${label}通知`,
-              type: 'tag'
+              type: 'tag',
+              on: this.showAccounts
             }
           })
         ]
-      }
+      },
+      accounts: ''
     }
   },
   methods: {
     onView ({ file }) {
       this.$refs.previewDialog.show(file)
+    },
+    showAccounts (val, { address }) {
+      this.accounts = address?.join(', ')
+      this.$refs.accountDIalog.show()
     }
   }
 }

+ 67 - 2
src/views/realm/user/Account.vue

@@ -70,11 +70,13 @@
 
 <script>
 import { mapGetters } from 'vuex'
+import { AlarmLevelInfo } from '@/constant'
 import {
   getUsersByDepartment,
   addUser,
   updateUserName,
-  toggleUser
+  toggleUser,
+  updateUserInformLevel
 } from '@/api/user'
 import Settings from './Settings'
 
@@ -114,7 +116,65 @@ export default {
             },
             on: { edit: val => this.onEditName(data, val) }
           }), 'class-name': 'c-edit-column' },
-          { prop: 'state', type: 'tag', render: ({ userId, enabled }) => userId === this.userId
+          { label: '消息推送', render: (data, h) => h('el-select', {
+            props: {
+              value: data.informLevel
+            },
+            on: {
+              change: val => this.updateInformLevel(val, data)
+            }
+          }, [
+            h('el-option', {
+              key: 'none',
+              props: {
+                value: -1,
+                label: '不预警'
+              }
+            }),
+            h('el-option', {
+              key: 'info',
+              props: {
+                value: 0,
+                label: `部门${AlarmLevelInfo[0]}`
+              }
+            }),
+            h('el-option', {
+              key: 'warning',
+              props: {
+                value: 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]}`
+              }
+            }),
+            h('el-option', {
+              key: 'terror',
+              props: {
+                value: 1002,
+                label: `所有${AlarmLevelInfo[2]}`
+              }
+            })
+          ]) },
+          { type: 'tag', render: ({ userId, enabled }) => userId === this.userId
             ? null
             : {
               type: enabled ? 'success' : 'danger',
@@ -247,6 +307,11 @@ export default {
       )).then(() => {
         user.enabled = enabled
       })
+    },
+    updateInformLevel (val, user) {
+      updateUserInformLevel(user.userId, val).then(() => {
+        user.informLevel = val
+      })
     }
   }
 }