devControl.vue 3.7 KB

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