From c5cf823b0e29fda5fe3a44e0c6ffc0936594ea95 Mon Sep 17 00:00:00 2001 From: ShineTomorrow Date: Sat, 7 Jan 2023 03:20:36 +0800 Subject: [PATCH] :sparkles: feat(project): add confirm component function --- src/api/pexel.js | 7 + src/constants/index.js | 38 ++++++ src/directives/modules/lazy.js | 33 +++-- src/libs/Button/index.vue | 1 + src/libs/Confirm/index.js | 43 ++++++ src/libs/Confirm/index.vue | 128 ++++++++++++++++++ src/libs/index.js | 2 + src/store/getters.js | 1 + src/store/modules/app.js | 6 + src/styles/index.scss | 8 ++ .../components/header/search/history.vue | 9 +- .../layout/components/header/search/index.vue | 5 + .../layout/components/header/search/theme.vue | 72 ++++++++++ src/views/main/components/list/index.vue | 10 +- src/views/main/components/list/item.vue | 5 +- 15 files changed, 354 insertions(+), 14 deletions(-) create mode 100644 src/libs/Confirm/index.js create mode 100644 src/libs/Confirm/index.vue create mode 100644 src/views/layout/components/header/search/theme.vue diff --git a/src/api/pexel.js b/src/api/pexel.js index cb3921d..c48ffa6 100644 --- a/src/api/pexel.js +++ b/src/api/pexel.js @@ -19,3 +19,10 @@ export const getHint = (q) => { }, }); }; + +//获取推荐主题 +export const getThemes = () => { + return request({ + url: '/thems', + }); +}; diff --git a/src/constants/index.js b/src/constants/index.js index 9c08208..f085c16 100644 --- a/src/constants/index.js +++ b/src/constants/index.js @@ -128,3 +128,41 @@ export const CATEGORY_NOMAR_DATA = [ { id: 'sports', name: '运动', urlname: 'sports' }, { id: 'funny', name: '搞笑', urlname: 'funny' }, ]; + +export const THEME_NOMAR_DATA = [ + { + id: 'Art', + photo: 'https://images.pexels.com/photos/9890370/pexels-photo-9890370.jpeg?auto=compress&cs=tinysrgb&dpr=1&fit=crop&h=250&w=360', + title: '艺术', + }, + { + id: 'black theme', + photo: 'https://images.pexels.com/photos/1356300/pexels-photo-1356300.jpeg?auto=compress&cs=tinysrgb&dpr=1&fit=crop&h=250&w=360', + title: '黑色', + }, + { + id: 'cute background', + photo: 'https://images.pexels.com/photos/7267852/pexels-photo-7267852.jpeg?auto=compress&cs=tinysrgb&dpr=1&fit=crop&h=250&w=360', + title: '可爱背景', + }, + { + id: 'Like a breath of fresh air', + photo: 'https://images.pexels.com/photos/7412111/pexels-photo-7412111.jpeg?auto=compress&cs=tinysrgb&dpr=1&fit=crop&h=250&w=360', + title: '小清新', + }, + { + id: 'green', + photo: 'https://images.pexels.com/photos/8117889/pexels-photo-8117889.jpeg?auto=compress&cs=tinysrgb&dpr=1&fit=crop&h=250&w=360', + title: '绿色', + }, + { + id: 'Happy Feet', + photo: 'https://images.pexels.com/photos/631988/pexels-photo-631988.jpeg?auto=compress&cs=tinysrgb&dpr=1&fit=crop&h=250&w=360', + title: '快乐', + }, + { + id: 'Botany', + photo: 'https://images.pexels.com/photos/212940/pexels-photo-212940.jpeg?auto=compress&cs=tinysrgb&dpr=1&fit=crop&h=250&w=360', + title: '植物', + }, +]; diff --git a/src/directives/modules/lazy.js b/src/directives/modules/lazy.js index 455b56c..4f370dc 100644 --- a/src/directives/modules/lazy.js +++ b/src/directives/modules/lazy.js @@ -2,18 +2,29 @@ * 图片懒加载 */ import { useIntersectionObserver } from '@vueuse/core'; + +const handleLazy = (el) => { + const imgSrc = el.dataset.src ? el.dataset.src : el.src; + if (el.src) { + el.src = ''; + } + const { stop } = useIntersectionObserver(el, ([{ isIntersecting }]) => { + if (isIntersecting) { + el.src = imgSrc; + // 停止监听 + stop(); + } + }); +}; export default { mounted(el) { - const imgSrc = el.dataset.src ? el.dataset.src : el.src; - if (el.src) { - el.src = ''; - } - const { stop } = useIntersectionObserver(el, ([{ isIntersecting }]) => { - if (isIntersecting) { - el.src = imgSrc; - // 停止监听 - stop(); - } - }); + handleLazy(el); + }, + updated(el, binding, vnode, prevVnode) { + if (!(vnode.props.src || vnode.props['data-src'])) return; + const newSrc = vnode.props['data-src'] || vnode.props.src; + const preSrc = prevVnode.props['data-src'] || prevVnode.props.src; + if (newSrc === preSrc) return; + handleLazy(el); }, }; diff --git a/src/libs/Button/index.vue b/src/libs/Button/index.vue index adc4b15..8c54a48 100644 --- a/src/libs/Button/index.vue +++ b/src/libs/Button/index.vue @@ -64,6 +64,7 @@ const sizeEnum = { + + diff --git a/src/libs/index.js b/src/libs/index.js index 78c7da8..e6fed66 100644 --- a/src/libs/index.js +++ b/src/libs/index.js @@ -1,5 +1,7 @@ import { defineAsyncComponent } from 'vue'; +export { Confirm } from '@/libs/Confirm/index.js'; + export default { install(app) { // 获取当前路径任意文件夹下的 组件 diff --git a/src/store/getters.js b/src/store/getters.js index ecd729d..78b3ec7 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -9,4 +9,5 @@ export default { return index; }, historys: (state) => state.search.historys, + searchText: (state) => state.app.searchText, }; diff --git a/src/store/modules/app.js b/src/store/modules/app.js index 534b225..7f6bf5e 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -5,11 +5,17 @@ export default { state: { // 当前选中的分类 currentCategory: ALL_CATEGORY_ITEM, + + // 搜索文本 + searchText: '', }, mutations: { changeCurrentCategory(state, newCategory) { state.currentCategory = newCategory; }, + changeSearchText(state, newText) { + state.searchText = newText; + }, }, actions: {}, }; diff --git a/src/styles/index.scss b/src/styles/index.scss index 2b75b09..9d70550 100644 --- a/src/styles/index.scss +++ b/src/styles/index.scss @@ -8,3 +8,11 @@ transform: translateY(-50%); top: 50%; } +.pcenterXY { + position: absolute; + left: 0; + top: 0; + right: 0; + bottom: 0; + margin: auto; +} diff --git a/src/views/layout/components/header/search/history.vue b/src/views/layout/components/header/search/history.vue index 4da4cb2..cea03d9 100644 --- a/src/views/layout/components/header/search/history.vue +++ b/src/views/layout/components/header/search/history.vue @@ -29,11 +29,18 @@ + + diff --git a/src/views/main/components/list/index.vue b/src/views/main/components/list/index.vue index 36f2a7b..716b390 100644 --- a/src/views/main/components/list/index.vue +++ b/src/views/main/components/list/index.vue @@ -79,13 +79,21 @@ const restQuery = (newQuery) => { watch( () => store.getters.currentCategory, (currentCategory) => { - console.log('[ currentCategory ]', currentCategory); restQuery({ page: 1, query: currentCategory.urlname, }); } ); +watch( + () => store.getters.searchText, + (value) => { + restQuery({ + page: 1, + query: value, + }); + } +); diff --git a/src/views/main/components/list/item.vue b/src/views/main/components/list/item.vue index dfada80..3a8b580 100644 --- a/src/views/main/components/list/item.vue +++ b/src/views/main/components/list/item.vue @@ -8,7 +8,9 @@ >