Commit f91952c1 by 李伟康

commit

1 parent e9d965d3
......@@ -17,15 +17,15 @@ const state = {
}
import router from '@/router'
const mutations = {
SET_PAGE_META(state, meta) {
SET_PAGE_META (state, meta) {
state.pageMeta = meta
},
PUSH_KEEP(state, name) {
PUSH_KEEP (state, name) {
if (!state.keepAlives.includes(name)) {
state.keepAlives.push(name)
}
},
REMOVE_KEEP(state, names) {
REMOVE_KEEP (state, names) {
state.keepAlives = state.keepAlives.reduce((arr, name) => {
if (!names.includes(name)) {
return arr.push(name)
......@@ -33,40 +33,40 @@ const mutations = {
return arr
}, [])
},
SET_LAST_PATH(state, path) {
SET_LAST_PATH (state, path) {
state.lastPath = path
}
}
const actions = {
// 设置name
setUserInfo({ commit }, user) {
setUserInfo ({ commit }, user) {
commit('SET_USER_INFO', user)
store.set(store.consts.USER_KEY, user)
},
setPageMeta({ commit }, meta) {
setPageMeta ({ commit }, meta) {
document.title = meta.title || '嘀加企微助手'
commit('SET_PAGE_META', meta || {})
},
setLoginToken({ commit }, val) {
setLoginToken ({ commit }, val) {
commit('SET_LOGIN_TOKEN', val)
},
setAccountList({ commit }, list) {
setAccountList ({ commit }, list) {
commit('SET_ACCOUNT_LIST', list)
},
setSessionId({ commit }, id) {
setSessionId ({ commit }, id) {
commit('SET_SESSION_ID', id)
},
pushKeep({ commit }, name) {
pushKeep ({ commit }, name) {
commit('PUSH_KEEP', name)
},
removeKeep({ commit }, names) {
removeKeep ({ commit }, names) {
commit('REMOVE_KEEP', names)
},
registerHttp({}, sessionId = '') {
registerHttp ({ }, sessionId = '') {
console.log('sessionId', sessionId)
window.$HTTP = new Http({ ...window.$fetchConfig, alert: Notify, headers: { token: sessionId } })
},
login({ dispatch }) {
login ({ dispatch }) {
let [redirectUrl] = window.location.href.split('?')
const code = getParams('code')
if (code) {
......@@ -136,27 +136,31 @@ const actions = {
window.location.href = `${wxUrl}?appid=${appid}&redirect_uri=${encodeURIComponent(redirectUrl)}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`
}
},
navigation({ dispatch }, to) {
navigation ({ dispatch }, to) {
let { redirect_uri, corpId } = getParams()
let userInfo = util.getLocalStorage('dj_scrm_userInfo')
if (corpId) util.setLocalStorage('dj_scrm_corpId', { corpId })
if (redirect_uri) util.setLocalStorage('dj_scrm_redirect_uri', redirect_uri)
let dj_scrm = util.getLocalStorage('dj_scrm_corpId')
if (dj_scrm && userInfo) {
if (dj_scrm.corpId != userInfo.entmicroId) {
util.showLoading()
util.removeLocalStorage('dj_scrm_userInfo')
util.removeLocalStorage('dj_scrm_accountList')
util.removeLocalStorage('dj_scrm_loginToken')
util.clearSessionId()
removeStoreage()
}
}
if (corpId && dj_scrm) {
util.setLocalStorage('dj_scrm_corpId', { corpId })
if (corpId != dj_scrm.corpId) {
util.showLoading()
removeStoreage()
}
}
login({
dispatch,
to
})
}
},
}
const login = ({ dispatch, to }) => {
let loginToken = util.getLocalStorage('dj_scrm_loginToken')
let userInfo = util.getLocalStorage('dj_scrm_userInfo')
......@@ -175,7 +179,7 @@ const login = ({ dispatch, to }) => {
}
}
state.showWindow = true
}
const getParams = name => {
let [url, paramsList] = window.location.href.split('?')
......@@ -188,6 +192,12 @@ const getParams = name => {
})
return name ? obj[name] : obj
}
const removeStoreage = () => {
util.removeLocalStorage('dj_scrm_userInfo')
util.removeLocalStorage('dj_scrm_accountList')
util.removeLocalStorage('dj_scrm_loginToken')
util.clearSessionId()
}
export default {
state,
mutations,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!