deviceControl.vue 16 KB

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