123456789101112131415161718192021222324252627282930313233 |
- export const setUser = (state, payload) => {
- state.user = payload;
- // let res = true;
- // //登陆时
- // if (payload) {
- // state.token = payload;
- // } else {
- // //已经登陆,切换路由时取出用户信息放在总store中
- // let token = localStorage.getItem('token');
- // if (token && token !== 'guest') {
- // state.user = jwt.decode(token);
- // } else if (token && token == 'guest') {
- // let user = localStorage.getItem('user');
- // state.user = JSON.parse(user);
- // } else {
- // let timestamp = new Date().getTime();
- // let user = {
- // // id: `guest${timestamp}`,
- // name: `游客${timestamp}`,
- // };
- // state.user = user;
- // localStorage.setItem('token', 'guest');
- // localStorage.setItem('user', JSON.stringify(user));
- // console.warn('游客身份');
- // }
- // }
- // return res;
- };
- export const deleteUser = (state, payload) => {
- state.user = {};
- localStorage.removeItem('token');
- };
|