From cbfa87d1b162cf5532762e8054579e0909489f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E5=90=AF=E9=BE=99?= Date: Mon, 26 Aug 2024 16:42:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ukey=20=E7=99=BB=E5=BD=95=E8=81=94?= =?UTF-8?q?=E8=B0=83=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/trxLogin.js | 10 +--- src/store/modules/ukey.js | 101 +++++++++++++++++++------------------- src/views/login/login.vue | 5 +- 3 files changed, 53 insertions(+), 63 deletions(-) diff --git a/src/services/trxLogin.js b/src/services/trxLogin.js index 4fe4f87..5f0520c 100644 --- a/src/services/trxLogin.js +++ b/src/services/trxLogin.js @@ -1,15 +1,7 @@ import request from 'utils/request' export function getLoginRandom(ngxCookie) { - return request.get( - '/sms/v1/trx/getRandomStr', - {}, - { - headers: { - ngxCookie - } - } - ) + return request.get('/sms/v1/trx/randomstr', { params: { ngxCookie } }) } export function trxLogin(params) { diff --git a/src/store/modules/ukey.js b/src/store/modules/ukey.js index 276462a..f04b915 100644 --- a/src/store/modules/ukey.js +++ b/src/store/modules/ukey.js @@ -10,58 +10,57 @@ 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) + getClientHello(password).then(checkRes => { + if (checkRes.result !== 0) { + Cookies.remove('ngx_cookie') + ElMessage({ message: checkRes.message, type: 'error' }) + resolve({ + success: false + }) } - ) + const clientHello = checkRes.clientHello + Cookies.set('ngx_cookie', clientHello) + // 调用天融信单点登录获取 serverHello + getLoginRandom(clientHello) + .then(randomRes => { + if (!randomRes.success) { + resolve({ + success: false + }) + } + let serverHello = randomRes.data + // 调用 ukey 获取 ClientAuth + getClientAuth(password, serverHello, clientHello) + .then(authRes => { + // 暂未用到 + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const ClientAuth = authRes.clientAuth + if (authRes.result !== 0) { + ElMessage({ message: authRes.message, type: 'error' }) + resolve({ + success: false + }) + } + trxLogin({ + clientHello, + serverHello + }).then(tokenRes => { + if (!tokenRes.success) { + resolve({ + success: false + }) + } + resolve(tokenRes) + }) + }) + .catch(err => { + reject(err) + }) + }) + .catch(err => { + reject(err) + }) + }) }) }, // 退出系统 diff --git a/src/views/login/login.vue b/src/views/login/login.vue index 765c3c7..8c83d93 100644 --- a/src/views/login/login.vue +++ b/src/views/login/login.vue @@ -142,13 +142,12 @@ async function handleUkeyLogin() { loginFormRef.value.validate(async valid => { if (valid) { loading.value = true - const res = await store.dispatch('ukey/Login', loginForm.ukeyPassword).catch(res => console.log(res)) - if (res.success) { + const res = await store.dispatch('ukey/Login', loginForm.ukeyPassword).finally(() => (loading.value = false)) + if (res && res.success) { // 用于保活与监测 ukey 是否拔出 setUkeyPassword(loginForm.ukeyPassword) goLogin(res.data) } - loading.value = false } }) }