index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <script setup lang="ts">
  2. import imageList from "@/data/home/index";
  3. import { useHome } from "@/store/Home/index";
  4. import Tabbar from "@/components/Tabbar.vue";
  5. import { baseURL } from "@/assets/data/Model";
  6. import { setActivePinia } from "pinia";
  7. const store = useHome();
  8. const animageList = ref([] as any);
  9. const getAssetURL = (image: string) => {
  10. return new URL(`../../assets/img/home/${image}`, import.meta.url).href;
  11. };
  12. const baseImageUrl = computed(() => {
  13. return baseURL + "/image/home/";
  14. });
  15. const images = ref([] as any);
  16. const imageOver = ref(false);
  17. const prestrainLoading = () => {
  18. const promises = [] as any;
  19. for (let i = 0; i < 45; i += 1) {
  20. new Promise((resolve: any) => {
  21. const image = new Image();
  22. image.src = `image/home/animation/${i}.png`;
  23. image.onload = () => {
  24. images[i] = image;
  25. resolve();
  26. };
  27. });
  28. }
  29. Promise.all(promises).then(() => {
  30. // console.log("加载完毕");
  31. imageOver.value = true;
  32. });
  33. };
  34. const viewTop = ref("");
  35. const viewLeft = ref("");
  36. const startY = ref();
  37. const startX = ref();
  38. const position = ref(-55);
  39. const transformLeft = ref(`translate3d(-230px, 0, 0)`);
  40. // 手指滑动
  41. const touchMove = (event: any) => {
  42. const dowmImage = document.getElementById("downImg");
  43. // console.log(dowmImage!.offsetWidth);
  44. const vw = window.innerWidth / 100;
  45. let moveEndX = event.changedTouches[0].pageX;
  46. let X = moveEndX - startX.value; //如果值为正,则代表手指右滑,反则则为左滑,为0则表示点击
  47. // console.log(X, position.value);
  48. if (X > 0) {
  49. if (position.value < 0) {
  50. position.value += 10;
  51. transformLeft.value = `translate3d(${position.value}px, 0, 0)`;
  52. }
  53. } else if (X < 0) {
  54. if (position.value > -(dowmImage!.offsetWidth - 60 * vw)) {
  55. position.value -= 10;
  56. transformLeft.value = `translate3d(${position.value}px, 0, 0)`;
  57. }
  58. }
  59. };
  60. // 开始滑动
  61. const handletouchstart = (event: any) => {
  62. startX.value = event.changedTouches[0].pageX;
  63. startY.value = event.changedTouches[0].pageY;
  64. };
  65. const downImageShow = ref(false);
  66. const upImageShow = ref(false);
  67. const textImageShow = ref(false);
  68. store.$subscribe((mutation: any, state: any) => {
  69. // // console.log("当前需要滚动滚动条", imageList, state.currentIndex);
  70. downImageShow.value = false;
  71. // position.value = imageList[state.currentIndex].left
  72. // transformLeft.value = `translate3d(${position.value}%, 0, 0)`;
  73. // // 实现滚动条居中
  74. // const downImage = document.querySelector("#downImg");
  75. // 加载底层图片
  76. var img = new Image();
  77. img.src = baseImageUrl.value + imageList[state.currentIndex].downCoverageURL;
  78. img.onload = () => {
  79. // 建筑图片加载完成后执行
  80. downImageShow.value = true;
  81. setTimeout(() => {
  82. const dowmImage = document.getElementById("downImg");
  83. // console.log(dowmImage!.offsetWidth);
  84. const imageavg = dowmImage!.offsetWidth / 2;
  85. const viewavg = window.innerWidth / 2;
  86. const vw = window.innerWidth / 100;
  87. // console.log(imageavg, viewavg, vw);
  88. position.value = Math.floor(-(imageavg + vw * 30 - viewavg));
  89. // position.value = Math.floor(-(dowmImage!.offsetWidth - window.innerWidth) / 2);
  90. // position.value = imageList[state.currentIndex].left
  91. transformLeft.value = `translate3d(${position.value}px, 0, 0)`;
  92. });
  93. };
  94. if (imageList[state.currentIndex].upCoverageURL != "img-up3.png") {
  95. // 加载上层图片
  96. var imgUp = new Image();
  97. imgUp.src =
  98. baseImageUrl.value + imageList[state.currentIndex].upCoverageURL;
  99. imgUp.onload = () => {
  100. // 上层图片加载完成后执行
  101. upImageShow.value = true;
  102. };
  103. } else {
  104. upImageShow.value = true;
  105. }
  106. // 加载文字层图片
  107. var imgText = new Image();
  108. imgText.src = baseImageUrl.value + `text.png`;
  109. imgText.onload = () => {
  110. // 上层图片加载完成后执行
  111. textImageShow.value = true;
  112. };
  113. // if (imageList[state.currentIndex].upCoverageURL == "img-up1.png") {
  114. // }
  115. });
  116. onMounted(() => {
  117. prestrainLoading();
  118. // 取出数据存到仓库(后期接口获取数据存到仓库)
  119. store.setBackgroundImages(imageList);
  120. store.setCurrentIndex(0);
  121. // animageList.value = import.meta.glob("/public/imgs/*.*", { eager: true });
  122. });
  123. </script>
  124. <template>
  125. <div class="home" id="homeid" v-if="imageOver">
  126. <img
  127. v-show="textImageShow"
  128. class="text-coverage"
  129. :src="baseImageUrl + `text.png`"
  130. alt=""
  131. />
  132. <!-- <img
  133. class="up-box"
  134. :src="store.currentIndex > 3 ? baseImageUrl + 'img-up1.png' : baseImageUrl + 'img-up2.png'"
  135. /> -->
  136. <div v-for="(item, index) in imageList" :key="index" class="home-item">
  137. <div
  138. id="animation"
  139. class="up-box"
  140. v-if="
  141. index === store.currentIndex && item.upCoverageURL == 'img-up3.png'
  142. "
  143. ></div>
  144. <img
  145. v-if="
  146. index === store.currentIndex && item.upCoverageURL != 'img-up3.png'
  147. "
  148. class="up-box2"
  149. :src="baseImageUrl + item.upCoverageURL"
  150. v-show="upImageShow"
  151. />
  152. <div
  153. :class="item.upCoverageURL == 'img-up1.png' ? 'down-boxs' : ''"
  154. @touchmove="touchMove"
  155. @touchstart="handletouchstart"
  156. v-show="downImageShow && upImageShow"
  157. >
  158. <img
  159. id="downImg"
  160. v-if="index === store.currentIndex"
  161. :class="
  162. item.upCoverageURL == 'img-up1.png' ? 'down-box2' : 'down-box'
  163. "
  164. :src="baseImageUrl + item.downCoverageURL"
  165. />
  166. </div>
  167. <!-- <transition name="fade">
  168. <img
  169. v-if="index === store.currentIndex"
  170. class="down-box"
  171. :src="getAssetURL(item.downCoverageURL)"
  172. />
  173. </transition> -->
  174. </div>
  175. </div>
  176. <Tabbar />
  177. </template>
  178. <style lang="scss" scoped>
  179. /* 设置滚动条宽度 */
  180. ::-webkit-scrollbar {
  181. width: 10px;
  182. }
  183. /* 设置滚动条轨道样式 */
  184. ::-webkit-scrollbar-track {
  185. background: #f1f1f1;
  186. }
  187. $imgCount: 44;
  188. .home {
  189. max-width: 100%;
  190. max-height: 100%;
  191. overflow: hidden;
  192. // text-align: center;
  193. // display: flex;
  194. // justify-content: center;
  195. .home-item {
  196. .up-box2 {
  197. width: 100vw;
  198. height: 100vh;
  199. height: calc(var(--vh, 1vh) * 100);
  200. object-fit: cover;
  201. position: fixed;
  202. z-index: 2;
  203. pointer-events: none;
  204. margin: auto;
  205. }
  206. .up-box {
  207. width: 100vw;
  208. height: 100vh;
  209. height: calc(var(--vh, 1vh) * 100);
  210. object-fit: cover;
  211. position: absolute;
  212. z-index: 2;
  213. background-size: 100vw calc(var(--vh, 1vh) * 100);
  214. background-position: 0 -1rem;
  215. animation: sequence 4s forwards;
  216. }
  217. @keyframes sequence {
  218. @for $i from 1 through $imgCount {
  219. #{calc($i * 100%/$imgCount)} {
  220. // background-image: v-bind('animageList');
  221. background-image: url(/image/home/animation/#{$i}.png);
  222. }
  223. }
  224. }
  225. // .down-box {
  226. // max-width: 100vw;
  227. // height: 100vh;
  228. // height: calc(var(--vh, 1vh) * 100);
  229. // object-fit: cover;
  230. // // position: absolute;
  231. // z-index: 1;
  232. // animation-name: fadenum;
  233. // animation-duration: 4s;
  234. // animation-fill-mode: forwards;
  235. // }
  236. .down-box {
  237. width: auto;
  238. height: 100vh;
  239. height: calc(var(--vh, 1vh) * 100);
  240. // object-fit: cover;
  241. // position: absolute;
  242. z-index: 1;
  243. animation-name: fadenum;
  244. animation-duration: 4s;
  245. animation-fill-mode: forwards;
  246. }
  247. .down-boxs {
  248. transform: v-bind(transformLeft);
  249. }
  250. .down-box2 {
  251. width: auto;
  252. height: 70vh;
  253. height: calc(var(--vh, 1vh) * 70 - 70px);
  254. margin-top: 30vh;
  255. margin-left: 30vw;
  256. margin-right: 30vw;
  257. // object-fit: cover;
  258. // position: absolute;
  259. z-index: 1;
  260. animation-name: fadenum;
  261. animation-duration: 4s;
  262. animation-fill-mode: forwards;
  263. // clip: rect(40px 40px 40px 40px)
  264. }
  265. @keyframes fadenum {
  266. from {
  267. transform: scale(1.05);
  268. /*放大1.1倍*/
  269. object-fit: cover;
  270. opacity: 0.5;
  271. }
  272. to {
  273. transform: scale(1.17);
  274. /*放大1.1倍*/
  275. object-fit: cover;
  276. opacity: 1;
  277. }
  278. }
  279. @keyframes fadenumOut {
  280. from {
  281. transform: scale(1.05);
  282. /*放大1.1倍*/
  283. object-fit: cover;
  284. opacity: 1;
  285. }
  286. to {
  287. transform: scale(1.17);
  288. /*放大1.1倍*/
  289. object-fit: cover;
  290. opacity: 0.5;
  291. }
  292. }
  293. }
  294. .text-coverage {
  295. width: 75%;
  296. position: absolute;
  297. left: 50%;
  298. top: 10%;
  299. transform: translateX(-50%);
  300. z-index: 3;
  301. }
  302. }
  303. </style>