Commit 62ef216c by 李伟康

```

feat(app): 添加企业微信登录回退和授权作用域功能

- 新增 ww_back_login_code 和 ww_login_type 本地存储
- 支持通过 URL 参数传递登录类型和回退登录 CODE
- 实现登录成功后的回退逻辑处理
- 支持 snsapi_base 和 snsapi_privateinfo 授权作用域配置
- 优化微信登录面板的登录类型参数传递
```
1 parent c5009072
......@@ -73,13 +73,24 @@ const actions = {
const wwcode = getParams('code')
if (wwcode) {
const { corpId, agentId } = util.getLocalStorage('ww_storage_info')
let redirect_uri = util.getLocalStorage('ww_redirect_uri'),
url = `${redirectUrl.split('#')[0]}#/`,
backLoginCode = util.getLocalStorage('ww_back_login_code')
if (backLoginCode) {
if (redirect_uri) {
let [URL, query] = decodeURIComponent(redirect_uri).split('?')
URL = `${URL}?code=${wwcode}`
if (query) URL = `${URL}&${query}`
window.location.href = URL
}
else window.location.href = url
return
}
ssoApi.login({
code: wwcode,
corpId,
agentId
}).then(res => {
let redirect_uri = util.getLocalStorage('ww_redirect_uri'),
url = `${redirectUrl.split('#')[0]}#/`
if (res.errCode == 0 && res.userId) {
util.setLocalStorage('ww_userInfo', {
userId: res.userId,
......@@ -98,8 +109,14 @@ const actions = {
util.showLoading()
let appid = getParams('corpId') //从链接获取
let agentid = getParams('agentId') //从链接获取
let logintype = getParams('loginType') //从链接登录类型
let backLoginCode = getParams('backLoginCode') // 返回登录CODE
let storage_info = util.getLocalStorage('ww_storage_info')
let scope = getParams('scope') || 'snsapi_privateinfo' //应用授权作用域。 oauth2登录时可选snsapi_base:静默授权,snsapi_privateinfo:手动授权, 默认手动
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV)
if (logintype) util.setLocalStorage('ww_login_type', logintype)
if (backLoginCode) util.setLocalStorage('ww_back_login_code', backLoginCode)
util.setLocalStorage('ww_scope', scope)
if (!appid) {
if (storage_info) {
appid = storage_info.corpId
......@@ -120,10 +137,10 @@ const actions = {
let wxUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize'
wxUrl = `${wxUrl}?appid=${appid}&redirect_uri=${encodeURIComponent(redirectUrl)}&response_type=code`
if (agentid && agentid != 'undefined') {
wxUrl = `${wxUrl}&scope=snsapi_privateinfo&agentid=${agentid}`
wxUrl = `${wxUrl}&scope=${scope}&agentid=${agentid}`
ww_storage_info.agentId = agentid
}
else wxUrl = `${wxUrl}&scope=snsapi_base`
else wxUrl = `${wxUrl}&scope=${scope}`
window.location.href = `${wxUrl}&state=STATE#wechat_redirect`
} else if (env == 2) {
......
......@@ -14,6 +14,12 @@ export default {
},
wwRedirectUrl () {
return this.getLocalStorage('ww_redirect_uri') || ''
},
loginType () {
return this.getLocalStorage('ww_login_type') || 'CorpApp'
},
backLoginCode () {
return this.getLocalStorage('ww_back_login_code') || false
}
},
data () {
......@@ -24,11 +30,13 @@ export default {
[redirectUrl] = window.location.href.split('?'),
url = `${redirectUrl.split('#')[0]}#/`,
redirect_uri = this.wwRedirectUrl,
{ loginType, backLoginCode } = this,
_this = this
ww.createWWLoginPanel({
el: '#wwlogin',
params: {
login_type: 'CorpApp',
login_type: loginType,
appid: corpId,
agentid: agentId,
redirect_uri: redirectUrl,
......@@ -37,6 +45,15 @@ export default {
},
async onLoginSuccess ({ code }) {
try {
if (backLoginCode) {
if (redirect_uri) {
let [URL, query] = decodeURIComponent(redirect_uri).split('?')
URL = `${URL}?code=${code}`
if (query) URL = `${URL}&${query}`
window.location.href = URL
} else throw '请设置回调地址'
return
}
const res = await ssoApi.login({ code, corpId, agentId })
if (res.errCode == 0 && res.userId) {
_this.setLocalStorage('ww_userInfo', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!