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 {
login (data = {}) {
data.method = 'scrm.api.sso.ww.bioauth.login'
data.productCode = 'PC00025'
return window.$HTTP({
url,
return window.$SCRM_HTTP({
url: ssoUrl,
data,
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 = {
}
const actions = {
setPageMeta ({ commit }, meta) {
document.title = meta.title || '标题'
document.title = meta.title || '企微招聘'
commit('SET_PAGE_META', meta)
},
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 }) {
const code = getParams('code'),
{ corpId, agentId } = util.getLocalStorage('ww_storage_info'),
{ loginUrl } = window.$fetchConfig,
[redirectUrl] = window.location.href.split('?')
if (code) {
const data = await ssoApi.login({
code,
corpId,
getUserInfoFlag: agentId ? true : false
})
console.log(data)
// let route = state.lastPath == 'index' ? '' : state.lastPath || ''
// route = route.replace('.', '/')
// util.setLocalStorage('ww_userInfo', userInfo)
// util.setSessionId(userInfo.sessionId)
// dispatch('registerHttp', userInfo.sessionId)
// state.showWindow = true
// window.location.replace(`${redirectUrl}#/${route}`)
}
else window.location.href = `${loginUrl}?redirect_uri=${encodeURIComponent(window.location.href)}&corpId=${corpId}&agentId=${agentId}&backLoginCode=BACKCODE`
try {
const wwCode = getParams('code'),
{ corpId, agentId } = util.getLocalStorage('ww_storage_info'),
paramsPhone = util.getLocalStorage('ww_params_phone'),
{ loginUrl } = window.$fetchConfig,
[redirectUrl] = window.location.href.split('?')
if (wwCode) {
const { code, data, message } = await ssoApi.login({
code: wwCode,
corpId,
getUserInfoFlag: false
})
if (code == 0) {
if (data.loginList && data.loginList.length) {
let [item] = data.loginList
if (item.loginList && item.loginList.length) {
let [userInfo] = item.loginList,
{ phone } = userInfo
if (paramsPhone == phone) {
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`
} catch (error) {
if (!error) error = '登录失败或无权限'
if (error) Notify(typeof error === 'string' ? error : error.toString())
}
},
navigation ({ dispatch }, to) {
let { corpId, agentId } = getParams()
let userInfo = util.getLocalStorage('ww_userInfo')
let { corpId, agentId, phone } = getParams(),
userInfo = util.getLocalStorage('ww_userInfo')
if (phone) util.setLocalStorage('ww_params_phone', phone)
dispatch('registerHttp')
if (corpId) {
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!