|
@@ -1,16 +1,28 @@
|
|
|
// import {getToken,setToken,removeToken} from '@/utils/auth'
|
|
|
+import { Message } from 'element-ui';
|
|
|
const state = {
|
|
|
- authToken:localStorage.getItem('authToken') ? localStorage.getItem('authToken'):'', //设置token为共享状态 初始化vuex的时候 就先从缓存中读取
|
|
|
- username:'',
|
|
|
+ authToken: localStorage.getItem('authToken') ? localStorage.getItem('authToken') : '', //设置token为共享状态 初始化vuex的时候 就先从缓存中读取
|
|
|
+ username: '',
|
|
|
}
|
|
|
const mutations = {
|
|
|
- REMOVE_TOKEN(state){
|
|
|
+ REMOVE_TOKEN(state) {
|
|
|
localStorage.removeItem('authToken');
|
|
|
+ localStorage.removeItem('username');
|
|
|
+ state.authToken = "";
|
|
|
+ state.username = "";
|
|
|
+ Message({
|
|
|
+ message: '退出成功',
|
|
|
+ type: 'success'
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ window.location.reload();
|
|
|
+ }, 1000);
|
|
|
+
|
|
|
},
|
|
|
SET_TOKEN: (state, token_name) => {
|
|
|
state.authToken = token_name.token;
|
|
|
state.username = token_name.username;
|
|
|
- localStorage.setItem('authToken', token_name.token);
|
|
|
+ localStorage.setItem('authToken', token_name.token);
|
|
|
localStorage.setItem('username', token_name.username);
|
|
|
},
|
|
|
SET_NAME: (state, name) => {
|
|
@@ -18,16 +30,16 @@ const mutations = {
|
|
|
},
|
|
|
}
|
|
|
const actions = {
|
|
|
- async login(context,data){
|
|
|
+ async login(context, data) {
|
|
|
const result = await login(data)
|
|
|
- if(result.data.sucess){
|
|
|
+ if (result.data.sucess) {
|
|
|
//调用vuex中setToken方法
|
|
|
- context.commit('setToken',result.data.data)
|
|
|
+ context.commit('setToken', result.data.data)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
export default {
|
|
|
- namespaced:true,
|
|
|
+ namespaced: true,
|
|
|
state,
|
|
|
mutations,
|
|
|
actions,
|