contros.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 40px;">
  5. <view style="position: fixed;z-index: 100;width: 100%;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="设备控制"></uni-nav-bar>
  7. </view>
  8. <view class="contros_box">
  9. <view class="operation">
  10. <p class="operation_title">操作</p>
  11. <view class="operation_btn" v-if="device_type_id==38">
  12. <button @click="operate('RC_LOC')">定 位</button>
  13. <button @click="operate('RC_LOC')">长在线</button>
  14. </view>
  15. <view class="operation_btn" v-else>
  16. <button @click="chongqi">重 启</button>
  17. <button @click="search">查询时间上传间隔</button>
  18. </view>
  19. </view>
  20. <view class="viewing" v-if="led == 1">
  21. <p class="operation_title">显示屏设置</p>
  22. <view class="viewing_text">
  23. <view class="viewing_text_top">
  24. 标题文字设置 :
  25. <input type="text" v-model="config.content" />
  26. </view>
  27. <view class="viewing_text_bot">
  28. <p>显示时间设置(min) :</p>
  29. <input type="number" v-model="config.timeout" />
  30. </view>
  31. </view>
  32. </view>
  33. <view class="timing">
  34. <p class="operation_title">上传时间间隔(min)</p>
  35. <view class="timing_text">
  36. <slider value="0" v-model="config.interval" @change="sliderChange" step="1" min="0" max="359" show-value block-size="18" activeColor="#57C878" />
  37. </view>
  38. </view>
  39. <view class="ensure">
  40. <view class="ensure_btn" @click="ensure">
  41. 确 定
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. config: {
  53. content: "",
  54. timeout: "",
  55. interval: 1
  56. },
  57. id: '',
  58. led:0,
  59. device_type_id:0
  60. }
  61. },
  62. methods: {
  63. // forecast.send_control.device_control_info 设备配置查询
  64. async controsdata() { //提交数据
  65. const res = await this.$myRequest({
  66. url: '/api/api_gateway?method=forecast.send_control.device_control_info',
  67. data: {
  68. d_id: this.id,
  69. cmd: "config"
  70. }
  71. })
  72. console.log(res)
  73. this.config.interval = res.interval
  74. this.led = Number(res.led)
  75. },
  76. async controsdataLow(){
  77. const res = await this.$myRequest({
  78. url: '/api/api_gateway?method=greenhouse.env_first.control_device',
  79. data: {
  80. device_id: this.device_id
  81. }
  82. })
  83. console.log(res)
  84. this.config.interval = res.interval
  85. },
  86. //forecast.send_control.device_control config: {"interval":10,"content":"content","timeout":"1"}
  87. async timing(datas) { //提交数据
  88. const res = await this.$myRequest({
  89. url: '/api/api_gateway?method=forecast.send_control.device_control',
  90. data: {
  91. device_type_id: 5,
  92. d_id: this.id,
  93. config: JSON.stringify(datas)
  94. }
  95. })
  96. console.log(res)
  97. if(res){
  98. uni.showToast({
  99. title: '指令下发成功!'
  100. });
  101. }else{
  102. uni.showToast({
  103. title: '指令下发失败!',
  104. icon: "none"
  105. });
  106. }
  107. },
  108. //forecast.send_control.admin_device_control
  109. async restart(datas) { //重启
  110. const res = await this.$myRequest({
  111. url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
  112. data: {
  113. device_type_id: 5,
  114. d_id: this.id,
  115. cmd: datas
  116. }
  117. })
  118. if (res == true) {
  119. uni.showToast({
  120. title: '指令下发成功!'
  121. });
  122. } else {
  123. uni.showToast({
  124. title: '指令下发失败!',
  125. icon: "none"
  126. });
  127. }
  128. },
  129. //forecast.send_control.get_device_config
  130. async uploading() { //上传时间
  131. const res = await this.$myRequest({
  132. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  133. data: {
  134. device_type_id: 5,
  135. d_id: this.id,
  136. control_type: "interval"
  137. }
  138. })
  139. console.log(res)
  140. if (res == true) {
  141. uni.showToast({
  142. title: '指令下发成功!'
  143. });
  144. } else {
  145. uni.showToast({
  146. title: '指令下发失败!',
  147. icon: "none"
  148. });
  149. }
  150. },
  151. clickLeft() { //返回
  152. uni.navigateBack({
  153. delta: 1
  154. })
  155. },
  156. ensure() { //提交
  157. this.timing(this.config)
  158. console.log(this.config)
  159. },
  160. sliderChange(e) { //滑动块
  161. this.config.interval = e.detail.value
  162. },
  163. chongqi() { //重启按钮
  164. this.restart('reboot')
  165. },
  166. async operate(cmd){
  167. const res = await this.$myRequest({
  168. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  169. data: {
  170. device_id: this.device_id,
  171. order: cmd
  172. }
  173. })
  174. console.log(res)
  175. if (res == true) {
  176. uni.showToast({
  177. title: '指令下发成功!'
  178. });
  179. } else {
  180. uni.showToast({
  181. title: '指令下发失败!',
  182. icon: "none"
  183. });
  184. }
  185. },
  186. async submit(){
  187. const res = await this.$myRequest({
  188. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  189. data: {
  190. device_id: this.device_id,
  191. interval: this.config.interval
  192. }
  193. })
  194. console.log(res)
  195. if (res == true) {
  196. uni.showToast({
  197. title: '指令下发成功!'
  198. });
  199. } else {
  200. uni.showToast({
  201. title: '指令下发失败!',
  202. icon: "none"
  203. });
  204. }
  205. },
  206. // shengji() { //升级按钮
  207. // this.restart('update')
  208. // },
  209. search() { //查询按钮
  210. this.uploading()
  211. }
  212. },
  213. onLoad(option) {
  214. this.id = option.id
  215. this.device_type_id = option.device_type_id
  216. if(option.device_id){
  217. this.device_id = option.device_id
  218. }
  219. },
  220. onShow() {
  221. if(this.device_type_id==38){
  222. this.controsdataLow()
  223. }else{
  224. this.controsdata()
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="scss">
  230. .operation_title {
  231. border-left: 6rpx solid #28AE4F;
  232. padding-left: 20rpx;
  233. margin-bottom: 20rpx;
  234. height: 36rpx;
  235. }
  236. .contros_box{
  237. position: absolute;
  238. top: 54px;
  239. width: 90%;
  240. left: 5%;
  241. }
  242. .operation {
  243. width: 95%;
  244. .operation_btn {
  245. display: flex;
  246. padding-left: 20rpx;
  247. box-sizing: border-box;
  248. button {
  249. font-size: 24rpx;
  250. background-color: #28AE4F;
  251. color: #FFFFFF;
  252. box-sizing: border-box;
  253. height: 60rpx;
  254. }
  255. button:last-child {
  256. width: 360rpx !important;
  257. }
  258. }
  259. }
  260. .viewing {
  261. width: 95%;
  262. margin-top: 30rpx;
  263. .viewing_text {
  264. .viewing_text_top,
  265. .viewing_text_bot {
  266. display: flex;
  267. background-color: #F7F8FA;
  268. padding-left: 20rpx;
  269. margin-bottom: 20rpx;
  270. height: 60rpx;
  271. line-height: 60rpx;
  272. font-size: 24rpx;
  273. input {
  274. font-size: 24rpx;
  275. margin: 16rpx 0 0 10rpx;
  276. width: 380rpx;
  277. }
  278. }
  279. }
  280. }
  281. .timing {
  282. width: 95%;
  283. margin-top: 30rpx;
  284. }
  285. .ensure {
  286. width: 100%;
  287. margin-top: 30rpx;
  288. .ensure_btn {
  289. width: 90%;
  290. margin: 0 auto;
  291. height: 60rpx;
  292. line-height: 60rpx;
  293. text-align: center;
  294. background-color: #28AE4F;
  295. color: #FFFFFF;
  296. border-radius: 200rpx;
  297. }
  298. }
  299. </style>