deviceControl2.vue 15 KB

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