deviceControl.vue 16 KB

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