control.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view class="container" v-show="show">
  3. <prodnum-06 v-if="detail.miniapppath == 'prodnum-06'" :control="control" />
  4. <prodnum-MT01
  5. v-else-if="detail.miniapppath == 'prodnum-MT01'"
  6. :control="control"
  7. />
  8. <prodnum-MT02
  9. v-else-if="detail.miniapppath == 'prodnum-MT02'"
  10. :control="control"
  11. />
  12. <prodnum-MT03
  13. v-else-if="detail.miniapppath == 'prodnum-MT03'"
  14. :control="control"
  15. />
  16. <prodnum-YK01
  17. v-else-if="detail.miniapppath == 'prodnum-YK01'"
  18. :control="control"
  19. />
  20. <block v-else-if="detail.miniapppath == 'prodnum-FW01'">
  21. <prodnum-FW01 v-if="mode == 0" :control="control" />
  22. <prodnum-FW01B v-else :control="control" />
  23. </block>
  24. <block v-else>
  25. <view style="height: 50px" />
  26. <u-empty mode="data" />
  27. </block>
  28. </view>
  29. </template>
  30. <script>
  31. let monitoring = null;
  32. export default {
  33. name: "control",
  34. props: {
  35. detail: Object,
  36. onUpdate: Function,
  37. mode: {
  38. type: Number,
  39. default: 0,
  40. },
  41. },
  42. data() {
  43. return {
  44. show: false,
  45. uninitialized: true,
  46. control: {},
  47. };
  48. },
  49. methods: {
  50. initialize(init = false) {
  51. if (init) this.getControl(true);
  52. },
  53. getControl(init) {
  54. if (init) this.control = null;
  55. this.$Http
  56. .basic({
  57. id: "20230628084901",
  58. content: {
  59. w_deviceid: this.detail.w_deviceid,
  60. mode: this.mode,
  61. },
  62. })
  63. .then((res) => {
  64. console.log("设备控制", res);
  65. if (this.cutoff(res.msg)) return;
  66. this.uninitialized = false;
  67. this.control = res.data;
  68. this.$Http.setControlItem = this.setControlItem.bind(this);
  69. this.setMonitoring();
  70. });
  71. },
  72. setControlItem(w_functionid, params, title = "已发送修改指令") {
  73. return this.$Http
  74. .basic({
  75. id: "20230627163701",
  76. content: {
  77. w_deviceid: this.detail.w_deviceid,
  78. w_functionid,
  79. params,
  80. },
  81. })
  82. .then((res) => {
  83. if (this.cutoff(res.msg, title)) return;
  84. console.log("更新设备控制", res);
  85. this.getControl(true);
  86. return res.msg == "成功";
  87. });
  88. },
  89. setMonitoring() {
  90. clearInterval(monitoring);
  91. monitoring = setInterval(() => {
  92. this.$Http
  93. .devicevaluecheck({
  94. w_deviceid: this.detail.w_deviceid,
  95. })
  96. .then((res) => {
  97. if (res == true) {
  98. this.$emit("onUpdate", true);
  99. this.$Http.updateFacilityList && this.$Http.updateFacilityList();
  100. }
  101. });
  102. }, 5000);
  103. },
  104. },
  105. beforeDestroy() {
  106. clearInterval(monitoring);
  107. },
  108. };
  109. </script>
  110. <style lang="scss" scoped>
  111. .container {
  112. width: 355px;
  113. margin: 0 auto;
  114. }
  115. </style>