devControl.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class="device-details-page">
  3. <cu-custom :isBack="true">
  4. <template slot="content">
  5. <view class="nav-title">设备控制</view>
  6. </template>
  7. </cu-custom>
  8. <view class="control-board">
  9. <view class="title">操作</view>
  10. <div style="margin-bottom: 48rpx;">
  11. <u-button type="success" class="reload-btn" @click="handleControl('RESET')">重启</u-button>
  12. </div>
  13. <u-button type="success" class="reload-btn" @click="handleControl('FWUPDATE')">升级</u-button>
  14. <view class="title date-title">本地存储间隔(min)</view>
  15. <view class="date-slider">
  16. <slider
  17. :value="storageVal"
  18. show-value="true"
  19. :min="1"
  20. :max="240"
  21. @change="changeStorageVal"
  22. block-color="#57C878"
  23. activeColor="#57C878"
  24. step="1"
  25. />
  26. </view>
  27. <u-button type="success" class="sub-btn" @click="handleControl('STORAGE_INR')">确定</u-button>
  28. <view class="title date-title">数据传输间隔(min)</view>
  29. <view class="date-slider">
  30. <slider
  31. :value="dataInterval"
  32. show-value="true"
  33. :min="1"
  34. :max="240"
  35. @change="changeDataInterval"
  36. block-color="#57C878"
  37. activeColor="#57C878"
  38. step="1"
  39. />
  40. </view>
  41. <u-button type="success" class="sub-btn" @click="handleControl('INTERVAL')">确定</u-button>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. onLoad(options) {
  48. this.loading = true
  49. const deviceInfo = JSON.parse(decodeURIComponent(options.deviceInfo));
  50. console.log(deviceInfo, "deviceInfo");
  51. this.deviceInfo = deviceInfo;
  52. this.getDevControlParams();
  53. },
  54. data() {
  55. return {
  56. deviceInfo: {},
  57. storageVal: "",
  58. dataInterval: "",
  59. };
  60. },
  61. methods: {
  62. // 改变本地存储间隔
  63. changeStorageVal(e) {
  64. this.storageVal = e.detail.value
  65. },
  66. // 改变数据传输间隔
  67. changeDataInterval(e) {
  68. this.dataInterval = e.detail.value
  69. },
  70. // 获取设备控制参数信息
  71. async getDevControlParams() {
  72. this.loading = true
  73. await this.$myRequest({
  74. url: '/api/api_gateway?method=qxz.device.control_args',
  75. data: {
  76. device_id: this.deviceInfo.devBid,
  77. }
  78. }).then(res => {
  79. console.log('设备控制参数信息', res)
  80. this.storageVal = res.storage_inr
  81. this.dataInterval = res.interval
  82. })
  83. },
  84. async handleControl(cmd) {
  85. const params = {
  86. device_id: this.deviceInfo.devBid,
  87. cmd,
  88. interval: cmd === 'INTERVAL' ? this.dataInterval : undefined,
  89. storage_inr: cmd === 'STORAGE_INR' ? this.storageVal : undefined,
  90. stnid: cmd === 'STNID' ? this.stnidVal : undefined
  91. };
  92. await this.$myRequest({
  93. url: '/api/api_gateway?method=qxz.device.control',
  94. data: params
  95. }).then(res => {
  96. console.log('设备控制参数信息', res)
  97. uni.showToast({
  98. title: "操作成功",
  99. icon: "none",
  100. });
  101. })
  102. },
  103. async handleSubmit() {
  104. // await this.handleControl('STORAGE_INR');
  105. // setTimeout(async ()=>{
  106. // await this.handleControl('INTERVAL');
  107. // },500)
  108. uni.showToast({
  109. title: "操作成功",
  110. icon: "none",
  111. });
  112. }
  113. },
  114. };
  115. </script>
  116. <style lang="scss" scoped>
  117. .device-details-page {
  118. background: linear-gradient(
  119. 180deg,
  120. #ffffff00 0%,
  121. #f5f6fa 23.64%,
  122. #f5f6fa 100%
  123. ),
  124. linear-gradient(102deg, #bfeadd 6.77%, #b8f1e7 40.15%, #b9eef5 84.02%);
  125. min-height: 100vh;
  126. padding: 0 32rpx;
  127. padding-top: 98rpx;
  128. }
  129. .control-board {
  130. border-radius: 16rpx;
  131. background: #fff;
  132. padding: 32rpx;
  133. margin-top: 46rpx;
  134. .title {
  135. margin-bottom: 16rpx;
  136. color: #303133;
  137. font-size: 28rpx;
  138. font-weight: 400;
  139. }
  140. .date-title {
  141. margin-bottom: 52rpx;
  142. }
  143. .reload-btn {
  144. width: 100%;
  145. background: #0bbc58;
  146. margin-bottom: 48rpx;
  147. border-radius: 16rpx;
  148. }
  149. .date-slider {
  150. }
  151. }
  152. .footer-board {
  153. border-top: 2rpx solid #e4e7ed;
  154. background: #fff;
  155. position: fixed;
  156. bottom: 0;
  157. left: 0;
  158. right: 0;
  159. height: 164rpx;
  160. padding: 16rpx 32rpx 0 32rpx;
  161. .sub-btn {
  162. width: 100%;
  163. background: #0bbc58;
  164. border-radius: 16rpx;
  165. }
  166. }
  167. </style>