lampControls.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. <template>
  2. <view>
  3. <!-- 警告提示 -->
  4. <u-notify ref="uNotify"></u-notify>
  5. <!-- 成功提示 -->
  6. <u-notify ref="Success"></u-notify>
  7. <view class="navigation">
  8. <scroll-view class="scrolls" scroll-x="true">
  9. <view v-for="(item,index) in records" :key="item.id" class="nav_item" @click="selectItem(index)"
  10. tabindex="1">
  11. {{item.poleGroupName}}
  12. </view>
  13. </scroll-view>
  14. <view class="lamp_data">
  15. <button type="primary" @click="lightDate()">数据</button>
  16. </view>
  17. </view>
  18. <view class="all">
  19. <button type="default" @click="allTactics()" style="width: 220rpx;left: 265rpx;">关联策略</button>
  20. <button @click="open(2)" style="left: 20rpx;" type="primary">全开</button>
  21. <button @click="shut(2)" style="right: 20rpx;" type="warn">全关</button>
  22. </view>
  23. <view class="list">
  24. <view v-for="(item2,index2) in tworacords" :key="item2.id" class="list_data">
  25. <image :src="item2.lightControlState == '2' ? imageAddress + '/lamp.png' : imageAddress + '/lamp1.png'">
  26. </image>
  27. <text>{{item2.publicName}}</text>
  28. <button type="default" @click="allTactics(item2.publicName,item2.publicId,1,item2.lightName)"
  29. style="right: 220rpx; width: 120rpx;">策略</button>
  30. <button type="primary" @click="open(1,item2.publicId,item2.publicName,index2)"
  31. style="right: 120rpx;">开</button>
  32. <button type="warn" @click="shut(1,item2.publicId,item2.publicName,index2)"
  33. style="right: 20rpx;">关</button>
  34. </view>
  35. <!-- 开启控制 -->
  36. <u-popup :show="openShow" mode="center" duration="0">
  37. <view class="openPopup">
  38. <view class="openText">
  39. 开灯控制
  40. </view>
  41. <view class="openTime">
  42. <select-lay slabel="label" :options="openlist" placeholder="开启时长" :value="openTime"
  43. @selectitem="modify" class="select-lay">
  44. </select-lay>
  45. </view>
  46. <view class="brightness">
  47. 开灯亮度:{{duration}}%
  48. <slider @change="durationChange" :value="duration" min="1" max="100">
  49. </slider>
  50. </view>
  51. <view class="remarks">
  52. <input placeholder="请输入备注(可不填)" @input="openlightControl" :value="openRemarks" type="text" />
  53. </view>
  54. <view class="send">
  55. <view style="width: 200rpx;">
  56. <u-button @click="openShow = false">取消</u-button>
  57. </view>
  58. <view style="width: 200rpx;margin-left: 100rpx;">
  59. <u-button type="primary" @click="distinguish.opensh == 1?
  60. openControl(1,1):openControl(1,2)">
  61. 确定</u-button>
  62. </view>
  63. </view>
  64. </view>
  65. </u-popup>
  66. <!-- 关闭控制 -->
  67. <u-popup :show="shutShow" mode="center" duration="0">
  68. <view class="openPopup" style="height: 500rpx;">
  69. <view class="openText">
  70. 关灯控制
  71. </view>
  72. <view class="openTime">
  73. <select-lay slabel="label" :options="shutlist" placeholder="关闭时长" :value="shutTime"
  74. @selectitem="shutModify" class="select-lay">
  75. </select-lay>
  76. </view>
  77. <view class="remarks">
  78. <input placeholder="请输入备注(可不填)" @input="shutlightControl" :value="shutRemarks" type="text" />
  79. </view>
  80. <view class="send">
  81. <view style="width: 200rpx;">
  82. <u-button @click="shutShow = false">取消</u-button>
  83. </view>
  84. <view style="width: 200rpx;margin-left: 100rpx;">
  85. <u-button type="primary" @click="distinguish.opensh == 1?
  86. shutControl(2,1):shutControl(2,2)">
  87. 确定</u-button>
  88. </view>
  89. </view>
  90. </view>
  91. </u-popup>
  92. </view>
  93. <view class="pagination">
  94. <uni-pagination :total="page.total" :pageSize="page.pageSize" :current="page.current" @change="pageTatble"
  95. style="width: 750rpx;
  96. height: 150rpx;">
  97. </uni-pagination>
  98. </view>
  99. <u-toast ref="uToast"></u-toast>
  100. </view>
  101. </template>
  102. <script>
  103. import {
  104. grouplist,
  105. list,
  106. Control,
  107. light
  108. } from '@/pages/api/lighting/lighting.js'
  109. export default {
  110. data() {
  111. return {
  112. page: {
  113. total: 80, //数据总量
  114. pageSize: 10, //每页的数据量
  115. current: 1, //当前页数
  116. thrifty: false, //节流阀
  117. },
  118. openShow: false,
  119. shutShow: false,
  120. openlist: [{
  121. label: '1分钟',
  122. value: 1
  123. },
  124. {
  125. label: '2分钟',
  126. value: 2
  127. },
  128. {
  129. label: '3分钟',
  130. value: 3
  131. },
  132. {
  133. label: '5分钟',
  134. value: 5
  135. },
  136. {
  137. label: '10分钟',
  138. value: 10
  139. },
  140. {
  141. label: '20分钟',
  142. value: 20
  143. },
  144. {
  145. label: '30分钟',
  146. value: 30
  147. },
  148. {
  149. label: '1小时',
  150. value: 60
  151. },
  152. {
  153. label: '2小时',
  154. value: 120
  155. },
  156. {
  157. label: '3小时',
  158. value: 180
  159. },
  160. {
  161. label: '5小时',
  162. value: 300
  163. },
  164. {
  165. label: '8小时',
  166. value: 480
  167. },
  168. ],
  169. shutlist: [{
  170. label: '1分钟',
  171. value: 1
  172. },
  173. {
  174. label: '2分钟',
  175. value: 2
  176. },
  177. {
  178. label: '3分钟',
  179. value: 3
  180. },
  181. {
  182. label: '5分钟',
  183. value: 5
  184. },
  185. {
  186. label: '10分钟',
  187. value: 10
  188. },
  189. {
  190. label: '20分钟',
  191. value: 20
  192. },
  193. {
  194. label: '30分钟',
  195. value: 30
  196. },
  197. {
  198. label: '1小时',
  199. value: 60
  200. },
  201. {
  202. label: '2小时',
  203. value: 120
  204. },
  205. {
  206. label: '3小时',
  207. value: 180
  208. },
  209. {
  210. label: '5小时',
  211. value: 300
  212. },
  213. {
  214. label: '8小时',
  215. value: 480
  216. },
  217. ],
  218. openTime: '', //开启时长
  219. shutTime: '', //关闭时长
  220. duration: '1', //开灯亮度
  221. openRemarks: '', //开灯备注
  222. shutRemarks: '', //关灯备注
  223. records: [],
  224. tworacords: [],
  225. topItem: '',
  226. //分组信息
  227. divide: {
  228. publicId: 0,
  229. publicName: '',
  230. groupIndex: 0, //当前的分组下标
  231. },
  232. //设备信息
  233. device: {
  234. publicId: '',
  235. publicName: '',
  236. index2: 0
  237. },
  238. //区分单个和多个开关控制
  239. distinguish: {
  240. opensh: 1,
  241. shutsh: 1,
  242. },
  243. imageAddress: 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image',
  244. //定时器id
  245. timerId:'',
  246. permit:true
  247. }
  248. },
  249. onLoad() {
  250. this.load()
  251. },
  252. onShow() {
  253. var that = this
  254. setTimeout(function(){
  255. var permit = that.permit
  256. //通过vuex中储存的quantity来记录执行的次数,以确保在第一次执行时不执行onshow中的方法
  257. var token = uni.getStorageSync('token')
  258. that.$store.commit('changeQuan',1)
  259. var quantity = that.$store.state.quantity
  260. //permit为true表示数据尚未加载成功,此时定时器尚未打开,
  261. //为false表示定时器打开过,但此时由于页面隐藏关闭了定时器,所以再次显示时重新打开
  262. if(quantity != 1){
  263. permit == true && token != ''? that.load() : that.timerId = setInterval(that.renovate,15000)
  264. }
  265. },1000)
  266. },
  267. onHide() {
  268. var that = this
  269. var permit = that.permit
  270. //在确保定时器打开且页面隐藏时关闭定时器
  271. if(permit == false){
  272. clearInterval(this.timerId)
  273. }
  274. },
  275. methods: {
  276. load() {
  277. const current = this.page.current
  278. const pageSize = this.page.pageSize
  279. var records = []
  280. grouplist().then(get => {
  281. if (get.code == 200) {
  282. this.records = get.data
  283. records = get.data
  284. list(records[0].id, current, pageSize).then(res => {
  285. if (res.code == 200) {
  286. let children = res.data.records[0].children
  287. this.page.total = res.data.total
  288. this.tworacords = children
  289. this.divide.publicId = records[0].id
  290. this.divide.publicName = records[0].poleGroupName
  291. this.timerId = setInterval(this.renovate,15000)
  292. this.permit = false
  293. }
  294. })
  295. }
  296. })
  297. },
  298. //过度动画
  299. cartoon(title, duration) {
  300. uni.showToast({
  301. title: title,
  302. icon: 'loading',
  303. duration: duration
  304. })
  305. },
  306. //切换分组
  307. selectItem(index) {
  308. var records = this.records
  309. let pageSize = this.page.pageSize
  310. let current = 1
  311. this.divide.groupIndex = index
  312. this.divide.publicId = records[index].id
  313. this.divide.publicName = records[index].poleGroupName
  314. list(records[index].id, current, pageSize).then(res => {
  315. if (res.code == 200) {
  316. this.tworacords = res.data.records[0].children
  317. this.page.current = 1
  318. this.page.total = res.data.total
  319. }
  320. })
  321. },
  322. open(ever, publicId, publicName, index2) {
  323. this.distinguish.opensh = ever
  324. if (ever == 1) {
  325. this.device.publicId = publicId
  326. this.device.publicName = publicName
  327. this.device.index2 = index2
  328. }
  329. this.openShow = true
  330. },
  331. shut(ever, publicId, publicName, index2) {
  332. this.distinguish.shutsh = ever
  333. if (ever == 1) {
  334. this.device.publicId = publicId
  335. this.device.publicName = publicName
  336. this.device.index2 = index2
  337. }
  338. this.shutShow = true
  339. },
  340. modify(index, item) {
  341. this.openTime = index >= 0 ? item.value : ''
  342. },
  343. durationChange(e) {
  344. this.duration = e.target.value
  345. },
  346. //时长未选择报错
  347. exError() {
  348. this.$refs.uNotify.show({
  349. top: 10,
  350. type: 'error',
  351. color: '#ffffff',
  352. bgColor: '#f56c6c',
  353. message: '请选择时长',
  354. duration: 1500,
  355. fontSize: 15,
  356. })
  357. },
  358. Success(message) {
  359. this.$refs.Success.show({
  360. top: 10,
  361. type: 'success',
  362. color: '#ffffff',
  363. message: message,
  364. duration: 1500,
  365. fontSize: 15,
  366. })
  367. },
  368. //开启
  369. openControl(handSwitch, handType) {
  370. var that = this
  371. const openTime = that.openTime
  372. const duration = that.duration
  373. const openRemarks = that.openRemarks
  374. var opensh = that.distinguish.opensh
  375. var tworacords = that.tworacords
  376. var tworacords = []
  377. if (openTime == '') {
  378. that.exError()
  379. } else {
  380. var publicId = 0
  381. var publicName = ''
  382. if (opensh == 1) {
  383. publicId = that.device.publicId
  384. publicName = that.device.publicName
  385. } else {
  386. publicId = that.divide.publicId
  387. publicName = that.divide.publicName
  388. }
  389. //handSwitch(开启:1,关闭:2)
  390. //handType(开/关:1,全开/全关:2)
  391. //publicId(分组/设备的id)
  392. //openTime(开启时间)
  393. //duration(光照度)
  394. //openRemarks(备注)
  395. //publicName(分组/设备名称)
  396. Control(handSwitch, handType, publicId, openTime, duration, openRemarks, publicName).then(res => {
  397. if (res.code == 200) {
  398. that.Success('开灯成功')
  399. }
  400. })
  401. }
  402. },
  403. shutModify(index, item) {
  404. this.shutTime = index >= 0 ? item.value : ''
  405. },
  406. //关闭
  407. shutControl(handSwitch, handType) {
  408. var that = this
  409. const shutTime = that.shutTime
  410. const shutRemarks = that.shutRemarks
  411. var tworacords = that.tworacords
  412. var index2 = that.device.index2
  413. var shutsh = that.distinguish.shutsh
  414. if (shutTime == '') {
  415. that.exError()
  416. } else {
  417. var publicId = 0
  418. var publicName = ''
  419. if (shutsh == 1) {
  420. publicId = that.device.publicId
  421. publicName = that.device.publicName
  422. } else {
  423. publicId = that.divide.publicId
  424. publicName = that.divide.publicName
  425. }
  426. Control(handSwitch, handType, publicId, shutTime, 0, shutRemarks, publicName).then(res => {
  427. if (res.code == 200) {
  428. that.Success('关灯成功')
  429. }
  430. })
  431. }
  432. },
  433. //获取输入的值(开启备注)
  434. openlightControl(e) {
  435. this.openRemarks = e.detail.value
  436. },
  437. //获取输入的值(关闭备注)
  438. shutlightControl(e) {
  439. this.shutRemarks = e.detail.value
  440. },
  441. //关联策略
  442. allTactics(publicName, publicId, relationType, lightName) {
  443. uni.navigateTo({
  444. url: '/pages/Tactics/Tactics?publicName=' + publicName + '&publicId=' + publicId +
  445. '&relationType=' + relationType + '&lightName=' + lightName
  446. })
  447. },
  448. lightDate() {
  449. uni.navigateTo({
  450. url: '/pages/Lighting_data/Lighting_data'
  451. })
  452. },
  453. //分页器页数改变
  454. pageTatble(e) {
  455. var that = this
  456. that.cartoon('加载中',1000)
  457. var publicId = that.divide.publicId
  458. var pageSize = that.page.pageSize
  459. that.page.current = e.current
  460. list(publicId, e.current, pageSize).then(res => {
  461. if (res.code == 200) {
  462. that.tworacords = res.data.records[0].children
  463. }
  464. })
  465. },
  466. //定时刷新
  467. renovate(){
  468. var that = this
  469. var publicId = that.divide.publicId
  470. var current = that.page.current
  471. var pageSize = that.page.pageSize
  472. list(publicId,current,pageSize).then(res => {
  473. if(res.code == 200){
  474. that.tworacords = res.data.records[0].children
  475. }
  476. })
  477. }
  478. },
  479. }
  480. </script>
  481. <style scoped lang="scss">
  482. .navigation {
  483. width: 750rpx;
  484. height: 120rpx;
  485. border-bottom: 1px solid royalblue;
  486. display: flex;
  487. }
  488. .scrolls {
  489. white-space: nowrap; // 滚动必须加的属性
  490. width: 80%;
  491. height: 120rpx;
  492. line-height: 120rpx;
  493. background-color: #363535;
  494. }
  495. .nav_item {
  496. height: 120rpx;
  497. display: inline-block;
  498. text-align: center;
  499. line-height: 120rpx;
  500. margin-left: 20rpx;
  501. margin-right: 20rpx;
  502. font-size: 36rpx;
  503. color: #ffffff;
  504. background-color: #363535;
  505. &:focus {
  506. background-color: #474747;
  507. }
  508. }
  509. .list {
  510. width: 750rpx;
  511. }
  512. .list_data {
  513. width: 100%;
  514. height: 100rpx;
  515. position: relative;
  516. border-bottom: 1px solid #363535;
  517. text {
  518. font-size: 32rpx;
  519. position: absolute;
  520. top: 34rpx;
  521. left: 110rpx;
  522. }
  523. image {
  524. width: 70rpx;
  525. height: 70rpx;
  526. position: absolute;
  527. top: 15rpx;
  528. left: 20rpx;
  529. }
  530. button {
  531. display: flex;
  532. justify-content: center;
  533. align-items: center;
  534. width: 70rpx;
  535. height: 70rpx;
  536. position: absolute;
  537. top: 15rpx;
  538. font-size: 30rpx;
  539. }
  540. }
  541. .all {
  542. width: 750rpx;
  543. height: 100rpx;
  544. border-bottom: 1px solid #363535;
  545. position: relative;
  546. button {
  547. width: 140rpx;
  548. height: 80rpx;
  549. font-size: 30rpx;
  550. position: absolute;
  551. top: 10rpx;
  552. display: flex;
  553. justify-content: center;
  554. align-items: center;
  555. }
  556. }
  557. .openPopup {
  558. width: 600rpx;
  559. height: 700rpx;
  560. background-color: #ffffff;
  561. }
  562. .openText {
  563. width: 100%;
  564. height: 120rpx;
  565. font-size: 40rpx;
  566. font-weight: 550px;
  567. text-align: center;
  568. line-height: 120rpx;
  569. }
  570. .openTime {
  571. width: 500rpx;
  572. height: 70rpx;
  573. margin: 0 auto;
  574. text-align: center;
  575. font-size: 30rpx;
  576. }
  577. .brightness {
  578. width: 500rpx;
  579. height: 120rpx;
  580. margin: 60rpx auto;
  581. display: flex;
  582. flex-direction: column;
  583. text-align: center;
  584. font-size: 32rpx;
  585. }
  586. .remarks {
  587. width: 500rpx;
  588. height: 80rpx;
  589. margin: 60rpx auto;
  590. }
  591. .remarks input {
  592. width: 100%;
  593. height: 100%;
  594. border: 1px solid #eaeaea;
  595. font-size: 30rpx;
  596. }
  597. .send {
  598. width: 500rpx;
  599. height: 80rpx;
  600. margin: 60rpx auto;
  601. font-size: 30rpx;
  602. display: flex;
  603. }
  604. .lightDate {
  605. width: 100%;
  606. height: 100rpx;
  607. position: relative;
  608. border-bottom: 1px #d2cece solid;
  609. button {
  610. width: 200rpx;
  611. height: 80rpx;
  612. display: flex;
  613. justify-content: center;
  614. align-items: center;
  615. font-size: 36rpx;
  616. position: absolute;
  617. top: 10rpx;
  618. left: 20rpx;
  619. }
  620. }
  621. .lamp_data {
  622. width: 20%;
  623. height: 100%;
  624. button {
  625. width: 100%;
  626. height: 100%;
  627. border-radius: 0;
  628. display: flex;
  629. justify-content: center;
  630. align-items: center;
  631. font-size: 36rpx;
  632. }
  633. }
  634. .pagination {
  635. width: 750rpx;
  636. height: 80rpx;
  637. margin-top: 40rpx;
  638. }
  639. </style>