control.vue 3.1 KB

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