first commit
This commit is contained in:
parent
eb44b5f2d5
commit
4bf83cc3fe
@ -71,10 +71,10 @@
|
||||
</el-link>
|
||||
</el-col>
|
||||
<el-col v-else>
|
||||
<nuxt-link to="login">
|
||||
<nuxt-link to="/login">
|
||||
<el-link :underline="false" style="margin-left: 10px;">登录</el-link>
|
||||
</nuxt-link>
|
||||
<nuxt-link to="register">
|
||||
<nuxt-link to="/register">
|
||||
<el-link :underline="false" style="margin-left: 10px;">注册</el-link>
|
||||
</nuxt-link>
|
||||
</el-col>
|
||||
@ -91,16 +91,16 @@
|
||||
return this.$store.state.activeMenu;
|
||||
},
|
||||
isLogin() {
|
||||
return this.$store.getters.isLogin;
|
||||
return this.$store.getters['auth/isLogin'];
|
||||
},
|
||||
avatarURL() {
|
||||
return this.$store.state.avatarURL;
|
||||
return this.$store.state['auth/avatarURL'];
|
||||
},
|
||||
nickname() {
|
||||
return this.$store.state.nickname;
|
||||
return this.$store.state['auth/nickname'];
|
||||
},
|
||||
hasPermissions() {
|
||||
return this.$store.getters.hasPermissions('blog_admin');
|
||||
return this.$store.getters['auth/hasPermissions(\'blog_admin\')'];
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@ -193,10 +193,10 @@
|
||||
},
|
||||
getUnreadNotifications() {
|
||||
let _ts = this;
|
||||
_ts.axios.get('/notification/unread').then(function (res) {
|
||||
_ts.$axios.$get('/api/v1/notification/unread').then(function (res) {
|
||||
if (res) {
|
||||
_ts.$set(_ts, 'notifications', res.notifications);
|
||||
_ts.$set(_ts, 'notificationNumbers', res.notifications.length == 0 ? "" : res.notifications.length);
|
||||
_ts.$set(_ts, 'notifications', res.data.notifications);
|
||||
_ts.$set(_ts, 'notificationNumbers', res.data.notifications.length == 0 ? "" : res.notifications.length);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { NODE_ENV } from '../environment'
|
||||
const apisMap = {
|
||||
development: {
|
||||
FE: 'http://localhost:3000',
|
||||
BASE: 'http://localhost:8099/vertical',
|
||||
BASE: 'https://rymcu.com/vertical-console',
|
||||
CDN: '',
|
||||
PROXY: '/proxy',
|
||||
SOCKET: 'http://localhost:3000',
|
||||
|
@ -52,6 +52,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapState } from 'vuex';
|
||||
export default {
|
||||
name: "login",
|
||||
data() {
|
||||
@ -67,6 +68,11 @@
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState({
|
||||
article: state => state.article.detail.data
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
login() {
|
||||
let _ts = this;
|
||||
@ -84,6 +90,7 @@
|
||||
_ts.$message(res.data.message);
|
||||
return false;
|
||||
}
|
||||
_ts.$store.dispatch('auth/initLogin', res.data.user);
|
||||
_ts.$router.push({
|
||||
name: 'index'
|
||||
})
|
||||
|
@ -59,7 +59,7 @@ export const actions = {
|
||||
fetchList({commit}, params = {}) {
|
||||
|
||||
// 清空已有数据
|
||||
// commit('updateListData', getDefaultListData())
|
||||
commit('updateListData', getDefaultListData())
|
||||
commit('updateListFetching', true)
|
||||
|
||||
return this.$axios
|
||||
|
83
store/auth.js
Normal file
83
store/auth.js
Normal file
@ -0,0 +1,83 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
export const state = () => {
|
||||
return {
|
||||
activeMenu: 'index'
|
||||
}
|
||||
}
|
||||
export const actions = {
|
||||
nuxtServerInit(store, {req}) {
|
||||
// 初始化时的全局任务
|
||||
|
Loading…
Reference in New Issue
Block a user