CurtainMore.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <div class="more-box">
  3. <div class="light-more-top">
  4. <div class="left">
  5. <div class="light-box">
  6. <img
  7. :src="curtainIcon"
  8. alt=""
  9. />
  10. </div>
  11. </div>
  12. <div class="right">
  13. <div
  14. class="control_all"
  15. :class="topActive ? 'active' : ''"
  16. @click="handle('all',1,'开启中','EquipOnSet')"
  17. >{{ $t(`common.全开`) }}</div>
  18. <div
  19. class="control_all"
  20. :class="downActive ? 'active' : ''"
  21. @click="handle('all',0,'关闭中','EquipOffSet')"
  22. >{{ $t(`common.全关`) }}</div>
  23. </div>
  24. </div>
  25. <div class="control_status">{{ controlStatus ? $t(`curtains.${controlStatus}`) : '' }}</div>
  26. <div class="light-bottom">
  27. <div
  28. class="item-box"
  29. v-for="(item, index) in childCurtains"
  30. :key="item.id"
  31. >
  32. <div class="name">{{ item.localName }}</div>
  33. <div class="control-box">
  34. <div
  35. class="control"
  36. @click="handle('child',1,'开启中','EquipOnSet',item.id)"
  37. >
  38. <img :src="item.isActive && item.activeButton === 1 ? UpActiveIcon : UpUnActiveIcon" alt="">
  39. </div>
  40. <div
  41. class="control"
  42. @click="handle('child',2,'暂停中','StopSet',item.id)"
  43. >
  44. <img :src="item.isActive && item.activeButton === 2 ? StopActiveIcon : StopUnActiveIcon" alt="">
  45. </div>
  46. <div
  47. class="control"
  48. @click="handle('child',0,'关闭中','EquipOffSet',item.id)"
  49. >
  50. <img :src="item.isActive && item.activeButton === 0 ? DownActiveIcon : DownUnActiveIcon" alt="">
  51. </div>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </template>
  57. <script setup>
  58. import { httpSetEnv } from '@/apis/taiguv1';
  59. import curtainIcon from '@/assets/taiguv1/svg/Curtain_card_active_icon.svg';
  60. import DownActiveIcon from '@/assets/taiguv1/svg/down_active_icon.svg';
  61. import DownUnActiveIcon from '@/assets/taiguv1/svg/down_icon.svg';
  62. import StopActiveIcon from '@/assets/taiguv1/svg/stop_active_icon.svg';
  63. import StopUnActiveIcon from '@/assets/taiguv1/svg/stop_icon.svg';
  64. import UpActiveIcon from '@/assets/taiguv1/svg/up_active_icon.svg';
  65. import UpUnActiveIcon from '@/assets/taiguv1/svg/up_icon.svg';
  66. import { ref, watch } from "vue";
  67. const props = defineProps({
  68. currentCurtains: {
  69. type: Array,
  70. default: () => []
  71. }
  72. })
  73. const childCurtains = ref([])
  74. const controlStatus = ref('')
  75. const topActive = ref(false)
  76. const downActive = ref(false)
  77. let timer = null // 添加timer变量
  78. let btnTimer = null;
  79. const setEnnv = (type,value,code,curentID )=>{
  80. const paramsData = []
  81. if (type === 'all') {
  82. childCurtains.value.forEach((item) => {
  83. paramsData.push({
  84. id:item.id,
  85. value,
  86. code
  87. })
  88. })
  89. }else{
  90. let paramsObj = {
  91. id:curentID,
  92. value,
  93. code
  94. }
  95. paramsData.push(paramsObj)
  96. }
  97. httpSetEnv(paramsData)
  98. }
  99. const handle = (type, status, name,code, curentID) => {
  100. controlStatus.value = name;
  101. // 清除之前的定时器
  102. if (timer) {
  103. clearTimeout(timer);
  104. }
  105. if (btnTimer) {
  106. clearTimeout(btnTimer);
  107. }
  108. // 设置新的定时器并保存引用
  109. timer = setTimeout(() => {
  110. controlStatus.value = '';
  111. }, 3000);
  112. if (type === 'all') {
  113. if (status === 1) {
  114. topActive.value = true;
  115. } else {
  116. downActive.value = true;
  117. }
  118. btnTimer = setTimeout(() => {
  119. topActive.value = false;
  120. downActive.value = false;
  121. }, 100);
  122. setEnnv(type,status,code )
  123. } else {
  124. setEnnv(type,status,code,curentID)
  125. childCurtains.value.forEach((item) => {
  126. if (item.id === curentID) {
  127. item.activeButton = status;
  128. item.isActive = true;
  129. } else {
  130. item.isActive = false;
  131. item.activeButton = null;
  132. }
  133. })
  134. btnTimer = setTimeout(() => {
  135. childCurtains.value.forEach(item => {
  136. item.isActive = false;
  137. item.activeButton = null;
  138. });
  139. }, 1000);
  140. }
  141. };
  142. watch(
  143. ()=>props.currentCurtains,
  144. (newVal) => {
  145. childCurtains.value = JSON.parse(JSON.stringify(newVal));
  146. childCurtains.value.forEach(item=>{
  147. item.isActive = false
  148. item.activeButton = null
  149. })
  150. },
  151. { immediate: true }
  152. )
  153. </script>
  154. <style lang="scss" scoped>
  155. .more-box {
  156. .light-more-top {
  157. display: flex;
  158. align-items: center;
  159. .left {
  160. margin-right: 36px;
  161. .light-box {
  162. width: 110px;
  163. height: 110px;
  164. background: rgba(255, 255, 255, 0.4);
  165. border-radius: 50%;
  166. text-align: center;
  167. margin-right: 27px;
  168. img {
  169. width: 36px;
  170. height: 36px;
  171. margin: 0 auto;
  172. margin-top: 37px;
  173. }
  174. }
  175. }
  176. .right {
  177. height: 92px;
  178. display: flex;
  179. flex-direction: column;
  180. justify-content: space-between;
  181. .control_all {
  182. display: flex;
  183. width: 100px;
  184. height: 40px;
  185. padding: 8px 12px;
  186. justify-content: center;
  187. align-items: center;
  188. gap: 12px;
  189. border-radius: 50px;
  190. background: #e1e1df;
  191. box-shadow: 0px 10px 20px 0px rgba(0, 0, 0, 0.05);
  192. color: #001428;
  193. text-align: center;
  194. font-family: "PingFang SC";
  195. font-size: 14px;
  196. font-style: normal;
  197. font-weight: 400;
  198. line-height: 18px; /* 128.571% */
  199. letter-spacing: 0.56px;
  200. }
  201. .control_all.active {
  202. background: rgba(255, 255, 255, 1);
  203. box-shadow: 0px 10px 20px 0px rgba(0, 20, 40, 0.1);
  204. }
  205. }
  206. }
  207. .control_status {
  208. margin-top: 12px;
  209. width: 110px;
  210. height: 22px;
  211. color: var(--Blue, #001428);
  212. text-align: center;
  213. /* Chi/Body Large */
  214. font-family: "PingFang SC";
  215. font-size: 16px;
  216. font-style: normal;
  217. font-weight: 300;
  218. line-height: normal;
  219. letter-spacing: 0.32px;
  220. }
  221. .light-bottom {
  222. margin-top: 36px;
  223. .item-box {
  224. display: flex;
  225. width: 300px;
  226. height: 84px;
  227. padding: 20px 23px 24px 24px;
  228. justify-content: space-between;
  229. align-items: center;
  230. /* card shadow */
  231. box-shadow: 0px 10px 20px 0px rgba(0, 20, 40, 0.05);
  232. border-radius: 24px 24px 44px 24px;
  233. background: rgba(255, 255, 255, 0.2);
  234. margin-bottom: 12px;
  235. .name {
  236. //styleName: Chi/Body Regular;
  237. color: var(--Blue, #001428);
  238. font-family: "PingFang SC";
  239. font-size: 14px;
  240. font-style: normal;
  241. font-weight: 400;
  242. line-height: normal;
  243. letter-spacing: 0.28px;
  244. }
  245. .control-box {
  246. display: flex;
  247. justify-content: space-between;
  248. align-items: center;
  249. .control {
  250. display: flex;
  251. width: 36px;
  252. height: 36px;
  253. justify-content: center;
  254. align-items: center;
  255. margin-left: 10px;
  256. // img{
  257. // width: 17px;
  258. // height: 17px;
  259. // }
  260. }
  261. }
  262. }
  263. .light-box-active {
  264. background: rgba(255, 255, 255, 0.6);
  265. }
  266. }
  267. }
  268. </style>
  269. <