AutoRestartConfigDialog.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <confirm-dialog
  3. ref="configDialog"
  4. title="定时重启设置"
  5. @confirm="onSave"
  6. >
  7. <div class="c-grid-form auto u-align-self--center">
  8. <span class="c-grid-form__label">启用</span>
  9. <div class="l-flex--row c-grid-form__option u-width--sm">
  10. <el-switch
  11. v-model="config.enable"
  12. active-color="#13ce66"
  13. inactive-color="#ff4949"
  14. />
  15. </div>
  16. <span class="c-grid-form__label u-required">时间</span>
  17. <el-time-picker
  18. v-model="config.time"
  19. class="has-info"
  20. data-info="设备会进行0~5分钟内的随机时间延长"
  21. placeholder="请选择重启时间"
  22. value-format="HH:mm:ss"
  23. :disabled="!config.enable"
  24. :clearable="false"
  25. />
  26. </div>
  27. </confirm-dialog>
  28. </template>
  29. <script>
  30. import {
  31. AUTORESTART,
  32. getTenantAttribute,
  33. updateTenantAttribute
  34. } from '../api'
  35. export default {
  36. name: 'AutoRestartConfigDialog',
  37. data () {
  38. return {
  39. config: { enable: false }
  40. }
  41. },
  42. methods: {
  43. show () {
  44. getTenantAttribute(AUTORESTART).then(({ data }) => {
  45. if (data) {
  46. const time = data.attributeValue
  47. this.config = {
  48. enable: !!time,
  49. time: time || ''
  50. }
  51. } else {
  52. this.config = {
  53. enable: false,
  54. time: ''
  55. }
  56. }
  57. this.$temp = this.config.time
  58. this.$refs.configDialog.show()
  59. })
  60. },
  61. onSave (done) {
  62. const { enable, time } = this.config
  63. if (enable && !time) {
  64. this.$message({
  65. type: 'warning',
  66. message: '请选择重启时间'
  67. })
  68. return
  69. }
  70. const val = enable ? time : ''
  71. if (this.$temp === val) {
  72. done()
  73. return
  74. }
  75. updateTenantAttribute(AUTORESTART, val).then(done)
  76. }
  77. }
  78. }
  79. </script>