From f494974cf3696e5fa8b37e140a770dddb97ced0e Mon Sep 17 00:00:00 2001 From: ShineTomorrow Date: Sat, 7 Jan 2023 09:19:00 +0800 Subject: [PATCH] :sparkles: feat(project): add pins router and as components --- src/api/pexel.js | 12 ++ src/libs/NavBar/index.vue | 62 ++++++++++ src/router/index.js | 8 +- .../{mobile-router.js => mobile-routes.js} | 5 + .../modules/{pc-router.js => pc-routes.js} | 5 + src/views/main/components/list/index.vue | 15 +-- src/views/main/components/list/item.vue | 4 +- src/views/pins/components/pins.vue | 107 +++++++++++++++++- src/views/pins/index.vue | 10 +- tailwind.config.cjs | 3 + 10 files changed, 207 insertions(+), 24 deletions(-) create mode 100644 src/libs/NavBar/index.vue rename src/router/modules/{mobile-router.js => mobile-routes.js} (52%) rename src/router/modules/{pc-router.js => pc-routes.js} (72%) diff --git a/src/api/pexel.js b/src/api/pexel.js index c48ffa6..95930bf 100644 --- a/src/api/pexel.js +++ b/src/api/pexel.js @@ -4,6 +4,7 @@ const request = new Request(); //获取分类列表 export const getListData = (data) => { + data.locale = 'zh-CN'; return request({ url: '/search', params: data, @@ -26,3 +27,14 @@ export const getThemes = () => { url: '/thems', }); }; + +//获取推荐主题 +export const getPhotoById = (id) => { + const language = 'zh-CN'; + return request({ + url: `/photos/${id}`, + params: { + locale: language, + }, + }); +}; diff --git a/src/libs/NavBar/index.vue b/src/libs/NavBar/index.vue new file mode 100644 index 0000000..251ae94 --- /dev/null +++ b/src/libs/NavBar/index.vue @@ -0,0 +1,62 @@ + + + + + diff --git a/src/router/index.js b/src/router/index.js index 906f2a7..769cf11 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,11 +1,11 @@ -import { createRouter, createWebHashHistory } from 'vue-router'; +import { createRouter, createWebHistory } from 'vue-router'; import { isMobileTerminal } from '@/utils/flexible'; -import mobileRouter from './modules/mobile-router'; -import pcRouter from './modules/pc-router'; +import mobileRouter from './modules/mobile-routes'; +import pcRouter from './modules/pc-routes'; // 创建vue-router实例 const router = createRouter({ - history: createWebHashHistory(), + history: createWebHistory(), routes: isMobileTerminal.value ? mobileRouter : pcRouter, }); diff --git a/src/router/modules/mobile-router.js b/src/router/modules/mobile-routes.js similarity index 52% rename from src/router/modules/mobile-router.js rename to src/router/modules/mobile-routes.js index 3209848..b6081ee 100644 --- a/src/router/modules/mobile-router.js +++ b/src/router/modules/mobile-routes.js @@ -4,4 +4,9 @@ export default [ name: 'home', component: () => import('@/views/main/index.vue'), }, + { + path: '/pins/:id', + name: 'pins', + component: () => import('@/views/pins/index.vue'), + }, ]; diff --git a/src/router/modules/pc-router.js b/src/router/modules/pc-routes.js similarity index 72% rename from src/router/modules/pc-router.js rename to src/router/modules/pc-routes.js index afd1a50..8513a4e 100644 --- a/src/router/modules/pc-router.js +++ b/src/router/modules/pc-routes.js @@ -11,4 +11,9 @@ export default [ }, ], }, + { + path: '/pins/:id', + name: 'pins', + component: () => import('@/views/pins/index.vue'), + }, ]; diff --git a/src/views/main/components/list/index.vue b/src/views/main/components/list/index.vue index 42dc713..b3ed209 100644 --- a/src/views/main/components/list/index.vue +++ b/src/views/main/components/list/index.vue @@ -25,7 +25,7 @@ @enter="onEnter" @leave="onLeave" > - + @@ -111,12 +111,13 @@ watch( const isPinVisible = ref(false); const currentPin = ref({}); -const onPinClick = (data) => { - console.log('[ data ]', data); +const currentLocation = ref({}); +const onPinClick = ({ data, location }) => { if (!data.id) return; // 修改地址 不会刷新 history.pushState(null, null, `/pins/${data.id}`); currentPin.value = data; + currentLocation.value = location; isPinVisible.value = true; }; // 监听浏览器回退按钮事件 @@ -129,8 +130,8 @@ const onBeforeEnd = (el) => { scaleX: 0, scaleY: 0, transformOrigin: '0 0', - translateX: currentPin.value.location?.translateX, - translateY: currentPin.value.location?.translateY, + translateX: currentLocation.value?.translateX, + translateY: currentLocation.value?.translateY, opacity: 0, }); }; @@ -150,8 +151,8 @@ const onLeave = (el, done) => { duration: 0.3, scaleX: 0, scaleY: 0, - translateX: currentPin.value.location?.translateX, - translateY: currentPin.value.location?.translateY, + translateX: currentLocation.value?.translateX, + translateY: currentLocation.value?.translateY, opacity: 1, onComplete: done, }); diff --git a/src/views/main/components/list/item.vue b/src/views/main/components/list/item.vue index 0846500..41de2f6 100644 --- a/src/views/main/components/list/item.vue +++ b/src/views/main/components/list/item.vue @@ -11,7 +11,7 @@ ref="imgTarget" v-lazy :data-src=" - isMobileTerminal ? data?.src?.medium : data?.src?.large + isMobileTerminal ? data?.src?.large : data?.src?.large2 " class="w-full bg-transparent" :style="{ @@ -115,7 +115,7 @@ const imgContainerCenter = computed(() => { // 进入详情 const onPinClick = () => { emits('click', { - id: props.data.id, + data: props.data, location: imgContainerCenter.value, }); }; diff --git a/src/views/pins/components/pins.vue b/src/views/pins/components/pins.vue index b23eb0a..ecbf62e 100644 --- a/src/views/pins/components/pins.vue +++ b/src/views/pins/components/pins.vue @@ -1,16 +1,113 @@ diff --git a/src/views/pins/index.vue b/src/views/pins/index.vue index 920e7ff..da9f50a 100644 --- a/src/views/pins/index.vue +++ b/src/views/pins/index.vue @@ -1,13 +1,11 @@ - + diff --git a/tailwind.config.cjs b/tailwind.config.cjs index b878b90..6f2a268 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -48,6 +48,9 @@ module.exports = { variants: { scrollbar: ['dark'], }, + backdropBlur: { + '4xl': '240px', + }, }, }, plugins: [require('tailwind-scrollbar')],