index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <div class="volumn-box" :class="isOpen ? 'active' : ''">
  3. <div class="top">
  4. <img
  5. :src="
  6. parseImgUrl('taiguv1/envmonitor', isOpen ? 'active/air-con.svg' : 'air-con.svg')
  7. "
  8. alt=""
  9. />
  10. <div class="top-right">
  11. <Switch
  12. @change="getAirStatus"
  13. class="switch-btn"
  14. inactive-color="rgba(0, 0, 0, 0.3)"
  15. v-model="isOpen"
  16. />
  17. </div>
  18. </div>
  19. <div class="bottom">
  20. <div class="air-info">
  21. <div class="left">
  22. <div class="text">空调</div>
  23. <div class="status">{{ isOpen ? "已开启" : "已关闭" }}</div>
  24. </div>
  25. <div class="temp" v-if="isOpen">
  26. {{ realTemp }}
  27. <sup>℃</sup>
  28. </div>
  29. </div>
  30. <!--温度⏭️-->
  31. <div class="temp-box" id="sliderAirId" v-if="isOpen">
  32. <div class="bar">
  33. <div class="text text-left active-text">{{ airData.minTempSet }}</div>
  34. <div class="active-bar" :style="{ width: barWidth + 'px' }" id="barAirId">
  35. <div class="hand-box" id="handAirId">
  36. <div class="line"></div>
  37. </div>
  38. </div>
  39. <div class="text text-right" :class="isWhite ? 'active-text' : ''">
  40. {{ airData.maxTempSet }}
  41. </div>
  42. </div>
  43. </div>
  44. <!--风量调整-->
  45. <div class="air-volume" v-if="isOpen">
  46. <div class="volume-left">
  47. <div class="volume-top">
  48. <span>1</span>
  49. <span>2</span>
  50. <span>3</span>
  51. <span class="span-active">4</span>
  52. </div>
  53. <div class="text">风量调节</div>
  54. </div>
  55. <div class="volume-right">
  56. <div class="control-item">
  57. <img class="icon" :src="parseImgUrl('taiguv1/envmonitor', 'minus.svg')" />
  58. </div>
  59. <div class="control-item">
  60. <img class="icon" :src="parseImgUrl('taiguv1/envmonitor', 'plus.svg')" />
  61. </div>
  62. <div class="control-item">A</div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </template>
  68. <script>
  69. import {
  70. defineComponent,
  71. onMounted,
  72. reactive,
  73. toRefs,
  74. computed,
  75. nextTick,
  76. watch,
  77. onUnmounted,
  78. onBeforeMount,
  79. onBeforeUnmount,
  80. } from "vue";
  81. import { Switch, Dialog, Loading, Toast } from "vant";
  82. import { parseImgUrl, fix } from "@/utils";
  83. import { swiper } from "@/utils/swiper";
  84. export default defineComponent({
  85. components: {
  86. Switch,
  87. [Dialog.Component.name]: Dialog.Component,
  88. Loading,
  89. },
  90. setup(props, contx) {
  91. const proxyData = reactive({
  92. parseImgUrl: parseImgUrl,
  93. isOpen: false,
  94. airData: {
  95. minTempSet: 16,
  96. maxTempSet: 32,
  97. airTemp: 0,
  98. },
  99. part: 1,
  100. realTemp: 24,
  101. isWhite: false,
  102. barWidth: 73,
  103. getAirStatus() {
  104. if (proxyData.isOpen) {
  105. nextTick(() => {
  106. proxyData.endBoxSwiper();
  107. });
  108. }
  109. contx.emit("getStatus", proxyData.isOpen);
  110. },
  111. getEleWidth(ele) {
  112. // debugger;
  113. if (ele) {
  114. return ele.getBoundingClientRect().width;
  115. } else {
  116. return 1;
  117. }
  118. },
  119. endBoxSwiper() {
  120. let sliderBox = document.querySelector("#sliderAirId");
  121. let handBox = document.querySelector("#handAirId");
  122. let barBox = document.querySelector("#barAirId");
  123. let isMove = false;
  124. let sliderWidth = proxyData.getEleWidth(sliderBox);
  125. let startBarWidth = proxyData.getEleWidth(barBox);
  126. if (sliderWidth > 1) {
  127. sliderWidth = sliderWidth;
  128. }
  129. let tempPart =
  130. (proxyData.airData.maxTempSet - proxyData.airData.minTempSet) /
  131. (sliderWidth - 30);
  132. let part = tempPart;
  133. proxyData.part = tempPart;
  134. if (!handBox) {
  135. return;
  136. }
  137. handBox.addEventListener("touchstart", function (e) {
  138. let oldBarWidth = (barBox && barBox.style && barBox.style.width) || 0;
  139. startBarWidth = isNaN(parseInt(oldBarWidth)) ? 0 : parseInt(oldBarWidth);
  140. isMove = true;
  141. });
  142. handBox.addEventListener("touchend", function (e) {
  143. isMove = false;
  144. });
  145. swiper(handBox, {
  146. swipeLeft: function (e) {
  147. if (isMove) {
  148. let moveRealX = Math.abs(e.mation.moveX - e.mation.startX);
  149. let barWidth = startBarWidth - moveRealX;
  150. barWidth = barWidth < 30 ? 30 : barWidth;
  151. if (barWidth >= sliderWidth) {
  152. proxyData.isWhite = true;
  153. } else {
  154. proxyData.isWhite = false;
  155. }
  156. barBox.style.width = barWidth + "px";
  157. let realTemp = proxyData.airData.minTempSet + barWidth * part;
  158. if (realTemp > proxyData.airData.maxTempSet) {
  159. realTemp = proxyData.airData.maxTempSet;
  160. }
  161. if (realTemp) {
  162. proxyData.realTemp = fix(realTemp.toFixed(1));
  163. }
  164. }
  165. },
  166. swipeRight: function (e) {
  167. if (isMove) {
  168. let moveRealX = Math.abs(e.mation.moveX - e.mation.startX);
  169. let barWidth = startBarWidth + moveRealX;
  170. barWidth = barWidth > sliderWidth ? sliderWidth : barWidth;
  171. if (barWidth >= sliderWidth) {
  172. proxyData.isWhite = true;
  173. } else {
  174. proxyData.isWhite = false;
  175. }
  176. barBox.style.width = barWidth + "px";
  177. let realTemp = barWidth * part + proxyData.airData.minTempSet;
  178. if (realTemp > proxyData.airData.maxTempSet) {
  179. realTemp = proxyData.airData.maxTempSet;
  180. }
  181. if (realTemp) {
  182. proxyData.realTemp = fix(realTemp.toFixed(1));
  183. }
  184. }
  185. },
  186. });
  187. },
  188. });
  189. onBeforeUnmount(() => {});
  190. onMounted(() => {});
  191. return {
  192. ...toRefs(proxyData),
  193. };
  194. },
  195. });
  196. </script>
  197. <style lang="scss" scoped>
  198. .volumn-box {
  199. box-sizing: border-box;
  200. display: flex;
  201. flex-direction: column;
  202. justify-content: space-between;
  203. padding: 16px;
  204. width: 100%;
  205. height: 100%;
  206. border-radius: 24px 24px 44px 24px;
  207. background-color: rgba(255, 255, 255, 0.2);
  208. backdrop-filter: blur(40px);
  209. box-shadow: 0px 10px 20px 0px rgba(0, 20, 40, 0.1);
  210. .top {
  211. display: flex;
  212. justify-content: space-between;
  213. img {
  214. width: 30px;
  215. }
  216. }
  217. .bottom {
  218. width: 100%;
  219. // margin-top: 18vh;
  220. // margin-top: 109px;
  221. .air-info {
  222. display: flex;
  223. justify-content: space-between;
  224. align-items: end;
  225. .temp {
  226. //styleName: En/H2;
  227. width: 80px;
  228. text-align: right;
  229. font-family: Jost;
  230. font-size: 20px;
  231. font-weight: 300;
  232. line-height: 28px;
  233. color: rgba(0, 20, 40, 1);
  234. sup {
  235. //styleName: En/Body XS;
  236. font-family: Jost;
  237. font-size: 11px;
  238. font-weight: 400;
  239. line-height: 15px;
  240. color: rgba(0, 20, 40, 1);
  241. }
  242. }
  243. }
  244. .text {
  245. //styleName: Chi/Body Large;
  246. font-family: PingFang SC;
  247. font-size: 16px;
  248. font-weight: 300;
  249. line-height: 22px;
  250. letter-spacing: 0.02em;
  251. text-align: left;
  252. text-underline-position: from-font;
  253. text-decoration-skip-ink: none;
  254. color: rgba(255, 255, 255, 1);
  255. padding-bottom: 2px;
  256. }
  257. .status {
  258. //styleName: Chi/Body XS;
  259. font-family: PingFang SC;
  260. font-size: 11px;
  261. font-weight: 400;
  262. line-height: 15px;
  263. letter-spacing: 0.02em;
  264. color: rgba(255, 255, 255, 0.4);
  265. }
  266. .temp-box {
  267. position: relative;
  268. box-sizing: border-box;
  269. width: 100%;
  270. padding: 2px;
  271. margin-top: 8px;
  272. height: 34px;
  273. border-radius: 12px;
  274. background: rgba(255, 255, 255, 0.6);
  275. .text {
  276. position: absolute;
  277. top: 50%;
  278. transform: translateY(-50%);
  279. font-family: Jost;
  280. font-size: 11px;
  281. font-weight: 400;
  282. line-height: 15px;
  283. color: rgba(116, 128, 141, 1);
  284. z-index: 2;
  285. }
  286. .text-left {
  287. left: 8px;
  288. }
  289. .text-right {
  290. right: 8px;
  291. }
  292. .active-text {
  293. color: rgba(255, 255, 255, 0.6);
  294. }
  295. .active-bar {
  296. position: absolute;
  297. background: linear-gradient(95.5deg, #99282b 21.44%, #a95459 84.95%);
  298. left: 2px;
  299. top: 50%;
  300. transform: translateY(-50%);
  301. z-index: 1;
  302. // width: 73px;
  303. // min-width: 18px;
  304. height: 30px;
  305. border-radius: 10px;
  306. .hand-box {
  307. padding-left: 6px;
  308. padding-right: 6px;
  309. position: absolute;
  310. top: 50%;
  311. transform: translateY(-50%);
  312. right: 0px;
  313. height: 100%;
  314. }
  315. .line {
  316. margin-top: 9px;
  317. height: 12px;
  318. width: 2px;
  319. background: rgba(255, 255, 255, 0.8);
  320. }
  321. }
  322. }
  323. }
  324. .switch-btn {
  325. margin-top: 0;
  326. width: 50px !important;
  327. height: 28px !important;
  328. border: none;
  329. }
  330. }
  331. .active {
  332. background: rgba(255, 255, 255, 0.8);
  333. backdrop-filter: blur(40px);
  334. box-shadow: 0px 10px 20px 0px rgba(0, 20, 40, 0.1);
  335. .bottom {
  336. .text {
  337. color: rgba(0, 20, 40, 1);
  338. }
  339. .status {
  340. color: rgba(116, 128, 141, 1);
  341. }
  342. }
  343. }
  344. .air-volume {
  345. display: flex;
  346. margin-top: 12px;
  347. .volume-left {
  348. width: 69px;
  349. .volume-top {
  350. padding-bottom: 2px;
  351. height: 3.33vh;
  352. line-height: 1;
  353. span {
  354. //styleName: En/Body Small;
  355. display: inline-block;
  356. margin-right: 5px;
  357. font-family: Jost;
  358. font-size: 12px;
  359. font-weight: 400;
  360. line-height: 17px;
  361. color: rgba(116, 128, 141, 1);
  362. }
  363. .span-active {
  364. color: rgba(0, 20, 40, 1);
  365. font-size: 16px;
  366. line-height: 22px;
  367. }
  368. }
  369. .text {
  370. //styleName: Chi/Body XS;
  371. font-family: PingFang SC;
  372. font-size: 11px;
  373. font-weight: 400;
  374. line-height: 15px;
  375. letter-spacing: 0.02em;
  376. color: rgba(0, 20, 40, 1);
  377. }
  378. }
  379. .volume-right {
  380. width: 120px;
  381. display: flex;
  382. justify-content: space-between;
  383. .control-item {
  384. width: 36px;
  385. height: 36px;
  386. background: rgba(255, 255, 255, 0.4);
  387. backdrop-filter: blur(60px);
  388. border-radius: 50%;
  389. text-align: center;
  390. .icon {
  391. width: 20px;
  392. height: 20px;
  393. margin-top: 8px;
  394. }
  395. &:nth-child(3) {
  396. font-family: Jost;
  397. font-size: 16px;
  398. font-weight: 300;
  399. line-height: 36px;
  400. text-align: center;
  401. color: rgba(0, 20, 40, 1);
  402. }
  403. }
  404. }
  405. }
  406. </style>
  407. <style lang="scss">
  408. .volumn-box {
  409. .van-switch__node {
  410. background: rgba(255, 255, 255, 0.6);
  411. width: 24px;
  412. height: 24px;
  413. top: 0.33vh;
  414. // top: 50%;
  415. // transform: translateY(-50%);
  416. }
  417. .van-switch--on.switch-btn {
  418. .van-switch__node {
  419. transform: translate(calc(50px - 28px)) !important;
  420. }
  421. }
  422. .van-switch--on {
  423. background: linear-gradient(95.5deg, #99282b 21.44%, #a95459 84.95%) !important;
  424. .van-switch__node {
  425. background: #fff !important;
  426. }
  427. }
  428. .van-loading__spinner {
  429. color: $elActiveColor !important;
  430. }
  431. .van-switch__loading {
  432. top: 0;
  433. left: 0;
  434. width: 100%;
  435. height: 100%;
  436. line-height: 1;
  437. }
  438. .van-switch--disabled {
  439. opacity: 0.5;
  440. }
  441. }
  442. </style>