equip-set.vue 14 KB

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