2024-05-31 10:42:15 +00:00
|
|
|
import { USERKEY } from "../actionKey"
|
|
|
|
|
import {
|
|
|
|
|
setSessionXToken,
|
|
|
|
|
getSessionXToken,
|
|
|
|
|
setSessionUserInfo,
|
|
|
|
|
getSessionUserInfo
|
|
|
|
|
} from "@/session"
|
|
|
|
|
import * as apiService from "@/common/api"
|
|
|
|
|
import { goto } from "@/common/untool"
|
2024-09-24 15:01:05 +00:00
|
|
|
import { goLogin } from "@/common/componentEventHandle"
|
2024-05-31 10:42:15 +00:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
state: {
|
|
|
|
|
info: getSessionUserInfo(),
|
|
|
|
|
token: getSessionXToken(),
|
|
|
|
|
},
|
|
|
|
|
mutations: {
|
|
|
|
|
[USERKEY.LOGIN](state, provider) {
|
2024-07-14 05:01:59 +00:00
|
|
|
const { token, info } = provider
|
2024-05-31 10:42:15 +00:00
|
|
|
state.token = provider
|
|
|
|
|
},
|
|
|
|
|
[USERKEY.GETUSERINFO](state, provider) {
|
|
|
|
|
state.info = provider
|
|
|
|
|
},
|
2024-07-14 05:01:59 +00:00
|
|
|
[USERKEY.LOGOUT](state, provider) {
|
|
|
|
|
const { token, info } = provider
|
|
|
|
|
state.token = token;
|
|
|
|
|
state.info = info
|
2024-05-31 10:42:15 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
getters: {
|
|
|
|
|
// packInfo(state) {
|
|
|
|
|
// return state.user
|
|
|
|
|
// }
|
|
|
|
|
},
|
|
|
|
|
actions: {
|
2024-07-13 17:06:04 +00:00
|
|
|
async [USERKEY.UPDATETOKEN]({
|
|
|
|
|
dispatch,
|
|
|
|
|
commit,
|
|
|
|
|
state,
|
|
|
|
|
rootState
|
|
|
|
|
}, options) {
|
|
|
|
|
let { token } = options
|
|
|
|
|
setSessionXToken(token)
|
|
|
|
|
commit(USERKEY.LOGIN, token)
|
|
|
|
|
},
|
2024-05-31 10:42:15 +00:00
|
|
|
async [USERKEY.LOGIN]({
|
|
|
|
|
dispatch,
|
|
|
|
|
commit,
|
|
|
|
|
state,
|
|
|
|
|
rootState
|
|
|
|
|
}, options) {
|
|
|
|
|
let token = state.token
|
|
|
|
|
const resLgn = await apiService.loginByApp(options)
|
|
|
|
|
token = resLgn.token
|
2024-07-13 17:06:04 +00:00
|
|
|
dispatch(USERKEY.UPDATETOKEN, { token })
|
2024-05-31 10:42:15 +00:00
|
|
|
},
|
|
|
|
|
async [USERKEY.LOGOUT]({
|
|
|
|
|
dispatch,
|
|
|
|
|
commit,
|
|
|
|
|
state,
|
|
|
|
|
rootState
|
|
|
|
|
}, options) {
|
2024-07-14 05:01:59 +00:00
|
|
|
let info = { logout: true }
|
|
|
|
|
let token = ''
|
|
|
|
|
setSessionUserInfo(info)
|
|
|
|
|
setSessionXToken(token)
|
2024-05-31 10:42:15 +00:00
|
|
|
|
2024-07-14 05:01:59 +00:00
|
|
|
commit(USERKEY.LOGOUT, { info, token })
|
2024-05-31 10:42:15 +00:00
|
|
|
},
|
|
|
|
|
async [USERKEY.GETUSERINFO]({
|
|
|
|
|
dispatch,
|
|
|
|
|
commit,
|
|
|
|
|
state,
|
|
|
|
|
rootState
|
|
|
|
|
}, options) {
|
|
|
|
|
if(!state.token) {
|
|
|
|
|
console.log('缺少token')
|
|
|
|
|
setTimeout(()=> {
|
2024-07-31 16:54:49 +00:00
|
|
|
goLogin()
|
2024-05-31 10:42:15 +00:00
|
|
|
}, 200)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-31 05:13:32 +00:00
|
|
|
const resInfo = await apiService.getInfoByApp()
|
|
|
|
|
const { userld, nickName } = resInfo.user
|
|
|
|
|
const kefuRes = await apiService.getOnlineKefuH5Url({ userld, nickName })
|
2024-05-31 10:42:15 +00:00
|
|
|
const info = {
|
|
|
|
|
...resInfo.user,
|
|
|
|
|
roles: resInfo.user,
|
2024-10-31 05:13:32 +00:00
|
|
|
permissions: resInfo.permissions,
|
|
|
|
|
kefuH5Url: kefuRes.data,
|
2024-05-31 10:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
commit(USERKEY.GETUSERINFO, info)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|