deviceControl.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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. <u-select v-model="show" :list="list" @confirm="confirmHandler"></u-select>
  13. <view class="device-detail__body">
  14. <view class="tabs">
  15. <view class="tab-container">
  16. <view class="tab-item" :class="activeTab === 'pestAnalysis'?'active':''" @click="handleTabClick('pestAnalysis')">
  17. 管理员
  18. </view>
  19. <view class="tab-item" :class="activeTab === 'viewImage'?'active':''" @click="handleTabClick('viewImage')">
  20. 设置
  21. </view>
  22. </view>
  23. </view>
  24. <view class="device-detail-content" v-if="activeTab === 'pestAnalysis'">
  25. <view class="device-detail-item">
  26. <text class="device-detail-label">联网模块</text>
  27. <view class="device-detail-btn-container">
  28. <view class="device-detail-btn" @click="setDeviceContorl('dtu_reboot')">数据单元重启</view>
  29. <view class="device-detail-btn" @click="setDeviceContorl('dtu_update')">数据单元升级</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="setDeviceContorl('led_on')">开启补光灯</view>
  36. <view class="device-detail-btn" @click="setDeviceContorl('led_off')">关闭补光灯</view>
  37. <view class="device-detail-btn" @click="setDeviceContorl('takephoto')">测试拍照</view>
  38. <view class="device-detail-btn" @click="setDeviceContorl('FB_Test')">卷带测试</view>
  39. </view>
  40. </view>
  41. <view class="device-detail-item">
  42. <text class="device-detail-label">强制操作</text>
  43. <view class="device-detail-btn-container">
  44. <view class="device-detail-btn force-btn" @click="setDeviceContorl('reboot')">控制单元重启</view>
  45. <view class="device-detail-btn force-btn" @click="setDeviceContorl('update')">控制单元升级</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. <text class="device-detail-label">设备操作:</text>
  52. <text @click="show = true">{{ formart(cmd1) }}</text>
  53. </view>
  54. <view class="device-detail-viewImage">
  55. <text class="device-detail-label">拍照时间:</text>
  56. <text @click="show1 = true">{{ fromTime(equipContrlForm.START_TIME) }} - {{ fromTime(equipContrlForm.END_TIME) }}</text>
  57. </view>
  58. <view class="device-detail-viewImage">
  59. <text class="device-detail-label">拍照频率(min):</text>
  60. <u-input
  61. v-model="equipContrlForm.PHO_T"
  62. type="number"
  63. :border="false"
  64. height="40"
  65. auto-height="true"
  66. input-align="right"
  67. />
  68. </view>
  69. <view class="device-detail-viewImage">
  70. <text class="device-detail-label">数据上传频率(min):</text>
  71. <u-input
  72. v-model="equipContrlForm.DATT"
  73. type="number"
  74. :border="false"
  75. height="40"
  76. auto-height="true"
  77. input-align="right"
  78. />
  79. </view>
  80. <view class="device-detail-viewImage">
  81. <text class="device-detail-label">是否温控:</text>
  82. <u-switch v-model="equipContrlForm.TEMP_LIMIT" size="40" active-color="#0BBC58" active-value="1" inactive-value="0"></u-switch>
  83. </view>
  84. <view class="device-detail-viewImage"
  85. v-if="equipContrlForm.TEMP_LIMIT == '1'"
  86. >
  87. <text class="device-detail-label">低温设置(℃):{{ equipContrlForm.TEMP_DOWN }}</text>
  88. </view>
  89. <view class="slider-container"
  90. v-if="equipContrlForm.TEMP_LIMIT == '1'"
  91. >
  92. <view class="slider-min-value">0</view>
  93. <view
  94. class="custom-progress"
  95. @touchstart.stop="onSliderTouchStart($event, 'TEMP_DOWN', 0, 20)"
  96. @touchmove.stop.prevent="onSliderTouchMove($event, 0, 20)"
  97. @touchend.stop="onSliderTouchEnd"
  98. @tap.stop="onSliderTap($event, 'TEMP_DOWN', 0, 20)"
  99. >
  100. <view class="progress-track">
  101. <view class="progress-fill" :style="{ width: getProgressWidth(equipContrlForm.TEMP_DOWN, 0, 20) + '%' }"></view>
  102. <view class="progress-thumb" :style="{ left: getProgressWidth(equipContrlForm.TEMP_DOWN, 0, 20) + '%' }"></view>
  103. </view>
  104. </view>
  105. <view class="slider-max-value">20</view>
  106. </view>
  107. <view class="device-detail-viewImage"
  108. v-if="equipContrlForm.TEMP_LIMIT == '1'"
  109. >
  110. <text class="device-detail-label">高温设置(℃):{{ equipContrlForm.TEMP_UP }}</text>
  111. </view>
  112. <view class="slider-container"
  113. v-if="equipContrlForm.TEMP_LIMIT == '1'"
  114. >
  115. <view class="slider-min-value">50</view>
  116. <view
  117. class="custom-progress"
  118. @touchstart.stop="onSliderTouchStart($event, 'TEMP_UP', 50, 80)"
  119. @touchmove.stop.prevent="onSliderTouchMove($event, 50, 80)"
  120. @touchend.stop="onSliderTouchEnd"
  121. @tap.stop="onSliderTap($event, 'TEMP_UP', 50, 80)"
  122. >
  123. <view class="progress-track">
  124. <view class="progress-fill" :style="{ width: getProgressWidth(equipContrlForm.TEMP_UP, 50, 80) + '%' }"></view>
  125. <view class="progress-thumb" :style="{ left: getProgressWidth(equipContrlForm.TEMP_UP, 50, 80) + '%' }"></view>
  126. </view>
  127. </view>
  128. <view class="slider-max-value">80</view>
  129. </view>
  130. </view>
  131. </view>
  132. <view class="device-detail-btn-footer" v-if="activeTab === 'viewImage'">
  133. <view class="device-detail-btn" @click="saveSettings">保存</view>
  134. </view>
  135. <u-select v-model="show1" mode="mutil-column" :list="list2" @confirm="confirmDateHandler"></u-select>
  136. </view>
  137. </template>
  138. <script>
  139. export default {
  140. data(){
  141. return {
  142. show: false,
  143. show1: false,
  144. list2:[],
  145. list: [
  146. { value: '0001', label: '开机' },
  147. { value: '0002', label: '关机' },
  148. { value: '0003', label: '拍照' },
  149. { value: 'JD_Clear', label: '卷带重置' }
  150. ],
  151. value: 10,
  152. cmd1: '0001',
  153. imageList: [],
  154. equipContrlForm: {},
  155. time: '',
  156. activeTab: 'pestAnalysis',
  157. title: '设置控制',
  158. deviceType: '',
  159. location: '',
  160. d_id: '',
  161. checked: false,
  162. sliderField: '',
  163. sliderMin: 0,
  164. sliderMax: 100,
  165. sliderRect: null
  166. }
  167. },
  168. onLoad(options){
  169. this.d_id = options.d_id
  170. const time1 = [];
  171. const time2 = [];
  172. for(let i = 0;i< 24;i++){
  173. let j = i;
  174. if(i < 10){
  175. j = '0' + i
  176. }
  177. time1.push({
  178. value: i,
  179. label: j + ':00'
  180. })
  181. time2.push({
  182. value: i,
  183. label: j + ':00'
  184. })
  185. }
  186. this.list2 = [time1, time2];
  187. this.deviceType = options.device_type
  188. this.getControlDeviceConfigInfo()
  189. },
  190. methods: {
  191. getProgressWidth(value, min, max) {
  192. if (max === min) return 0
  193. return ((value - min) / (max - min)) * 100
  194. },
  195. onSliderTouchStart(e, field, min, max) {
  196. this.sliderField = field
  197. this.sliderMin = min
  198. this.sliderMax = max
  199. const query = uni.createSelectorQuery().in(this)
  200. query.select('.custom-progress').boundingClientRect(rect => {
  201. this.sliderRect = rect
  202. }).exec()
  203. this.updateSliderValue(e.touches[0].clientX, field, min, max)
  204. },
  205. onSliderTouchMove(e, min, max) {
  206. if (!this.sliderField || !this.sliderRect) return
  207. this.updateSliderValue(e.touches[0].clientX, this.sliderField, min, max)
  208. },
  209. onSliderTouchEnd() {
  210. this.sliderField = ''
  211. },
  212. onSliderTap(e, field, min, max) {
  213. const query = uni.createSelectorQuery().in(this)
  214. query.select('.custom-progress').boundingClientRect(rect => {
  215. this.sliderRect = rect
  216. this.updateSliderValue(e.detail.x + rect.left, field, min, max)
  217. }).exec()
  218. },
  219. updateSliderValue(clientX, field, min, max) {
  220. if (!this.sliderRect) return
  221. let ratio = (clientX - this.sliderRect.left) / this.sliderRect.width
  222. ratio = Math.max(0, Math.min(1, ratio))
  223. const value = Math.round(min + ratio * (max - min))
  224. this.$set(this.equipContrlForm, field, value)
  225. },
  226. fromTime(time){
  227. if(time < 10){
  228. time = '0' + time + ':00'
  229. }else{
  230. time = time + ':00'
  231. }
  232. return time
  233. },
  234. confirmDateHandler(e){
  235. console.log(e,'e')
  236. this.show1 = false
  237. this.equipContrlForm.START_TIME = e[0].value
  238. this.equipContrlForm.END_TIME = e[1].value
  239. },
  240. confirmHandler(item){
  241. this.cmd1 = item[0].value
  242. this.operate()
  243. },
  244. formart(cmd1){
  245. let text = ''
  246. this.list.forEach(item => {
  247. if(item.value === cmd1){
  248. text = item.label
  249. }
  250. })
  251. return text
  252. },
  253. operate() {
  254. this.$myRequest({
  255. method: 'POST',
  256. url: '/api/api_gateway?method=new_gateway.device_info.send_control',
  257. data: {
  258. id: this.d_id,
  259. device_type_id: this.deviceType,
  260. COMMAND: this.cmd1
  261. }
  262. }).then(res => {
  263. console.log(res,'resres')
  264. this.show = false
  265. if (res) {
  266. this.$message.success('指令下发成功')
  267. } else {
  268. this.$message.error(res.data.data.msg)
  269. }
  270. })
  271. },
  272. handleBack() {
  273. uni.navigateBack({
  274. delta: 1
  275. });
  276. },
  277. handleTabClick(tab) {
  278. this.activeTab = tab;
  279. },
  280. async setDeviceContorl(type){
  281. const data = {
  282. device_type_id: this.deviceType,
  283. d_id: this.d_id,
  284. cmd: type,
  285. }
  286. if(type === 'imei'){
  287. data.imei = this.equipContrlForm.imei
  288. }else{
  289. delete data.imei
  290. }
  291. this.$myRequest({
  292. url: '/api/api_gateway?method=new_gateway.device_info.send_control',
  293. method: 'POST',
  294. data
  295. }).then(res => {
  296. if (res) {
  297. uni.showToast({
  298. title: '设备控制修改成功!',
  299. icon: 'success',
  300. });
  301. } else {
  302. uni.showToast({
  303. title: '设备控制修改失败',
  304. icon: 'error',
  305. });
  306. }
  307. });
  308. },
  309. saveSettings(){
  310. let newForm = Object.assign({}, this.equipContrlForm) // 深拷贝
  311. this.$myRequest({
  312. url: '/api/api_gateway?method=new_gateway.device_info.update_device_config',
  313. method: 'POST',
  314. data: {
  315. device_type_id: this.deviceType,
  316. id: this.d_id,
  317. ...newForm,
  318. TEMP_LIMIT: newForm.TEMP_LIMIT ? '1' : '0'
  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=new_gateway.device_info.get_device_config',
  338. method: 'POST',
  339. data: {
  340. device_type_id: this.deviceType,
  341. id: this.d_id,
  342. },
  343. });
  344. console.log(res,'resresresresressssssss')
  345. this.equipContrlForm = res
  346. },
  347. }
  348. }
  349. </script>
  350. <style scoped lang="scss">
  351. .device-detail {
  352. display: flex;
  353. width: 100%;
  354. height: calc(100vh - 112rpx);
  355. padding-top: 112rpx;
  356. flex-direction: column;
  357. align-items: center;
  358. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  359. .device-detail__header {
  360. width: 100%;
  361. font-size: 28rpx;
  362. color: #999;
  363. color: #042118;
  364. font-family: 'Source Han Sans CN VF';
  365. font-weight: 700;
  366. position: relative;
  367. text-align: center;
  368. .arrow-left {
  369. position: absolute;
  370. left: 32rpx;
  371. margin-right: 12rpx;
  372. }
  373. }
  374. .device-detail__body {
  375. width: calc(100% - 64rpx);
  376. margin: 0 auto;
  377. border-radius: 16rpx;
  378. overflow-x: hidden;
  379. overflow-y: auto;
  380. // 隐藏滚动条
  381. -ms-overflow-style: none;
  382. scrollbar-width: none;
  383. }
  384. .tabs {
  385. margin: 24rpx 0;
  386. border-radius: 16rpx;
  387. padding: 16rpx 0;
  388. padding-top: 0;
  389. .tab-container{
  390. display: flex;
  391. width: 100%;
  392. height: 88rpx;
  393. line-height: 88rpx;
  394. text-align: center;
  395. font-size: 28rpx;
  396. font-weight: 700;
  397. color: #042118;
  398. font-family: 'Source Han Sans CN VF';
  399. }
  400. .tab-item {
  401. margin-right: 40rpx;
  402. color:#999999;
  403. }
  404. .active{
  405. position: relative;
  406. color: #303133;
  407. text-align: center;
  408. font-family: "Source Han Sans CN VF";
  409. font-size: 28rpx;
  410. font-weight: 700;
  411. &::after {
  412. content: '';
  413. position: absolute;
  414. bottom: 10rpx;
  415. left: 50%;
  416. transform: translateX(-50%);
  417. width: 100%;
  418. height: 36rpx;
  419. border-bottom: 6rpx solid #303133;
  420. }
  421. }
  422. }
  423. .device-detail-content{
  424. display: flex;
  425. padding: 24rpx 32rpx;
  426. flex-direction: column;
  427. align-items: flex-start;
  428. gap: 20rpx;
  429. border-radius: 16rpx;
  430. background: #FFF;
  431. .device-detail-item{
  432. .device-detail-label{
  433. color: #303133;
  434. font-family: "Source Han Sans CN VF";
  435. font-size: 28rpx;
  436. font-weight: 400;
  437. }
  438. .device-detail-btn-container{
  439. display: flex;
  440. gap: 24rpx;
  441. margin-top: 12rpx;
  442. }
  443. .device-detail-btn{
  444. display: flex;
  445. padding: 10rpx 16rpx;
  446. justify-content: center;
  447. align-items: center;
  448. gap: 16rpx;
  449. border-radius: 16rpx;
  450. background: #0BBC58;
  451. color: #ffffff;
  452. font-family: "Source Han Sans CN VF";
  453. font-size: 24rpx;
  454. font-weight: 400;
  455. }
  456. .force-btn{
  457. background: #FB4E52;
  458. }
  459. }
  460. .device-detail-viewImage{
  461. width: 100%;
  462. display: flex;
  463. justify-content: space-between;
  464. align-items: center;
  465. padding-bottom: 20rpx;
  466. }
  467. }
  468. .slider-container{
  469. position: relative;
  470. margin: 10rpx 0 20rpx 0;
  471. .slider-min-value{
  472. position: absolute;
  473. left: 0;
  474. top: -50rpx;
  475. }
  476. .slider{
  477. width: 600rpx;
  478. }
  479. .slider-max-value{
  480. position: absolute;
  481. right: 0;
  482. top: -50rpx;
  483. }
  484. }
  485. .custom-progress{
  486. width: 600rpx;
  487. padding: 0;
  488. .progress-track{
  489. position: relative;
  490. height: 12rpx;
  491. background-color: #ebedf0;
  492. border-radius: 6rpx;
  493. }
  494. .progress-fill{
  495. position: absolute;
  496. left: 0;
  497. top: 0;
  498. height: 100%;
  499. background-color: #0BBC58;
  500. border-radius: 6rpx;
  501. transition: width 0.2s;
  502. }
  503. .progress-thumb{
  504. position: absolute;
  505. top: 50%;
  506. width: 28rpx;
  507. height: 28rpx;
  508. margin-left: -14rpx;
  509. margin-top: -14rpx;
  510. border-radius: 50%;
  511. background-color: #fff;
  512. box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  513. transition: left 0.2s;
  514. }
  515. }
  516. .device-detail-btn-footer{
  517. position: fixed;
  518. bottom: 0;
  519. left: 0;
  520. width: 100%;
  521. height: 112rpx;
  522. line-height: 112rpx;
  523. text-align: center;
  524. font-size: 28rpx;
  525. font-weight: 700;
  526. color: #042118;
  527. font-family: 'Source Han Sans CN VF';
  528. background: #ffffff;
  529. display: flex;
  530. justify-content: center;
  531. align-items: center;
  532. .device-detail-btn{
  533. display: flex;
  534. height: 80rpx;
  535. width: 90%;
  536. margin: 0 auto;
  537. padding: 0rpx 20rpx;
  538. justify-content: center;
  539. align-items: center;
  540. gap: 8rpx;
  541. border-radius: 16rpx;
  542. background:#0BBC58;
  543. color: #ffffff;
  544. text-align: center;
  545. font-family: "Source Han Sans CN VF";
  546. font-size: 14px;
  547. font-style: normal;
  548. font-weight: 500;
  549. }
  550. }
  551. }
  552. </style>