PLCSwitch.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 {
  34. getBoundPLCs,
  35. plcCommand
  36. } from '@/api/external'
  37. export default {
  38. name: 'ScreenSwitchPLC',
  39. props: {
  40. device: {
  41. type: Object,
  42. required: true
  43. }
  44. },
  45. methods: {
  46. onInvoke () {
  47. const loading = this.$showLoading()
  48. getBoundPLCs(this.device.id).finally(() => {
  49. this.$closeLoading(loading)
  50. }).then(data => {
  51. if (data.length) {
  52. this.$refs.dialog.show()
  53. } else {
  54. this.$message({
  55. type: 'warning',
  56. message: '暂未绑定PLC,请联系管理员'
  57. })
  58. }
  59. })
  60. },
  61. onSwitch (open) {
  62. this.$confirm(
  63. `立即${open ? '开启' : '关闭'}?`,
  64. '操作确认',
  65. { type: 'warning' }
  66. ).then(() => {
  67. plcCommand(this.device.id, open ? 1 : 0)
  68. })
  69. }
  70. }
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .o-icon {
  75. background-image: url("~@/assets/icon_device_switch.png");
  76. }
  77. </style>