RelicListMobile.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <template>
  2. <div class="relic-list">
  3. <button
  4. class="return"
  5. @click="() => fakeBack({
  6. hideIntroVideo: 1
  7. })"
  8. />
  9. <el-cascader
  10. v-model="cascaderValue"
  11. popper-class="relic-cascader"
  12. :options="cameraTree"
  13. :show-all-levels="false"
  14. :props="{
  15. expandTrigger: 'hover',
  16. }"
  17. />
  18. <div class="search-ui">
  19. <input
  20. v-model.trim="keyword"
  21. type="text"
  22. placeholder="请输入要搜索内容"
  23. @keydown.enter="onSearch"
  24. >
  25. <button
  26. class="search"
  27. />
  28. </div>
  29. <div
  30. class="the-list"
  31. :class="{
  32. scene1: cascaderValue[0] === '0',
  33. scene2: cascaderValue[0] === '1',
  34. scene3: cascaderValue[0] === '2',
  35. }"
  36. >
  37. <div
  38. ref="listEl"
  39. class="content-wrap"
  40. @scroll="handleScroll"
  41. >
  42. <div
  43. class="first-item"
  44. :class="{
  45. scene1: cascaderValue[0] === '0',
  46. scene2: cascaderValue[0] === '1',
  47. scene3: cascaderValue[0] === '2',
  48. }"
  49. />
  50. <div
  51. v-for="(item, idx) in relicData"
  52. :key="idx"
  53. class="relic-item"
  54. :class="{
  55. isScene1: item.sceneIdx === 0,
  56. isScene2: item.sceneIdx === 1,
  57. isScene3: item.sceneIdx === 2,
  58. isOdd: (idx) % 2 === 0,
  59. isEven: (idx) % 2 === 1,
  60. }"
  61. @click="onClickItem(item.idx)"
  62. >
  63. <span
  64. class="name"
  65. :class="{
  66. wide: item['名称'].length > 9,
  67. smallFontSize: item['名称'].length > 17,
  68. }"
  69. :title="item['名称']"
  70. v-html="item['名称']"
  71. />
  72. <img
  73. class=""
  74. :src="getRelicThumbUrl(idx)"
  75. alt=""
  76. draggable="false"
  77. >
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. <div :style="{height: `${clientHeight}px`}" />
  83. </template>
  84. <script setup>
  85. /**
  86. * todo: 自动恢复上次滚动位置
  87. */
  88. import { ref, computed, watch, onMounted, nextTick, inject } from "vue"
  89. import { useRoute, useRouter } from "vue-router"
  90. import { useStore } from "vuex"
  91. import useSmoothSwipe from '@/useFunctions/useSmoothSwipe.js'
  92. import { useElementSize, useWindowSize } from '@vueuse/core'
  93. import { debounce } from "lodash"
  94. const fakeBack = inject('fakeBack')
  95. const $isMobile = inject('$isMobile')
  96. const SCROLL_KEY = 'relicListScrollLeft'
  97. const route = useRoute()
  98. const router = useRouter()
  99. const store = useStore()
  100. const clientHeight = document.body.clientHeight
  101. const { height: windowHeight } = useWindowSize()
  102. const cascaderValueInit = (route.query.sceneIdx && route.query.cameraIdx) ? [route.query.sceneIdx, route.query.cameraIdx] : ['0', '0']
  103. const cascaderValue = ref(cascaderValueInit)
  104. const cameraTree = ref([
  105. {
  106. value: '0',
  107. label: '天下大都',
  108. children: [
  109. {
  110. value: '0',
  111. label: '帝都',
  112. },
  113. {
  114. value: '1',
  115. label: '宫阙',
  116. },
  117. {
  118. value: '2',
  119. label: '览胜',
  120. },
  121. ]
  122. },
  123. {
  124. value: '1',
  125. label: '河润大都',
  126. children: [
  127. {
  128. value: '0',
  129. label: '河畅',
  130. },
  131. {
  132. value: '1',
  133. label: '航运',
  134. },
  135. {
  136. value: '2',
  137. label: '市井',
  138. },
  139. ]
  140. },
  141. {
  142. value: '2',
  143. label: '风雅大都',
  144. children: [
  145. {
  146. value: '0',
  147. label: '雅集',
  148. },
  149. {
  150. value: '1',
  151. label: '曲苑',
  152. },
  153. ]
  154. },
  155. ])
  156. const keyword = ref('')
  157. watch(route, () => {
  158. cascaderValue.value = (route.query.sceneIdx && route.query.cameraIdx) ? [route.query.sceneIdx, route.query.cameraIdx] : ['0', '0']
  159. })
  160. const relicData = computed(() => {
  161. return store.getters.relicData.filter((item) => {
  162. const selectedSceneIdx = Number(cascaderValue.value[0])
  163. if (selectedSceneIdx !== item.sceneIdx) {
  164. return false
  165. } else {
  166. const selectedCameraIdx = Number(cascaderValue.value[1])
  167. if (selectedCameraIdx === item.cameraIdx) {
  168. return true
  169. } else {
  170. return false
  171. }
  172. }
  173. }).filter((item) => {
  174. if (!keyword.value) {
  175. return true
  176. } else {
  177. if (item['名称'].includes(keyword.value)) {
  178. return true
  179. } else {
  180. return false
  181. }
  182. }
  183. })
  184. })
  185. function getRelicThumbUrl(idx) {
  186. if (Array.isArray(relicData.value[idx]['图片名']) && relicData.value[idx]['图片名'][0]) {
  187. return `${process.env.BASE_URL}relic-data/small-photo/${relicData.value[idx]['图片名'][0]}`
  188. } else {
  189. return ''
  190. }
  191. }
  192. const listEl = ref(null)
  193. let scrollLeft = Number(localStorage.getItem(SCROLL_KEY) || 0)
  194. const { width: listWidth, height: listHeight } = useElementSize(listEl)
  195. const { translateLength, hasOperatedThisTime, updateWidth, updateTranslateLength } = useSmoothSwipe({
  196. scrollTargetRef: listEl,
  197. viewportWidth: listWidth,
  198. dontHandlerMobile: true
  199. })
  200. watch(relicData, (vNew) => {
  201. nextTick(() => {
  202. updateWidth()
  203. })
  204. }, {
  205. deep: true
  206. })
  207. function onClickItem(idx) {
  208. if (!hasOperatedThisTime.value) {
  209. router[$isMobile ? 'replace' : 'push']({
  210. name: 'RelicDetail',
  211. query: {
  212. sceneIdx: route.query.sceneIdx,
  213. cameraIdx: route.query.cameraIdx,
  214. relicIdx: idx,
  215. }
  216. })
  217. }
  218. }
  219. watch(cascaderValue, val => {
  220. router.replace({
  221. name: 'RelicListMobile',
  222. query: {
  223. sceneIdx: val[0],
  224. cameraIdx: val[1]
  225. }
  226. })
  227. updateTranslateLength(0)
  228. localStorage.setItem(SCROLL_KEY, 0)
  229. })
  230. router.beforeEach((to) => {
  231. if (!['RelicDetail', 'RelicListMobile'].includes(to.name)) {
  232. localStorage.removeItem(SCROLL_KEY)
  233. }
  234. })
  235. onMounted(() => {
  236. if (scrollLeft) {
  237. updateTranslateLength(scrollLeft)
  238. }
  239. })
  240. const handleScroll = debounce(() => {
  241. listEl.value && localStorage.setItem(SCROLL_KEY, listEl.value.scrollLeft)
  242. }, 100)
  243. const {
  244. windowSizeInCssForRef,
  245. windowSizeWhenDesignForRef,
  246. } = useSizeAdapt(1920, 968)
  247. </script>
  248. <style lang="less" scoped>
  249. @page-height-design-px: 970;
  250. .relic-list {
  251. display: flex;
  252. flex-direction: column;
  253. justify-content: flex-end;
  254. height: 100vh;
  255. background-image: url(@/assets/images/relic-list-bg.jpg);
  256. background-size: cover;
  257. background-repeat: no-repeat;
  258. background-position: center center;
  259. >button.return {
  260. position: absolute;
  261. left: calc(42 / 970* 100vh);
  262. top: calc(5 / 970* 100vh);
  263. width: calc(110 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  264. height: calc(110 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  265. background-image: url(@/assets/images/btn-return.png);
  266. background-size: contain;
  267. background-repeat: no-repeat;
  268. background-position: center center;
  269. }
  270. :deep {
  271. .el-cascader {
  272. position: absolute;
  273. width: calc(250 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  274. height: calc(70 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  275. left: calc(190 / @page-height-design-px * 100vh);
  276. top: calc(26 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  277. z-index: 1;
  278. .el-input {
  279. height: 100%;
  280. background-image: url(@/assets/images/cascader-bg.png);
  281. background-size: 100% 100%;
  282. border: 0;
  283. .el-input__wrapper {
  284. background: none;
  285. border: 0;
  286. box-shadow: none;
  287. .el-input__inner {
  288. height: 100%;
  289. font-size: calc(40 / @page-height-design-px * 100vh);
  290. text-align: center;
  291. font-family: "Source Han Serif CN Heavy";
  292. color: #6A3906;
  293. }
  294. .el-input__suffix {
  295. color: #6A3906;
  296. }
  297. }
  298. .icon-arrow-down {
  299. font-size: calc(24 / @page-height-design-px * 100vh);
  300. margin-top: calc(10 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  301. }
  302. }
  303. }
  304. .el-popper .is-light {
  305. background: red;
  306. }
  307. }
  308. >.search-ui {
  309. position: absolute;
  310. top: calc(26 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  311. right: calc(27 / @page-height-design-px * 100vh);
  312. padding: calc(10 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef')) 0;
  313. width: calc(502 / @page-height-design-px * 100vh);
  314. height: calc(70 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  315. background-image: url(@/assets/images/search-bg.png);
  316. background-size: cover;
  317. background-repeat: no-repeat;
  318. background-position: center center;
  319. z-index: 1;
  320. box-sizing: border-box;
  321. >input {
  322. position: absolute;
  323. left: 50px;
  324. top: 50%;
  325. transform: translateY(-50%);
  326. height: 100%;
  327. width: calc(350 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  328. font-size: calc(30 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  329. font-family: Source Han Sans CN, Source Han Sans CN;
  330. font-weight: 400;
  331. color: rgba(255, 255, 255, 0.7);
  332. &::placeholder {
  333. font-size: calc(30 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  334. font-family: Source Han Sans CN, Source Han Sans CN;
  335. font-weight: 400;
  336. color: rgba(255, 255, 255, 0.3);
  337. }
  338. }
  339. >button.search {
  340. position: absolute;
  341. width: calc(31 / @page-height-design-px * 100vh);
  342. height: calc(31 / @page-height-design-px * 100vh);
  343. position: absolute;
  344. top: 50%;
  345. right: calc(53 / @page-height-design-px * 100vh);
  346. transform: translateY(-50%);
  347. background-image: url(@/assets/images/icon-search.png);
  348. background-size: cover;
  349. background-repeat: no-repeat;
  350. background-position: center center;
  351. }
  352. }
  353. >.the-list {
  354. position: absolute;
  355. left: 0;
  356. bottom: 0;
  357. width: 100%;
  358. height: calc(850 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  359. background-size: auto 100%;
  360. background-repeat: no-repeat;
  361. background-position: left center;
  362. box-sizing: border-box;
  363. &.scene1 {
  364. .content-wrap::after {
  365. background: #B8AD9C;
  366. }
  367. }
  368. &.scene2 {
  369. .content-wrap::after {
  370. background: #AEC5BB;
  371. }
  372. }
  373. &.scene3 {
  374. .content-wrap::after {
  375. background: #A6A3AD;
  376. }
  377. }
  378. >.content-wrap {
  379. position: relative;
  380. &::after {
  381. content: '';
  382. position: absolute;
  383. top: calc(42 / @page-height-design-px * 100vh);
  384. left: 0;
  385. right: 0;
  386. bottom: calc(42 / @page-height-design-px * 100vh);
  387. z-index: -1;
  388. }
  389. &::-webkit-scrollbar {
  390. height: 0;
  391. }
  392. box-sizing: border-box;
  393. margin-top: calc(27 / @page-height-design-px * 100vh);
  394. height: calc(589 / @page-height-design-px * 100vh);
  395. width: 100%;
  396. overflow: auto;
  397. user-select: none;
  398. display: flex;
  399. align-items: center;
  400. >.first-item{
  401. flex: 0 0 auto;
  402. width: calc(277 / @page-height-design-px * 100vh * 0.83);
  403. height: calc(608 / @page-height-design-px * 100vh * 0.83);
  404. background-size: cover;
  405. background-repeat: no-repeat;
  406. background-position: center center;
  407. }
  408. >.first-item.scene1{
  409. background-image: url(@/assets/images/relic-first-item-bg-1.jpg);
  410. }
  411. >.first-item.scene2{
  412. background-image: url(@/assets/images/relic-first-item-bg-2.jpg);
  413. }
  414. >.first-item.scene3{
  415. background-image: url(@/assets/images/relic-first-item-bg-3.jpg);
  416. }
  417. >.relic-item {
  418. flex: 0 0 auto;
  419. width: calc(277 / @page-height-design-px * 100vh * 0.83);
  420. height: calc(608 / @page-height-design-px * 100vh * 0.83);
  421. cursor: pointer;
  422. background-size: cover;
  423. background-repeat: no-repeat;
  424. background-position: center center;
  425. position: relative;
  426. >.name {
  427. flex: 0 0 auto;
  428. position: absolute;
  429. top: calc(10 / @page-height-design-px * 100vh * 0.83);
  430. right: calc(32 / @page-height-design-px * 100vh * 0.83);
  431. width: calc(47 / @page-height-design-px * 100vh * 0.83);
  432. line-height: calc(47 / @page-height-design-px * 100vh * 0.83);
  433. height: calc(261 / @page-height-design-px * 100vh * 0.83);
  434. font-size: calc(19 / @page-height-design-px * 100vh * 0.83);
  435. font-family: "Source Han Serif CN Heavy";
  436. color: #43310E;
  437. overflow: hidden;
  438. writing-mode: vertical-rl;
  439. letter-spacing: 0.2em;
  440. background-image: url(@/assets/images/relic-item-title-bg.png);
  441. background-size: contain;
  442. background-repeat: no-repeat;
  443. background-position: center center;
  444. text-align: center;
  445. padding-top: calc(17 / @page-height-design-px * 100vh * 0.83);
  446. padding-bottom: calc(17 / @page-height-design-px * 100vh * 0.83);
  447. z-index: 1;
  448. }
  449. >.name.wide{
  450. right: calc(22 / @page-height-design-px * 100vh * 0.83);
  451. width: calc(82 / @page-height-design-px * 100vh * 0.83);
  452. height: calc(255 / @page-height-design-px * 100vh * 0.83);
  453. line-height: 1.5em;
  454. background-image: url(@/assets/images/relic-item-title-bg-wide.png);
  455. padding-right: 0.7em;
  456. padding-top: calc(26 / @page-height-design-px * 100vh * 0.83);
  457. padding-bottom: calc(26 / @page-height-design-px * 100vh * 0.83);
  458. z-index: 1;
  459. }
  460. >.name.smallFontSize{
  461. padding-right: calc(20 / @page-height-design-px * 100vh * 0.83);;
  462. font-size: calc(14 / @page-height-design-px * 100vh * 0.83);
  463. }
  464. >.name.smFontSize {
  465. font-size: calc(14 / @page-height-design-px * 100vh * 0.83);
  466. }
  467. >img {
  468. position: absolute;
  469. left: 50%;
  470. transform: translateX(-50%) scale(calc(v-bind('windowHeight') / 700));
  471. object-fit: contain;
  472. transform-origin: center bottom;
  473. pointer-events: none;
  474. }
  475. }
  476. >.relic-item.isOdd{
  477. >img{
  478. bottom: calc(250 / @page-height-design-px * 100vh * 0.83);
  479. }
  480. }
  481. >.relic-item.isEven{
  482. >img{
  483. bottom: calc(120 / @page-height-design-px * 100vh * 0.83);
  484. }
  485. }
  486. >.relic-item.isScene1.isOdd{
  487. background-image: url(@/assets/images/relic-item-bg-1-odd.jpg);
  488. }
  489. >.relic-item.isScene1.isEven{
  490. background-image: url(@/assets/images/relic-item-bg-1-even.jpg);
  491. }
  492. >.relic-item.isScene2.isOdd{
  493. background-image: url(@/assets/images/relic-item-bg-2-odd.jpg);
  494. }
  495. >.relic-item.isScene2.isEven{
  496. background-image: url(@/assets/images/relic-item-bg-2-even.jpg);
  497. }
  498. >.relic-item.isScene3.isOdd{
  499. background-image: url(@/assets/images/relic-item-bg-3-odd.jpg);
  500. }
  501. >.relic-item.isScene3.isEven{
  502. background-image: url(@/assets/images/relic-item-bg-3-even.jpg);
  503. }
  504. }
  505. }
  506. }
  507. @media screen and (max-height: 740px) {
  508. .relic-list > .the-list {
  509. .content-wrap {
  510. margin-top: 0;
  511. height: inherit;
  512. .first-item,
  513. .relic-item {
  514. width: calc(450 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  515. height: inherit;
  516. }
  517. .relic-item {
  518. .name {
  519. width: calc(85 / 970* 100vh* 0.83);
  520. line-height: calc(85 / 970* 100vh* 0.83);
  521. height: calc(475 / 970* 100vh* 0.83);
  522. font-size: calc(40 / 970* 100vh* 0.83);
  523. &.wide {
  524. padding-right: calc(14 / 970* 100vh* 0.83);
  525. width: calc(152 / 970* 100vh* 0.83);
  526. height: calc(475 / 970* 100vh* 0.83);
  527. }
  528. &.smallFontSize {
  529. padding-right: calc(24 / 970* 100vh* 0.83);
  530. font-size: calc(32 / 970* 100vh* 0.83);
  531. }
  532. }
  533. &.isOdd > img {
  534. bottom: calc(340 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  535. }
  536. &.isEven > img {
  537. bottom: calc(140 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  538. }
  539. }
  540. }
  541. }
  542. }
  543. </style>
  544. <style lang="less">
  545. .relic-cascader {
  546. .el-cascader-node {
  547. height: 50px;
  548. }
  549. .el-cascader-node__label {
  550. font-size: 34px;
  551. }
  552. .el-cascader-menu__wrap.el-scrollbar__wrap {
  553. height: fit-content !important;
  554. }
  555. }
  556. </style>