Ver Fonte

feat(device): auto restart

Casper Dai há 2 anos atrás
pai
commit
bf74a9a143

+ 19 - 0
src/views/realm/settings/api.js

@@ -38,3 +38,22 @@ export function updateInformStrategy (strategy) {
     data: addTenant({ strategy })
   })
 }
+
+export function getAutoRestartTime () {
+  return send({
+    url: '/tenant/attribute/query',
+    method: 'GET',
+    params: addTenant({ attributeKey: 'autorestart' })
+  })
+}
+
+export function updateAutoRestartTime (time) {
+  return update({
+    url: '/tenant/attribute/save',
+    method: 'POST',
+    data: addTenant({
+      attributeKey: 'autorestart',
+      attributeValue: time
+    })
+  })
+}

+ 80 - 0
src/views/realm/settings/components/AutoRestartConfigDialog.vue

@@ -0,0 +1,80 @@
+<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 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>
+  </confirm-dialog>
+</template>
+
+<script>
+import {
+  getAutoRestartTime,
+  updateAutoRestartTime
+} from '../api'
+
+export default {
+  name: 'AutoRestartConfigDialog',
+  data () {
+    return {
+      config: { enable: false }
+    }
+  },
+  methods: {
+    show () {
+      getAutoRestartTime().then(({ data }) => {
+        if (data) {
+          const time = data.attributeValue
+          this.config = {
+            enable: !!time,
+            time: time || ''
+          }
+        } else {
+          this.config = {
+            enable: false,
+            time: ''
+          }
+        }
+        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) {
+        done()
+        return
+      }
+      updateAutoRestartTime(val).then(done)
+    }
+  }
+}
+</script>

+ 13 - 1
src/views/realm/settings/index.vue

@@ -12,22 +12,34 @@
       >
         告警策略
       </button>
+      <button
+        class="o-button"
+        @click="onAutoRestartConfig"
+      >
+        设备定时重启
+      </button>
       <alarm-strat-config-dialog ref="alarmStratConfigDialog" />
+      <auto-restart-config-dialog ref="autoRestartConfigDialog" />
     </div>
   </wrapper>
 </template>
 
 <script>
 import AlarmStratConfigDialog from './components/AlarmStratConfigDialog'
+import AutoRestartConfigDialog from './components/AutoRestartConfigDialog'
 
 export default {
   name: 'TenantSettings',
   components: {
-    AlarmStratConfigDialog
+    AlarmStratConfigDialog,
+    AutoRestartConfigDialog
   },
   methods: {
     onAlarmStratConfig () {
       this.$refs.alarmStratConfigDialog.show()
+    },
+    onAutoRestartConfig () {
+      this.$refs.autoRestartConfigDialog.show()
     }
   }
 }