equip-set-sy2.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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=='0'">
  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=='1'">
  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: 1, label: '光控模式' },
  136. { value: 0, 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. this.tsArrLabel = e[0].label
  373. this.equipContrlForm.ctrlMode = e[0].value
  374. },
  375. gkArrConfirm(e){
  376. this.gkongLabel = e[0].label
  377. this.equipContrlForm.lightDuration = e[0].value
  378. },
  379. dataconfirm(e){
  380. this.equipContrlForm[this.currentFormKey] = e[0].value
  381. },
  382. shikongconfirm(e){
  383. console.log(e)
  384. this.shikongLabel = e[0].label+'-'+e[1].label
  385. this.equipContrlForm.startHour = e[0].value
  386. this.equipContrlForm.endHour = e[1].value
  387. },
  388. photoConfirm(e){
  389. this.photoLabel = e[0].label+'-'+e[1].label
  390. this.equipContrlForm.P_START = e[0].value
  391. this.equipContrlForm.P_END = e[1].value
  392. },
  393. turnChange(e, a) {
  394. this.equipContrlForm.ts = e.target.value
  395. },
  396. async getInfo() {
  397. let res = await this.$myRequest({
  398. url: '/api/api_gateway?method=new_gateway.device_info.get_device_config',
  399. data: {
  400. device_type_id:this.device_type,
  401. id: this.d_id
  402. }
  403. })
  404. if(res.code==4000){
  405. this.submitBtnDisabled = true
  406. this.$refs.toast.show({
  407. title: res.msg,
  408. type: 'warning'
  409. })
  410. return
  411. }
  412. this.equipContrlForm = res
  413. this.tsArrLabel = res.ctrlMode=='1' ? '光控模式':'时控模式'
  414. this.gkongLabel = res.lightDuration + 'h'
  415. this.shikongLabel = res.startHour + ':00' + ' - '+res.endHour + ':00'
  416. console.log(this.equipContrlForm)
  417. },
  418. async submit() {
  419. console.log(this.equipContrlForm)
  420. let res = await this.$myRequest({
  421. url: '/api/api_gateway?method=new_gateway.device_info.update_device_config',
  422. data: {
  423. device_type_id: this.device_type,
  424. id: this.d_id,
  425. ...this.equipContrlForm
  426. }
  427. })
  428. console.log('响应',res)
  429. if(res){
  430. this.$refs.toast.show({
  431. title: '设备控制指令下发成功!',
  432. type: 'success',
  433. })
  434. }
  435. if(res.code==4000){
  436. this.$refs.toast.show({
  437. title: res.msg+'无法修改',
  438. type: 'warning'
  439. })
  440. }
  441. },
  442. async equipBtnControl(cmd) {
  443. let res = await this.$myRequest({
  444. url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
  445. data: {
  446. cmd,
  447. device_type_id: this.device_type,
  448. d_id: this.d_id
  449. }
  450. })
  451. console.log(res,'响应----')
  452. if (res) {
  453. this.$refs.toast.show({
  454. title: '指令下发成功!',
  455. type: 'success',
  456. })
  457. }
  458. },
  459. async mqttInfo() {
  460. let res = await this.$myRequest({
  461. url: '/api/api_gateway?method=forecast.send_control.device_control_info',
  462. data: {
  463. cmd: 'netconf',
  464. d_id: this.d_id
  465. }
  466. })
  467. if (res) {
  468. let {
  469. ftp,
  470. mqtt
  471. } = res
  472. this.mqttConfig = {
  473. muid: mqtt.uid,
  474. mpwd: mqtt.pwd,
  475. mip: mqtt.ip,
  476. mport: mqtt.port,
  477. mpub: mqtt.pub,
  478. msub: mqtt.sub,
  479. fuid: ftp.uid,
  480. fpwd: ftp.pwd,
  481. fip: ftp.ip,
  482. fport: ftp.port
  483. }
  484. }
  485. this.mqttShow = true
  486. },
  487. async mqttSubm() {
  488. let obj = {
  489. mqtt: {
  490. uid: this.mqttConfig.muid,
  491. pwd: this.mqttConfig.mpwd,
  492. ip: this.mqttConfig.mip,
  493. port: this.mqttConfig.mport,
  494. pub: this.mqttConfig.mpub,
  495. sub: this.mqttConfig.msub,
  496. keepalive: 60,
  497. lastwill: '/yfkj/cbd/offline/'
  498. },
  499. ftp: {
  500. uid: this.mqttConfig.fuid,
  501. pwd: this.mqttConfig.fpwd,
  502. ip: this.mqttConfig.fip,
  503. port: this.mqttConfig.fport
  504. }
  505. }
  506. let res = await this.$myRequest({
  507. url: '/api/api_gateway?method=forecast.send_control.device_control',
  508. data: {
  509. device_type_id: 3,
  510. d_id: this.d_id,
  511. cmd: 'setnet',
  512. config: JSON.stringify(obj)
  513. }
  514. })
  515. }
  516. }
  517. }
  518. </script>
  519. <style lang="scss" scoped>
  520. page {
  521. padding: 20rpx;
  522. box-sizing: border-box;
  523. .tit {
  524. line-height: 30rpx;
  525. font-size: 28rpx;
  526. margin: 30rpx 0;
  527. color: #666666;
  528. }
  529. .adminTit {
  530. border-left-color: #e64340;
  531. }
  532. .btns {
  533. display: flex;
  534. justify-content: flex-start;
  535. flex-wrap: wrap;
  536. gap: 16rpx;
  537. button {
  538. margin: 0;
  539. margin-right: 10rpx;
  540. padding: 0 25rpx;
  541. }
  542. }
  543. .uni-list-cell {
  544. // background: #F7F8FA;
  545. // padding: 10rpx 40rpx;
  546. height: 80rpx;
  547. line-height: 80rpx;
  548. font-size: 28rpx;
  549. box-sizing: border-box;
  550. .arrow{
  551. margin-left: 30rpx;
  552. }
  553. .right-data{
  554. color: #CCCCCC;
  555. }
  556. }
  557. .selectTime {
  558. display: flex;
  559. float: right;
  560. width: 30%;
  561. color: #CCCCCC;
  562. justify-content: space-between;
  563. .time {
  564. // width: 350rpx;
  565. // display: flex;
  566. // justify-content: space-between;
  567. }
  568. .line {
  569. width: 50rpx;
  570. text-align: center;
  571. }
  572. }
  573. .submit-box {
  574. margin-top: 60rpx
  575. }
  576. .mqtt-popup {
  577. width: 580rpx;
  578. }
  579. .mqtt-btn-box {
  580. margin-top: 50rpx;
  581. text-align: center;
  582. }
  583. }
  584. </style>