|
@@ -7,67 +7,67 @@ Vue.use(Vuex)
|
|
|
const KEY_LAST_ROUTE = 'last_route'
|
|
|
|
|
|
const store = new Vuex.Store({
|
|
|
- modules: {},
|
|
|
- state: {
|
|
|
- name: '这里是全局的',
|
|
|
- projects: [
|
|
|
- ],
|
|
|
- projectId: 'Pj4419000005',
|
|
|
- comeUrl: '',
|
|
|
- flag: 'wanke',
|
|
|
- token: null,
|
|
|
- lastRoute: null,
|
|
|
- userInfo: {
|
|
|
+ modules: {},
|
|
|
+ state: {
|
|
|
+ name: '这里是全局的',
|
|
|
+ projects: [
|
|
|
+ ],
|
|
|
+ projectId: 'Pj4419000005',
|
|
|
+ comeUrl: '',
|
|
|
+ flag: 'wanke',
|
|
|
+ token: null,
|
|
|
+ lastRoute: null,
|
|
|
+ userInfo: {
|
|
|
|
|
|
- }
|
|
|
- },
|
|
|
- getters: {
|
|
|
- flag: state => state.flag,
|
|
|
- token: state => state.token,
|
|
|
- lastRoute: state => {
|
|
|
- if (!state.lastRoute) {
|
|
|
- let lastRoute = storage.get(KEY_LAST_ROUTE)
|
|
|
- if (lastRoute) {
|
|
|
- state.lastRoute = lastRoute
|
|
|
}
|
|
|
- }
|
|
|
- return state.lastRoute
|
|
|
- }
|
|
|
- },
|
|
|
- mutations: {
|
|
|
- setProjects(state, projects) {
|
|
|
- state.projects = projects
|
|
|
},
|
|
|
- setProId(state, projectId) {
|
|
|
- state.projectId = projectId
|
|
|
+ getters: {
|
|
|
+ flag: state => state.flag,
|
|
|
+ token: state => state.token,
|
|
|
+ lastRoute: state => {
|
|
|
+ if (!state.lastRoute) {
|
|
|
+ let lastRoute = storage.get(KEY_LAST_ROUTE)
|
|
|
+ if (lastRoute) {
|
|
|
+ state.lastRoute = lastRoute
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return state.lastRoute
|
|
|
+ }
|
|
|
},
|
|
|
- setComeUrl(state, comeUrl) {
|
|
|
- state.comeUrl = comeUrl
|
|
|
+ mutations: {
|
|
|
+ setProjects(state, projects) {
|
|
|
+ state.projects = projects
|
|
|
+ },
|
|
|
+ setProId(state, projectId) {
|
|
|
+ state.projectId = projectId
|
|
|
+ },
|
|
|
+ setComeUrl(state, comeUrl) {
|
|
|
+ state.comeUrl = comeUrl
|
|
|
+ },
|
|
|
+ setSsoToken: (state, val) => (state.token = val),
|
|
|
+ setLastRoute: (state, val) => {
|
|
|
+ state.lastRoute = val
|
|
|
+ storage.set(KEY_LAST_ROUTE, val)
|
|
|
+ },
|
|
|
+ setUserInfo(state, { userInfo }) {
|
|
|
+ state.userInfo = userInfo
|
|
|
+ }
|
|
|
},
|
|
|
- setSsoToken: (state, val) => (state.token = val),
|
|
|
- setLastRoute: (state, val) => {
|
|
|
- state.lastRoute = val
|
|
|
- storage.set(KEY_LAST_ROUTE, val)
|
|
|
+ actions: {
|
|
|
+ async loadUserInfo(context, { token }) {
|
|
|
+ let res = await axios.get('/server/userInfo', { params: { token: token } })
|
|
|
+ if (res.data.result == 'success') {
|
|
|
+ // commit 到vuex, 供全局使用
|
|
|
+ context.commit('setUserInfo', { userInfo: res.data })
|
|
|
+ context.commit('setProjects', { projects: res.data.projects })
|
|
|
+ localStorage.setItem('token', token)
|
|
|
+ } else {
|
|
|
+ let ssoServer = 'http://10.199.143.85:7003'
|
|
|
+ let redirectUrl = window.location.protocol + '//' + window.location.host + '/strategy'
|
|
|
+ window.location.href = `${ssoServer}/login?redirectUrl=${redirectUrl}`
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
- setUserInfo(state, { userInfo }) {
|
|
|
- state.userInfo = userInfo
|
|
|
- }
|
|
|
- },
|
|
|
- actions: {
|
|
|
- async loadUserInfo(context, { token }) {
|
|
|
- let res = await axios.get('/server/userInfo', { params: { token: token } })
|
|
|
- if (res.data.result == 'success') {
|
|
|
- // commit 到vuex, 供全局使用
|
|
|
- context.commit('setUserInfo', { userInfo: res.data })
|
|
|
- context.commit('setProjects', { projects: res.data.projects })
|
|
|
- localStorage.setItem('token', token)
|
|
|
- } else {
|
|
|
- let ssoServer = 'http://sso.sagacloud.cn'
|
|
|
- let redirectUrl = window.location.protocol + '//' + window.location.host + '/strategy'
|
|
|
- window.location.href = `${ssoServer}/login?redirectUrl=${redirectUrl}`
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
})
|
|
|
|
|
|
export default store
|