devControl.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. v-model="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. v-model="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 class="footer-board">
  44. <u-button type="success" class="sub-btn" @click="handleSubmit()">确定</u-button>
  45. </view> -->
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. onLoad(options) {
  51. const deviceInfo = JSON.parse(decodeURIComponent(options.deviceInfo));
  52. console.log(deviceInfo, "deviceInfo");
  53. this.deviceInfo = deviceInfo;
  54. this.getDevControlParams();
  55. },
  56. data() {
  57. return {
  58. deviceInfo: {},
  59. storageVal: "",
  60. dataInterval: "",
  61. };
  62. },
  63. methods: {
  64. changeDataInterval(v){
  65. this.dataInterval = v.detail.value
  66. },
  67. changeStorageVal(v){
  68. this.storageVal = v.detail.value
  69. },
  70. // 获取设备控制参数信息
  71. async getDevControlParams() {
  72. await this.$myRequest({
  73. url: '/api/api_gateway?method=qxz.device.control_args',
  74. data: {
  75. device_id: this.deviceInfo.devBid,
  76. }
  77. }).then(res => {
  78. console.log('设备控制参数信息', res)
  79. this.storageVal = res.storage_inr
  80. this.dataInterval = res.interval
  81. })
  82. },
  83. async handleControl(cmd) {
  84. const params = {
  85. device_id: this.deviceInfo.devBid,
  86. cmd,
  87. interval: cmd === 'INTERVAL' ? this.dataInterval : undefined,
  88. storage_inr: cmd === 'STORAGE_INR' ? this.storageVal : undefined,
  89. stnid: cmd === 'STNID' ? this.stnidVal : undefined
  90. };
  91. await this.$myRequest({
  92. url: '/api/api_gateway?method=qxz.device.control',
  93. data: params
  94. }).then(res => {
  95. console.log('设备控制参数信息', res)
  96. uni.showToast({
  97. title: "操作成功",
  98. icon: "none",
  99. });
  100. })
  101. },
  102. async handleSubmit() {
  103. await this.handleControl('STORAGE_INR');
  104. await this.handleControl('INTERVAL');
  105. uni.showToast({
  106. title: "操作成功",
  107. icon: "none",
  108. });
  109. }
  110. },
  111. };
  112. </script>
  113. <style lang="scss" scoped>
  114. .device-details-page {
  115. background: linear-gradient(
  116. 180deg,
  117. #ffffff00 0%,
  118. #f5f6fa 23.64%,
  119. #f5f6fa 100%
  120. ),
  121. linear-gradient(102deg, #bfeadd 6.77%, #b8f1e7 40.15%, #b9eef5 84.02%);
  122. min-height: 100vh;
  123. padding: 0 32rpx;
  124. padding-top: 98rpx;
  125. }
  126. .nav-title{
  127. text-align: center;
  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>