index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template >
  2. <div class="scrollbar">
  3. <div class="swiper">
  4. <div class="swiper-wrapper">
  5. <swiper-container autoplay-delay="2000" loop="true" css-mode="true" navigation="true" pagination="true" scrollbar="true">
  6. <swiper-slide style="cursor: pointer" class="banner " v-for="(item,index) in sliders " :key="index" @click="goToBlog(item.linkToBlog)" >
  7. <p class="title">{{ item.title }}</p>
  8. <p class="info">{{ item.subTitle }}</p>
  9. <v-lazy-image :src="item.imageUrl" alt="" />
  10. </swiper-slide>
  11. </swiper-container>
  12. </div>
  13. </div>
  14. <section class="wrapper mt-84">
  15. <div class="item-title pd-20 flex-between">
  16. <p>Destinations</p>
  17. <p class="more-destinations flex-between" @click="goPage('/destination')">More destinations
  18. <el-icon>
  19. <ArrowRight/>
  20. </el-icon>
  21. </p>
  22. </div>
  23. <p class="bat pd-20">Places to go in China!</p>
  24. <div class="wrapper-img flex-between mt-38">
  25. <!-- <x-hover-item class="wrapper-item" v-for="i in 6"/> -->
  26. <div v-for="item in randDestinations" :key="item.destinationId" class="item radius wrapper-item" @mouseenter="hoverFlag = true"
  27. @mouseleave="hoverFlag = false">
  28. <v-lazy-image class="destination-profile" @click="goPage('/destination-detail/'+item.destinationId)" :src="normalizeMultiImageUrl(item.destinationProfileImage)" alt="" />
  29. <div class="notice" :class="{ open: hoverFlag }">
  30. <slot>
  31. <p>{{item.destinationName}}</p>
  32. <span class="parent-info">{{item.parentDestinationName}}</span>
  33. </slot>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="pd-20">
  38. <button class="help">Want a Tailor Made Trip to China? Click Here for help</button>
  39. </div>
  40. <div class="banner-center pd-20 mt-20">
  41. <div class="title">
  42. <p>Editor's Choice</p>
  43. <p class="info">What's New this Week?</p>
  44. </div>
  45. <v-lazy-image style="cursor: pointer;" @click="goToBlog(homePostLink)" :src="homePostImageUrl" alt="" />
  46. </div>
  47. <div class="item-title pd-20 flex-between mt-36">
  48. <p>People are traveling</p>
  49. </div>
  50. <p class="bat pd-20">What's in China</p>
  51. </section>
  52. <div class="float pd-20 mt-28" v-loading="loading">
  53. <div v-for="(item, index) in globalUnifiedItemList" v-bind:key="index">
  54. <div v-if="item.type === 'video'" class="video-content">
  55. <video src="http://mp42.china.com.cn/video_tide/video/2023/3/13/20233131678679710349_367_2.mp4" controls></video>
  56. <p class="video-info">From Blog Title My 30 days of Going to Tibet</p>
  57. </div>
  58. <blog-item class="product-item" :blog="item.value" v-if="item.type==='blog'" float/>
  59. <other-product-item :productSummary="item.value" :showIcon="true" class="other-item" v-if="item.type === 'product'" float/>
  60. <special-product-item class="scale-item" :special="item.value" v-if="item.type==='scaleblog'" float/>
  61. </div>
  62. </div>
  63. <!-- <div style="width: 100%;">
  64. <el-button type="primary" plain class="get-more mt-100" @click="loadMore" style="cursor: pointer;">Click to load more</el-button>
  65. </div> -->
  66. </div>
  67. </template>
  68. <script setup>
  69. import VLazyImage from "v-lazy-image";
  70. import BlogItem from '../home/components/BlogItem'
  71. import {AXIOS} from '@/common/http-commons'
  72. import ProductItem from './components/ProductItem'
  73. import XHoverItem from '@/components/XHoverItem'
  74. import OtherProductItem from './components/OtherProductItem'
  75. import SpecialProductItem from './components/SpecialProductItem'
  76. import { useRouter } from 'vue-router';
  77. import { debounce } from 'lodash';
  78. const sliders = ref([])
  79. const randDestinations = ref([])
  80. const activeIndex = ref(1)
  81. const imgPopupShowFlag = ref([false, false, false, false, false, false])
  82. const router = useRouter()
  83. const currentPage = ref(1)
  84. const loading= ref(false)
  85. const blogPageSizePage = ref(30)
  86. const productPageSizePage = ref(5)
  87. const bloglist =ref([])
  88. const productlist = ref([])
  89. const totalBlogCount=ref(-1)
  90. const globalUnifiedItemList = ref([])
  91. const unifiedItemList = ref([])
  92. const homePostLink = ref("")
  93. const homePostImageUrl = ref("")
  94. function loadMore(){
  95. currentPage.value+=1
  96. var maxPage = totalBlogCount.value/blogPageSizePage.value
  97. if(currentPage.value<=maxPage+1){
  98. loadBlogList()
  99. }
  100. }
  101. function normalizeMultiImageUrl(input){
  102. if(input.indexOf(',')>-1){
  103. return input.split(',').shift();
  104. }else if(input.indexOf(';')>-1){
  105. return input.split(';').shift();
  106. }
  107. return input;
  108. }
  109. function loadBlogList(){
  110. loading.value = true;
  111. unifiedItemList.value=[]
  112. var params = {}
  113. params.pageSize = blogPageSizePage.value;
  114. params.query="";
  115. console.log("loading page: "+currentPage.value)
  116. params.page = currentPage.value;
  117. AXIOS.get("/api/public/blog/list", {params: params}).then(function (response) {
  118. if(totalBlogCount.value==-1){
  119. totalBlogCount.value = response.data.data.total
  120. }
  121. bloglist.value = response.data.data.data
  122. for(var index in bloglist.value){
  123. var obj = {}
  124. // obj.type=parseInt(Math.random() * 2)==0?'blog':'scaleblog';
  125. obj.type='blog';
  126. obj.value = bloglist.value[index]
  127. unifiedItemList.value.push(obj)
  128. }
  129. loadProducts();
  130. })
  131. .catch(function (error) {
  132. console.log(error);
  133. });
  134. }
  135. function shuffleArray(anyarr){
  136. if(anyarr==null || anyarr.length<=1){
  137. return
  138. }else{
  139. for (let i = 0; i < 20; i++) {
  140. var left = parseInt(Math.random() * anyarr.length )
  141. var right = parseInt(Math.random() * anyarr.length )
  142. var tmp = anyarr[left]
  143. anyarr[left]=anyarr[right]
  144. anyarr[right]=tmp
  145. }
  146. }
  147. }
  148. function loadProducts(){
  149. var params = {}
  150. params.pageSize = productPageSizePage.value;
  151. params.query="";
  152. params.page = currentPage.value;
  153. params.productTypeId=""
  154. AXIOS.get("/api/public/productsku/productskugrouplist", {params: params}).then(function (response) {
  155. // console.log("product list:")
  156. // console.log(response.data)
  157. productlist.value = response.data.data.data
  158. for(var index in productlist.value){
  159. var obj = {}
  160. obj.type='product';
  161. obj.value = productlist.value[index]
  162. unifiedItemList.value.push(obj)
  163. }
  164. // console.log("unifiedItemList.value")
  165. // console.log(unifiedItemList.value)
  166. // shuffleArray(unifiedItemList.value)
  167. globalUnifiedItemList.value=globalUnifiedItemList.value.concat(unifiedItemList.value)
  168. // console.log("globalUnifiedItemList.value")
  169. // console.log(globalUnifiedItemList.value)
  170. loading.value = false;
  171. })
  172. .catch(function (error) {
  173. console.log(error);
  174. });
  175. }
  176. function goPage(val){
  177. router.push({ path: val })
  178. }
  179. function loadHomeSliders(){
  180. AXIOS.get('/api/public/pagecontent/homesliders').then(response=>{
  181. sliders.value = response.data.data
  182. loadBlogList()
  183. }).catch(e=>{
  184. console.log(e)
  185. })
  186. }
  187. function loadHomePost(){
  188. AXIOS.get('/api/public/pagecontent/homepost').then(response=>{
  189. console.log("loaded home post: ")
  190. console.log(response.data.data)
  191. homePostLink.value = response.data.data.postLink;
  192. homePostImageUrl.value = response.data.data.postImageUrl;
  193. }).catch(e=>{
  194. console.log(e)
  195. })
  196. }
  197. function loadRand6Destinations(){
  198. AXIOS.get('/api/public/destination/rand6').then(response=>{
  199. randDestinations.value = response.data.data
  200. }).catch(e=>{
  201. alert(e)
  202. })
  203. }
  204. onMounted(() => {
  205. // load slider
  206. loadHomeSliders()
  207. loadHomePost()
  208. // load destination
  209. loadRand6Destinations()
  210. getNextBatch()
  211. })
  212. const hoverFlag = ref(false)
  213. const arr = getRandomArr()
  214. function getRandomArr() {
  215. // 这是你xiaopiu上的默认布局,下面的20个是随机生成
  216. const arr = [0, 1, 1, 3, 2, 2, 2, 2, 2, 2]
  217. for (let i = 0; i < 20; i++) {
  218. arr.push(parseInt(Math.random() * 4 ))
  219. }
  220. return arr
  221. }
  222. function goToBlog(url){
  223. window.location.href = url
  224. }
  225. function getNextBatch() {
  226. window.onscroll = debounce(function() {
  227. let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight + 100 > document.documentElement.scrollHeight;
  228. if(bottomOfWindow){
  229. loadMore()
  230. }
  231. }, 500)
  232. // window.onscroll = () => {
  233. // let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight > document.documentElement.scrollHeight;
  234. // if(bottomOfWindow){
  235. // loadMore()
  236. // }
  237. // }
  238. }
  239. </script>
  240. <style scoped lang="scss">
  241. .scrollbar{
  242. overflow: scroll;
  243. }
  244. .float {
  245. max-width: $min-width;
  246. margin: 0 auto;
  247. overflow: hidden;
  248. &::after {
  249. height: 0;
  250. content: '';
  251. display: block;
  252. clear: both;
  253. }
  254. }
  255. .banner {
  256. position: relative;
  257. height: 547px;
  258. overflow: hidden;
  259. .title {
  260. position: absolute;
  261. left: 107px;
  262. top: 175px;
  263. color: rgba(255, 255, 255, 1);
  264. font-size: 111px;
  265. line-height: 150%;
  266. text-align: left;
  267. }
  268. .info {
  269. position: absolute;
  270. width: 498px;
  271. height: 63px;
  272. left: 112px;
  273. top: 342px;
  274. color: rgba(255, 255, 255, 1);
  275. font-size: 21px;
  276. line-height: 150%;
  277. text-align: left;
  278. }
  279. img {
  280. width: 100%;
  281. height: auto;
  282. max-height: 547px;
  283. }
  284. }
  285. .bat {
  286. color: rgba(80, 80, 80, 1);
  287. font-size: 48px;
  288. line-height: 150%;
  289. }
  290. .wrapper-img {
  291. .wrapper-item {
  292. width: 208px;
  293. height: 276px;
  294. }
  295. }
  296. .help {
  297. margin-top: 73px;
  298. width: 100%;
  299. height: 78px;
  300. left: 260px;
  301. top: 293px;
  302. text-indent: 31px;
  303. color: rgba(255, 255, 255, 1);
  304. background-color: rgba(42, 130, 228, 1);
  305. border-radius: 14px;
  306. font-size: 22px;
  307. line-height: 150%;
  308. text-align: center;
  309. font-weight: bold;
  310. }
  311. .video {
  312. float: left;
  313. margin-bottom: 20px;
  314. width: 997px;
  315. height: 595px;
  316. }
  317. .banner-center {
  318. position: relative;
  319. height: 192px;
  320. img {
  321. width: 100%;
  322. height: 100%;
  323. }
  324. .title {
  325. position: absolute;
  326. top: 29px;
  327. left: 55px;
  328. color: rgba(255, 255, 255, 1);
  329. font-size: 66px;
  330. font-weight: bold;
  331. }
  332. .info {
  333. color: rgba(255, 255, 255, 1);
  334. font-size: 24px;
  335. font-weight: 400;
  336. }
  337. }
  338. .list {
  339. flex-wrap: wrap;
  340. .product {
  341. margin-right: 25px;
  342. }
  343. }
  344. .get-more {
  345. margin: 0 auto;
  346. color: rgba(80, 80, 80, 1);
  347. font-size: 14px;
  348. width: 100%;
  349. text-align: center;
  350. }
  351. .item {
  352. position: relative;
  353. width: 244px;
  354. height: 324px;
  355. overflow: hidden;
  356. &.radius {
  357. border-radius: 10px;
  358. }
  359. }
  360. .notice {
  361. position: absolute;
  362. width: 100%;
  363. height: 74px;
  364. padding: 17px 14px 7px;
  365. left: 0;
  366. bottom: -74px;
  367. color: white;
  368. background-color: rgba(153, 153, 153, .51);
  369. border-radius: 2px;
  370. font-size: 23px;
  371. transition: .3s;
  372. line-height: 23px;
  373. &.open {
  374. bottom: 0;
  375. }
  376. }
  377. .parent-info {
  378. color: rgba(255, 235, 235, 1);
  379. font-size: 13px;
  380. }
  381. .destination-profile {
  382. cursor: pointer;
  383. width: 100%;
  384. height: 100%;
  385. box-shadow: 0px 7px 7px 0px rgba(0, 0, 0, 0.5);
  386. object-fit: cover;
  387. }
  388. .more-destinations{
  389. cursor: pointer;
  390. color: rgba(42, 130, 228, 1);
  391. font-size: 14px;
  392. line-height: 150%;
  393. }
  394. </style>