From 05e0fa354a1bd775c26d1317c94a22f7dcb295e2 Mon Sep 17 00:00:00 2001 From: ronger Date: Thu, 20 May 2021 22:02:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:poop:=20=E6=90=9C=E7=B4=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/archive/list.vue | 4 +- components/common/portfolio/list.vue | 4 +- components/common/user/list.vue | 4 +- components/layouts/pc/header.vue | 72 ++------------- pages/search.vue | 99 +++++++++++++++++++++ store/index.js | 3 +- store/search.js | 127 ++++++++++++++++++++++++--- 7 files changed, 229 insertions(+), 84 deletions(-) create mode 100644 pages/search.vue diff --git a/components/archive/list.vue b/components/archive/list.vue index 111472d..497de54 100644 --- a/components/archive/list.vue +++ b/components/archive/list.vue @@ -10,7 +10,7 @@ - {{ article.articleTitle }} + # {{ tag.tagTitle }} -
{{ article.articlePreviewContent }}
+

- {{ portfolio.portfolioTitle }} +

-
{{ portfolio.portfolioDescription }}
+
diff --git a/components/common/user/list.vue b/components/common/user/list.vue index d0ff3ed..2ccc057 100644 --- a/components/common/user/list.vue +++ b/components/common/user/list.vue @@ -8,9 +8,9 @@
- {{ user.nickname }} + - {{ user.signature }} +
diff --git a/components/layouts/pc/header.vue b/components/layouts/pc/header.vue index 05b2ead..68985c5 100644 --- a/components/layouts/pc/header.vue +++ b/components/layouts/pc/header.vue @@ -19,29 +19,7 @@
- - - - - - + @@ -115,8 +93,7 @@ export default { computed: { ...mapState({ activeMenu: state => state.activeMenu, - user: state => state.oauth, - initialSearchData: state => state.search.list + user: state => state.oauth }), avatarURL() { let _ts = this; @@ -173,21 +150,10 @@ export default { } }, methods: { - querySearchAsync(queryString, cb) { - let initialSearchData = this.initialSearchData; - let results = queryString ? initialSearchData.filter(this.createStateFilter(queryString)) : initialSearchData; - - clearTimeout(this.timeout); - this.timeout = setTimeout(() => { - cb(results); - }, 3000 * Math.random()); - }, - createStateFilter(queryString) { - return (state) => { - if (state && state.label) { - return (state.label.toLowerCase().indexOf(queryString.toLowerCase()) > -1); - } - }; + querySearchAsync() { + this.$router.push({ + path: `/search?q=${this.queryString}` + }) }, handleSelectMenu(item) { let _ts = this; @@ -217,15 +183,6 @@ export default { } } }, - handleSelect(item) { - console.log(item); - let _ts = this; - if (item) { - _ts.$router.push({ - path: `/${item.type}/${item.value}` - }) - } - }, handleCommand(item) { let _ts = this; switch (item) { @@ -260,23 +217,6 @@ export default { } }) } - }, - search() { - console.log(this.queryString) - }, - getSearchResultType(type) { - switch (type) { - case 'article': - type = '文章'; - break; - case 'portfolio': - type = '作品集'; - break; - case 'user': - type = '用户'; - break; - } - return type; } }, mounted() { diff --git a/pages/search.vue b/pages/search.vue new file mode 100644 index 0000000..03389ed --- /dev/null +++ b/pages/search.vue @@ -0,0 +1,99 @@ + + + + + diff --git a/store/index.js b/store/index.js index 72fd046..cd986cd 100644 --- a/store/index.js +++ b/store/index.js @@ -76,8 +76,7 @@ export const actions = { const initFetchAppData = [ // 内容数据 store.dispatch('topic/fetchNavList'), - store.dispatch('article/fetchList'), - store.dispatch('search/fetchList'), + store.dispatch('article/fetchList') ] return Promise.all(initFetchAppData) diff --git a/store/search.js b/store/search.js index 96caed8..3ae44d3 100644 --- a/store/search.js +++ b/store/search.js @@ -1,9 +1,39 @@ -export const BASE_API_PATH = '/api/console'; +export const BASE_API_PATH = '/api/lucene'; +const getDefaultArticleListData = () => { + return { + articles: [], + pagination: {} + } +} +const getDefaultUserListData = () => { + return { + users: [], + pagination: {} + } +} +const getDefaultPortfolioListData = () => { + return { + portfolios: [], + pagination: {} + } +} export const state = () => { return { fetching: false, - list: [] + list: [], + articles: { + fetching: false, + data: getDefaultArticleListData() + }, + users: { + fetching: false, + data: getDefaultUserListData() + }, + portfolios: { + fetching: false, + data: getDefaultPortfolioListData() + } } } @@ -14,25 +44,102 @@ export const mutations = { }, updateListData(state, action) { state.list = action - } + }, + // 数据列表 + updateArticleListFetching(state, action) { + state.articles.fetching = action + }, + updateArticleListData(state, action) { + state.articles.data = action + }, + // 数据列表 + updateUserListFetching(state, action) { + state.users.fetching = action + }, + updateUserListData(state, action) { + state.users.data = action + }, + // 数据列表 + updatePortfolioFetching(state, action) { + state.portfolios.fetching = action + }, + updatePortfolioListData(state, action) { + state.portfolios.data = action + }, } export const actions = { // 获取文章列表 - fetchList({commit}, params = {}) { + fetchArticleList({commit}, params = {}) { // 清空已有数据 - commit('updateListData', []); - commit('updateListFetching', true); + commit('updateArticleListData', getDefaultArticleListData()); + if (!params.queryString) { + return false; + } + commit('updateArticleListFetching', true); return this.$axios - .$get(`${BASE_API_PATH}/initial-search`) + .$get(`${BASE_API_PATH}/search-article`, { + params: { + q: params.queryString, + page: params.page || 1 + } + }) .then(response => { - commit('updateListFetching', false); - commit('updateListData', response); + commit('updateArticleListFetching', false); + commit('updateArticleListData', response ? response : getDefaultArticleListData()); }) .catch(error => { console.log(error); - commit('updateListFetching', false); + commit('updateArticleListFetching', false); + }); + }, + fetchUserList({commit}, params = {}) { + // 清空已有数据 + commit('updateUserListData', getDefaultUserListData()); + if (!params.queryString) { + return false; + } + commit('updateUserListFetching', true); + + return this.$axios + .$get(`${BASE_API_PATH}/search-user`, { + params: { + q: params.queryString, + page: params.page || 1 + } + }) + .then(response => { + commit('updateUserListFetching', false); + commit('updateUserListData', response ? response : getDefaultUserListData()); + }) + .catch(error => { + console.log(error); + commit('updateUserListFetching', false); + }); + }, + fetchPortfolioList({commit}, params = {}) { + // 清空已有数据 + commit('updatePortfolioListData', getDefaultPortfolioListData()); + if (!params.queryString) { + return false; + } + commit('updatePortfolioFetching', true); + + return this.$axios + .$get(`${BASE_API_PATH}/search-portfolio`, { + params: { + q: params.queryString, + page: params.page || 1 + } + }) + .then(response => { + commit('updatePortfolioFetching', false); + commit('updatePortfolioListData', response ? response : getDefaultPortfolioListData()); + }) + .catch(error => { + console.log(error); + commit('updatePortfolioFetching', false); }); } } From d82a07755048d4715f0b27f01e05c7ee1f4766b9 Mon Sep 17 00:00:00 2001 From: ronger Date: Sun, 30 May 2021 12:08:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:poop:=20=E6=90=9C=E7=B4=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/layouts/pc/header.vue | 41 +++++++++++++++++++++++++++----- pages/search.vue | 14 +++++++---- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/components/layouts/pc/header.vue b/components/layouts/pc/header.vue index 68985c5..a9d81d2 100644 --- a/components/layouts/pc/header.vue +++ b/components/layouts/pc/header.vue @@ -18,12 +18,21 @@ - - - - + + + + + + + 创建作品集 @@ -69,6 +78,17 @@ + + + + + + 登录 @@ -141,7 +161,9 @@ export default { timeout: null, show: false, notifications: [], - notificationNumbers: "" + notificationNumbers: "", + showPopover: false, + autofocus: false }; }, watch: { @@ -154,6 +176,13 @@ export default { this.$router.push({ path: `/search?q=${this.queryString}` }) + this.$set(this, 'showPopover', false); + this.$set(this, 'queryString', ''); + }, + handleShowPopover() { + setTimeout(function () { + document.getElementById("searchInput").focus() + }, 500); }, handleSelectMenu(item) { let _ts = this; @@ -223,7 +252,7 @@ export default { let user = this.user; if (user) { this.getUnreadNotifications(); - sockClient.initSocket(this.$store.state.userInfo); + // sockClient.initSocket(this.$store.state.userInfo); } } diff --git a/pages/search.vue b/pages/search.vue index 03389ed..9ec0214 100644 --- a/pages/search.vue +++ b/pages/search.vue @@ -1,7 +1,9 @@