deviceControl.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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" v-if="myuser_type" :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. myuser_type: false,
  166. sliderRect: null
  167. }
  168. },
  169. onLoad(options){
  170. this.d_id = options.d_id
  171. const time1 = [];
  172. const time2 = [];
  173. for(let i = 0;i< 24;i++){
  174. let j = i;
  175. if(i < 10){
  176. j = '0' + i
  177. }
  178. time1.push({
  179. value: i,
  180. label: j + ':00'
  181. })
  182. time2.push({
  183. value: i,
  184. label: j + ':00'
  185. })
  186. }
  187. uni.getStorage({
  188. key:"myuser_type",
  189. success:(res)=>{
  190. if(Number(res.data) == 1){
  191. this.myuser_type = true
  192. this.activeTab = 'pestAnalysis'
  193. }else{
  194. this.activeTab = 'viewImage'
  195. }
  196. }
  197. })
  198. this.list2 = [time1, time2];
  199. this.deviceType = options.device_type
  200. this.getControlDeviceConfigInfo()
  201. },
  202. methods: {
  203. getProgressWidth(value, min, max) {
  204. if (max === min) return 0
  205. return ((value - min) / (max - min)) * 100
  206. },
  207. onSliderTouchStart(e, field, min, max) {
  208. this.sliderField = field
  209. this.sliderMin = min
  210. this.sliderMax = max
  211. const query = uni.createSelectorQuery().in(this)
  212. query.select('.custom-progress').boundingClientRect(rect => {
  213. this.sliderRect = rect
  214. }).exec()
  215. this.updateSliderValue(e.touches[0].clientX, field, min, max)
  216. },
  217. onSliderTouchMove(e, min, max) {
  218. if (!this.sliderField || !this.sliderRect) return
  219. this.updateSliderValue(e.touches[0].clientX, this.sliderField, min, max)
  220. },
  221. onSliderTouchEnd() {
  222. this.sliderField = ''
  223. },
  224. onSliderTap(e, field, min, max) {
  225. const query = uni.createSelectorQuery().in(this)
  226. query.select('.custom-progress').boundingClientRect(rect => {
  227. this.sliderRect = rect
  228. this.updateSliderValue(e.detail.x + rect.left, field, min, max)
  229. }).exec()
  230. },
  231. updateSliderValue(clientX, field, min, max) {
  232. if (!this.sliderRect) return
  233. let ratio = (clientX - this.sliderRect.left) / this.sliderRect.width
  234. ratio = Math.max(0, Math.min(1, ratio))
  235. const value = Math.round(min + ratio * (max - min))
  236. this.$set(this.equipContrlForm, field, value)
  237. },
  238. fromTime(time){
  239. if(time < 10){
  240. time = '0' + time + ':00'
  241. }else{
  242. time = time + ':00'
  243. }
  244. return time
  245. },
  246. confirmDateHandler(e){
  247. console.log(e,'e')
  248. this.show1 = false
  249. this.equipContrlForm.START_TIME = e[0].value
  250. this.equipContrlForm.END_TIME = e[1].value
  251. },
  252. confirmHandler(item){
  253. this.cmd1 = item[0].value
  254. this.operate()
  255. },
  256. formart(cmd1){
  257. let text = ''
  258. this.list.forEach(item => {
  259. if(item.value === cmd1){
  260. text = item.label
  261. }
  262. })
  263. return text
  264. },
  265. operate() {
  266. this.$myRequest({
  267. method: 'POST',
  268. url: '/api/api_gateway?method=new_gateway.device_info.send_control',
  269. data: {
  270. id: this.d_id,
  271. device_type_id: this.deviceType,
  272. COMMAND: this.cmd1
  273. }
  274. }).then(res => {
  275. console.log(res,'resres')
  276. this.show = false
  277. if (res) {
  278. this.$message.success('指令下发成功')
  279. } else {
  280. this.$message.error(res.data.data.msg)
  281. }
  282. })
  283. },
  284. handleBack() {
  285. uni.navigateBack({
  286. delta: 1
  287. });
  288. },
  289. handleTabClick(tab) {
  290. this.activeTab = tab;
  291. },
  292. async setDeviceContorl(type){
  293. const data = {
  294. device_type_id: this.deviceType,
  295. d_id: this.d_id,
  296. cmd: type,
  297. }
  298. if(type === 'imei'){
  299. data.imei = this.equipContrlForm.imei
  300. }else{
  301. delete data.imei
  302. }
  303. this.$myRequest({
  304. url: '/api/api_gateway?method=new_gateway.device_info.send_control',
  305. method: 'POST',
  306. data
  307. }).then(res => {
  308. if (res) {
  309. uni.showToast({
  310. title: '设备控制修改成功!',
  311. icon: 'success',
  312. });
  313. } else {
  314. uni.showToast({
  315. title: '设备控制修改失败',
  316. icon: 'error',
  317. });
  318. }
  319. });
  320. },
  321. saveSettings(){
  322. let newForm = Object.assign({}, this.equipContrlForm) // 深拷贝
  323. this.$myRequest({
  324. url: '/api/api_gateway?method=new_gateway.device_info.update_device_config',
  325. method: 'POST',
  326. data: {
  327. device_type_id: this.deviceType,
  328. id: this.d_id,
  329. ...newForm,
  330. TEMP_LIMIT: newForm.TEMP_LIMIT ? '1' : '0'
  331. }
  332. }).then(res => {
  333. if (res) {
  334. // 设备控制修改成功
  335. uni.showToast({
  336. title: '设备控制修改成功!',
  337. icon: 'success',
  338. });
  339. } else {
  340. uni.showToast({
  341. title: '设备控制修改失败',
  342. icon: 'error',
  343. });
  344. }
  345. })
  346. },
  347. async getControlDeviceConfigInfo(){
  348. const res = await this.$myRequest({
  349. url: '/api/api_gateway?method=new_gateway.device_info.get_device_config',
  350. method: 'POST',
  351. data: {
  352. device_type_id: this.deviceType,
  353. id: this.d_id,
  354. },
  355. });
  356. console.log(res,'resresresresressssssss')
  357. this.equipContrlForm = res
  358. },
  359. }
  360. }
  361. </script>
  362. <style scoped lang="scss">
  363. .device-detail {
  364. display: flex;
  365. width: 100%;
  366. height: calc(100vh - 112rpx);
  367. padding-top: 112rpx;
  368. flex-direction: column;
  369. align-items: center;
  370. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  371. .device-detail__header {
  372. width: 100%;
  373. font-size: 28rpx;
  374. color: #999;
  375. color: #042118;
  376. font-family: 'Source Han Sans CN VF';
  377. font-weight: 700;
  378. position: relative;
  379. text-align: center;
  380. .arrow-left {
  381. position: absolute;
  382. left: 32rpx;
  383. margin-right: 12rpx;
  384. }
  385. }
  386. .device-detail__body {
  387. width: calc(100% - 64rpx);
  388. margin: 0 auto;
  389. border-radius: 16rpx;
  390. overflow-x: hidden;
  391. overflow-y: auto;
  392. // 隐藏滚动条
  393. -ms-overflow-style: none;
  394. scrollbar-width: none;
  395. }
  396. .tabs {
  397. margin: 24rpx 0;
  398. border-radius: 16rpx;
  399. padding: 16rpx 0;
  400. padding-top: 0;
  401. .tab-container{
  402. display: flex;
  403. width: 100%;
  404. height: 88rpx;
  405. line-height: 88rpx;
  406. text-align: center;
  407. font-size: 28rpx;
  408. font-weight: 700;
  409. color: #042118;
  410. font-family: 'Source Han Sans CN VF';
  411. }
  412. .tab-item {
  413. margin-right: 40rpx;
  414. color:#999999;
  415. }
  416. .active{
  417. position: relative;
  418. color: #303133;
  419. text-align: center;
  420. font-family: "Source Han Sans CN VF";
  421. font-size: 28rpx;
  422. font-weight: 700;
  423. &::after {
  424. content: '';
  425. position: absolute;
  426. bottom: 10rpx;
  427. left: 50%;
  428. transform: translateX(-50%);
  429. width: 100%;
  430. height: 36rpx;
  431. border-bottom: 6rpx solid #303133;
  432. }
  433. }
  434. }
  435. .device-detail-content{
  436. display: flex;
  437. padding: 24rpx 32rpx;
  438. flex-direction: column;
  439. align-items: flex-start;
  440. gap: 20rpx;
  441. border-radius: 16rpx;
  442. background: #FFF;
  443. .device-detail-item{
  444. .device-detail-label{
  445. color: #303133;
  446. font-family: "Source Han Sans CN VF";
  447. font-size: 28rpx;
  448. font-weight: 400;
  449. }
  450. .device-detail-btn-container{
  451. display: flex;
  452. gap: 24rpx;
  453. margin-top: 12rpx;
  454. }
  455. .device-detail-btn{
  456. display: flex;
  457. padding: 10rpx 16rpx;
  458. justify-content: center;
  459. align-items: center;
  460. gap: 16rpx;
  461. border-radius: 16rpx;
  462. background: #0BBC58;
  463. color: #ffffff;
  464. font-family: "Source Han Sans CN VF";
  465. font-size: 24rpx;
  466. font-weight: 400;
  467. }
  468. .force-btn{
  469. background: #FB4E52;
  470. }
  471. }
  472. .device-detail-viewImage{
  473. width: 100%;
  474. display: flex;
  475. justify-content: space-between;
  476. align-items: center;
  477. padding-bottom: 20rpx;
  478. }
  479. }
  480. .slider-container{
  481. position: relative;
  482. margin: 10rpx 0 20rpx 0;
  483. .slider-min-value{
  484. position: absolute;
  485. left: 0;
  486. top: -50rpx;
  487. }
  488. .slider{
  489. width: 600rpx;
  490. }
  491. .slider-max-value{
  492. position: absolute;
  493. right: 0;
  494. top: -50rpx;
  495. }
  496. }
  497. .custom-progress{
  498. width: 600rpx;
  499. padding: 0;
  500. .progress-track{
  501. position: relative;
  502. height: 12rpx;
  503. background-color: #ebedf0;
  504. border-radius: 6rpx;
  505. }
  506. .progress-fill{
  507. position: absolute;
  508. left: 0;
  509. top: 0;
  510. height: 100%;
  511. background-color: #0BBC58;
  512. border-radius: 6rpx;
  513. transition: width 0.2s;
  514. }
  515. .progress-thumb{
  516. position: absolute;
  517. top: 50%;
  518. width: 28rpx;
  519. height: 28rpx;
  520. margin-left: -14rpx;
  521. margin-top: -14rpx;
  522. border-radius: 50%;
  523. background-color: #fff;
  524. box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  525. transition: left 0.2s;
  526. }
  527. }
  528. .device-detail-btn-footer{
  529. position: fixed;
  530. bottom: 0;
  531. left: 0;
  532. width: 100%;
  533. height: 112rpx;
  534. line-height: 112rpx;
  535. text-align: center;
  536. font-size: 28rpx;
  537. font-weight: 700;
  538. color: #042118;
  539. font-family: 'Source Han Sans CN VF';
  540. background: #ffffff;
  541. display: flex;
  542. justify-content: center;
  543. align-items: center;
  544. .device-detail-btn{
  545. display: flex;
  546. height: 80rpx;
  547. width: 90%;
  548. margin: 0 auto;
  549. padding: 0rpx 20rpx;
  550. justify-content: center;
  551. align-items: center;
  552. gap: 8rpx;
  553. border-radius: 16rpx;
  554. background:#0BBC58;
  555. color: #ffffff;
  556. text-align: center;
  557. font-family: "Source Han Sans CN VF";
  558. font-size: 14px;
  559. font-style: normal;
  560. font-weight: 500;
  561. }
  562. }
  563. }
  564. </style>