diff --git a/components/layouts/mobile/footer.vue b/components/layouts/mobile/footer.vue
index 6f463a8..5570247 100644
--- a/components/layouts/mobile/footer.vue
+++ b/components/layouts/mobile/footer.vue
@@ -1,42 +1,46 @@
-
diff --git a/components/layouts/mobile/header.vue b/components/layouts/mobile/header.vue
index c884aed..e5749bd 100644
--- a/components/layouts/mobile/header.vue
+++ b/components/layouts/mobile/header.vue
@@ -1,224 +1,242 @@
-
-
-
-
-
- RYMCU
-
-
-
-
-
-
- 首页
- 专题
- 开源代码
- 资料下载
-
-
-
-
-
-
-
-
-
-
-
- 创建作品集
- 发帖
-
-
-
-
-
-
- {{ notification.dataSummary }}
- 查看所有消息
-
-
-
-
-
-
-
-
-
-
-
- {{ nickname }}
-
- 系统管理
- 资料与账号
- 我的草稿
- 退出登录
-
-
-
-
-
- 登录
- 注册
-
-
+
+
+
+
+
+ RYMCU
+
+
+
+
+
+
+ 首页
+ 专题
+ 开源代码
+ 资料下载
+
+
+
+
+
+
+
+
-
+
+
+ 创建作品集
+
+ 发帖
+
+
+
+
+
+
+ {{ notification.dataSummary }}
+
+ 查看所有消息
+
+
+
+
+
+
+
+
+
+
+
+ {{ nickname }}
+
+ 系统管理
+ 资料与账号
+ 我的草稿
+ 退出登录
+
+
+
+
+
+
+ 登录
+
+
+ 注册
+
+
+
+
+
diff --git a/components/layouts/mobile/main.vue b/components/layouts/mobile/main.vue
index 8b81654..f9e4ab1 100644
--- a/components/layouts/mobile/main.vue
+++ b/components/layouts/mobile/main.vue
@@ -1,27 +1,58 @@
-
+
-
+
-
+
diff --git a/components/layouts/pc/header.vue b/components/layouts/pc/header.vue
index 138eab7..8af9635 100644
--- a/components/layouts/pc/header.vue
+++ b/components/layouts/pc/header.vue
@@ -84,6 +84,7 @@
diff --git a/pages/login.vue b/pages/login.vue
index 3db1cfb..7a07dac 100644
--- a/pages/login.vue
+++ b/pages/login.vue
@@ -52,9 +52,12 @@
diff --git a/pages/register.vue b/pages/register.vue
index 2df10ee..1c39fdb 100644
--- a/pages/register.vue
+++ b/pages/register.vue
@@ -69,7 +69,9 @@
if (response.data) {
_ts.$message(response.data.message)
}
- }).catch(error=>{ console.log(error) })
+ }).catch(error => {
+ console.log(error)
+ })
},
register() {
let _ts = this;
@@ -107,6 +109,9 @@
}
)
}
+ },
+ mounted() {
+ this.$store.commit('setActiveMenu', 'register')
}
}
diff --git a/plugins/axios.js b/plugins/axios.js
index 150eda6..b2ddde1 100644
--- a/plugins/axios.js
+++ b/plugins/axios.js
@@ -1,28 +1,2 @@
import apiConfig from '~/config/api.config'
-export default function ({ app: { $axios, $cookies } }) {
- $axios.defaults.baseURL = apiConfig.BASE
- $axios.defaults.timeout = 30000
- $axios.interceptors.request.use(config => {
- config.headers['X-Token'] = $cookies.get('token') || ''
- config.headers['X-Device-Id'] = $cookies.get('clientId') || ''
- config.headers['X-Uid'] = $cookies.get('userId') || ''
- return config
- })
- $axios.interceptors.response.use(response => {
- if (/^[4|5]/.test(response.status)) {
- return Promise.reject(response.statusText)
- }
- let message;
- if (typeof(response.data.data) !== 'undefined') {
- message = response.data.data.message
- } else if (typeof(response.data) !== 'undefined') {
- message = response.data.message
- }
- console.log(message);
- if (response.data.success) {
- return response.data.data
- }
- return response.data
- })
-}
diff --git a/store/auth.js b/store/auth.js
deleted file mode 100644
index 85d41c6..0000000
--- a/store/auth.js
+++ /dev/null
@@ -1,83 +0,0 @@
-export const state = () => {
- return {
- isLogin: false,
- token: '',
- nickname: '',
- idUser: '',
- avatarURL: '',
- role: 0, // 0-no login, 1-admin, 2-blog admin, 3-blog author, 4-blog user, 5-visitor
- login: false
- }
-}
-
-export const mutations = {
- updateUserInfo(state, data) {
- state.isLogin = true;
- state.avatarURL = data.avatarUrl;
- state.nickname = data.nickname;
- state.token = data.token;
- state.account = data.account;
- state.role = data.weights;
- state.idUser = data.idUser;
- }
-
-}
-export const actions = {
- setLogin(state, data){
- state.login = data
- },
- setUserInfo(state, data) {
- state.avatarURL = data.avatarUrl;
- state.nickname = data.nickname;
- },
- initLogin({commit}, data = {}){
- commit('updateUserInfo', data)
- },
- logout(state){
- state.isLogin = false;
- state.avatarURL = '';
- state.nickname = '';
- state.token = '';
- state.account = '';
- state.role = '';
- state.idUser = '';
- }
-}
-
-export const getters = {
- isLogin(state){
- return state.isLogin
- },
- hasPermissions:(state)=>(scenes)=>{
- let hasPermissions = false;
- if (state.role) {
- switch (scenes) {
- case 'user':
- hasPermissions = state.role < 5;
- break;
- case 'role':
- hasPermissions = state.role < 2;
- break;
- case 'topic':
- hasPermissions = state.role < 3;
- break;
- case 'tag':
- hasPermissions = state.role < 3;
- break;
- case 'admin':
- hasPermissions = state.role < 2;
- break;
- case 'blog_admin':
- hasPermissions = state.role < 3;
- break;
- default:
- hasPermissions = false;
- this.commit('logout');
- }
- }
- return hasPermissions;
- },
- isAuthor: (state)=>(scenes)=> {
- return state.nickname === scenes ? true : false;
- }
-}
diff --git a/store/index.js b/store/index.js
index 459d60d..fce8c3c 100644
--- a/store/index.js
+++ b/store/index.js
@@ -1,11 +1,34 @@
+const cookieparser = process.server ? require('cookieparser') : undefined
+
export const state = () => {
return {
- activeMenu: 'index'
+ activeMenu: 'index',
+ oauth: null
}
}
+
+export const mutations = {
+ setAuth (state, auth) {
+ state.oauth = auth
+ },
+ setActiveMenu (state, activeMenu) {
+ state.activeMenu = activeMenu
+ }
+}
+
export const actions = {
nuxtServerInit(store, {req}) {
// 初始化时的全局任务
+ let auth = null
+ if (req.headers.cookie) {
+ const parsed = cookieparser.parse(req.headers.cookie)
+ try {
+ auth = JSON.parse(parsed.auth)
+ } catch (err) {
+ // No valid cookie found
+ }
+ store.commit('setAuth', auth)
+ }
const initFetchAppData = [
// 内容数据
store.dispatch('article/fetchList')
@@ -13,3 +36,36 @@ export const actions = {
return Promise.all(initFetchAppData)
}
}
+
+export const getters = {
+ hasPermissions: (state) => (scenes) => {
+ let hasPermissions = false;
+ const role = state.oauth?.role
+ if (role) {
+ switch (scenes) {
+ case 'user':
+ hasPermissions = role < 5;
+ break;
+ case 'role':
+ hasPermissions = role < 2;
+ break;
+ case 'topic':
+ hasPermissions = role < 3;
+ break;
+ case 'tag':
+ hasPermissions = role < 3;
+ break;
+ case 'admin':
+ hasPermissions = role < 2;
+ break;
+ case 'blog_admin':
+ hasPermissions = role < 3;
+ break;
+ default:
+ hasPermissions = false;
+ this.commit('logout');
+ }
+ }
+ return hasPermissions;
+ }
+}