control.vue 2.9 KB

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