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); }); } }