control.vue 2.4 KB

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