equip-set.vue 14 KB

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