@@ -39,12 +52,13 @@ import { login } from 'services'
import { computed, defineComponent, onMounted, onUnmounted, reactive, ref, toRefs } from 'vue'
import setLoginData from './tools'
import { required } from '@/validate'
-
+import { setUkeyPassword } from 'utils/auth'
export default defineComponent({
setup() {
const state = reactive({
loginForm: {
- password: ''
+ password: '',
+ ukeyPassword: ''
},
loading: false
})
@@ -93,6 +107,7 @@ export default defineComponent({
store.dispatch('permission/ResetRoutes')
}
const loginFormRef = ref()
+ const ukeyLoginFormRef = ref()
const router = useRouter()
async function handleLogin() {
const { validate } = loginFormRef.value as any
@@ -103,7 +118,7 @@ export default defineComponent({
account: userData.value.account,
password: encrypt(state.loginForm.password),
isManager: true
- })
+ }).finally(() => (state.loading = false))
if (res.success) {
setLoginData(res.data)
router.replace(lockData.path)
@@ -116,7 +131,31 @@ export default defineComponent({
})
)
}
- state.loading = false
+ })
+ }
+ async function handleUkeyLogin() {
+ const { validate } = ukeyLoginFormRef.value as any
+ validate(async (valid: boolean) => {
+ if (!valid) return
+ state.loading = true
+ const res = await store
+ .dispatch('ukey/Login', state.loginForm.ukeyPassword)
+ .catch(res => console.log(res))
+ .finally(() => (state.loading = false))
+ if (res.success) {
+ // 用于保活与监测 ukey 是否拔出
+ setUkeyPassword(state.loginForm.ukeyPassword)
+ setLoginData(res.data)
+ router.replace(lockData.path)
+ store.commit('SET_OPERATETIME')
+ localStorage.setItem(
+ 'lockData',
+ JSON.stringify({
+ ...lockData,
+ isLock: false
+ })
+ )
+ }
})
}
return {
@@ -124,9 +163,11 @@ export default defineComponent({
currentTime,
userData,
loginFormRef,
+ ukeyLoginFormRef,
required,
switchUser,
- handleLogin
+ handleLogin,
+ handleUkeyLogin
}
}
})
diff --git a/src/views/login/login.vue b/src/views/login/login.vue
index df07379..37923a1 100644
--- a/src/views/login/login.vue
+++ b/src/views/login/login.vue
@@ -13,36 +13,52 @@
{{ configs.promotionalTitle }}
-
- 账号登录
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 登录
+
+
+
+ 账号登录
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 登录
+
+
+
+
+
+
+
+
+
+
+
+ 登录
+
+
{{ configs.copyrightInformation }}
@@ -56,11 +72,14 @@ import { useStore } from 'vuex'
import { useRouter, useRoute } from 'vue-router'
import setLoginData from './tools'
import { required } from '@/validate'
+import { setUkeyPassword } from 'utils/auth'
import type { FormInstance } from 'element-plus'
+const activeName = ref('normal')
const loginForm = reactive({
account: '',
- password: ''
+ password: '',
+ ukeyPassword: ''
})
const remember = ref(false)
const loading = ref(false)
@@ -116,7 +135,22 @@ function handleLogin() {
}
})
}
-
+// ukey 登录
+async function handleUkeyLogin() {
+ if (!loginFormRef.value) return
+ 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) {
+ // 用于保活与监测 ukey 是否拔出
+ setUkeyPassword(loginForm.ukeyPassword)
+ goLogin(res.data)
+ }
+ loading.value = false
+ }
+ })
+}
function checkCapslock({ shiftKey, key }: { shiftKey: boolean; key: string }) {
if (key && key.length === 1) {
if ((shiftKey && key >= 'a' && key <= 'z') || (!shiftKey && key >= 'A' && key <= 'Z')) {
diff --git a/src/views/login/tools.ts b/src/views/login/tools.ts
index 558bb2c..2f1c86f 100644
--- a/src/views/login/tools.ts
+++ b/src/views/login/tools.ts
@@ -1,4 +1,4 @@
-import { setToken } from 'utils/auth'
+import { setToken, setTrxToken } from 'utils/auth'
import { enablePermissionStorage, menuKey, enableUserStorage, userKey } from '@/config'
export default function setLoginData(data: any) {
@@ -12,4 +12,5 @@ export default function setLoginData(data: any) {
localStorage.setItem('buttonData', JSON.stringify(data.buttons || []))
localStorage.removeItem('lockData')
setToken(data.token)
+ setTrxToken(data.trxToken)
}