From 63bc0e3201cf385258513c13f8e8651e3115312d Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 31 Jul 2020 17:40:17 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E4=B8=93=E9=A2=98=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/layouts/pc/header.vue | 89 ++++++++++++++++---------------- nuxt.config.js | 2 +- pages/topic/_topic_uri.vue | 56 ++++++++++++++++++++ store/index.js | 1 + store/topic.js | 39 ++++++++++++++ 5 files changed, 142 insertions(+), 45 deletions(-) create mode 100644 pages/topic/_topic_uri.vue create mode 100644 store/topic.js diff --git a/components/layouts/pc/header.vue b/components/layouts/pc/header.vue index f405c92..6f88e52 100644 --- a/components/layouts/pc/header.vue +++ b/components/layouts/pc/header.vue @@ -32,8 +32,8 @@ @select="handleSelect" /> - - + + 创建作品集 发帖 @@ -91,7 +91,7 @@ getActiveMenu() { return this.$store.state.activeMenu; }, - isLogin() { + user() { return this.$store.state.oauth; }, avatarURL() { @@ -115,7 +115,7 @@ }; }, watch: { - isLogin: function () { + user: function () { this.getUnreadNotifications(); } }, @@ -145,25 +145,23 @@ let _ts = this; let activeMenu = _ts.$store.state.activeMenu; if (activeMenu !== item) { - if (item === 'topic') { - _ts.$router.push( - { - name: item, - params: { - name: '51mcu' + switch (item) { + case 'topic': + _ts.$router.push({ + path: '/topic/news' + }) + break; + case 'github': + window.open("https://github.com/Hugh-rymcu"); + return false; + break; + default: + _ts.$router.push( + { + name: item } - } - ) + ) } - if (item === 'github') { - window.open("https://github.com/Hugh-rymcu"); - return false; - } - _ts.$router.push( - { - name: item - } - ) } }, handleSelect(item) { @@ -171,31 +169,34 @@ }, handleCommand(item) { let _ts = this; - if (item === 'user') { - _ts.$router.push({ - path: '/user/' + _ts.$store.state.nickname - }) + switch (item) { + case 'user': + _ts.$router.push({ + path: '/user/' + _ts.nickname + }) + break; + case 'user-info': + _ts.$router.push({ + name: 'account', + params: { + id: _ts.user.idUser + } + }) + break; + case 'logout': + Cookie.remove('auth') + _ts.$store.commit('setAuth', null) + item = 'login'; + break; + default: + _ts.$router.push({ + name: item + }) } - if (item === 'user-info') { - _ts.$router.push({ - name: 'account', - params: { - id: _ts.$store.state.idUser - } - }) - } - if (item === 'logout') { - Cookie.remove('auth') - _ts.$store.commit('setAuth', null) - item = 'login'; - } - _ts.$router.push({ - name: item - }) }, getUnreadNotifications() { let _ts = this; - if (_ts.isLogin) { + if (_ts.user) { _ts.$axios.$get('/api/notification/unread').then(function (res) { if (res) { _ts.$set(_ts, 'notifications', res.notifications); @@ -207,8 +208,8 @@ }, mounted() { this.restaurants = this.loadAll(); - let isLogin = this.isLogin; - if (isLogin) { + let user = this.user; + if (user) { this.getUnreadNotifications(); } } diff --git a/nuxt.config.js b/nuxt.config.js index 948a79c..2d8b6ae 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -74,7 +74,7 @@ export default { }, proxy: [ //proxy配置 ['/api', { - target:'https://rymcu.com/vertical-console/', //api请求路径 + target: apiConfig.BASE, //api请求路径 pathRewrite: { '^/api' : '/api/v1' } //重定向请求路径,防止路由、api路径的冲突 }] ], diff --git a/pages/topic/_topic_uri.vue b/pages/topic/_topic_uri.vue new file mode 100644 index 0000000..aba758e --- /dev/null +++ b/pages/topic/_topic_uri.vue @@ -0,0 +1,56 @@ + + + + + diff --git a/store/index.js b/store/index.js index 85446e3..47e0a44 100644 --- a/store/index.js +++ b/store/index.js @@ -32,6 +32,7 @@ export const actions = { } const initFetchAppData = [ // 内容数据 + store.dispatch('topic/fetchList'), store.dispatch('article/fetchList') ] return Promise.all(initFetchAppData) diff --git a/store/topic.js b/store/topic.js new file mode 100644 index 0000000..5d3a437 --- /dev/null +++ b/store/topic.js @@ -0,0 +1,39 @@ +/** + * @file 分类数据状态 / ES module + * @module store/category + * @author Surmon + */ + +export const TOPIC_API_PATH = '/api/topic' + +export const state = () => { + return { + fetching: false, + data: [] + } +} + +export const mutations = { + updateFetching(state, action) { + state.fetching = action + }, + updateListData(state, action) { + state.data = action + } +} + +export const actions = { + fetchList({ commit }, params) { + commit('updateFetching', true) + console.log(params) + return this.$axios + .$get(`${TOPIC_API_PATH}/topic-nav`) + .then(response => { + commit('updateListData', response) + commit('updateFetching', false) + }) + .catch(error => { + commit('updateFetching', false) + }) + } +}