deviceControl.vue 18 KB

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