devControl.vue 4.6 KB

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