产品库增加企微端登录,登录修复

This commit is contained in:
aixianling
2022-06-13 19:47:49 +08:00
parent dcf0271990
commit ff0414cb79
2 changed files with 40 additions and 11 deletions

View File

@@ -10,7 +10,7 @@ export const config = {
mutations: {
getConfig(state, params) {
for (const key in params) {
Vue.set(state, key, user[key])
Vue.set(state, key, params[key])
}
},
clearConfig(state) {
@@ -26,7 +26,6 @@ export const config = {
if (state.agentSignURL == url) {
return Promise.resolve()
} else {
commit("clearConfig")
commit("getConfig", {agentSignURL: url})
let action = "/app/wxcp/portal/agentSign"
if (!!params?.action) {
@@ -50,6 +49,7 @@ export const config = {
...res.data,
agentSignURL: url
}
if (!!state.corpid && res.data.corpid != state.corpid) commit('clearConfig')
commit("getConfig", config)
return config
}
@@ -59,18 +59,19 @@ export const config = {
}
},
getCode({state, dispatch}, tryAgentSign = false) {
let {corpId} = state, url = location.href, REDIRECT_URI = encodeURIComponent(url), scope = "snsapi_base"
let {corpid: corpId} = state, url = location.href, REDIRECT_URI = encodeURIComponent(url), scope = "snsapi_base"
if (/\/AppForm\//.test(location.search)) {
scope = "snsapi_userinfo"
}
return new Promise((resolve, reject) => {
if (corpId && scope) {
location.replace('https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE#wechat_redirect'
.replace(/APPID/g, cid)
let oauthURL = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE#wechat_redirect'
.replace(/APPID/g, corpId)
.replace(/REDIRECT_URI/g, REDIRECT_URI)
.replace(/SCOPE/g, scope))
.replace(/SCOPE/g, scope)
location.replace(oauthURL)
} else if (!tryAgentSign) {
dispatch("agentSign").then(() => dispatch("getCode", true))
dispatch("agentSign").then(() => dispatch("getCode", true)).then(() => resolve())
} else reject("URL缺少必要参数(corpId)")
})
},
@@ -104,7 +105,7 @@ export const config = {
}).then(res => {
if (res?.access_token) {
return [res?.token_type, res?.access_token].join(" ").trim()
}
} else return Promise.reject(res.msg)
}).catch(err => {
uni.showToast({title: err, icon: 'none'})
})