app.js
3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { util } from 'utils'
import { Http } from 'glsx-common'
import { Notify } from 'vant'
import { ssoApi } from '@/api'
const state = {
showWindow: false,
lastPath: ''
}
import router from '@/router'
const mutations = {
SET_PAGE_META(state, meta) {
state.pageMeta = meta
},
SET_LAST_PATH(state, path) {
state.lastPath = path
}
}
const actions = {
setPageMeta({ commit }, meta) {
document.title = meta.title || '企微招聘'
commit('SET_PAGE_META', meta)
},
registerHttp({}, 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 }) {
console.log('login')
//agentId=1000002&corpId=wwa55ffac1225eb25e //开发环境
// return
try {
const wwCode = getParams('code'),
{ corpId, agentId } = util.getLocalStorage('ww_storage_info') || {},
paramsPhone = util.getLocalStorage('ww_params_phone'),
{ loginUrl } = window.$fetchConfig
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 || '',
[jumpUrl] = window.location.href.split('/#/')
route = route.replace('.', '/')
util.setLocalStorage('ww_userInfo', userInfo)
// util.setSessionId(res.sessionId)
// dispatch('registerHttp', res.sessionId)
state.showWindow = true
console.log(jumpUrl)
window.location.replace(`${jumpUrl}/#/${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, 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')
if (corpId) {
let ww_storage_info = {}
ww_storage_info.corpId = corpId
if (agentId && agentId != 'undefined') ww_storage_info.agentId = agentId
util.setLocalStorage('ww_storage_info', ww_storage_info)
}
if (userInfo) {
state.showWindow = true
} else {
util.showLoading()
dispatch('login')
}
}
}
const getParams = name => {
let [url, paramsList] = window.location.href.split('?')
if (!paramsList) return name ? null : {}
let param = paramsList.split('&')
let obj = {}
param.map(e => {
let [key, value] = e.split('=')
obj[key] = value
})
return name ? obj[name] : obj
}
export default {
state,
mutations,
actions
}