deviceControl2.vue 15 KB

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