فهرست منبع

feat(tenant): attributes

Casper Dai 2 سال پیش
والد
کامیت
dec0bb6e0b

+ 10 - 6
src/views/realm/settings/api.js

@@ -39,23 +39,27 @@ export function updateInformStrategy (strategy) {
   })
 }
 
-const AUTORESTART = 'autorestart'
+export const AUTORESTART = 'autorestart'
+export const UNATTEND = 'sensor_power'
+export const TEMPERATURE = 'Temperature'
+export const DEVIATION = 'Deviation'
+export const POWERTYPE = 'target_type'
 
-export function getAutoRestartTime () {
+export function getTenantAttribute (key) {
   return send({
     url: '/tenant/attribute/query',
     method: 'GET',
-    params: addTenant({ attributeKey: AUTORESTART })
+    params: addTenant({ attributeKey: key })
   })
 }
 
-export function updateAutoRestartTime (time) {
+export function updateTenantAttribute (key, val) {
   return update({
     url: '/tenant/attribute/save',
     method: 'POST',
     data: addTenant({
-      attributeKey: AUTORESTART,
-      attributeValue: time
+      attributeKey: key,
+      attributeValue: val
     })
   })
 }

+ 53 - 44
src/views/realm/settings/components/AutoRestartConfigDialog.vue

@@ -1,27 +1,37 @@
 <template>
   <confirm-dialog
     ref="configDialog"
-    title="自动重启设置"
+    title="三轴传感器阈值设置"
     @confirm="onSave"
   >
     <div class="c-grid-form auto u-align-self--center">
-      <span class="c-grid-form__label">启用</span>
-      <div class="l-flex--row c-grid-form__option u-width--sm">
-        <el-switch
-          v-model="config.enable"
-          active-color="#13ce66"
-          inactive-color="#ff4949"
-        />
-      </div>
-      <span class="c-grid-form__label u-required">时间</span>
-      <el-time-picker
-        v-model="config.time"
-        class="has-info"
-        data-info="设备会进行0~5分钟内的随机时间延长"
-        placeholder="请选择重启时间"
-        value-format="HH:mm:ss"
-        :disabled="!config.enable"
-        :clearable="false"
+      <div class="c-grid-form__label">一级预警</div>
+      <el-input-number
+        v-model="config.level1"
+        controls-position="right"
+        :min="0"
+        step-strictly
+      />
+      <div class="c-grid-form__label">二级预警</div>
+      <el-input-number
+        v-model="config.level2"
+        controls-position="right"
+        :min="0"
+        step-strictly
+      />
+      <div class="c-grid-form__label">三级预警</div>
+      <el-input-number
+        v-model="config.level3"
+        controls-position="right"
+        :min="0"
+        step-strictly
+      />
+      <div class="c-grid-form__label">四级预警</div>
+      <el-input-number
+        v-model="config.level4"
+        controls-position="right"
+        :min="0"
+        step-strictly
       />
     </div>
   </confirm-dialog>
@@ -29,51 +39,50 @@
 
 <script>
 import {
-  getAutoRestartTime,
-  updateAutoRestartTime
+  DEVIATION,
+  getTenantAttribute,
+  updateTenantAttribute
 } from '../api'
 
 export default {
-  name: 'AutoRestartConfigDialog',
+  name: 'DeviationConfigDialog',
   data () {
     return {
-      config: { enable: false }
+      config: {
+        level1: 0,
+        level2: 0,
+        level3: 0,
+        level4: 0
+      }
     }
   },
   methods: {
     show () {
-      getAutoRestartTime().then(({ data }) => {
+      getTenantAttribute(DEVIATION).then(({ data }) => {
         if (data) {
-          const time = data.attributeValue
-          this.config = {
-            enable: !!time,
-            time: time || ''
-          }
+          this.$temp = data.attributeValue
+          this.$temp.split(',').forEach((val, index) => {
+            this.config[`level${index + 1}`] = val
+          })
         } else {
-          this.config = {
-            enable: false,
-            time: ''
-          }
+          this.$temp = ''
         }
-        this.$time = this.config.time
         this.$refs.configDialog.show()
       })
     },
     onSave (done) {
-      const { enable, time } = this.config
-      if (enable && !time) {
-        this.$message({
-          type: 'warning',
-          message: '请选择重启时间'
-        })
-        return
-      }
-      const val = enable ? time : ''
-      if (this.$time === val) {
+      const val = [
+        this.config.level1,
+        this.config.level2,
+        this.config.level3,
+        this.config.level4
+      ].join(',')
+
+      if (this.$temp === val) {
         done()
         return
       }
-      updateAutoRestartTime(val).then(done)
+      updateTenantAttribute(DEVIATION, val).then(done)
     }
   }
 }

+ 101 - 0
src/views/realm/settings/components/DeviationThresholdConfigDialog.vue

@@ -0,0 +1,101 @@
+<template>
+  <confirm-dialog
+    ref="configDialog"
+    title="位移传感器阈值设置"
+    @confirm="onSave"
+  >
+    <div class="c-grid-form auto u-align-self--center">
+      <div class="c-grid-form__label">X轴初始值</div>
+      <el-input-number
+        v-model.trim="config.val1"
+        controls-position="right"
+        :step-strictly="0.01"
+      />
+      <div class="c-grid-form__label">X轴阈值</div>
+      <el-input-number
+        v-model.trim="config.val2"
+        controls-position="right"
+        :step-strictly="0.01"
+      />
+      <div class="c-grid-form__label">Y轴初始值</div>
+      <el-input-number
+        v-model.trim="config.val3"
+        controls-position="right"
+        :step-strictly="0.01"
+      />
+      <div class="c-grid-form__label">Y轴阈值</div>
+      <el-input-number
+        v-model.trim="config.val4"
+        controls-position="right"
+        :step-strictly="0.01"
+      />
+      <div class="c-grid-form__label">Z轴初始值</div>
+      <el-input-number
+        v-model.trim="config.val5"
+        controls-position="right"
+        :step-strictly="0.01"
+      />
+      <div class="c-grid-form__label">Z轴阈值</div>
+      <el-input-number
+        v-model.trim="config.val6"
+        controls-position="right"
+        :step-strictly="0.01"
+      />
+    </div>
+  </confirm-dialog>
+</template>
+
+<script>
+import {
+  DEVIATION,
+  getTenantAttribute,
+  updateTenantAttribute
+} from '../api'
+
+export default {
+  name: 'PowerConfigDialog',
+  data () {
+    return {
+      config: {
+        val1: 0,
+        val2: 0,
+        val3: 0,
+        val4: 0,
+        val5: 0,
+        val6: 0
+      }
+    }
+  },
+  methods: {
+    show () {
+      getTenantAttribute(DEVIATION).then(({ data }) => {
+        if (data) {
+          this.$temp = data.attributeValue
+          this.$temp.split(',').forEach((val, index) => {
+            this.config[`val${index + 1}`] = val
+          })
+        } else {
+          this.$temp = ''
+        }
+        this.$refs.configDialog.show()
+      })
+    },
+    onSave (done) {
+      const val = [
+        this.config.val1,
+        this.config.val2,
+        this.config.val3,
+        this.config.val4,
+        this.config.val5,
+        this.config.val6
+      ].join(',')
+
+      if (this.$temp === val) {
+        done()
+        return
+      }
+      updateTenantAttribute(DEVIATION, val).then(done)
+    }
+  }
+}
+</script>

+ 79 - 0
src/views/realm/settings/components/PowerConfigDialog.vue

@@ -0,0 +1,79 @@
+<template>
+  <confirm-dialog
+    ref="configDialog"
+    title="温度传感器阈值设置"
+    @confirm="onSave"
+  >
+    <div class="c-grid-form auto u-align-self--center">
+      <div class="c-grid-form__label">屏体电源标签</div>
+      <el-input
+        v-model.trim="config.power1"
+      />
+      <div class="c-grid-form__label">风机电源标签</div>
+      <el-input
+        v-model.trim="config.power2"
+      />
+    </div>
+  </confirm-dialog>
+</template>
+
+<script>
+import {
+  POWERTYPE,
+  getTenantAttribute,
+  updateTenantAttribute
+} from '../api'
+
+export default {
+  name: 'PowerConfigDialog',
+  data () {
+    return {
+      config: {
+        power1: '',
+        power2: ''
+      }
+    }
+  },
+  methods: {
+    show () {
+      getTenantAttribute(POWERTYPE).then(({ data }) => {
+        if (data) {
+          this.$temp = data.attributeValue
+          this.$temp.split(',').forEach((val, index) => {
+            this.config[`power${index + 1}`] = val
+          })
+        } else {
+          this.$temp = ''
+        }
+        this.$refs.configDialog.show()
+      })
+    },
+    onSave (done) {
+      if (!this.config.power1) {
+        this.$message({
+          type: 'warning',
+          message: '请配置屏体电源标签'
+        })
+      }
+
+      if (!this.config.power2) {
+        this.$message({
+          type: 'warning',
+          message: '请配置风机电源标签'
+        })
+      }
+
+      const val = [
+        this.config.power1,
+        this.config.power2
+      ].join(',')
+
+      if (this.$temp === val) {
+        done()
+        return
+      }
+      updateTenantAttribute(POWERTYPE, val).then(done)
+    }
+  }
+}
+</script>

+ 89 - 0
src/views/realm/settings/components/TemperatureThresholdConfigDialog.vue

@@ -0,0 +1,89 @@
+<template>
+  <confirm-dialog
+    ref="configDialog"
+    title="温度传感器阈值设置"
+    @confirm="onSave"
+  >
+    <div class="c-grid-form auto u-align-self--center">
+      <div class="c-grid-form__label">一级预警</div>
+      <el-input-number
+        v-model="config.level1"
+        controls-position="right"
+        :min="0"
+        step-strictly
+      />
+      <div class="c-grid-form__label">二级预警</div>
+      <el-input-number
+        v-model="config.level2"
+        controls-position="right"
+        :min="0"
+        step-strictly
+      />
+      <div class="c-grid-form__label">三级预警</div>
+      <el-input-number
+        v-model="config.level3"
+        controls-position="right"
+        :min="0"
+        step-strictly
+      />
+      <div class="c-grid-form__label">四级预警</div>
+      <el-input-number
+        v-model="config.level4"
+        controls-position="right"
+        :min="0"
+        step-strictly
+      />
+    </div>
+  </confirm-dialog>
+</template>
+
+<script>
+import {
+  TEMPERATURE,
+  getTenantAttribute,
+  updateTenantAttribute
+} from '../api'
+
+export default {
+  name: 'TemperatureConfigDialog',
+  data () {
+    return {
+      config: {
+        level1: 0,
+        level2: 0,
+        level3: 0,
+        level4: 0
+      }
+    }
+  },
+  methods: {
+    show () {
+      getTenantAttribute(TEMPERATURE).then(({ data }) => {
+        if (data) {
+          this.$temp = data.attributeValue
+          this.$temp.split(',').forEach((val, index) => {
+            this.config[`level${index + 1}`] = val
+          })
+        } else {
+          this.$temp = ''
+        }
+        this.$refs.configDialog.show()
+      })
+    },
+    onSave (done) {
+      const val = [
+        this.config.level1,
+        this.config.level2,
+        this.config.level3,
+        this.config.level4
+      ].join(',')
+
+      if (this.$temp === val) {
+        done()
+        return
+      }
+      updateTenantAttribute(TEMPERATURE, val).then(done)
+    }
+  }
+}
+</script>

+ 56 - 0
src/views/realm/settings/components/UnattendConfigDialog.vue

@@ -0,0 +1,56 @@
+<template>
+  <confirm-dialog
+    ref="configDialog"
+    title="无人值守设置"
+    @confirm="onSave"
+  >
+    <div class="c-grid-form auto u-align-self--center">
+      <span class="c-grid-form__label">启用</span>
+      <div class="l-flex--row">
+        <el-switch
+          v-model="enable"
+          active-color="#13ce66"
+          inactive-color="#ff4949"
+        />
+      </div>
+    </div>
+  </confirm-dialog>
+</template>
+
+<script>
+import {
+  UNATTEND,
+  getTenantAttribute,
+  updateTenantAttribute
+} from '../api'
+
+export default {
+  name: 'UnattendConfigDialog',
+  data () {
+    return {
+      enable: false
+    }
+  },
+  methods: {
+    show () {
+      getTenantAttribute(UNATTEND).then(({ data }) => {
+        if (data) {
+          this.enable = data.attributeValue === '0'
+          this.$temp = this.enable
+        } else {
+          this.enable = false
+          this.$temp = null
+        }
+        this.$refs.configDialog.show()
+      })
+    },
+    onSave (done) {
+      if (this.$temp === this.enable) {
+        done()
+        return
+      }
+      updateTenantAttribute(UNATTEND, this.enable ? '1' : '0').then(done)
+    }
+  }
+}
+</script>

+ 59 - 7
src/views/realm/settings/index.vue

@@ -5,7 +5,8 @@
     padding
     background
   >
-    <div class="l-grid--info mini">
+    <span class="c-sibling-item--v u-font-size--sm u-bold">策略配置</span>
+    <div class="c-sibling-item--v l-grid--info mini">
       <button
         class="o-button"
         @click="onAlarmStratConfig"
@@ -16,23 +17,62 @@
         class="o-button"
         @click="onAutoRestartConfig"
       >
-        设备定时重启
+        定时重启策略
       </button>
-      <alarm-strat-config-dialog ref="alarmStratConfigDialog" />
-      <auto-restart-config-dialog ref="autoRestartConfigDialog" />
     </div>
+    <span class="c-sibling-item--v u-font-size--sm u-bold">安全配置</span>
+    <div class="c-sibling-item--v l-grid--info mini">
+      <button
+        class="o-button"
+        @click="onPowerConfig"
+      >
+        电源标签
+      </button>
+      <button
+        class="o-button"
+        @click="onUnattendConfig"
+      >
+        无人值守
+      </button>
+      <button
+        class="o-button"
+        @click="onTemperatureThresholdConfig"
+      >
+        温度传感器阈值
+      </button>
+      <button
+        class="o-button"
+        @click="onDeviationThresholdConfig"
+      >
+        位移传感器阈值
+      </button>
+    </div>
+    <alarm-strat-config-dialog ref="alarmStratConfigDialog" />
+    <auto-restart-config-dialog ref="autoRestartConfigDialog" />
+    <power-config-dialog ref="powerConfigDialog" />
+    <unattend-config-dialog ref="unattendConfigDialog" />
+    <temperature-Threshold-config-dialog ref="temperatureThresholdConfigDialog" />
+    <deviation-Threshold-config-dialog ref="DeviationThresholdConfigDialog" />
   </wrapper>
 </template>
 
 <script>
-import AlarmStratConfigDialog from './components/AlarmStratConfigDialog'
-import AutoRestartConfigDialog from './components/AutoRestartConfigDialog'
+import AlarmStratConfigDialog from './components/AlarmStratConfigDialog.vue'
+import AutoRestartConfigDialog from './components/AutoRestartConfigDialog.vue'
+import PowerConfigDialog from './components/PowerConfigDialog.vue'
+import UnattendConfigDialog from './components/UnattendConfigDialog.vue'
+import TemperatureThresholdConfigDialog from './components/TemperatureThresholdConfigDialog.vue'
+import DeviationThresholdConfigDialog from './components/DeviationThresholdConfigDialog.vue'
 
 export default {
   name: 'TenantSettings',
   components: {
     AlarmStratConfigDialog,
-    AutoRestartConfigDialog
+    AutoRestartConfigDialog,
+    PowerConfigDialog,
+    UnattendConfigDialog,
+    TemperatureThresholdConfigDialog,
+    DeviationThresholdConfigDialog
   },
   methods: {
     onAlarmStratConfig () {
@@ -40,6 +80,18 @@ export default {
     },
     onAutoRestartConfig () {
       this.$refs.autoRestartConfigDialog.show()
+    },
+    onPowerConfig () {
+      this.$refs.powerConfigDialog.show()
+    },
+    onUnattendConfig () {
+      this.$refs.unattendConfigDialog.show()
+    },
+    onTemperatureThresholdConfig () {
+      this.$refs.temperatureThresholdConfigDialog.show()
+    },
+    onDeviationThresholdConfig () {
+      this.$refs.DeviationThresholdConfigDialog.show()
     }
   }
 }