parent
cf3d489d9d
commit
3307514ce0
3 changed files with 67 additions and 6 deletions
@ -0,0 +1,9 @@ |
||||
import request from "@/request/index.js" |
||||
|
||||
export const userInfo = (data) => { |
||||
return request({ |
||||
url: '/personal/userinfo', |
||||
method: 'get', |
||||
data, |
||||
}) |
||||
} |
@ -1,12 +1,27 @@ |
||||
import {createStore} from "vuex"; |
||||
|
||||
import user from "./modules/user.js" |
||||
|
||||
export default createStore({ |
||||
modules: { |
||||
user |
||||
}, |
||||
state: { |
||||
count: 0, |
||||
routeLoaded: false, // 菜单和路由是否已经加载
|
||||
firstRoute: null, // 第一个路由,用于设置进入主页 的redirect
|
||||
menuTree: null, // 菜单树
|
||||
}, |
||||
mutations: { |
||||
increase (state, count) { |
||||
state.count += count; |
||||
} |
||||
} |
||||
// 改变菜单和路由的加载状态
|
||||
setRouteLoaded(state, loaded) { |
||||
state.routeLoaded = loaded; |
||||
}, |
||||
setFirstRoute(state, route) { |
||||
state.firstRoute = route; |
||||
}, |
||||
setMenuTree(state, data) { |
||||
state.menuTree = data |
||||
}, |
||||
}, |
||||
actions: {}, |
||||
}) |
@ -0,0 +1,37 @@ |
||||
import { userInfo } from "@/apis/personal.js" |
||||
import {info} from "sass"; |
||||
export default { |
||||
namespaced: true, |
||||
state: { |
||||
token: '', |
||||
userInfo: {} // 用户基本信息
|
||||
}, |
||||
getters: { |
||||
isLogin(state) { |
||||
return !!state.token || !!localStorage.getItem("pm_token"); |
||||
} |
||||
}, |
||||
mutations: { |
||||
setToken(state, token) { |
||||
localStorage.setItem('pm_token', token); |
||||
state.token = token; |
||||
}, |
||||
clearToken(state) { |
||||
state.token = ''; |
||||
localStorage.removeItem('pm_token'); |
||||
}, |
||||
setUserInfo(state, info) { |
||||
state.userInfo = info || {}; |
||||
}, |
||||
clearUserInfo(state) { |
||||
state.userInfo = {} |
||||
} |
||||
}, |
||||
actions: { |
||||
refreshInfo({commit}) { |
||||
userInfo().then((res) => { |
||||
commit('setUserInfo', res.data) |
||||
}) |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue