PLCSwitch.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div class="l-flex--col center has-border radius has-padding">
  3. <i
  4. class="o-icon lg u-pointer"
  5. @click="onInvoke"
  6. />
  7. <div class="has-padding u-color--black u-bold">开关电源(PLC)</div>
  8. <c-dialog
  9. ref="dialog"
  10. size="medium"
  11. title="开关电源"
  12. >
  13. <div class="l-flex__fill l-flex--col jcenter center has-bottom-padding">
  14. <div>
  15. <button
  16. class="o-button c-sibling-item"
  17. @click="onSwitch(true)"
  18. >
  19. 即刻开启
  20. </button>
  21. <button
  22. class="o-button c-sibling-item far"
  23. @click="onSwitch(false)"
  24. >
  25. 即刻关闭
  26. </button>
  27. </div>
  28. </div>
  29. </c-dialog>
  30. </div>
  31. </template>
  32. <script>
  33. import { ThirdPartyDevice } from '@/constant'
  34. import {
  35. getThirdPartyDevicesByThirdPartyDevice,
  36. getFollowThirdPartyDevicesByThirdPartyDevice
  37. } from '@/api/mesh'
  38. import { plcCommand } from '@/api/external'
  39. export default {
  40. name: 'ScreenSwitchPLC',
  41. props: {
  42. device: {
  43. type: Object,
  44. required: true
  45. }
  46. },
  47. methods: {
  48. onInvoke () {
  49. const loading = this.$showLoading()
  50. getThirdPartyDevicesByThirdPartyDevice(this.device.id, [ThirdPartyDevice.GATEWAY])
  51. .then(({ data }) => {
  52. const gateway = data.find(({ instance }) => instance)
  53. if (!gateway) {
  54. this.$message({
  55. type: 'warning',
  56. message: '暂未绑定网关,请联系管理员'
  57. })
  58. return Promise.reject()
  59. }
  60. return getFollowThirdPartyDevicesByThirdPartyDevice(gateway.instance.id, [ThirdPartyDevice.PLC])
  61. })
  62. .then(({ data }) => {
  63. const plc = data.find(({ instance }) => instance)
  64. if (!plc) {
  65. this.$message({
  66. type: 'warning',
  67. message: '网关暂未绑定PLC,请联系管理员'
  68. })
  69. return Promise.reject()
  70. }
  71. return Promise.resolve()
  72. })
  73. .finally(() => {
  74. this.$closeLoading(loading)
  75. })
  76. .then(() => {
  77. this.$refs.dialog.show()
  78. })
  79. },
  80. onSwitch (open) {
  81. this.$confirm(
  82. `立即${open ? '开启' : '关闭'}?`,
  83. '操作确认',
  84. { type: 'warning' }
  85. ).then(() => {
  86. plcCommand(this.device.id, open ? 1 : 0)
  87. })
  88. }
  89. }
  90. }
  91. </script>
  92. <style lang="scss" scoped>
  93. .o-icon {
  94. background-image: url("~@/assets/icon_device_switch.png");
  95. }
  96. </style>