equip-set-sy2.vue 14 KB

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