88 lines
2.6 KiB
JavaScript
88 lines
2.6 KiB
JavaScript
|
import { getClientHello, getClientAuth } from 'services/ukeyAuth.js'
|
||
|
import { getLoginRandom, trxLogin, offlineToken } from 'services/trxLogin.js'
|
||
|
import Cookies from 'js-cookie'
|
||
|
import { ElMessage } from 'element-plus'
|
||
|
const state = {}
|
||
|
const mutations = {}
|
||
|
const actions = {
|
||
|
// 登录
|
||
|
Login({ commit }, password) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
// 调用 ukey 获取 clientHello
|
||
|
getClientHello(password).then(
|
||
|
checkRes => {
|
||
|
if (checkRes.result !== 0) {
|
||
|
Cookies.remove('ngx_cookie')
|
||
|
ElMessage({ message: checkRes.message, type: 'error' })
|
||
|
return Promise.reject(new Error(checkRes.message))
|
||
|
}
|
||
|
const clientHello = checkRes.clientHello
|
||
|
Cookies.set('ngx_cookie', clientHello)
|
||
|
// 调用天融信单点登录获取 serverHello
|
||
|
getLoginRandom(clientHello).then(
|
||
|
randomRes => {
|
||
|
if (!randomRes.success) {
|
||
|
ElMessage({ message: randomRes.message, type: 'error' })
|
||
|
return Promise.reject(new Error(randomRes.message))
|
||
|
}
|
||
|
let serverHello = randomRes.data
|
||
|
// 调用 ukey 获取 ClientAuth
|
||
|
getClientAuth(password, serverHello, clientHello).then(
|
||
|
authRes => {
|
||
|
// 暂未用到
|
||
|
const ClientAuth = authRes.clientAuth
|
||
|
trxLogin({
|
||
|
clientHello,
|
||
|
serverHello
|
||
|
}).then(
|
||
|
tokenRes => {
|
||
|
if (!tokenRes.success) {
|
||
|
ElMessage({ message: tokenRes.message, type: 'error' })
|
||
|
return Promise.reject(new Error(tokenRes.message))
|
||
|
}
|
||
|
resolve(tokenRes)
|
||
|
},
|
||
|
err => {
|
||
|
reject(err)
|
||
|
}
|
||
|
)
|
||
|
},
|
||
|
err => {
|
||
|
reject(err)
|
||
|
}
|
||
|
)
|
||
|
},
|
||
|
err => {
|
||
|
reject(err)
|
||
|
}
|
||
|
)
|
||
|
},
|
||
|
err => {
|
||
|
reject(err)
|
||
|
}
|
||
|
)
|
||
|
})
|
||
|
},
|
||
|
// 退出系统
|
||
|
Logout() {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
// 调用天融信单点退出系统
|
||
|
offlineToken().then(
|
||
|
res => {
|
||
|
console.log('调用天融信单点退出系统', res)
|
||
|
resolve(res)
|
||
|
},
|
||
|
err => {
|
||
|
reject(err)
|
||
|
}
|
||
|
)
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
export default {
|
||
|
namespaced: true,
|
||
|
state,
|
||
|
mutations,
|
||
|
actions
|
||
|
}
|