devControl.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. <view style="margin-bottom: 48rpx;">
  11. <u-button type="success" class="reload-btn" @click="handleControl('reboot')">重启</u-button>
  12. </view>
  13. <view style="margin-bottom: 48rpx;">
  14. <u-button type="success" class="reload-btn" @click="handleControl('update')">升级</u-button>
  15. </view>
  16. <u-button type="success" class="reload-btn" @click="handleControl('read')">查询上传时间间隔</u-button>
  17. <view class="title date-title">上传时间间隔(min)</view>
  18. <view class="date-slider">
  19. <slider
  20. v-model="interval"
  21. show-value="true"
  22. :min="1"
  23. :max="240"
  24. @change="changeDataInterval"
  25. block-color="#57C878"
  26. activeColor="#57C878"
  27. step="1"
  28. />
  29. </view>
  30. <u-button type="success" class="sub-btn" @click="handleControl2('interval')">确定</u-button>
  31. </view>
  32. <!-- <view class="footer-board">
  33. <u-button type="success" class="sub-btn" @click="handleSubmit()">确定</u-button>
  34. </view> -->
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. onLoad(options) {
  40. const deviceInfo = JSON.parse(decodeURIComponent(options.deviceInfo));
  41. console.log(deviceInfo, "deviceInfo");
  42. this.deviceInfo = deviceInfo;
  43. this.getDevControlParams();
  44. },
  45. data() {
  46. return {
  47. deviceInfo: {},
  48. interval: "",
  49. };
  50. },
  51. methods: {
  52. changeDataInterval(v){
  53. this.interval = v.detail.value
  54. },
  55. // 获取设备控制参数信息
  56. async getDevControlParams() {
  57. await this.$myRequest({
  58. url: '/api/api_gateway?method=greenhouse.env_first.control_device',
  59. data: {
  60. device_id: this.deviceInfo.devBid,
  61. }
  62. }).then(res => {
  63. console.log('设备控制参数信息', res)
  64. this.interval = res.interval
  65. })
  66. },
  67. async handleControl(cmd) {
  68. let params = {};
  69. if(cmd == 'interval'){
  70. params = {
  71. device_id: this.deviceInfo.devBid,
  72. interval: this.interval,
  73. };
  74. }else if(cmd == 'read'){
  75. params = {
  76. device_id: this.deviceInfo.devBid,
  77. pub_code: JSON.stringify({cmd,ext:{type:'interval'}}),
  78. };
  79. }else{
  80. params = {
  81. device_id: this.deviceInfo.devBid,
  82. pub_code: JSON.stringify({cmd}),
  83. };
  84. }
  85. await this.$myRequest({
  86. url: '/api/api_gateway?method=weather.weather.qxz_send_control',
  87. data: params
  88. }).then(res => {
  89. console.log('设备控制参数信息', res)
  90. uni.showToast({
  91. title: "操作成功",
  92. icon: "none",
  93. });
  94. })
  95. },
  96. async handleControl2(){
  97. console.log(this.deviceInfo,'handleControl2handleControl2')
  98. const params = {
  99. device_type_id: 5,
  100. d_id: this.deviceInfo.d_id,
  101. config: JSON.stringify({content:'',timeout:'',interval:this.interval}),
  102. }
  103. await this.$myRequest({
  104. url: '/api/api_gateway?method=forecast.send_control.device_control',
  105. data: params
  106. }).then(res => {
  107. console.log('设备控制参数信息', res)
  108. uni.showToast({
  109. title: "操作成功",
  110. icon: "none",
  111. });
  112. })
  113. },
  114. async handleSubmit() {
  115. await this.handleControl('STORAGE_INR');
  116. await this.handleControl('INTERVAL');
  117. uni.showToast({
  118. title: "操作成功",
  119. icon: "none",
  120. });
  121. }
  122. },
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. .device-details-page {
  127. background: linear-gradient(
  128. 180deg,
  129. #ffffff00 0%,
  130. #f5f6fa 23.64%,
  131. #f5f6fa 100%
  132. ),
  133. linear-gradient(102deg, #bfeadd 6.77%, #b8f1e7 40.15%, #b9eef5 84.02%);
  134. min-height: 100vh;
  135. padding: 0 32rpx;
  136. padding-top: 98rpx;
  137. }
  138. .nav-title{
  139. text-align: center;
  140. }
  141. .control-board {
  142. border-radius: 16rpx;
  143. background: #fff;
  144. padding: 32rpx;
  145. margin-top: 46rpx;
  146. .title {
  147. margin-bottom: 16rpx;
  148. color: #303133;
  149. font-size: 28rpx;
  150. font-weight: 400;
  151. }
  152. .date-title {
  153. margin-bottom: 52rpx;
  154. }
  155. .reload-btn {
  156. width: 100%;
  157. background: #0bbc58;
  158. margin-bottom: 48rpx;
  159. border-radius: 16rpx;
  160. }
  161. }
  162. .footer-board {
  163. border-top: 2rpx solid #e4e7ed;
  164. background: #fff;
  165. position: fixed;
  166. bottom: 0;
  167. left: 0;
  168. right: 0;
  169. height: 164rpx;
  170. padding: 16rpx 32rpx 0 32rpx;
  171. .sub-btn {
  172. width: 100%;
  173. background: #0bbc58;
  174. border-radius: 16rpx;
  175. }
  176. }
  177. </style>