equip-set.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <view>
  3. <view class="tit adminTit">
  4. 联网模块
  5. </view>
  6. <view class="btns">
  7. <button type="warn" @click="equipBtnControl('dtu_update')" size="mini">升级</button>
  8. <button type="warn" @click="equipBtnControl('dtu_reboot')" size="mini">重启</button>
  9. <button type="warn" @click="mqttInfo" size="mini">MQTT配置</button>
  10. </view>
  11. <view class="tit adminTit">
  12. 板子设置
  13. </view>
  14. <view class="btns">
  15. <button type="warn" size="mini">查看原始IMEI</button>
  16. <button type="warn" size="mini">更改IMEI</button>
  17. </view>
  18. <view class="tit adminTit">
  19. 强制操作
  20. </view>
  21. <view class="btns">
  22. <button type="warn" @click="equipBtnControl('takephoto')" size="mini">拍照</button>
  23. <button type="warn" @click="equipBtnControl('update')" size="mini">升级</button>
  24. <button type="warn" @click="equipBtnControl('reboot')" size="mini">重启</button>
  25. <button type="warn" @click="equipBtnControl('close_shake')" size="mini">震动关闭</button>
  26. <button type="warn" @click="equipBtnControl('open_shake')" size="mini">震动开启</button>
  27. </view>
  28. <view class="tit">
  29. 设备开关
  30. </view>
  31. <view class="uni-list-cell">
  32. <picker @change="turnChange($event,'ds')" value="equipContrlForm.ds" :range="dsArr">
  33. <text class="uni-input">{{dsArr[equipContrlForm.ds]}}</text>
  34. <view class="arrow"></view>
  35. </picker>
  36. </view>
  37. <!-- <view class="tit">
  38. 工作状态
  39. </view>
  40. <view class="uni-list-cell">
  41. <picker @change="turnChange($event,'ws')" :value="equipContrlForm.ws" :range="wsArr">
  42. <text class="uni-input">{{wsArr[equipContrlForm.ws]}}</text>
  43. <view class="arrow"></view>
  44. </picker>
  45. <u-modal v-model="wsModelShow" content="确定修改工作模式?" show-cancel-button @confirm="wsConfirm" @cancel="wsCancel" ref="uModal" ></u-modal>
  46. <u-toast ref="wsToast" />
  47. </view> -->
  48. <view class="tit">
  49. 定时模式
  50. </view>
  51. <view class="uni-list-cell">
  52. <picker @change="turnChange($event,'ts')" :value="equipContrlForm.ts" :range="tsArr">
  53. <text class="uni-input">{{tsArr[equipContrlForm.ts]}}</text>
  54. <view class="arrow"></view>
  55. </picker>
  56. </view>
  57. <template v-if="equipContrlForm.ts==0">
  58. <view class="tit">
  59. 定时时长(h)
  60. </view>
  61. <view class="">
  62. <slider :value="equipContrlForm.tt" show-value="true" :min="1" :max="10" @change="sliderChange($event,'tt')" block-color="#57C878" activeColor="#57C878" step="1" />
  63. </view>
  64. </template>
  65. <template v-if="equipContrlForm.ts==1">
  66. <view class="tit">
  67. 开始结束时间
  68. </view>
  69. <view class="selectTime">
  70. <view class="uni-list-cell time" @click="selectTime('st')">
  71. <text>{{stLabel}}</text>
  72. <u-icon name="clock"></u-icon>
  73. </view>
  74. <text class="line">-</text>
  75. <view class="uni-list-cell time" @click="selectTime('et')">
  76. <text>{{etLabel}}</text>
  77. <u-icon name="clock"></u-icon>
  78. </view>
  79. </view>
  80. <u-select v-model="stShow" mode="single-column" :list="list" @confirm="stConfirm"></u-select>
  81. <u-select v-model="etShow" mode="single-column" :list="list" @confirm="etConfirm"></u-select>
  82. </template>
  83. <view class="tit">
  84. 落虫时间(min)
  85. </view>
  86. <view class="">
  87. <slider :value="equipContrlForm.collt" show-value="true" :min="1" :max="20" @change="sliderChange($event,'collt')" block-color="#57C878" activeColor="#57C878" step="1" />
  88. </view>
  89. <view class="tit">
  90. 加热时间(min)
  91. </view>
  92. <view class="">
  93. <slider :value="equipContrlForm.htim" show-value="true" :min="1" :max="20" @change="sliderChange($event,'htim')" block-color="#57C878" activeColor="#57C878" step="1" />
  94. </view>
  95. <view class="tit">
  96. 加热温度(℃)
  97. </view>
  98. <view class="">
  99. <slider :value="equipContrlForm.hst" show-value="true" :min="75" :max="120" @change="sliderChange($event,'hst')" block-color="#57C878" activeColor="#57C878" step="1" />
  100. </view>
  101. <view class="tit">
  102. 高温保护阈值(℃)
  103. </view>
  104. <view class="">
  105. <slider :value="equipContrlForm.tph" show-value="true" :min="50" :max="70" @change="sliderChange($event,'tph')" block-color="#57C878" activeColor="#57C878" step="1" />
  106. </view>
  107. <view class="tit">
  108. 低温保护阈值(℃)
  109. </view>
  110. <view class="">
  111. <slider :value="equipContrlForm.tpl" show-value="true" :min="1" :max="10" @change="sliderChange($event,'tpl')" block-color="#57C878" activeColor="#57C878" step="1" />
  112. </view>
  113. <view class="tit">
  114. 数据上传间隔(min)
  115. </view>
  116. <view class="">
  117. <slider :value="equipContrlForm.datt" show-value="true" :min="10" :max="60" @change="sliderChange($event,'datt')" block-color="#57C878" activeColor="#57C878" step="1" />
  118. </view>
  119. <view class="submit-box">
  120. <u-button @click="submit" type="success">确定</u-button>
  121. </view>
  122. <u-toast ref="toast" />
  123. <u-popup v-model="mqttShow">
  124. <view class="mqtt-popup">
  125. <u-field
  126. required
  127. v-model="mqttConfig.muid"
  128. label="MQTT用户名"
  129. label-width="180"
  130. >
  131. </u-field>
  132. <u-field
  133. required
  134. v-model="mqttConfig.mpwd"
  135. label="MQTT密码"
  136. label-width="180"
  137. >
  138. </u-field>
  139. <u-field
  140. required
  141. v-model="mqttConfig.mpi"
  142. label="MQTT地址"
  143. label-width="180"
  144. >
  145. </u-field>
  146. <u-field
  147. required
  148. v-model="mqttConfig.mport"
  149. label="MQTT端口"
  150. label-width="180"
  151. >
  152. </u-field>
  153. <u-field
  154. required
  155. v-model="mqttConfig.mpub"
  156. label="上传地址"
  157. label-width="180"
  158. >
  159. </u-field>
  160. <u-field
  161. required
  162. v-model="mqttConfig.msub"
  163. label="下发地址"
  164. label-width="180"
  165. >
  166. </u-field>
  167. <u-field
  168. v-model="mqttConfig.fuid"
  169. label="FTP用户名"
  170. label-width="180"
  171. >
  172. </u-field>
  173. <u-field
  174. v-model="mqttConfig.fpwd"
  175. label="FTP密码"
  176. label-width="180"
  177. >
  178. </u-field>
  179. <u-field
  180. required
  181. v-model="mqttConfig.fip"
  182. label="图片上传地址"
  183. label-width="180"
  184. >
  185. </u-field>
  186. <u-field
  187. required
  188. v-model="mqttConfig.fport"
  189. label="图片上传接口"
  190. label-width="180"
  191. >
  192. </u-field>
  193. </view>
  194. <view class="mqtt-btn-box">
  195. <u-button @click="" size="medium" type="success">确定</u-button>
  196. </view>
  197. </u-popup>
  198. </view>
  199. </template>
  200. <script>
  201. export default {
  202. data() {
  203. return {
  204. d_id:'',
  205. dsArr:['开机','关机'],
  206. dsIndex:0,
  207. wsArr:['待机','工作'],
  208. wsIndex:0,
  209. tsArr:['光控','时控'],
  210. tsIndex:0,
  211. imgresArr:['高','中','低'],
  212. imgresIndex:"",
  213. wsModelShow:false,
  214. equipContrlForm:{
  215. ds:0,//设备开关
  216. ts:0,//定时模式
  217. tt:1,//定时时长
  218. ws:0,//工作状态
  219. collt: 1,
  220. htim: 1,
  221. hst: 75,
  222. tph: 50,
  223. tpl: 1,
  224. datt: 10,
  225. st: null,
  226. et: null,
  227. },
  228. stShow:false,
  229. etShow:false,
  230. stLabel:'00:00',
  231. etLabel:'00:00',
  232. list:[
  233. {
  234. value:0,
  235. label:'00:00'
  236. },
  237. {
  238. value:1,
  239. label:'01:00'
  240. },
  241. {
  242. value:2,
  243. label:'02:00'
  244. },
  245. {
  246. value:3,
  247. label:'03:00'
  248. },
  249. {
  250. value:4,
  251. label:'04:00'
  252. },
  253. {
  254. value:5,
  255. label:'05:00'
  256. },
  257. {
  258. value:6,
  259. label:'06:00'
  260. },
  261. {
  262. value:7,
  263. label:'04:00'
  264. }, {
  265. value:8,
  266. label:'08:00'
  267. },
  268. {
  269. value:9,
  270. label:'09:00'
  271. },
  272. {
  273. value:10,
  274. label:'10:00'
  275. },
  276. {
  277. value:11,
  278. label:'11:00'
  279. },
  280. {
  281. value:12,
  282. label:'12:00'
  283. },
  284. {
  285. value:13,
  286. label:'13:00'
  287. },
  288. {
  289. value:14,
  290. label:'14:00'
  291. }, {
  292. value:15,
  293. label:'15:00'
  294. },
  295. {
  296. value:16,
  297. label:'16:00'
  298. },
  299. {
  300. value:17,
  301. label:'17:00'
  302. },
  303. {
  304. value:18,
  305. label:'18:00'
  306. },
  307. {
  308. value:19,
  309. label:'19:00'
  310. },
  311. {
  312. value:20,
  313. label:'20:00'
  314. },
  315. {
  316. value:21,
  317. label:'21:00'
  318. }, {
  319. value:22,
  320. label:'22:00'
  321. },
  322. {
  323. value:23,
  324. label:'23:00'
  325. },
  326. ],
  327. mqttShow:false,
  328. mqttConfig: {
  329. muid: '',
  330. mpwd: '',
  331. mip: '',
  332. mport: '',
  333. mpub: '',
  334. msub: '',
  335. fuid: '',
  336. fpwd: '',
  337. fip: '',
  338. fport: ''
  339. },
  340. }
  341. },
  342. onLoad(option){
  343. this.d_id=option.d_id
  344. this.getInfo()
  345. },
  346. methods: {
  347. turnChange(e,a){
  348. if(a=='ds'){
  349. // this.dsIndex = e.target.value
  350. this.equipContrlForm.ds=e.target.value
  351. }else if(a=='ws'){
  352. // this.wsIndex = e.target.value
  353. this.wsModelShow=true
  354. this.equipContrlForm.ws=e.target.value
  355. }else if(a=='ts'){
  356. // this.tsIndex = e.target.value
  357. this.equipContrlForm.ts=e.target.value
  358. }
  359. },
  360. stConfirm(e){
  361. this.stLabel=e[0].label
  362. this.equipContrlForm.st=e[0].value
  363. },
  364. etConfirm(e){
  365. this.etLabel=e[0].label
  366. this.equipContrlForm.et=e[0].value
  367. },
  368. async wsConfirm(){
  369. console.log(222)
  370. const res=await this.$myRequest({
  371. url:'/api/api_gateway?method=forecast.send_control.device_control',
  372. data:{
  373. device_type_id:3,
  374. d_id:this.d_id,
  375. work_type: this.equipContrlForm.ws,
  376. }
  377. })
  378. if(res){
  379. this.$refs.wsToast.show({
  380. title: '修改成功',
  381. type: 'success',
  382. })
  383. }
  384. },
  385. wsCancel(){
  386. this.$refs.wsToast.show({
  387. title: '取消修改',
  388. type: 'default',
  389. })
  390. },
  391. selectTime(a){
  392. if(a=='st'){
  393. this.stShow=true;
  394. }else{
  395. this.etShow=true;
  396. }
  397. },
  398. sliderChange(e,a){
  399. let val=e.detail.value
  400. switch(a){
  401. case 'tt':
  402. this.equipContrlForm.tt=val;
  403. break;
  404. case 'collt':
  405. this.equipContrlForm.collt=val;
  406. break;
  407. case 'htim':
  408. this.equipContrlForm.htim=val;
  409. break;
  410. case 'hst':
  411. this.equipContrlForm.hst=val;
  412. break;
  413. case 'tph':
  414. this.equipContrlForm.tph=val;
  415. break;
  416. case 'tpl':
  417. this.equipContrlForm.tpl=val;
  418. break;
  419. case 'datt':
  420. this.equipContrlForm.datt=val;
  421. break;
  422. }
  423. },
  424. async getInfo(){
  425. let res=await this.$myRequest({
  426. url:'/api/api_gateway?method=forecast.send_control.device_control_info',
  427. data:{
  428. d_id:this.d_id,
  429. cmd: 'paramconf'
  430. }
  431. })
  432. this.stLabel =
  433. res.st && res.st < 10 ? '0' + res.st + ':00' : res.st + ':00'
  434. this.etLabel=
  435. res.et && res.et < 10 ? '0' + res.et + ':00' : res.et + ':00'
  436. this.equipContrlForm=res
  437. },
  438. async submit(){
  439. console.log(this.equipContrlForm)
  440. let res=await this.$myRequest({
  441. url:'/api/api_gateway?method=forecast.send_control.device_control',
  442. data:{
  443. device_type_id:3,
  444. d_id: this.d_id,
  445. config: JSON.stringify(this.equipContrlForm)
  446. }
  447. })
  448. if(res){
  449. this.$refs.toast.show({
  450. title: '修改成功!',
  451. type: 'success',
  452. callback:function(){
  453. uni.navigateBack({
  454. delta: 1
  455. });
  456. }
  457. })
  458. }
  459. },
  460. async equipBtnControl(cmd){
  461. let res=await this.$myRequest({
  462. url:'/api/api_gateway?method=forecast.send_control.admin_device_control',
  463. data:{
  464. cmd,
  465. device_type_id: 3,
  466. d_id: this.d_id
  467. }
  468. })
  469. if(res){
  470. this.$refs.toast.show({
  471. title: '指令下发成功!',
  472. type: 'success',
  473. })
  474. }
  475. },
  476. async mqttInfo(){
  477. let res=await this.$myRequest({
  478. url:'/api/api_gateway?method=forecast.send_control.device_control_info',
  479. data:{
  480. cmd:'netconf',
  481. d_id: this.d_id
  482. }
  483. })
  484. if(res){
  485. let {ftp, mqtt } =res
  486. this.mqttConfig = {
  487. muid: mqtt.uid,
  488. mpwd: mqtt.pwd,
  489. mip: mqtt.ip,
  490. mport: mqtt.port,
  491. mpub: mqtt.pub,
  492. msub: mqtt.sub,
  493. fuid:ftp.uid,
  494. fpwd:ftp.pwd,
  495. fip:ftp.ip,
  496. fport:ftp.port
  497. }
  498. }
  499. this.mqttShow=true
  500. },
  501. async mqttSubm(){
  502. let obj = {
  503. mqtt: {
  504. uid: this.mqttConfig.muid,
  505. pwd: this.mqttConfig.mpwd,
  506. ip: this.mqttConfig.mip,
  507. port: this.mqttConfig.mport,
  508. pub: this.mqttConfig.mpub,
  509. sub: this.mqttConfig.msub,
  510. keepalive: 60,
  511. lastwill: '/yfkj/cbd/offline/'
  512. },
  513. ftp: {
  514. uid: this.mqttConfig.fuid,
  515. pwd: this.mqttConfig.fpwd,
  516. ip: this.mqttConfig.fip,
  517. port: this.mqttConfig.fport
  518. }
  519. }
  520. let res=await this.$myRequest({
  521. url:'/api/api_gateway?method=forecast.send_control.device_control',
  522. data:{
  523. device_type_id: 3,
  524. d_id: this.d_id,
  525. cmd: 'setnet',
  526. config: JSON.stringify(obj)
  527. }
  528. })
  529. }
  530. }
  531. }
  532. </script>
  533. <style lang="scss">
  534. page{
  535. padding:20rpx;
  536. box-sizing: border-box;
  537. .tit{
  538. line-height:30rpx;
  539. font-size:30rpx;
  540. padding-left:20rpx;
  541. border-left-width:2px;
  542. border-left-style: solid;
  543. border-left-color:$uni-color-success;
  544. margin:30rpx 0;
  545. }
  546. .adminTit{border-left-color:#e64340;}
  547. .btns{
  548. display:flex;
  549. justify-content: flex-start;
  550. flex-wrap:no-wrap;
  551. button{margin:0;margin-right:10rpx;padding:0 25rpx;}
  552. }
  553. .uni-list-cell{
  554. background:#F7F8FA;
  555. padding:10rpx 40rpx;
  556. font-size:28rpx;
  557. box-sizing: border-box;
  558. .arrow{
  559. display:inline-block;
  560. border-width:12rpx 8rpx ;
  561. border-style: solid;
  562. float:right;
  563. margin-top:10rpx;
  564. border-color:#888 transparent transparent transparent;
  565. }
  566. }
  567. .selectTime{
  568. display:flex;
  569. .time{
  570. width:350rpx;
  571. display:flex;
  572. justify-content: space-between;
  573. }
  574. .line{width:50rpx;text-align: center;}
  575. }
  576. .submit-box{
  577. margin-top:60rpx
  578. }
  579. .mqtt-popup{
  580. width:580rpx;
  581. }
  582. .mqtt-btn-box{
  583. margin-top:50rpx;
  584. text-align: center;
  585. }
  586. }
  587. </style>