deviceControl.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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">查看原始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. myuser_type: false,
  137. title: '设置控制',
  138. deviceType: '',
  139. location: '',
  140. d_id: '',
  141. show: false,
  142. checked: false,
  143. currentIndex: -1,
  144. currentType: ''
  145. }
  146. },
  147. onLoad(options){
  148. this.d_id = options.d_id;
  149. this.getControlDeviceConfigInfo();
  150. this.timeList = [];
  151. for(let i = 0;i<24;i++){
  152. this.timeList.push({
  153. value:i,
  154. label:i < 10 ? '0' + i + ':00' : i + ':00'
  155. })
  156. }
  157. uni.getStorage({
  158. key:"myuser_type",
  159. success:(res)=>{
  160. if(Number(res.data) == 1){
  161. this.myuser_type = true
  162. this.activeTab = 'pestAnalysis'
  163. }else{
  164. this.activeTab = 'viewImage'
  165. }
  166. }
  167. })
  168. },
  169. methods: {
  170. clearTime(){
  171. this.coll_time.forEach(item => {
  172. item.start_time = '';
  173. item.start_time_label = '';
  174. item.end_time = '';
  175. item.end_time_label = '';
  176. })
  177. },
  178. confirmPicker(e){
  179. const value = e[0].value;
  180. const label = e[0].label;
  181. if(this.currentType == 'end_time'){
  182. if(this.coll_time[this.currentIndex]['start_time'] > value){
  183. uni.showToast({
  184. title: '结束时间不能早于开始时间',
  185. icon: 'none',
  186. })
  187. return
  188. }
  189. }
  190. if(this.currentType == 'start_time' && this.currentIndex > 0){
  191. if(this.coll_time[this.currentIndex-1]['end_time'] > value){
  192. uni.showToast({
  193. title: '开始时间不能早于前面采集时间的结束时间',
  194. icon: 'none',
  195. })
  196. return
  197. }
  198. }
  199. if(this.currentType == 'start_time' && this.coll_time[this.currentIndex]['end_time'] !== ''){
  200. if(value > this.coll_time[this.currentIndex]['end_time']){
  201. uni.showToast({
  202. title: '开始时间不能晚于结束时间',
  203. icon: 'none',
  204. })
  205. return
  206. }
  207. }
  208. this.coll_time[this.currentIndex][this.currentType] = value;
  209. this.coll_time[this.currentIndex][this.currentType + '_label'] = label;
  210. },
  211. showPickerHandler(index,type){
  212. if(type == 'end_time'){
  213. if(this.coll_time[index]['start_time'] === ''){
  214. uni.showToast({
  215. title: '请先选择开始时间',
  216. icon: 'none',
  217. })
  218. return
  219. }
  220. }
  221. if(index != 0){
  222. if(this.coll_time[index-1]['start_time_label'] === '' || this.coll_time[index-1]['end_time_label'] === ''){
  223. uni.showToast({
  224. title: '请先选择前面采集时间的开始和结束时间',
  225. icon: 'none',
  226. })
  227. return
  228. }
  229. }
  230. this.showPicker = true;
  231. this.currentIndex = index
  232. this.currentType = type
  233. },
  234. closePicker(){
  235. this.showPicker = false;
  236. this.currentType = ''
  237. this.currentIndex = -1
  238. },
  239. handleBack() {
  240. uni.navigateBack({
  241. delta: 1
  242. });
  243. },
  244. handleTabClick(tab) {
  245. this.activeTab = tab;
  246. },
  247. showMqttConfig(){
  248. this.show = true;
  249. },
  250. closeMqttConfig(){
  251. this.show = false;
  252. },
  253. async setDeviceContorl(type){
  254. const data = {
  255. device_type_id: 3,
  256. d_id: this.d_id,
  257. cmd: type,
  258. }
  259. if(type === 'imei'){
  260. data.imei = this.equipContrlForm.imei
  261. }else{
  262. delete data.imei
  263. }
  264. this.$myRequest({
  265. url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
  266. method: 'POST',
  267. data
  268. }).then(res => {
  269. this.closeMqttConfig()
  270. if (res) {
  271. uni.showToast({
  272. title: '设备控制修改成功!',
  273. icon: 'success',
  274. });
  275. } else {
  276. uni.showToast({
  277. title: '设备控制修改失败',
  278. icon: 'error',
  279. });
  280. }
  281. });
  282. },
  283. saveSettings(){
  284. let newForm = Object.assign({}, this.equipContrlForm) // 深拷贝
  285. newForm.st = newForm.st + ''
  286. newForm.et = newForm.et + ''
  287. newForm.st && newForm.st.slice(0, 2).charAt(0) != '0'
  288. ? newForm.st.slice(0, 2)
  289. : newForm.st.slice(1, 2)
  290. newForm.et =
  291. newForm.et && newForm.et.slice(0, 2).charAt(0) != '0'
  292. ? newForm.et.slice(0, 2)
  293. : newForm.et.slice(1, 2)
  294. for (let k in newForm) {
  295. if (typeof newForm[k] === 'number') {
  296. newForm[k] = newForm[k] + ''
  297. }
  298. }
  299. newForm.st = newForm.st.replace(':00', '')
  300. console.log(this.coll_time,'coll_timecoll_timecoll_time')
  301. const coll_time = [];
  302. for(let i = 0;i< this.coll_time.length;i++){
  303. const coll_item = this.coll_time[i];
  304. if(String(coll_item.start_time) && String(coll_item.end_time)){
  305. coll_time.push(String(coll_item.start_time) + '-' + String(coll_item.end_time))
  306. }
  307. }
  308. newForm.coll_time = coll_time
  309. this.$myRequest({
  310. url: '/api/api_gateway?method=forecast.send_control.device_control',
  311. method: 'POST',
  312. data: {
  313. device_type_id: 3,
  314. d_id: this.d_id,
  315. config: JSON.stringify(newForm)
  316. }
  317. }).then(res => {
  318. if (res) {
  319. // 设备控制修改成功
  320. uni.showToast({
  321. title: '设备控制修改成功!',
  322. icon: 'success',
  323. });
  324. } else {
  325. uni.showToast({
  326. title: '设备控制修改失败',
  327. icon: 'error',
  328. });
  329. }
  330. })
  331. },
  332. async getControlDeviceConfigInfo(){
  333. const res = await this.$myRequest({
  334. url: '/api/api_gateway?method=forecast.send_control.device_control_info',
  335. method: 'POST',
  336. data: {
  337. d_id: this.d_id,
  338. cmd:'paramconf'
  339. },
  340. });
  341. this.equipContrlForm = res
  342. const coll_time = res?.coll_time || [];
  343. for(let i = 0;i< coll_time.length;i++){
  344. const coll_item = coll_time[i];
  345. const start_time = coll_item.split('-')[0];
  346. const end_time = coll_item.split('-')[1];
  347. this.coll_time[i]['start_time'] = start_time;
  348. this.coll_time[i]['end_time'] = end_time;
  349. this.coll_time[i]['start_time_label'] = start_time >= 10 ? start_time + ':00' : '0' + start_time + ':00';
  350. this.coll_time[i]['end_time_label'] = end_time >= 10 ? end_time + ':00' : '0' + end_time + ':00';
  351. }
  352. console.log(this.coll_time,'coll_timecoll_timecoll_time')
  353. this.equipContrlForm.tph = Number(this.equipContrlForm.tph || 50)
  354. this.equipContrlForm.tpl = Number(this.equipContrlForm.tpl || 0)
  355. },
  356. }
  357. }
  358. </script>
  359. <style scoped lang="scss">
  360. .device-detail {
  361. display: flex;
  362. width: 100%;
  363. height: calc(100vh - 112rpx);
  364. padding-top: 112rpx;
  365. flex-direction: column;
  366. align-items: center;
  367. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  368. .device-detail__header {
  369. width: 100%;
  370. font-size: 28rpx;
  371. color: #999;
  372. color: #042118;
  373. font-family: 'Source Han Sans CN VF';
  374. font-weight: 700;
  375. position: relative;
  376. text-align: center;
  377. .arrow-left {
  378. position: absolute;
  379. left: 32rpx;
  380. margin-right: 12rpx;
  381. }
  382. }
  383. .time-container{
  384. display: flex;
  385. justify-content: center;
  386. align-items: center;
  387. color: #999999;
  388. border-radius: 8rpx;
  389. background:#F6F8FC;
  390. gap: 12rpx;
  391. .start-time{
  392. width: 250rpx;
  393. height: 50rpx;
  394. line-height: 50rpx;
  395. text-align: left;
  396. font-size: 24rpx;
  397. color: #999999;
  398. font-family: 'Source Han Sans CN VF';
  399. border-radius: 16rpx;
  400. padding: 0 24rpx;
  401. }
  402. .end-time{
  403. width: 200rpx;
  404. height: 50rpx;
  405. line-height: 50rpx;
  406. text-align: left;
  407. font-size: 24rpx;
  408. color: #999999;
  409. font-family: 'Source Han Sans CN VF';
  410. border-radius: 16rpx;
  411. padding: 0 24rpx;
  412. }
  413. }
  414. .device-detail__body {
  415. width: calc(100% - 64rpx);
  416. margin: 0 auto;
  417. border-radius: 16rpx;
  418. overflow-x: hidden;
  419. overflow-y: auto;
  420. // 隐藏滚动条
  421. -ms-overflow-style: none;
  422. scrollbar-width: none;
  423. }
  424. .tabs {
  425. margin: 24rpx 0;
  426. border-radius: 16rpx;
  427. padding: 16rpx 0;
  428. padding-top: 0;
  429. .tab-container{
  430. display: flex;
  431. width: 100%;
  432. height: 88rpx;
  433. line-height: 88rpx;
  434. text-align: center;
  435. font-size: 28rpx;
  436. color: #042118;
  437. font-family: 'Source Han Sans CN VF';
  438. }
  439. .tab-item {
  440. margin-right: 40rpx;
  441. color:#999999;
  442. }
  443. .active{
  444. position: relative;
  445. color: #0bbc58;
  446. text-align: center;
  447. font-family: "Source Han Sans CN VF";
  448. font-size: 28rpx;
  449. font-weight: 700;
  450. &::after {
  451. content: '';
  452. position: absolute;
  453. bottom: 10rpx;
  454. left: 50%;
  455. transform: translateX(-50%);
  456. width: 100%;
  457. height: 36rpx;
  458. border-bottom: 6rpx solid #0bbc58;
  459. }
  460. }
  461. }
  462. .slider-container{
  463. position: relative;
  464. margin-bottom: 20rpx;
  465. .slider-min-value{
  466. position: absolute;
  467. left: 0;
  468. top: -50rpx;
  469. }
  470. .slider{
  471. width: 600rpx;
  472. }
  473. .slider-max-value{
  474. position: absolute;
  475. right: 0;
  476. top: -50rpx;
  477. }
  478. }
  479. .device-detail-content{
  480. display: flex;
  481. padding: 24rpx 32rpx;
  482. flex-direction: column;
  483. align-items: flex-start;
  484. gap: 20rpx;
  485. border-radius: 16rpx;
  486. background: #FFF;
  487. .device-detail-item{
  488. .device-detail-label{
  489. color: #303133;
  490. font-family: "Source Han Sans CN VF";
  491. font-size: 28rpx;
  492. font-weight: 400;
  493. }
  494. .device-detail-btn-container{
  495. display: flex;
  496. gap: 24rpx;
  497. margin-top: 12rpx;
  498. }
  499. .device-detail-btn{
  500. display: flex;
  501. padding: 10rpx 16rpx;
  502. justify-content: center;
  503. align-items: center;
  504. gap: 16rpx;
  505. border-radius: 16rpx;
  506. background: #0bbc58;
  507. color: #ffffff;
  508. font-family: "Source Han Sans CN VF";
  509. font-size: 24rpx;
  510. font-weight: 400;
  511. }
  512. .force-btn{
  513. background: #FB4E52;
  514. }
  515. }
  516. .device-detail-viewImage{
  517. width: 100%;
  518. display: flex;
  519. align-items: center;
  520. padding-bottom: 20rpx;
  521. position: relative;
  522. .clear-btn{
  523. position: absolute;
  524. right: 0rpx;
  525. border: 1rpx solid #0bbc58;
  526. border-radius: 8rpx;
  527. padding: 4rpx 12rpx;
  528. font-size: 24rpx;
  529. color: #0bbc58;
  530. font-family: 'Source Han Sans CN VF';
  531. font-weight: 400;
  532. }
  533. }
  534. }
  535. .device-detail-btn-footer{
  536. position: fixed;
  537. bottom: 0;
  538. left: 0;
  539. width: 100%;
  540. height: 112rpx;
  541. line-height: 112rpx;
  542. text-align: center;
  543. font-size: 28rpx;
  544. font-weight: 700;
  545. color: #042118;
  546. font-family: 'Source Han Sans CN VF';
  547. background: #ffffff;
  548. display: flex;
  549. justify-content: center;
  550. align-items: center;
  551. .device-detail-btn{
  552. display: flex;
  553. height: 80rpx;
  554. width: 90%;
  555. margin: 0 auto;
  556. padding: 0rpx 20rpx;
  557. justify-content: center;
  558. align-items: center;
  559. gap: 8rpx;
  560. border-radius: 16rpx;
  561. background:#0bbc58;
  562. color: #ffffff;
  563. text-align: center;
  564. font-family: "Source Han Sans CN VF";
  565. font-size: 14px;
  566. font-style: normal;
  567. font-weight: 500;
  568. }
  569. }
  570. }
  571. </style>