Commit cd893faa by 李伟康

```

feat(sso): 新增手机号登录功能并重构SSO登录逻辑

- 添加loginByPhone接口方法用于手机号登录
- 配置双HTTP客户端($SCRM_HTTP和$DJ_HTTP)支持不同业务域
- 重构登录流程,支持企业微信授权码和手机号双重验证
- 增强错误处理机制,提供更详细的错误提示信息
- 更新页面标题默认值为"企微招聘"
```
1 parent 410ff717
const url = '/rop-scrm-sso/router' const ssoUrl = '/rop-scrm-sso/router',
biUrl = 'rop-dj-pe-analysis/router'
export default { export default {
login (data = {}) { login (data = {}) {
data.method = 'scrm.api.sso.ww.bioauth.login' data.method = 'scrm.api.sso.ww.bioauth.login'
data.productCode = 'PC00025' data.productCode = 'PC00025'
return window.$HTTP({ return window.$SCRM_HTTP({
url, url: ssoUrl,
data, data,
returnAll: true returnAll: true
}) })
}, },
loginByPhone(data = {}){
data.method = 'dj.api.smartcarlife.peAnalysis.loginByPhone'
return window.$DJ_HTTP({
url: biUrl,
data,
// returnAll: true
})
}
} }
...@@ -19,37 +19,61 @@ const mutations = { ...@@ -19,37 +19,61 @@ const mutations = {
} }
const actions = { const actions = {
setPageMeta ({ commit }, meta) { setPageMeta ({ commit }, meta) {
document.title = meta.title || '标题' document.title = meta.title || '企微招聘'
commit('SET_PAGE_META', meta) commit('SET_PAGE_META', meta)
}, },
registerHttp ({ }, sessionId = '') { registerHttp ({ }, sessionId = '') {
window.$HTTP = new Http({ ...window.$fetchConfig, alert: Notify, headers: { token: sessionId } }) let { scrmRequest, djRequest } = window.$fetchConfig
window.$SCRM_HTTP = new Http({ ...scrmRequest, alert: Notify })
window.$DJ_HTTP = new Http({ ...djRequest, alert: Notify, headers: { token: sessionId } })
}, },
async login ({ dispatch }) { async login ({ dispatch }) {
const code = getParams('code'), try {
const wwCode = getParams('code'),
{ corpId, agentId } = util.getLocalStorage('ww_storage_info'), { corpId, agentId } = util.getLocalStorage('ww_storage_info'),
paramsPhone = util.getLocalStorage('ww_params_phone'),
{ loginUrl } = window.$fetchConfig, { loginUrl } = window.$fetchConfig,
[redirectUrl] = window.location.href.split('?') [redirectUrl] = window.location.href.split('?')
if (code) { if (wwCode) {
const data = await ssoApi.login({ const { code, data, message } = await ssoApi.login({
code, code: wwCode,
corpId, corpId,
getUserInfoFlag: agentId ? true : false getUserInfoFlag: false
}) })
console.log(data) if (code == 0) {
// let route = state.lastPath == 'index' ? '' : state.lastPath || '' if (data.loginList && data.loginList.length) {
// route = route.replace('.', '/') let [item] = data.loginList
// util.setLocalStorage('ww_userInfo', userInfo) if (item.loginList && item.loginList.length) {
// util.setSessionId(userInfo.sessionId) let [userInfo] = item.loginList,
// dispatch('registerHttp', userInfo.sessionId) { phone } = userInfo
// state.showWindow = true if (paramsPhone == phone) {
// window.location.replace(`${redirectUrl}#/${route}`) const res = await ssoApi.loginByPhone({
phone,
})
if (res) {
let route = state.lastPath == 'index' ? '' : state.lastPath || ''
route = route.replace('.', '/')
util.setLocalStorage('ww_userInfo', res)
util.setSessionId(res.sessionId)
dispatch('registerHttp', res.sessionId)
state.showWindow = true
window.location.replace(`${redirectUrl}#/${route}`)
} else throw ''
} else throw '手机号不一致'
} else throw ''
} else throw ''
} else throw message
} }
else window.location.href = `${loginUrl}?redirect_uri=${encodeURIComponent(window.location.href)}&corpId=${corpId}&agentId=${agentId}&backLoginCode=BACKCODE` else window.location.href = `${loginUrl}?redirect_uri=${encodeURIComponent(window.location.href)}&corpId=${corpId}&agentId=${agentId}&backLoginCode=BACKCODE`
} catch (error) {
if (!error) error = '登录失败或无权限'
if (error) Notify(typeof error === 'string' ? error : error.toString())
}
}, },
navigation ({ dispatch }, to) { navigation ({ dispatch }, to) {
let { corpId, agentId } = getParams() let { corpId, agentId, phone } = getParams(),
let userInfo = util.getLocalStorage('ww_userInfo') userInfo = util.getLocalStorage('ww_userInfo')
if (phone) util.setLocalStorage('ww_params_phone', phone)
dispatch('registerHttp') dispatch('registerHttp')
if (corpId) { if (corpId) {
let ww_storage_info = {} let ww_storage_info = {}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!