switch-task.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import taskMixin from './task'
  2. import { createListOptions } from '@/utils'
  3. export default {
  4. mixins: [taskMixin],
  5. data () {
  6. return {
  7. tabs: [
  8. { key: 'immediate', name: '实时控制' },
  9. { key: 'delayOpen', name: '定时开机' },
  10. { key: 'delayClose', name: '定时关机' }
  11. ],
  12. delayOpenOptions: null,
  13. delayCloseOptions: null,
  14. schema: this.createSchema(null, () => { return { label: this.isDelayClose ? '关机时间' : '开启时间' } })
  15. }
  16. },
  17. computed: {
  18. currOptions: {
  19. get () {
  20. return this[this.isDelayClose ? 'delayCloseOptions' : 'delayOpenOptions']
  21. },
  22. set (val) {
  23. this[this.isDelayClose ? 'delayCloseOptions' : 'delayOpenOptions'] = val
  24. }
  25. },
  26. type () {
  27. return this.isDelayClose ? '定时关机' : '定时开机'
  28. },
  29. isDelayClose () {
  30. return this.active === 'delayClose'
  31. }
  32. },
  33. methods: {
  34. invoke () {
  35. this.active = 'immediate'
  36. this.delayOpenOptions = createListOptions({ functionKey: this.openFunctionKey })
  37. this.delayCloseOptions = createListOptions({ functionKey: this.closeFunctionKey })
  38. this.show = true
  39. },
  40. onSwitch (open) {
  41. if (!this.online) {
  42. this.$message({
  43. type: 'warning',
  44. message: '设备未上线,请稍后再试'
  45. })
  46. return
  47. }
  48. this.$confirm(
  49. `立即${open ? '开机' : '关机'}?`,
  50. { type: 'warning' }
  51. ).then(() => {
  52. this.sendTopic(open ? 'bootDevice' : 'shutdownDevice')
  53. })
  54. }
  55. }
  56. }