69 lines
2.6 KiB
JavaScript
69 lines
2.6 KiB
JavaScript
|
import { getClientHello } from 'services/ukeyAuth.js'
|
||
|
import { getSoftLoginRandom, trxSoftLogin } from 'services/trxLogin.js'
|
||
|
import Cookies from 'js-cookie'
|
||
|
import { ElMessage } from 'element-plus'
|
||
|
const state = {}
|
||
|
const mutations = {}
|
||
|
const actions = {
|
||
|
// 登录
|
||
|
Login({ commit }, loginParam) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
// 调用 skey 获取 clientHello
|
||
|
console.log('执行 store.dispatch(skey/Login)开始,传参为password:', loginParam.password)
|
||
|
getClientHello(loginParam.password).then(checkRes => {
|
||
|
console.log('调用 skey getClientHello 方法,接口返回结果为:', checkRes)
|
||
|
if (checkRes.result !== 0) {
|
||
|
console.log('调用 skey getClientHello 方法失败,接口返回结果为:', checkRes)
|
||
|
Cookies.remove('ngx_cookie')
|
||
|
ElMessage({ message: checkRes.message, type: 'error' })
|
||
|
resolve({
|
||
|
success: false
|
||
|
})
|
||
|
}
|
||
|
const clientHello = checkRes.clientHello
|
||
|
console.log('clientHello:', clientHello)
|
||
|
Cookies.set('ngx_cookie', clientHello)
|
||
|
// 调用天融信单点登录获取 serverHello
|
||
|
getSoftLoginRandom(clientHello, loginParam.account)
|
||
|
.then(randomRes => {
|
||
|
console.log('调用 getSoftLoginRandom 方法,接口返回结果为:', randomRes)
|
||
|
if (!randomRes.success) {
|
||
|
console.log('调用 getSoftLoginRandom 方法失败,接口返回结果为:', randomRes)
|
||
|
resolve({
|
||
|
success: false
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
const randoms = randomRes.result
|
||
|
console.log('loginRandom:', randoms)
|
||
|
trxSoftLogin({clientHello, randoms, password: loginParam.password}).then(loginRes=>{
|
||
|
console.log('调用 trxSoftLogin 方法,接口返回结果为:', loginRes)
|
||
|
if (!loginRes.success) {
|
||
|
console.log('调用 trxSoftLogin 方法失败,接口返回结果为:', loginRes)
|
||
|
resolve({
|
||
|
success: false
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
resolve(loginRes)
|
||
|
return
|
||
|
}).catch(err => {
|
||
|
console.log('调用 trxSoftLogin 方法 [catch] ,接口返回结果为:', err)
|
||
|
reject(err)
|
||
|
})
|
||
|
})
|
||
|
.catch(err => {
|
||
|
console.log('调用 getSoftLoginRandom 方法 [catch] ,接口返回结果为:', err)
|
||
|
reject(err)
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
export default {
|
||
|
namespaced: true,
|
||
|
state,
|
||
|
mutations,
|
||
|
actions
|
||
|
}
|