deviceControl.vue 16 KB

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