Commit 41014c0b by yancanhua

fix: 企业微信授权登录开发

1 parent 2d1f8285
...@@ -17,6 +17,7 @@ export default { ...@@ -17,6 +17,7 @@ export default {
name: 'App', name: 'App',
data() { data() {
return { return {
showWindow: false
} }
}, },
watch: { watch: {
...@@ -33,8 +34,7 @@ export default { ...@@ -33,8 +34,7 @@ export default {
return this.$store.state.app.showWindow return this.$store.state.app.showWindow
} }
}, },
mounted() { mounted() {},
},
methods: {} methods: {}
} }
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
* @LastEditTime: 2021-06-17 18:23:27 * @LastEditTime: 2021-06-17 18:23:27
*/ */
import indexApi from './indexApi' import indexApi from './indexApi'
import ssoApi from './ssoApi'
export { export {
indexApi, indexApi,
ssoApi,
} }
\ No newline at end of file \ No newline at end of file
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.$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
})
},
}
...@@ -36,6 +36,9 @@ router.beforeEach((to, from, next) => { ...@@ -36,6 +36,9 @@ router.beforeEach((to, from, next) => {
document.documentElement.style.backgroundColor = to.meta.backgroundColor || '#fff' document.documentElement.style.backgroundColor = to.meta.backgroundColor || '#fff'
to.matched.forEach(recode => { to.matched.forEach(recode => {
console.log(recode) console.log(recode)
setTimeout(() => {
store.dispatch('login')
}, 1200)
}) })
if (to.matched.some(recode => recode.meta.noAuth)) { if (to.matched.some(recode => recode.meta.noAuth)) {
console.log('noAuth') console.log('noAuth')
......
...@@ -10,16 +10,24 @@ ...@@ -10,16 +10,24 @@
import { util } from 'utils' import { util } from 'utils'
import { Http } from 'glsx-common' import { Http } from 'glsx-common'
import { Notify } from 'vant' import { Notify } from 'vant'
import { ssoApi } from '@/api'
const state = { const state = {
showWindow: false showWindow: false,
lastPath: ''
} }
import router from '@/router' import router from '@/router'
const mutations = { const mutations = {
SET_PAGE_META (state, meta) { SET_PAGE_META(state, meta) {
state.pageMeta = meta state.pageMeta = meta
}, },
SET_LAST_PATH(state, path) {
state.lastPath = path
}
} }
const actions = { const actions = {
setPageMeta ({ commit }, meta) { setPageMeta ({ commit }, meta) {
document.title = meta.title || '企微通知模板' document.title = meta.title || '企微通知模板'
...@@ -31,14 +39,58 @@ const actions = { ...@@ -31,14 +39,58 @@ const actions = {
window.$HTTP = new Http({ ...djRequest, alert: Notify, headers: { token: sessionId } }) window.$HTTP = new Http({ ...djRequest, alert: Notify, headers: { token: sessionId } })
// window.$HTTP = new Http({ ...window.$fetchConfig, alert: Notify, headers: { token: sessionId } }) // window.$HTTP = new Http({ ...window.$fetchConfig, alert: Notify, headers: { token: sessionId } })
}, },
login ({ dispatch }) {
const { corpId, agentId } = util.getLocalStorage('ww_storage_info'),
{ loginUrl } = window.$fetchConfig login({ dispatch, state }) {
window.location.href = `${loginUrl}?redirect_uri=${encodeURIComponent(window.location.href)}&corpId=${corpId}&agentId=${agentId}` //获取当前路由路径
const currentPath = window.location.href;
const pathKeywords = ['/department', '/personage', '/company'];
const isTargetPath = pathKeywords.some(keyword => currentPath.includes(keyword));
if (isTargetPath) {
try {
let { corpId, agentId } = getParams();
const wwCode = getParams('code');
let { loginUrl } = window.$fetchConfig;
let userInfo = util.getLocalStorage('ww_userInfo');
if(userInfo) return state.showWindow = true;
if (wwCode) {
ssoApi.login({ code: wwCode, corpId, getUserInfoFlag: false }).then(res => {
const { code, data, message } = res;
state.showWindow = false
if (code == 0) {
state.showWindow = true;
if (data.loginList && data.loginList.length) {
let [item] = data.loginList
if (item.loginList && item.loginList.length) {
let [userInfo] = item.loginList,
{ phone } = userInfo
if (phone) util.setLocalStorage('ww_params_phone', phone)
util.setLocalStorage('ww_userInfo', userInfo)
} 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())
}
} else {
state.showWindow = true
const { corpId, agentId } = util.getLocalStorage('ww_storage_info'),
{ loginUrl } = window.$fetchConfig;
window.location.href = `${loginUrl}?redirect_uri=${encodeURIComponent(window.location.href)}&corpId=${corpId}&agentId=${agentId}`
}
}, },
navigation ({ dispatch }, to) {
let { corpId, agentId } = getParams() navigation({ dispatch }, to) {
let userInfo = util.getLocalStorage('ww_userInfo') let { corpId, agentId, phone, name,id } = getParams(),
userInfo = util.getLocalStorage('ww_userInfo')
if (phone) util.setLocalStorage('ww_params_phone', phone)
if (name) util.setLocalStorage('ww_params_name', name)
if (id) util.setLocalStorage('ww_params_id', id)
dispatch('registerHttp') dispatch('registerHttp')
if (corpId) { if (corpId) {
let ww_storage_info = {} let ww_storage_info = {}
...@@ -52,7 +104,7 @@ const actions = { ...@@ -52,7 +104,7 @@ const actions = {
util.showLoading() util.showLoading()
dispatch('login') dispatch('login')
} }
}, }
} }
const getParams = name => { const getParams = name => {
let [url, paramsList] = window.location.href.split('?') let [url, paramsList] = window.location.href.split('?')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!