index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="volumn-box" :class="lampData.isOpen ? 'active' : ''">
  3. <div>
  4. <div class="top">
  5. <img :src="parseImgUrl('taiguv1/envmonitor', lampData.isOpen ? 'active/lamp.svg' : 'lamp.svg')" alt="" />
  6. <div class="top-right">
  7. <SwitchButton
  8. :loading="allLampStatus.all?.loading"
  9. @click.stop
  10. v-model="lampData.isOpen"
  11. @change="setLampStatus('isOpen')" />
  12. </div>
  13. </div>
  14. <div class="filter-box">
  15. <div class="filter-item" @click="searchMore">
  16. <img :src="FilterIcon" alt="" />
  17. </div>
  18. </div>
  19. </div>
  20. <div class="bottom">
  21. <div class="bottom-box">
  22. <div class="bottom-left">
  23. <div class="text">光照</div>
  24. <div class="status">{{ lampData.lampStatusText }}</div>
  25. </div>
  26. <div class="bottom-right" v-if="lampData.isOpen">
  27. {{ lampData.brightValue }}
  28. </div>
  29. </div>
  30. <div class="lamp-slider" v-if="lampData.isOpen">
  31. <Slider v-model="lampData.brightValue" :min="min" :max="max" @onEnd="setLampStatus('bright')"></Slider>
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. <script setup>
  37. import FilterIcon from '@/assets/taiguv1/svg/filter_icon.svg'
  38. import Slider from '@/components/slider/Slider.vue'
  39. import SwitchButton from '@/components/switch-button/SwitchButton.vue'
  40. import { parseImgUrl } from '@/utils'
  41. import { ref, watch, computed } from 'vue'
  42. import { useStore } from '@/store'
  43. import useDeviceControl from '@/hooks/useDeviceControl'
  44. const min = 0
  45. const max = 100
  46. const emit = defineEmits(['getStatus', 'showMore'])
  47. // 接收父组件传递的开关状态
  48. const props = defineProps({
  49. lampStatus: {
  50. type: Object,
  51. default: () => {
  52. return {
  53. isOpen: false,
  54. brightValue: 0
  55. }
  56. }
  57. },
  58. equipList: {
  59. type: Array,
  60. default: () => {
  61. return []
  62. }
  63. }
  64. })
  65. const store = useStore()
  66. const deviceControl = useDeviceControl()
  67. const allLampStatus = computed(() => store.state.taiguv1.lampSwitchStatus)
  68. const searchMore = () => {
  69. emit('showMore', 'lamp', true)
  70. }
  71. const lampData = ref({
  72. isOpen: false,
  73. brightValue: 0
  74. })
  75. watch(
  76. () => props.lampStatus,
  77. (newVal, oldVal) => {
  78. if (!newVal) {
  79. return
  80. }
  81. console.log('props.lampStaus')
  82. compareStatus(newVal)
  83. },
  84. { deep: true } // 添加深度监听
  85. )
  86. const compareStatus = data => {
  87. if (allLampStatus.value.all) {
  88. if (allLampStatus.value.all.lastSwitchStatus == data.isOpen) {
  89. store.dispatch('taiguv1/setLampStatus', {
  90. id: 'all',
  91. status: {
  92. loading: false,
  93. lastSwitchStatus: data.isOpen
  94. }
  95. })
  96. lampData.value = {
  97. ...data,
  98. isOpen: data.isOpen
  99. }
  100. } else {
  101. lampData.value = {
  102. ...data,
  103. isOpen: allLampStatus.value.all.lastSwitchStatus
  104. }
  105. }
  106. } else {
  107. lampData.value = {
  108. ...data,
  109. isOpen: data.isOpen
  110. }
  111. }
  112. emit('getStatus', lampData.value.isOpen)
  113. }
  114. const setLampStatus = type => {
  115. if (type == 'isOpen') {
  116. store.dispatch('taiguv1/setLampStatus', {
  117. id: 'all',
  118. status: {
  119. loading: true,
  120. lastSwitchStatus: lampData.value.isOpen
  121. }
  122. })
  123. }
  124. const params = deviceControl.assemblyLampCommand(lampData.value[type], type, props.equipList)
  125. deviceControl.sendCommands(params)
  126. emit('getStatus', lampData.value.isOpen)
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .volumn-box {
  131. box-sizing: border-box;
  132. display: flex;
  133. flex-direction: column;
  134. justify-content: space-between;
  135. padding: 16px;
  136. width: 100%;
  137. height: 100%;
  138. border-radius: 24px 24px 44px 24px;
  139. background-color: rgba(255, 255, 255, 0.2);
  140. backdrop-filter: blur(40px);
  141. box-shadow: 0px 10px 20px 0px rgba(0, 20, 40, 0.1);
  142. .top {
  143. display: flex;
  144. justify-content: space-between;
  145. align-items: center;
  146. img {
  147. width: 30px;
  148. height: 30px;
  149. }
  150. }
  151. .filter-box {
  152. margin-top: 10px;
  153. display: flex;
  154. justify-content: flex-end;
  155. gap: 10px;
  156. .filter-item {
  157. display: flex;
  158. width: 36px;
  159. height: 36px;
  160. justify-content: center;
  161. align-items: center;
  162. gap: 10px;
  163. flex-shrink: 0;
  164. border-radius: 60px;
  165. background: var(--White-White-40, rgba(255, 255, 255, 0.4));
  166. }
  167. }
  168. .bottom {
  169. .bottom-box {
  170. flex: 1;
  171. display: flex;
  172. justify-content: space-between;
  173. }
  174. .text {
  175. width: 100%;
  176. //styleName: Chi/Body Large;
  177. font-family: PingFang SC;
  178. font-size: 16px;
  179. font-weight: 300;
  180. line-height: 22px;
  181. letter-spacing: 0.02em;
  182. text-align: left;
  183. text-underline-position: from-font;
  184. text-decoration-skip-ink: none;
  185. color: rgba(255, 255, 255, 1);
  186. padding-bottom: 2px;
  187. }
  188. .status {
  189. width: 100%;
  190. //styleName: Chi/Body XS;
  191. font-family: PingFang SC;
  192. font-size: 11px;
  193. font-weight: 400;
  194. line-height: 14px;
  195. letter-spacing: 0.02em;
  196. color: rgba(255, 255, 255, 0.4);
  197. }
  198. .bottom-right {
  199. text-align: center;
  200. font-size: 20px;
  201. width: 50px;
  202. height: 30px;
  203. // color: var(--Blue, #001428);
  204. align-self: end;
  205. line-height: 100%;
  206. display: flex;
  207. align-items: center;
  208. justify-content: end;
  209. }
  210. .lamp-slider {
  211. margin-top: 8px;
  212. background: rgba(255, 255, 255, 0.6);
  213. width: 100%;
  214. height: 34px;
  215. border-radius: 12px;
  216. }
  217. }
  218. // .switch-btn {
  219. // // margin-top: 0;
  220. // // width: 50px !important;
  221. // // height: 28px !important;
  222. // // border: none;
  223. // }
  224. }
  225. .active {
  226. background: rgba(255, 255, 255, 0.8);
  227. backdrop-filter: blur(40px);
  228. box-shadow: 0px 10px 20px 0px rgba(0, 20, 40, 0.1);
  229. .bottom {
  230. .text {
  231. color: rgba(0, 20, 40, 1);
  232. }
  233. .status {
  234. color: rgba(116, 128, 141, 1);
  235. }
  236. .bottom-right {
  237. font-family: Jost;
  238. color: rgba(0, 20, 40, 1);
  239. }
  240. }
  241. }
  242. </style>