2024-08-22 08:50:27 +00:00
|
|
|
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'
|
2024-08-23 08:44:39 +00:00
|
|
|
import { getTrxToken } from 'utils/auth'
|
2024-08-22 08:50:27 +00:00
|
|
|
const state = {}
|
|
|
|
const mutations = {}
|
|
|
|
const actions = {
|
|
|
|
// 登录
|
|
|
|
Login({ commit }, password) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
// 调用 ukey 获取 clientHello
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('执行 store.dispatch(ukey/Login)开始,传参为password:', password)
|
2024-08-26 08:42:26 +00:00
|
|
|
getClientHello(password).then(checkRes => {
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('调用 ukey getClientHello 方法,接口返回结果为:', checkRes)
|
2024-08-26 08:42:26 +00:00
|
|
|
if (checkRes.result !== 0) {
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('调用 ukey getClientHello 方法失败,接口返回结果为:', checkRes)
|
2024-08-26 08:42:26 +00:00
|
|
|
Cookies.remove('ngx_cookie')
|
|
|
|
ElMessage({ message: checkRes.message, type: 'error' })
|
|
|
|
resolve({
|
|
|
|
success: false
|
|
|
|
})
|
2024-08-22 08:50:27 +00:00
|
|
|
}
|
2024-08-26 08:42:26 +00:00
|
|
|
const clientHello = checkRes.clientHello
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('clientHello:', clientHello)
|
2024-08-26 08:42:26 +00:00
|
|
|
Cookies.set('ngx_cookie', clientHello)
|
|
|
|
// 调用天融信单点登录获取 serverHello
|
|
|
|
getLoginRandom(clientHello)
|
|
|
|
.then(randomRes => {
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('调用 getLoginRandom 方法,接口返回结果为:', randomRes)
|
2024-08-26 08:42:26 +00:00
|
|
|
if (!randomRes.success) {
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('调用 getLoginRandom 方法失败,接口返回结果为:', randomRes)
|
2024-08-26 08:42:26 +00:00
|
|
|
resolve({
|
|
|
|
success: false
|
|
|
|
})
|
2024-08-28 13:19:43 +00:00
|
|
|
return
|
2024-08-26 08:42:26 +00:00
|
|
|
}
|
2024-08-28 07:28:51 +00:00
|
|
|
const serverHello = randomRes.data
|
|
|
|
console.log('serverHello:', serverHello)
|
2024-08-26 08:42:26 +00:00
|
|
|
// 调用 ukey 获取 ClientAuth
|
|
|
|
getClientAuth(password, serverHello, clientHello)
|
|
|
|
.then(authRes => {
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('调用 ukey getClientAuth 方法,接口返回结果为:', authRes)
|
2024-08-26 08:42:26 +00:00
|
|
|
// 暂未用到
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
const ClientAuth = authRes.clientAuth
|
|
|
|
if (authRes.result !== 0) {
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('调用 ukey getClientAuth 方法失败,接口返回结果为:', authRes)
|
2024-08-26 08:42:26 +00:00
|
|
|
ElMessage({ message: authRes.message, type: 'error' })
|
|
|
|
resolve({
|
|
|
|
success: false
|
|
|
|
})
|
2024-08-28 13:19:43 +00:00
|
|
|
return
|
2024-08-26 08:42:26 +00:00
|
|
|
}
|
2024-08-28 14:24:27 +00:00
|
|
|
const loginName = 'key'
|
2024-08-26 08:42:26 +00:00
|
|
|
trxLogin({
|
2024-08-28 14:24:27 +00:00
|
|
|
loginName,
|
|
|
|
passwd: password,
|
|
|
|
clientHello, // 其实是接口文档里面的 cookie
|
2024-08-28 13:03:14 +00:00
|
|
|
serverHello: ClientAuth
|
2024-08-26 08:42:26 +00:00
|
|
|
}).then(tokenRes => {
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('调用 trxLogin 方法,接口返回结果为:', tokenRes)
|
2024-08-26 08:42:26 +00:00
|
|
|
if (!tokenRes.success) {
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('调用 trxLogin 方法失败,接口返回结果为:', tokenRes)
|
2024-08-26 08:42:26 +00:00
|
|
|
resolve({
|
|
|
|
success: false
|
|
|
|
})
|
2024-08-28 13:19:43 +00:00
|
|
|
return
|
2024-08-26 08:42:26 +00:00
|
|
|
}
|
|
|
|
resolve(tokenRes)
|
2024-08-28 13:19:43 +00:00
|
|
|
return
|
2024-08-26 08:42:26 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('调用 ukey getClientAuth 方法 [catch] ,接口返回结果为:', err)
|
2024-08-26 08:42:26 +00:00
|
|
|
reject(err)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2024-08-28 07:28:51 +00:00
|
|
|
console.log('调用 getLoginRandom 方法 [catch] ,接口返回结果为:', err)
|
2024-08-26 08:42:26 +00:00
|
|
|
reject(err)
|
|
|
|
})
|
|
|
|
})
|
2024-08-22 08:50:27 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
// 退出系统
|
|
|
|
Logout() {
|
|
|
|
return new Promise((resolve, reject) => {
|
2024-08-23 07:09:06 +00:00
|
|
|
resolve({
|
|
|
|
success: true
|
|
|
|
})
|
2024-08-22 08:50:27 +00:00
|
|
|
// 调用天融信单点退出系统
|
2024-08-23 08:44:39 +00:00
|
|
|
const trxToken = getTrxToken()
|
|
|
|
if (!trxToken) reject(new Error('未找到 trxToken'))
|
|
|
|
offlineToken(trxToken).then(
|
|
|
|
res => {
|
|
|
|
console.log('调用天融信单点退出系统', res)
|
|
|
|
resolve(res)
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
reject(err)
|
|
|
|
}
|
|
|
|
)
|
2024-08-22 08:50:27 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state,
|
|
|
|
mutations,
|
|
|
|
actions
|
|
|
|
}
|