1. 登录模块新增软key登录模块代码

develop
admin 2024-10-31 11:45:22 +08:00
parent 1c9f7fe3bf
commit ac44b970dd
3 changed files with 138 additions and 0 deletions

View File

@ -4,6 +4,14 @@ export function getLoginRandom(ngxCookie) {
return request.get('/sms/v1/trx/randomstr', { params: { ngxCookie } })
}
export function getSoftLoginRandom(ngxCookie,account) { //多传一个账号这个接口返回的结果作为randoms
return request.get('/sms/v1/trx/soft/randomstr', { params: { ngxCookie,account } })
}
export function trxSoftLogin(params) {
return request.post('/sms/v1/trx/softlogin', params)
}
export function trxLogin(params) {
return request.post('/sms/v1/trx/login', params)
}
@ -12,6 +20,14 @@ export function offlineToken(trxToken) {
return request.post('/sms/v1/trx/logout', { trxToken })
}
export function getSoftLoginRandom(ngxCookie,account) { //多传一个账号这个接口返回的结果作为randoms
return request.get('/sms/v1/trx/soft/randomstr', { params: { ngxCookie,account } })
}
export function trxSoftLogin(params) {
return request.post('/sms/v1/trx/softlogin', params)
}
// 理想那边给的代码调用 getAuthToken 时需要传 ip,云管目前不传
export function getIp() {
return request({

68
src/store/modules/skey.js Normal file
View File

@ -0,0 +1,68 @@
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
}

View File

@ -62,6 +62,39 @@
<el-button class="login-btn" type="primary" :loading="loading" @click="handleUkeyLogin"></el-button>
</div>
</el-tab-pane>
<el-tab-pane label="软KEY登录" name="SKEY">
<div v-if="activeName === 'SKEY'">
<div class="login-title">账号登录</div>
<el-form-item class="login-form-item" prop="account" :rules="[{ ...required, message: '请输入用户名' }]">
<el-input v-model="loginForm.saccount" autocomplete="off" placeholder="登录账户">
<template #prefix>
<el-icon>
<icon-ep-user />
</el-icon>
</template>
</el-input>
</el-form-item>
<el-tooltip :visible="capsTooltip" content="大写锁定已打开" placement="right" :manual="true">
<el-form-item class="login-form-item" prop="password" :rules="[{ ...required, message: '请输入密码' }]">
<el-input show-password v-model="loginForm.spassword" placeholder="密码" @blur="capsTooltip = false" @keyup="checkCapslock">
<template #prefix>
<el-icon><icon-ep-lock /></el-icon>
</template>
</el-input>
</el-form-item>
</el-tooltip>
<el-form-item class="login-form-item">
<div class="operate-region">
<span class="remember">
<el-switch v-model="remember"></el-switch>
<span class="m-l-xs">记住密码</span>
</span>
<a :href="`mailto:${configs.helpInformationLink}`" type="text" class="text-info help-info" :title="configs.helpInformationContent">{{ configs.helpInformationContent }}</a>
</div>
</el-form-item>
<el-button class="login-btn" type="primary" :loading="loading" @click="handleLogin4sKey"></el-button>
</div>
</el-tab-pane>
</el-tabs>
</el-form>
</div>
@ -144,6 +177,27 @@ function handleLogin() {
}
})
}
// key
function handleLogin4sKey() {
if (!loginFormRef.value) return
loginFormRef.value.validate(async valid => {
if (valid) {
loading.value = true
const { saccount, spassword } = loginForm
const res = await store
.dispatch('skey/Login', {account: saccount, password: spassword})
.finally(() => (loading.value = false))
.catch(() => (loading.value = false))
if (res && res.success) {
console.log('SKEY: 登录成功,云管融合登录接口返回', res)
goLogin(res.data)
} else {
console.log('SKEY: 登录失败,云管融合登录接口返回', res)
}
}
})
// ukey
async function handleUkeyLogin() {
if (!loginFormRef.value) return