control.vue 2.6 KB

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