deviceControl.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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-child-settings" style="width:100%">
  25. <view class="device-detail-viewImage">
  26. <text class="device-detail-label">设备名称:</text>
  27. <view class="device-detail-value" >
  28. <u-input v-model="deviceName" disabled type="text" placeholder="设备名称" input-align="right" :custom-style="{'font-size':'24rpx'}"/>
  29. </view>
  30. </view>
  31. <view class="device-detail-viewImage">
  32. <text class="device-detail-label">设备ID:</text>
  33. <view class="device-detail-value" >
  34. <u-input v-model="deviceID" disabled type="text" placeholder="设备ID" input-align="right" :custom-style="{'font-size':'24rpx'}"/>
  35. </view>
  36. </view>
  37. <view class="device-detail-viewImage">
  38. <text class="device-detail-label">相机1:</text>
  39. <view class="device-detail-value" @click="openCameraIdPicker('camera1ID')">
  40. <text class="week-text">{{ camera1ID || '请选择相机' }}</text>
  41. <u-icon name="arrow-right" color="#999999" size="24"></u-icon>
  42. </view>
  43. </view>
  44. <view class="device-detail-viewImage">
  45. <text class="device-detail-label">相机2:</text>
  46. <view class="device-detail-value" @click="openCameraIdPicker('camera2ID')">
  47. <text class="week-text">{{ camera2ID || '请选择相机' }}</text>
  48. <u-icon name="arrow-right" color="#999999" size="24"></u-icon>
  49. </view>
  50. </view>
  51. <view class="device-detail-viewImage">
  52. <text class="device-detail-label">相机3:</text>
  53. <view class="device-detail-value" @click="openCameraIdPicker('camera3ID')">
  54. <text class="week-text">{{ camera3ID || '请选择相机' }}</text>
  55. <u-icon name="arrow-right" color="#999999" size="24"></u-icon>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="device-detail-content" style="padding-bottom: 50rpx" v-if="activeTab === 'viewImage'">
  61. <view v-for="(item, index) in deviceList" :key="index" style="width:100%">
  62. <view class="device-detail-name" @click="toggleChildItem(index)">
  63. <text>{{ item.label }}</text>
  64. <u-icon name="arrow-down" size="24" :class="actionChildItem == index ? 'rotate':''"></u-icon>
  65. </view>
  66. <view v-show="actionChildItem == index" class="device-detail-child-settings-container">
  67. <view class="tabs">
  68. <view class="tab-container">
  69. <view class="tab-item" :class="item.activeTab === 'settings'?'active':''" @click="handleTabChildClick(item, 'settings')">
  70. 拍摄设置
  71. </view>
  72. <view class="tab-item" :class="item.activeTab === 'schedule'?'active':''" @click="handleTabChildClick(item, 'schedule')">
  73. 定时设置
  74. </view>
  75. <view class="tab-item" :class="item.activeTab === 'warning'?'active':''" @click="handleTabChildClick(item, 'warning')">
  76. 触发报警设置
  77. </view>
  78. <view class="tab-item" :class="item.activeTab === 'other'?'active':''" @click="handleTabChildClick(item, 'other')">
  79. 其他设置
  80. </view>
  81. </view>
  82. </view>
  83. <view class="device-detail-child-settings" v-if="item.activeTab === 'settings'">
  84. <view class="device-detail-viewImage">
  85. <text class="device-detail-label">拍照模式:</text>
  86. <view class="device-detail-value" @click="setDeviceItemContorl(item, 'takephoto')">
  87. <text class="week-text">{{ formatPhotoModel(item.photoSettings.photoModel) }}</text>
  88. <u-icon name="arrow-right" color="#999999" size="24"></u-icon>
  89. </view>
  90. </view>
  91. <view class="device-detail-viewImage">
  92. <text class="device-detail-label">图片大小:</text>
  93. <view class="device-detail-value" @click="setDeviceItemContorl(item, 'imageSize')">
  94. <text class="week-text">{{ formatImageSize(item.photoSettings.imageSize) }}</text>
  95. <u-icon name="arrow-right" color="#999999" size="24"></u-icon>
  96. </view>
  97. </view>
  98. <view class="device-detail-viewImage">
  99. <text class="device-detail-label">视频大小:</text>
  100. <view class="device-detail-value" @click="setDeviceItemContorl(item, 'videoSize')">
  101. <text class="week-text">{{ formatImageSize(item.photoSettings.videoSize) }}</text>
  102. <u-icon name="arrow-right" color="#999999" size="24"></u-icon>
  103. </view>
  104. </view>
  105. <view class="device-detail-viewImage">
  106. <text class="device-detail-label">连拍:</text>
  107. <view class="device-detail-value">
  108. <u-input v-model="item.photoSettings.burstPhoto" type="number" :maxlength="4" placeholder="连拍(1-1000)" input-align="right" :custom-style="{'font-size':'24rpx'}" @blur="handlePositiveIntBlur(item.photoSettings, 'burstPhoto')"/>
  109. <text class="unit-text">次</text>
  110. </view>
  111. </view>
  112. <view class="device-detail-viewImage">
  113. <text class="device-detail-label">视频长度:</text>
  114. <view class="device-detail-value">
  115. <u-input v-model="item.photoSettings.videoLength" type="number" :maxlength="4" placeholder="视频长度(1-1000)" input-align="right" :custom-style="{'font-size':'24rpx'}" @blur="handlePositiveIntBlur(item.photoSettings, 'videoLength')"/>
  116. <text class="unit-text">秒</text>
  117. </view>
  118. </view>
  119. <view class="device-detail-viewImage">
  120. <text class="device-detail-label">拍摄限制:</text>
  121. <view class="device-detail-value">
  122. <u-input v-model="item.photoSettings.photoInterval" type="number" :maxlength="4" placeholder="拍摄限制(1-1000)" input-align="right" :custom-style="{'font-size':'24rpx'}" @blur="handlePositiveIntBlur(item.photoSettings, 'photoInterval')" />
  123. <text class="unit-text">次</text>
  124. </view>
  125. </view>
  126. </view>
  127. <view class="device-detail-child-settings" v-if="item.activeTab === 'schedule'">
  128. <view class="device-detail-viewImage">
  129. <text class="device-detail-label">定时拍照:</text>
  130. <text class="device-detail-value">
  131. <u-switch v-model="item.timeSettings.timePhoto" active-value="1" inactive-value="0" size="36" />
  132. </text>
  133. </view>
  134. <view class="device-detail-viewImage">
  135. <text class="device-detail-label">循环拍摄间隔:</text>
  136. <view class="device-detail-value">
  137. <u-input v-model="item.timeSettings.photoTime" type="number" :maxlength="4" placeholder="循环拍摄间隔(1-1000)" input-align="right" :custom-style="{'font-size':'24rpx'}" @blur="handlePositiveIntBlur(item.timeSettings, 'photoTime')" />
  138. <text class="unit-text">秒</text>
  139. </view>
  140. </view>
  141. <view class="device-detail-viewImage">
  142. <text class="device-detail-label">时间段1:</text>
  143. <view class="device-detail-value">
  144. <text class="time-text" @click="openTimePicker(item, 'time1', 0)">{{ (item.timeSettings.time1 && item.timeSettings.time1[0]) || '开始' }}</text>
  145. <text class="time-sep">-</text>
  146. <text class="time-text" @click="openTimePicker(item, 'time1', 1)">{{ (item.timeSettings.time1 && item.timeSettings.time1[1]) || '结束' }}</text>
  147. </view>
  148. </view>
  149. <view class="device-detail-viewImage">
  150. <text class="device-detail-label">时间段2:</text>
  151. <view class="device-detail-value">
  152. <text class="time-text" @click="openTimePicker(item, 'time2', 0)">{{ (item.timeSettings.time2 && item.timeSettings.time2[0]) || '开始' }}</text>
  153. <text class="time-sep">-</text>
  154. <text class="time-text" @click="openTimePicker(item, 'time2', 1)">{{ (item.timeSettings.time2 && item.timeSettings.time2[1]) || '结束' }}</text>
  155. </view>
  156. </view>
  157. <view class="device-detail-viewImage">
  158. <text class="device-detail-label">时间段3:</text>
  159. <view class="device-detail-value">
  160. <text class="time-text" @click="openTimePicker(item, 'time3', 0)">{{ (item.timeSettings.time3 && item.timeSettings.time3[0]) || '开始' }}</text>
  161. <text class="time-sep">-</text>
  162. <text class="time-text" @click="openTimePicker(item, 'time3', 1)">{{ (item.timeSettings.time3 && item.timeSettings.time3[1]) || '结束' }}</text>
  163. </view>
  164. </view>
  165. <view class="device-detail-viewImage">
  166. <text class="device-detail-label">周重复:</text>
  167. <view class="device-detail-value" @click="openWeekPicker(item)">
  168. <view class="week-text">{{ (item.timeSettings.weekLoop || []).join('、') || '请选择' }}</view>
  169. <u-icon name="arrow-right" color="#999999" size="24"></u-icon>
  170. </view>
  171. </view>
  172. </view>
  173. <view class="device-detail-child-settings" v-if="item.activeTab === 'warning'">
  174. <view class="device-detail-viewImage">
  175. <text class="device-detail-label">PIR开关:</text>
  176. <text class="device-detail-value">
  177. <u-switch v-model="item.warning.pirOpenOrClose" active-value="1" inactive-value="0" size="36" />
  178. </text>
  179. </view>
  180. <view class="device-detail-viewImage">
  181. <text class="device-detail-label">PIR灵敏度:</text>
  182. <view class="device-detail-value" @click="setDeviceItemContorl(item, 'pirSensitivity')">
  183. <text class="week-text">{{ item.warning.pirSensitivity == 0 ? '低' : '高' }}</text>
  184. <u-icon name="arrow-right" color="#999999" size="24"></u-icon>
  185. </view>
  186. </view>
  187. <view class="device-detail-viewImage">
  188. <text class="device-detail-label">触发时间间隔:</text>
  189. <view class="device-detail-value">
  190. <u-input v-model="item.warning.triggerTimeInterval" type="number" :maxlength="4" placeholder="触发时间间隔(1-1000)" input-align="right" :custom-style="{'font-size':'24rpx'}" @blur="handlePositiveIntBlur(item.warning, 'triggerTimeInterval')" />
  191. <text class="unit-text">秒</text>
  192. </view>
  193. </view>
  194. </view>
  195. <view class="device-detail-child-settings" v-if="item.activeTab === 'other'">
  196. <view class="device-detail-viewImage">
  197. <text class="device-detail-label">信息戳记:</text>
  198. <text class="device-detail-value">
  199. <u-switch v-model="item.other.informationStamp" active-value="1" inactive-value="0" size="36" />
  200. </text>
  201. </view>
  202. <view class="device-detail-viewImage">
  203. <text class="device-detail-label">自动覆盖:</text>
  204. <text class="device-detail-value">
  205. <u-switch v-model="item.other.autoOverWrite" active-value="1" inactive-value="0" size="36" />
  206. </text>
  207. </view>
  208. <view class="device-detail-viewImage">
  209. <text class="device-detail-label">相机名称:</text>
  210. <view class="device-detail-value">
  211. <u-input v-model="item.other.photoName" :maxlength="20" placeholder="相机名称(最多20字)" input-align="right" :custom-style="{'font-size':'24rpx'}" />
  212. </view>
  213. </view>
  214. </view>
  215. </view>
  216. </view>
  217. </view>
  218. </view>
  219. <view class="device-detail-btn-footer">
  220. <view class="device-detail-btn" @click="saveSettings">保存</view>
  221. </view>
  222. <u-select v-model="showContorl" :list="list" @confirm="confirmDeviceItemContorl"></u-select>
  223. <u-select v-model="showImageTypeContorl" :list="imageList" @confirm="confirmDeviceItemContorl"></u-select>
  224. <u-select v-model="showVideoTypeContorl" :list="videoList" @confirm="confirmDeviceItemContorl"></u-select>
  225. <u-select v-model="showPirTypeContorl" :list="pirList" @confirm="confirmDeviceItemContorl"></u-select>
  226. <u-picker
  227. v-model="showDateTime"
  228. mode="time"
  229. :params="timeParams"
  230. :default-time="currentDefaultTime"
  231. @confirm="confirmTimePicker"
  232. ></u-picker>
  233. <u-popup v-model="showWeekPicker" mode="bottom" border-radius="16">
  234. <view class="week-picker">
  235. <view class="week-picker__title">周重复</view>
  236. <view class="week-picker__list">
  237. <view
  238. v-for="day in weekList"
  239. :key="day"
  240. class="week-picker__item"
  241. :class="{ active: selectedWeeks.indexOf(day) > -1 }"
  242. @click="toggleWeek(day)"
  243. >{{ day }}</view>
  244. </view>
  245. <view class="week-picker__btn" @click="confirmWeekPicker">确定</view>
  246. </view>
  247. </u-popup>
  248. <u-select v-model="showCameraSelect" :list="cameraList" @confirm="confirmCameraSelect"></u-select>
  249. </view>
  250. </template>
  251. <script>
  252. export default {
  253. data(){
  254. return {
  255. value: 10,
  256. camera1ID: '123',
  257. camera2ID: '456',
  258. camera3ID: '789',
  259. timeParams: {
  260. year: false,
  261. month: false,
  262. day: false,
  263. hour: true,
  264. minute: true,
  265. second: false
  266. },
  267. list: [
  268. {
  269. label: '自动',
  270. value: 'takephoto'
  271. },
  272. {
  273. label: '手动',
  274. value: 'manual'
  275. }
  276. ],
  277. imageList: [
  278. {
  279. label: '1280',
  280. value: '1280'
  281. },
  282. {
  283. label: '720',
  284. value: '720'
  285. }
  286. ],
  287. videoList: [
  288. {
  289. label: '1280',
  290. value: '1280'
  291. },
  292. {
  293. label: '720',
  294. value: '720'
  295. }
  296. ],
  297. actionChildItem: 0,
  298. equipContrlForm: {},
  299. time: '',
  300. activeTab: 'pestAnalysis',
  301. title: '设置控制',
  302. myuser_type: false,
  303. deviceType: '',
  304. location: '',
  305. deviceList: [{
  306. label: '相机1',
  307. content:'',
  308. show:false,
  309. activeTab: 'settings',
  310. photoSettings:{
  311. photoModel: '1',
  312. imageSize: '0',
  313. videoSize: '0',
  314. burstPhoto: 1,
  315. videoLength: 60,
  316. photoInterval: 1,
  317. },
  318. timeSettings:{
  319. timePhoto: '1',
  320. photoTime: 60,
  321. time1: ['08:00','09:00'],
  322. time2: ['11:00','12:00'],
  323. time3: ['15:00','16:00'],
  324. weekLoop:['周一','周二','周三'],
  325. },
  326. warning:{
  327. pirOpenOrClose:'1',
  328. pirSensitivity:'0',
  329. triggerTimeInterval:30,
  330. },
  331. other:{
  332. informationStamp:'1',
  333. autoOverWrite:'1',
  334. photoName:'相机1',
  335. }
  336. },{
  337. label: '相机2',
  338. content:'',
  339. show:false,
  340. activeTab: 'settings',
  341. photoSettings:{
  342. photoModel: '1',
  343. imageSize: '0',
  344. videoSize: '0',
  345. burstPhoto: 1,
  346. videoLength: 60,
  347. photoInterval: 1,
  348. },
  349. timeSettings:{
  350. timePhoto: '1',
  351. photoTime: 60,
  352. time1: ['08:00','09:00'],
  353. time2: ['11:00','12:00'],
  354. time3: ['15:00','16:00'],
  355. weekLoop:['周一','周二','周三'],
  356. },
  357. warning:{
  358. pirOpenOrClose:'1',
  359. pirSensitivity:'0',
  360. triggerTimeInterval:30,
  361. },
  362. other:{
  363. informationStamp:'1',
  364. autoOverWrite:'1',
  365. photoName:'相机1',
  366. }
  367. },{
  368. label: '相机3',
  369. content:'',
  370. show:false,
  371. activeTab: 'settings',
  372. photoSettings:{
  373. photoModel: '1',
  374. imageSize: '0',
  375. videoSize: '0',
  376. burstPhoto: 1,
  377. videoLength: 60,
  378. photoInterval: 1,
  379. },
  380. timeSettings:{
  381. timePhoto: '1',
  382. photoTime: 60,
  383. time1: ['08:00','09:00'],
  384. time2: ['11:00','12:00'],
  385. time3: ['15:00','16:00'],
  386. weekLoop:['周一','周二','周三'],
  387. },
  388. warning:{
  389. pirOpenOrClose:'1',
  390. pirSensitivity:'0',
  391. triggerTimeInterval:30,
  392. },
  393. other:{
  394. informationStamp:'1',
  395. autoOverWrite:'1',
  396. photoName:'相机1',
  397. }
  398. }],
  399. d_id: '',
  400. show: false,
  401. checked: false,
  402. showContorl: false,
  403. showPirTypeContorl: false,
  404. pirList: [
  405. {
  406. label: '自动',
  407. value: 'auto'
  408. },
  409. {
  410. label: '高',
  411. value: 'high'
  412. },
  413. {
  414. label: '中',
  415. value: 'middle'
  416. },
  417. {
  418. label: '低',
  419. value: 'low'
  420. }
  421. ],
  422. showDateTime: false,
  423. currentTimeItem: null,
  424. currentTimeField: '',
  425. currentTimeIndex: 0,
  426. currentDefaultTime: '08:00',
  427. showImageTypeContorl: false,
  428. showVideoTypeContorl: false,
  429. showWeekPicker: false,
  430. weekList: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
  431. selectedWeeks: [],
  432. currentWeekItem: null,
  433. currentItem: null,
  434. currentFieldType: '',
  435. deviceName: '',
  436. deviceID: '',
  437. camera1ID: '',
  438. camera2ID: '',
  439. camera3ID: '',
  440. showCameraSelect: false,
  441. currentCameraField: '',
  442. cameraList: [
  443. {
  444. label: 'CAM-0001',
  445. value: 'CAM-0001'
  446. },
  447. {
  448. label: 'CAM-0002',
  449. value: 'CAM-0002'
  450. },
  451. {
  452. label: 'CAM-0003',
  453. value: 'CAM-0003'
  454. },
  455. {
  456. label: 'CAM-0004',
  457. value: 'CAM-0004'
  458. },
  459. {
  460. label: 'CAM-0005',
  461. value: 'CAM-0005'
  462. },
  463. {
  464. label: 'CAM-0006',
  465. value: 'CAM-0006'
  466. },
  467. {
  468. label: 'CAM-0007',
  469. value: 'CAM-0007'
  470. },
  471. {
  472. label: 'CAM-0008',
  473. value: 'CAM-0008'
  474. }
  475. ]
  476. }
  477. },
  478. onLoad(options){
  479. this.d_id = options.d_id
  480. this.getControlDeviceConfigInfo()
  481. uni.getStorage({
  482. key:"myuser_type",
  483. success:(res)=>{
  484. if(Number(res.data) == 1){
  485. this.myuser_type = true
  486. this.activeTab = 'pestAnalysis'
  487. }else{
  488. this.activeTab = 'viewImage'
  489. }
  490. }
  491. })
  492. },
  493. methods: {
  494. setDeviceItemContorl(item, type){
  495. this.currentItem = item
  496. this.currentFieldType = type
  497. switch(type){
  498. case 'takephoto':
  499. this.showContorl = true
  500. break;
  501. case 'imageSize':
  502. this.showImageTypeContorl = true
  503. break;
  504. case 'videoSize':
  505. this.showVideoTypeContorl = true
  506. break;
  507. case 'pirSensitivity':
  508. this.showPirTypeContorl = true
  509. break;
  510. }
  511. },
  512. confirmDeviceItemContorl(e){
  513. const fieldMap = {
  514. takephoto: ['photoSettings', 'photoModel'],
  515. imageSize: ['photoSettings', 'imageSize'],
  516. videoSize: ['photoSettings', 'videoSize'],
  517. pirSensitivity: ['warning', 'pirSensitivity']
  518. }
  519. const target = fieldMap[this.currentFieldType]
  520. if (this.currentItem && target) {
  521. this.$set(this.currentItem[target[0]], target[1], e[0].label)
  522. }
  523. },
  524. // photoModel编码转文案(与后台约定:0=自动,1=手动),已是文案的直接返回
  525. formatPhotoModel(value){
  526. if (value === '0') return '自动'
  527. if (value === '1') return '手动'
  528. return value || '自动'
  529. },
  530. // 图片/视频大小:兼容mock编码(0=1280,1=720)与选择后存入的文案
  531. formatImageSize(value){
  532. if (value == 0 || value === '1280') return '1280'
  533. if (value == 1 || value === '720') return '720'
  534. return value || '1280'
  535. },
  536. handleTabChildClick(item, tab){
  537. item.activeTab = tab;
  538. },
  539. // 展开/收起相机设置面板(同时只展开一个,再点一次收起;-1表示全部收起)
  540. toggleChildItem(index){
  541. this.actionChildItem = this.actionChildItem == index ? -1 : index
  542. },
  543. // 失焦时校验:只保留正整数,范围1-1000(空/非法/小于1置为1,大于1000置为1000)
  544. // 小程序上@input回传参数拿不到输入值,且边输入边改值会引发输入框错乱,所以统一在失焦时校正
  545. handlePositiveIntBlur(item, field){
  546. let value = (item[field] === null || item[field] === undefined ? '' : item[field] + '').replace(/\D/g, '')
  547. value = value.replace(/^0+/, '')
  548. if (value === '' || Number(value) < 1) {
  549. value = '1'
  550. }
  551. if (Number(value) > 1000) {
  552. value = '1000'
  553. }
  554. this.$set(item, field, value)
  555. },
  556. openCameraIdPicker(field) {
  557. this.currentCameraField = field
  558. this.showCameraSelect = true
  559. },
  560. confirmCameraSelect(e) {
  561. const value = e[0].value
  562. const fields = ['camera1ID', 'camera2ID', 'camera3ID']
  563. for (let i = 0; i < fields.length; i++) {
  564. if (fields[i] !== this.currentCameraField && this[fields[i]] === value) {
  565. uni.showToast({ title: '该相机已被其他项选择', icon: 'none' })
  566. return
  567. }
  568. }
  569. this[this.currentCameraField] = value
  570. },
  571. openTimePicker(item, field, index) {
  572. this.currentTimeItem = item
  573. this.currentTimeField = field
  574. this.currentTimeIndex = index
  575. const range = item.timeSettings[field] || []
  576. this.currentDefaultTime = range[index] || '08:00'
  577. this.showDateTime = true
  578. },
  579. confirmTimePicker(e) {
  580. const item = this.currentTimeItem
  581. const field = this.currentTimeField
  582. const index = this.currentTimeIndex
  583. if (!item || !field) return
  584. const value = e.hour + ':' + e.minute
  585. // 用修改后的临时数据做校验,通过才写入(time1~time3为[开始,结束]数组)
  586. const slots = ['time1', 'time2', 'time3'].map((key, i) => {
  587. const source = item.timeSettings[key] || []
  588. const range = [source[0] || '', source[1] || '']
  589. if (key === field) range[index] = value
  590. return { name: '时间段' + (i + 1), start: range[0], end: range[1] }
  591. })
  592. for (let i = 0; i < slots.length; i++) {
  593. if (slots[i].start && slots[i].end && slots[i].start >= slots[i].end) {
  594. uni.showToast({ title: slots[i].name + '的开始时间需小于结束时间', icon: 'none' })
  595. return
  596. }
  597. }
  598. for (let i = 0; i < slots.length - 1; i++) {
  599. const a = slots[i]
  600. const b = slots[i + 1]
  601. if (a.start && a.end && b.start && b.end) {
  602. if (a.start === b.start && a.end === b.end) {
  603. uni.showToast({ title: a.name + '与' + b.name + '不能重复', icon: 'none' })
  604. return
  605. }
  606. if (a.end > b.start) {
  607. uni.showToast({ title: a.name + '需早于' + b.name, icon: 'none' })
  608. return
  609. }
  610. }
  611. }
  612. if (!item.timeSettings[field] || item.timeSettings[field].length !== 2) {
  613. this.$set(item.timeSettings, field, ['', ''])
  614. }
  615. this.$set(item.timeSettings[field], index, value)
  616. },
  617. openWeekPicker(item) {
  618. this.currentWeekItem = item
  619. this.selectedWeeks = item.timeSettings.weekLoop ? item.timeSettings.weekLoop.slice() : []
  620. this.showWeekPicker = true
  621. },
  622. toggleWeek(day) {
  623. const index = this.selectedWeeks.indexOf(day)
  624. if (index > -1) {
  625. if (this.selectedWeeks.length === 1) {
  626. uni.showToast({
  627. title: '至少保留一个',
  628. icon: 'none'
  629. })
  630. return
  631. }
  632. this.selectedWeeks.splice(index, 1)
  633. } else {
  634. this.selectedWeeks.push(day)
  635. }
  636. },
  637. confirmWeekPicker() {
  638. if (this.selectedWeeks.length === 0) {
  639. uni.showToast({
  640. title: '请至少选择一个',
  641. icon: 'none'
  642. })
  643. return
  644. }
  645. if (this.currentWeekItem) {
  646. const ordered = this.weekList.filter(day => this.selectedWeeks.indexOf(day) > -1)
  647. this.$set(this.currentWeekItem.timeSettings, 'weekLoop', ordered)
  648. }
  649. this.showWeekPicker = false
  650. },
  651. getProgressWidth(value, min, max) {
  652. if (max === min) return 0
  653. return ((value - min) / (max - min)) * 100
  654. },
  655. onSliderTouchStart(e, field, min, max) {
  656. this.sliderField = field
  657. this.sliderMin = min
  658. this.sliderMax = max
  659. const query = uni.createSelectorQuery().in(this)
  660. query.select('.custom-progress').boundingClientRect(rect => {
  661. this.sliderRect = rect
  662. }).exec()
  663. this.updateSliderValue(e.touches[0].clientX, field, min, max)
  664. },
  665. onSliderTouchMove(e, min, max) {
  666. if (!this.sliderField || !this.sliderRect) return
  667. this.updateSliderValue(e.touches[0].clientX, this.sliderField, min, max)
  668. },
  669. onSliderTouchEnd() {
  670. this.sliderField = ''
  671. },
  672. onSliderTap(e, field, min, max) {
  673. const query = uni.createSelectorQuery().in(this)
  674. query.select('.custom-progress').boundingClientRect(rect => {
  675. this.sliderRect = rect
  676. this.updateSliderValue(e.detail.x + rect.left, field, min, max)
  677. }).exec()
  678. },
  679. updateSliderValue(clientX, field, min, max) {
  680. if (!this.sliderRect) return
  681. let ratio = (clientX - this.sliderRect.left) / this.sliderRect.width
  682. ratio = Math.max(0, Math.min(1, ratio))
  683. const value = Math.round(min + ratio * (max - min))
  684. this.$set(this.equipContrlForm, field, value)
  685. },
  686. handleBack() {
  687. uni.navigateBack({
  688. delta: 1
  689. });
  690. },
  691. handleTabClick(tab) {
  692. this.activeTab = tab;
  693. },
  694. showMqttConfig(){
  695. this.show = true;
  696. },
  697. closeMqttConfig(){
  698. this.show = false;
  699. },
  700. async setDeviceContorl(type){
  701. const data = {
  702. device_type_id: 3,
  703. d_id: this.d_id,
  704. cmd: type,
  705. }
  706. if(type === 'imei'){
  707. data.imei = this.equipContrlForm.imei
  708. }else{
  709. delete data.imei
  710. }
  711. this.$myRequest({
  712. url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
  713. method: 'POST',
  714. data
  715. }).then(res => {
  716. this.closeMqttConfig()
  717. if (res) {
  718. uni.showToast({
  719. title: '设备控制修改成功!',
  720. icon: 'success',
  721. });
  722. } else {
  723. uni.showToast({
  724. title: '设备控制修改失败',
  725. icon: 'error',
  726. });
  727. }
  728. });
  729. },
  730. saveSettings(){
  731. let newForm = Object.assign({}, this.equipContrlForm) // 深拷贝
  732. newForm.st = newForm.st + ''
  733. newForm.et = newForm.et + ''
  734. newForm.st && newForm.st.slice(0, 2).charAt(0) != '0'
  735. ? newForm.st.slice(0, 2)
  736. : newForm.st.slice(1, 2)
  737. newForm.et =
  738. newForm.et && newForm.et.slice(0, 2).charAt(0) != '0'
  739. ? newForm.et.slice(0, 2)
  740. : newForm.et.slice(1, 2)
  741. for (let k in newForm) {
  742. if (typeof newForm[k] === 'number') {
  743. newForm[k] = newForm[k] + ''
  744. }
  745. }
  746. newForm.st = newForm.st.replace(':00', '')
  747. this.$myRequest({
  748. url: '/api/api_gateway?method=forecast.send_control.device_control',
  749. method: 'POST',
  750. data: {
  751. device_type_id: 3,
  752. d_id: this.d_id,
  753. config: JSON.stringify(newForm)
  754. }
  755. }).then(res => {
  756. if (res) {
  757. // 设备控制修改成功
  758. uni.showToast({
  759. title: '设备控制修改成功!',
  760. icon: 'success',
  761. });
  762. } else {
  763. uni.showToast({
  764. title: '设备控制修改失败',
  765. icon: 'error',
  766. });
  767. }
  768. })
  769. },
  770. async getControlDeviceConfigInfo(){
  771. const res = await this.$myRequest({
  772. url: '/api/api_gateway?method=forecast.send_control.device_control_info',
  773. method: 'POST',
  774. data: {
  775. d_id: this.d_id,
  776. cmd:'paramconf'
  777. },
  778. });
  779. this.equipContrlForm = res
  780. },
  781. }
  782. }
  783. </script>
  784. <style scoped lang="scss">
  785. .device-detail {
  786. display: flex;
  787. width: 100%;
  788. height: calc(100vh - 112rpx);
  789. padding-top: 112rpx;
  790. flex-direction: column;
  791. align-items: center;
  792. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  793. .device-detail__header {
  794. width: 100%;
  795. font-size: 28rpx;
  796. color: #999;
  797. color: #042118;
  798. font-family: 'Source Han Sans CN VF';
  799. font-weight: 700;
  800. position: relative;
  801. text-align: center;
  802. .arrow-left {
  803. position: absolute;
  804. left: 32rpx;
  805. margin-right: 12rpx;
  806. }
  807. }
  808. .device-detail__body {
  809. width: calc(100% - 64rpx);
  810. margin: 0 auto;
  811. border-radius: 16rpx;
  812. overflow-x: hidden;
  813. overflow-y: auto;
  814. // 隐藏滚动条
  815. -ms-overflow-style: none;
  816. scrollbar-width: none;
  817. }
  818. .tabs {
  819. margin: 24rpx 0;
  820. border-radius: 16rpx;
  821. padding: 16rpx 0;
  822. padding-top: 0;
  823. .tab-container{
  824. display: flex;
  825. width: 100%;
  826. height: 88rpx;
  827. line-height: 88rpx;
  828. text-align: center;
  829. font-size: 28rpx;
  830. font-weight: 700;
  831. color: #042118;
  832. font-family: 'Source Han Sans CN VF';
  833. }
  834. .tab-item {
  835. margin-right: 40rpx;
  836. color:#999999;
  837. }
  838. .active{
  839. position: relative;
  840. color: #303133;
  841. text-align: center;
  842. font-family: "Source Han Sans CN VF";
  843. font-size: 28rpx;
  844. font-weight: 700;
  845. &::after {
  846. content: '';
  847. position: absolute;
  848. bottom: 10rpx;
  849. left: 50%;
  850. transform: translateX(-50%);
  851. width: 100%;
  852. height: 36rpx;
  853. border-bottom: 6rpx solid #303133;
  854. }
  855. }
  856. }
  857. .device-detail-content{
  858. display: flex;
  859. padding: 24rpx 32rpx;
  860. flex-direction: column;
  861. align-items: flex-start;
  862. gap: 20rpx;
  863. border-radius: 16rpx;
  864. background: #FFF;
  865. .device-detail-name{
  866. flex:1;
  867. width: 100%;
  868. display: flex;
  869. justify-content: space-between;
  870. .rotate{
  871. transform: rotate(180deg);
  872. transition: all 0.3s ease-in-out;
  873. }
  874. }
  875. .device-detail-child-settings-container{
  876. transition: all 0.3s ease-in-out;
  877. padding: 0 24rpx;
  878. }
  879. .tabs {
  880. margin: 2rpx 0;
  881. border-radius: 16rpx;
  882. padding: 6rpx 0;
  883. padding-top: 0;
  884. .tab-container{
  885. display: flex;
  886. width: 100%;
  887. height: 68rpx;
  888. line-height: 68rpx;
  889. text-align: center;
  890. font-size: 24rpx;
  891. color: #042118;
  892. font-family: 'Source Han Sans CN VF';
  893. }
  894. .tab-item {
  895. margin-right: 20rpx;
  896. color:#999999;
  897. }
  898. .active{
  899. position: relative;
  900. color: #303133;
  901. text-align: center;
  902. font-family: "Source Han Sans CN VF";
  903. font-size: 24rpx;
  904. &::after {
  905. content: '';
  906. position: absolute;
  907. bottom: 10rpx;
  908. left: 50%;
  909. transform: translateX(-50%);
  910. width: 100%;
  911. height: 36rpx;
  912. border-bottom: 6rpx solid #303133;
  913. }
  914. }
  915. }
  916. .device-detail-item{
  917. .device-detail-btn-container{
  918. display: flex;
  919. gap: 24rpx;
  920. margin-top: 12rpx;
  921. }
  922. .device-detail-btn{
  923. display: flex;
  924. padding: 10rpx 16rpx;
  925. justify-content: center;
  926. align-items: center;
  927. gap: 16rpx;
  928. border-radius: 16rpx;
  929. background: #0BBC58;
  930. color: #ffffff;
  931. font-family: "Source Han Sans CN VF";
  932. font-size: 26rpx;
  933. font-weight: 400;
  934. }
  935. .force-btn{
  936. background: #FB4E52;
  937. }
  938. }
  939. .device-detail-viewImage{
  940. width: 100%;
  941. display: flex;
  942. justify-content: space-between;
  943. align-items: center;
  944. height: 70rpx;
  945. .device-detail-label{
  946. color: #303133;
  947. font-family: "Source Han Sans CN VF";
  948. font-size: 26rpx;
  949. flex-shrink: 0;
  950. }
  951. .device-detail-value{
  952. color: #303133;
  953. font-family: "Source Han Sans CN VF";
  954. font-size: 26rpx;
  955. display: flex;
  956. align-items: center;
  957. justify-content: space-between;
  958. .week-text{
  959. flex: 1;
  960. min-width: 0;
  961. overflow: hidden;
  962. text-overflow: ellipsis;
  963. white-space: nowrap;
  964. text-align: right;
  965. margin-right: 8rpx;
  966. }
  967. .time-text{
  968. min-width: 96rpx;
  969. height: 48rpx;
  970. line-height: 48rpx;
  971. padding: 0 16rpx;
  972. text-align: center;
  973. border-radius: 10rpx;
  974. background: #F6F8FC;
  975. color: #303133;
  976. font-size: 24rpx;
  977. font-family: "Source Han Sans CN VF";
  978. }
  979. .time-sep{
  980. margin: 0 8rpx;
  981. color: #999999;
  982. }
  983. .unit-text{
  984. margin-left: 8rpx;
  985. flex-shrink: 0;
  986. color: #303133;
  987. font-size: 24rpx;
  988. font-family: "Source Han Sans CN VF";
  989. }
  990. }
  991. }
  992. }
  993. .slider-container{
  994. position: relative;
  995. margin-bottom: 20rpx;
  996. .slider-min-value{
  997. position: absolute;
  998. left: 0;
  999. top: -50rpx;
  1000. }
  1001. .slider{
  1002. width: 600rpx;
  1003. }
  1004. .slider-max-value{
  1005. position: absolute;
  1006. right: 0;
  1007. top: -50rpx;
  1008. }
  1009. }
  1010. .custom-progress{
  1011. width: 600rpx;
  1012. padding: 0;
  1013. .progress-track{
  1014. position: relative;
  1015. height: 12rpx;
  1016. background-color: #ebedf0;
  1017. border-radius: 6rpx;
  1018. }
  1019. .progress-fill{
  1020. position: absolute;
  1021. left: 0;
  1022. top: 0;
  1023. height: 100%;
  1024. background-color: #0BBC58;
  1025. border-radius: 6rpx;
  1026. transition: width 0.2s;
  1027. }
  1028. .progress-thumb{
  1029. position: absolute;
  1030. top: 50%;
  1031. width: 28rpx;
  1032. height: 28rpx;
  1033. margin-left: -14rpx;
  1034. margin-top: -14rpx;
  1035. border-radius: 50%;
  1036. background-color: #fff;
  1037. box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  1038. transition: left 0.2s;
  1039. }
  1040. }
  1041. .device-detail-btn-footer{
  1042. position: fixed;
  1043. bottom: 0;
  1044. left: 0;
  1045. width: 100%;
  1046. height: 112rpx;
  1047. line-height: 112rpx;
  1048. text-align: center;
  1049. font-size: 28rpx;
  1050. font-weight: 700;
  1051. color: #042118;
  1052. font-family: 'Source Han Sans CN VF';
  1053. background: #ffffff;
  1054. display: flex;
  1055. justify-content: center;
  1056. align-items: center;
  1057. .device-detail-btn{
  1058. display: flex;
  1059. height: 80rpx;
  1060. width: 90%;
  1061. margin: 0 auto;
  1062. padding: 0rpx 20rpx;
  1063. justify-content: center;
  1064. align-items: center;
  1065. gap: 8rpx;
  1066. border-radius: 16rpx;
  1067. background:#0BBC58;
  1068. color: #ffffff;
  1069. text-align: center;
  1070. font-family: "Source Han Sans CN VF";
  1071. font-size: 14px;
  1072. font-style: normal;
  1073. font-weight: 500;
  1074. }
  1075. }
  1076. .week-picker{
  1077. padding: 32rpx 32rpx 40rpx;
  1078. .week-picker__title{
  1079. text-align: center;
  1080. font-size: 30rpx;
  1081. font-weight: 700;
  1082. color: #042118;
  1083. font-family: 'Source Han Sans CN VF';
  1084. margin-bottom: 32rpx;
  1085. }
  1086. .week-picker__list{
  1087. display: flex;
  1088. flex-wrap: wrap;
  1089. gap: 24rpx;
  1090. margin-bottom: 40rpx;
  1091. }
  1092. .week-picker__item{
  1093. width: calc((100% - 72rpx) / 4);
  1094. height: 64rpx;
  1095. line-height: 64rpx;
  1096. text-align: center;
  1097. border-radius: 12rpx;
  1098. background: #F6F8FC;
  1099. color: #666666;
  1100. font-size: 26rpx;
  1101. font-family: 'Source Han Sans CN VF';
  1102. &.active{
  1103. background: #0BBC58;
  1104. color: #ffffff;
  1105. }
  1106. }
  1107. .week-picker__btn{
  1108. height: 80rpx;
  1109. line-height: 80rpx;
  1110. text-align: center;
  1111. border-radius: 16rpx;
  1112. background: #0BBC58;
  1113. color: #ffffff;
  1114. font-size: 28rpx;
  1115. font-family: 'Source Han Sans CN VF';
  1116. font-weight: 500;
  1117. }
  1118. }
  1119. }
  1120. </style>