deviceControl.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <template>
  2. <view class="device-detail">
  3. <view class="device-detail__header">
  4. <u-icon
  5. size="36"
  6. class="arrow-left"
  7. name="arrow-left"
  8. @click="handleBack"
  9. ></u-icon>
  10. {{ title }}
  11. </view>
  12. <view class="device-detail__body">
  13. <view class="tabs">
  14. <view class="tab-container">
  15. <view class="tab-item" :class="activeTab === 'pestAnalysis'?'active':''" @click="handleTabClick('pestAnalysis')">
  16. 管理员
  17. </view>
  18. <view class="tab-item" :class="activeTab === 'viewImage'?'active':''" @click="handleTabClick('viewImage')">
  19. 设置
  20. </view>
  21. </view>
  22. </view>
  23. <view class="device-detail-content" v-if="activeTab === 'pestAnalysis'">
  24. <view class="device-detail-item">
  25. <text class="device-detail-label">联网模块</text>
  26. <view class="device-detail-btn-container">
  27. <view class="device-detail-btn" @click="setDeviceContorl('dtu_update')">升级</view>
  28. <view class="device-detail-btn" @click="setDeviceContorl('dtu_reboot')">重启</view>
  29. <!-- <view class="device-detail-btn" @click="showMqttConfig">MQTT配置</view> -->
  30. </view>
  31. </view>
  32. <view class="device-detail-item">
  33. <text class="device-detail-label">板子设置</text>
  34. <view class="device-detail-btn-container">
  35. <!-- <view class="device-detail-btn">查看原始IMEI</view> -->
  36. <view class="device-detail-btn" @click="showMqttConfig('imei')">更改IMEI</view>
  37. </view>
  38. </view>
  39. <view class="device-detail-item">
  40. <text class="device-detail-label">强制操作</text>
  41. <view class="device-detail-btn-container">
  42. <view class="device-detail-btn force-btn" @click="setDeviceContorl('takephoto')">拍照</view>
  43. <view class="device-detail-btn force-btn" @click="setDeviceContorl('update')">升级</view>
  44. <view class="device-detail-btn force-btn" @click="setDeviceContorl('reboot')">重启</view>
  45. <view class="device-detail-btn force-btn" @click="setDeviceContorl('autotakephoto')">对焦拍照</view>
  46. <view class="device-detail-btn force-btn" @click="setDeviceContorl('turn')">转仓</view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="device-detail-content" style="padding-bottom: 50rpx" v-if="activeTab === 'viewImage'">
  51. <view class="device-detail-viewImage">
  52. <u-icon name="clock" color="#0bbc58" size="46"></u-icon>
  53. <text class="device-detail-label" style="margin-left: 10rpx">
  54. 采集开始和关闭时间
  55. </text>
  56. <view class="clear-btn" @click="clearTime">清空</view>
  57. </view>
  58. <view class="time-container" v-for="(item,index) in coll_time" :key="index">
  59. <view class="start-time" @click="showPickerHandler(index,'start_time')">{{item.start_time_label || '开始时间'}}</view>-
  60. <view class="end-time" @click="showPickerHandler(index,'end_time')">{{item.end_time_label || '结束时间'}}
  61. </view><u-icon name="clock" color="#4E5969" size="26" style="padding-right: 20rpx"></u-icon>
  62. </view>
  63. <view class="device-detail-viewImage">
  64. <text class="device-detail-label">高温保护阀值(℃)
  65. {{ equipContrlForm.tph }}</text>
  66. </view>
  67. <view class="slider-container">
  68. <view class="slider-min-value">50</view>
  69. <u-slider v-model="equipContrlForm.tph" class="slider" :min="50" :max="70" active-color="#0bbc58"></u-slider>
  70. <view class="slider-max-value">70</view>
  71. </view>
  72. <view class="device-detail-viewImage">
  73. <text class="device-detail-label">低温保护阀值(℃)
  74. {{ equipContrlForm.tpl }}</text>
  75. </view>
  76. <view class="slider-container">
  77. <view class="slider-min-value">-30</view>
  78. <u-slider v-model="equipContrlForm.tpl" class="slider" :min="-30" :max="20" active-color="#0bbc58"></u-slider>
  79. <view class="slider-max-value">20</view>
  80. </view>
  81. <view class="device-detail-viewImage">
  82. <text class="device-detail-label">数据上传间隔(min)
  83. {{ equipContrlForm.datt }}</text>
  84. </view>
  85. <view class="slider-container">
  86. <view class="slider-min-value">10</view>
  87. <u-slider v-model="equipContrlForm.datt" class="slider" :max="60" :min="10" active-color="#0bbc58"></u-slider>
  88. <view class="slider-max-value">60</view>
  89. </view>
  90. </view>
  91. </view>
  92. <view class="device-detail-btn-footer" v-if="activeTab === 'viewImage'">
  93. <view class="device-detail-btn" @click="saveSettings">保存</view>
  94. </view>
  95. <u-popup v-model="show" mode="bottom">
  96. <view class="device-detail-content" style="height: 50vh">
  97. <view class="device-detail-item">
  98. <text class="device-detail-label">请输入imei</text>
  99. <u-input v-model="equipContrlForm.imei" placeholder="请输入imei"></u-input>
  100. </view>
  101. </view>
  102. <view class="device-detail-btn-footer">
  103. <view class="device-detail-btn" @click="setDeviceContorl('imei')">保存</view>
  104. </view>
  105. </u-popup>
  106. <u-select v-model="showPicker" :list="timeList" @confirm="confirmPicker"></u-select>
  107. </view>
  108. </template>
  109. <script>
  110. export default {
  111. data(){
  112. return {
  113. showPicker: false,
  114. value: 10,
  115. timeList: [],
  116. imageList: [],
  117. coll_time:[{
  118. start_time: '',
  119. start_time_label: '',
  120. end_time: '',
  121. end_time_label: '',
  122. },{
  123. start_time: '',
  124. start_time_label: '',
  125. end_time: '',
  126. end_time_label: '',
  127. },{
  128. start_time: '',
  129. start_time_label: '',
  130. end_time: '',
  131. end_time_label: '',
  132. }],
  133. equipContrlForm: {},
  134. time: '',
  135. activeTab: 'pestAnalysis',
  136. title: '设置控制',
  137. deviceType: '',
  138. location: '',
  139. d_id: '',
  140. show: false,
  141. checked: false,
  142. currentIndex: -1,
  143. currentType: ''
  144. }
  145. },
  146. onLoad(options){
  147. this.d_id = options.d_id;
  148. this.getControlDeviceConfigInfo();
  149. this.timeList = [];
  150. for(let i = 0;i<24;i++){
  151. this.timeList.push({
  152. value:i,
  153. label:i < 10 ? '0' + i + ':00' : i + ':00'
  154. })
  155. }
  156. },
  157. methods: {
  158. clearTime(){
  159. this.coll_time.forEach(item => {
  160. item.start_time = '';
  161. item.start_time_label = '';
  162. item.end_time = '';
  163. item.end_time_label = '';
  164. })
  165. },
  166. confirmPicker(e){
  167. const value = e[0].value;
  168. const label = e[0].label;
  169. if(this.currentType == 'end_time'){
  170. if(this.coll_time[this.currentIndex]['start_time'] > value){
  171. uni.showToast({
  172. title: '结束时间不能早于开始时间',
  173. icon: 'none',
  174. })
  175. return
  176. }
  177. }
  178. if(this.currentType == 'start_time' && this.currentIndex > 0){
  179. if(this.coll_time[this.currentIndex-1]['end_time'] > value){
  180. uni.showToast({
  181. title: '开始时间不能早于前面采集时间的结束时间',
  182. icon: 'none',
  183. })
  184. return
  185. }
  186. }
  187. if(this.currentType == 'start_time' && this.coll_time[this.currentIndex]['end_time'] !== ''){
  188. if(value > this.coll_time[this.currentIndex]['end_time']){
  189. uni.showToast({
  190. title: '开始时间不能晚于结束时间',
  191. icon: 'none',
  192. })
  193. return
  194. }
  195. }
  196. this.coll_time[this.currentIndex][this.currentType] = value;
  197. this.coll_time[this.currentIndex][this.currentType + '_label'] = label;
  198. },
  199. showPickerHandler(index,type){
  200. if(type == 'end_time'){
  201. if(this.coll_time[index]['start_time'] === ''){
  202. uni.showToast({
  203. title: '请先选择开始时间',
  204. icon: 'none',
  205. })
  206. return
  207. }
  208. }
  209. if(index != 0){
  210. if(this.coll_time[index-1]['start_time_label'] === '' || this.coll_time[index-1]['end_time_label'] === ''){
  211. uni.showToast({
  212. title: '请先选择前面采集时间的开始和结束时间',
  213. icon: 'none',
  214. })
  215. return
  216. }
  217. }
  218. this.showPicker = true;
  219. this.currentIndex = index
  220. this.currentType = type
  221. },
  222. closePicker(){
  223. this.showPicker = false;
  224. this.currentType = ''
  225. this.currentIndex = -1
  226. },
  227. handleBack() {
  228. uni.navigateBack({
  229. delta: 1
  230. });
  231. },
  232. handleTabClick(tab) {
  233. this.activeTab = tab;
  234. },
  235. showMqttConfig(){
  236. this.show = true;
  237. },
  238. closeMqttConfig(){
  239. this.show = false;
  240. },
  241. async setDeviceContorl(type){
  242. const data = {
  243. device_type_id: 3,
  244. d_id: this.d_id,
  245. cmd: type,
  246. }
  247. if(type === 'imei'){
  248. data.imei = this.equipContrlForm.imei
  249. }else{
  250. delete data.imei
  251. }
  252. this.$myRequest({
  253. url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
  254. method: 'POST',
  255. data
  256. }).then(res => {
  257. this.closeMqttConfig()
  258. if (res) {
  259. uni.showToast({
  260. title: '设备控制修改成功!',
  261. icon: 'success',
  262. });
  263. } else {
  264. uni.showToast({
  265. title: '设备控制修改失败',
  266. icon: 'error',
  267. });
  268. }
  269. });
  270. },
  271. saveSettings(){
  272. let newForm = Object.assign({}, this.equipContrlForm) // 深拷贝
  273. newForm.st = newForm.st + ''
  274. newForm.et = newForm.et + ''
  275. newForm.st && newForm.st.slice(0, 2).charAt(0) != '0'
  276. ? newForm.st.slice(0, 2)
  277. : newForm.st.slice(1, 2)
  278. newForm.et =
  279. newForm.et && newForm.et.slice(0, 2).charAt(0) != '0'
  280. ? newForm.et.slice(0, 2)
  281. : newForm.et.slice(1, 2)
  282. for (let k in newForm) {
  283. if (typeof newForm[k] === 'number') {
  284. newForm[k] = newForm[k] + ''
  285. }
  286. }
  287. newForm.st = newForm.st.replace(':00', '')
  288. console.log(this.coll_time,'coll_timecoll_timecoll_time')
  289. const coll_time = [];
  290. for(let i = 0;i< this.coll_time.length;i++){
  291. const coll_item = this.coll_time[i];
  292. if(String(coll_item.start_time) && String(coll_item.end_time)){
  293. coll_time.push(String(coll_item.start_time) + '-' + String(coll_item.end_time))
  294. }
  295. }
  296. newForm.coll_time = coll_time
  297. this.$myRequest({
  298. url: '/api/api_gateway?method=forecast.send_control.device_control',
  299. method: 'POST',
  300. data: {
  301. device_type_id: 3,
  302. d_id: this.d_id,
  303. config: JSON.stringify(newForm)
  304. }
  305. }).then(res => {
  306. if (res) {
  307. // 设备控制修改成功
  308. uni.showToast({
  309. title: '设备控制修改成功!',
  310. icon: 'success',
  311. });
  312. } else {
  313. uni.showToast({
  314. title: '设备控制修改失败',
  315. icon: 'error',
  316. });
  317. }
  318. })
  319. },
  320. async getControlDeviceConfigInfo(){
  321. const res = await this.$myRequest({
  322. url: '/api/api_gateway?method=forecast.send_control.device_control_info',
  323. method: 'POST',
  324. data: {
  325. d_id: this.d_id,
  326. cmd:'paramconf'
  327. },
  328. });
  329. this.equipContrlForm = res
  330. const coll_time = res?.coll_time || [];
  331. for(let i = 0;i< coll_time.length;i++){
  332. const coll_item = coll_time[i];
  333. const start_time = coll_item.split('-')[0];
  334. const end_time = coll_item.split('-')[1];
  335. this.coll_time[i]['start_time'] = start_time;
  336. this.coll_time[i]['end_time'] = end_time;
  337. this.coll_time[i]['start_time_label'] = start_time >= 10 ? start_time + ':00' : '0' + start_time + ':00';
  338. this.coll_time[i]['end_time_label'] = end_time >= 10 ? end_time + ':00' : '0' + end_time + ':00';
  339. }
  340. console.log(this.coll_time,'coll_timecoll_timecoll_time')
  341. this.equipContrlForm.tph = Number(this.equipContrlForm.tph || 50)
  342. this.equipContrlForm.tpl = Number(this.equipContrlForm.tpl || 0)
  343. },
  344. }
  345. }
  346. </script>
  347. <style scoped lang="scss">
  348. .device-detail {
  349. display: flex;
  350. width: 100%;
  351. height: calc(100vh - 112rpx);
  352. padding-top: 112rpx;
  353. flex-direction: column;
  354. align-items: center;
  355. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  356. .device-detail__header {
  357. width: 100%;
  358. font-size: 28rpx;
  359. color: #999;
  360. color: #042118;
  361. font-family: 'Source Han Sans CN VF';
  362. font-weight: 700;
  363. position: relative;
  364. text-align: center;
  365. .arrow-left {
  366. position: absolute;
  367. left: 32rpx;
  368. margin-right: 12rpx;
  369. }
  370. }
  371. .time-container{
  372. display: flex;
  373. justify-content: center;
  374. align-items: center;
  375. color: #999999;
  376. border-radius: 8rpx;
  377. background:#F6F8FC;
  378. gap: 12rpx;
  379. .start-time{
  380. width: 250rpx;
  381. height: 50rpx;
  382. line-height: 50rpx;
  383. text-align: left;
  384. font-size: 24rpx;
  385. color: #999999;
  386. font-family: 'Source Han Sans CN VF';
  387. border-radius: 16rpx;
  388. padding: 0 24rpx;
  389. }
  390. .end-time{
  391. width: 200rpx;
  392. height: 50rpx;
  393. line-height: 50rpx;
  394. text-align: left;
  395. font-size: 24rpx;
  396. color: #999999;
  397. font-family: 'Source Han Sans CN VF';
  398. border-radius: 16rpx;
  399. padding: 0 24rpx;
  400. }
  401. }
  402. .device-detail__body {
  403. width: calc(100% - 64rpx);
  404. margin: 0 auto;
  405. border-radius: 16rpx;
  406. overflow-x: hidden;
  407. overflow-y: auto;
  408. // 隐藏滚动条
  409. -ms-overflow-style: none;
  410. scrollbar-width: none;
  411. }
  412. .tabs {
  413. margin: 24rpx 0;
  414. border-radius: 16rpx;
  415. padding: 16rpx 0;
  416. padding-top: 0;
  417. .tab-container{
  418. display: flex;
  419. width: 100%;
  420. height: 88rpx;
  421. line-height: 88rpx;
  422. text-align: center;
  423. font-size: 28rpx;
  424. color: #042118;
  425. font-family: 'Source Han Sans CN VF';
  426. }
  427. .tab-item {
  428. margin-right: 40rpx;
  429. color:#999999;
  430. }
  431. .active{
  432. position: relative;
  433. color: #0bbc58;
  434. text-align: center;
  435. font-family: "Source Han Sans CN VF";
  436. font-size: 28rpx;
  437. font-weight: 700;
  438. &::after {
  439. content: '';
  440. position: absolute;
  441. bottom: 10rpx;
  442. left: 50%;
  443. transform: translateX(-50%);
  444. width: 100%;
  445. height: 36rpx;
  446. border-bottom: 6rpx solid #0bbc58;
  447. }
  448. }
  449. }
  450. .slider-container{
  451. position: relative;
  452. margin-bottom: 20rpx;
  453. .slider-min-value{
  454. position: absolute;
  455. left: 0;
  456. top: -50rpx;
  457. }
  458. .slider{
  459. width: 600rpx;
  460. }
  461. .slider-max-value{
  462. position: absolute;
  463. right: 0;
  464. top: -50rpx;
  465. }
  466. }
  467. .device-detail-content{
  468. display: flex;
  469. padding: 24rpx 32rpx;
  470. flex-direction: column;
  471. align-items: flex-start;
  472. gap: 20rpx;
  473. border-radius: 16rpx;
  474. background: #FFF;
  475. .device-detail-item{
  476. .device-detail-label{
  477. color: #303133;
  478. font-family: "Source Han Sans CN VF";
  479. font-size: 28rpx;
  480. font-weight: 400;
  481. }
  482. .device-detail-btn-container{
  483. display: flex;
  484. gap: 24rpx;
  485. margin-top: 12rpx;
  486. }
  487. .device-detail-btn{
  488. display: flex;
  489. padding: 10rpx 16rpx;
  490. justify-content: center;
  491. align-items: center;
  492. gap: 16rpx;
  493. border-radius: 16rpx;
  494. background: #0bbc58;
  495. color: #ffffff;
  496. font-family: "Source Han Sans CN VF";
  497. font-size: 24rpx;
  498. font-weight: 400;
  499. }
  500. .force-btn{
  501. background: #FB4E52;
  502. }
  503. }
  504. .device-detail-viewImage{
  505. width: 100%;
  506. display: flex;
  507. align-items: center;
  508. padding-bottom: 20rpx;
  509. position: relative;
  510. .clear-btn{
  511. position: absolute;
  512. right: 0rpx;
  513. border: 1rpx solid #0bbc58;
  514. border-radius: 8rpx;
  515. padding: 4rpx 12rpx;
  516. font-size: 24rpx;
  517. color: #0bbc58;
  518. font-family: 'Source Han Sans CN VF';
  519. font-weight: 400;
  520. }
  521. }
  522. }
  523. .device-detail-btn-footer{
  524. position: fixed;
  525. bottom: 0;
  526. left: 0;
  527. width: 100%;
  528. height: 112rpx;
  529. line-height: 112rpx;
  530. text-align: center;
  531. font-size: 28rpx;
  532. font-weight: 700;
  533. color: #042118;
  534. font-family: 'Source Han Sans CN VF';
  535. background: #ffffff;
  536. display: flex;
  537. justify-content: center;
  538. align-items: center;
  539. .device-detail-btn{
  540. display: flex;
  541. height: 80rpx;
  542. width: 90%;
  543. margin: 0 auto;
  544. padding: 0rpx 20rpx;
  545. justify-content: center;
  546. align-items: center;
  547. gap: 8rpx;
  548. border-radius: 16rpx;
  549. background:#0bbc58;
  550. color: #ffffff;
  551. text-align: center;
  552. font-family: "Source Han Sans CN VF";
  553. font-size: 14px;
  554. font-style: normal;
  555. font-weight: 500;
  556. }
  557. }
  558. }
  559. </style>