|
|
|
|
@@ -9,7 +9,7 @@
|
|
|
|
|
<el-input v-model='loginForm.username' placeholder='用户名'>
|
|
|
|
|
<template #prefix>
|
|
|
|
|
<el-icon class='el-input__icon'>
|
|
|
|
|
<user />
|
|
|
|
|
<user/>
|
|
|
|
|
</el-icon>
|
|
|
|
|
</template>
|
|
|
|
|
</el-input>
|
|
|
|
|
@@ -24,11 +24,14 @@
|
|
|
|
|
>
|
|
|
|
|
<template #prefix>
|
|
|
|
|
<el-icon class='el-input__icon'>
|
|
|
|
|
<lock />
|
|
|
|
|
<lock/>
|
|
|
|
|
</el-icon>
|
|
|
|
|
</template>
|
|
|
|
|
</el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item prop='checked'>
|
|
|
|
|
<el-checkbox v-model="loginForm.checked">记住我</el-checkbox>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<div class='login-btn'>
|
|
|
|
|
<el-button
|
|
|
|
|
@@ -53,21 +56,22 @@
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang='ts'>
|
|
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
import { HOME_URL } from '@/config'
|
|
|
|
|
import { getTimeState } from '@/utils'
|
|
|
|
|
import { type Dict } from '@/api/interface'
|
|
|
|
|
import { type Login } from '@/api/user/interface/user'
|
|
|
|
|
import { ElNotification } from 'element-plus'
|
|
|
|
|
import { getDictList, loginApi } from '@/api/user/login'
|
|
|
|
|
import { useUserStore } from '@/stores/modules/user'
|
|
|
|
|
import { useTabsStore } from '@/stores/modules/tabs'
|
|
|
|
|
import { useKeepAliveStore } from '@/stores/modules/keepAlive'
|
|
|
|
|
import { initDynamicRouter } from '@/routers/modules/dynamicRouter'
|
|
|
|
|
import { CircleClose, UserFilled } from '@element-plus/icons-vue'
|
|
|
|
|
import { useAuthStore } from '@/stores/modules/auth'
|
|
|
|
|
import type { ElForm } from 'element-plus'
|
|
|
|
|
import {useRouter} from 'vue-router'
|
|
|
|
|
import {HOME_URL} from '@/config'
|
|
|
|
|
import {getTimeState} from '@/utils'
|
|
|
|
|
import {type Dict} from '@/api/interface'
|
|
|
|
|
import {type Login} from '@/api/user/interface/user'
|
|
|
|
|
import type {ElForm} from 'element-plus'
|
|
|
|
|
import {ElNotification} from 'element-plus'
|
|
|
|
|
import {getDictList, getPublicKey, loginApi} from '@/api/user/login'
|
|
|
|
|
import {useUserStore} from '@/stores/modules/user'
|
|
|
|
|
import {useTabsStore} from '@/stores/modules/tabs'
|
|
|
|
|
import {useKeepAliveStore} from '@/stores/modules/keepAlive'
|
|
|
|
|
import {initDynamicRouter} from '@/routers/modules/dynamicRouter'
|
|
|
|
|
import {CircleClose, UserFilled} from '@element-plus/icons-vue'
|
|
|
|
|
import {useAuthStore} from '@/stores/modules/auth'
|
|
|
|
|
import {useDictStore} from "@/stores/modules/dict";
|
|
|
|
|
import forge from 'node-forge'
|
|
|
|
|
|
|
|
|
|
const authStore = useAuthStore()
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
@@ -76,19 +80,22 @@ const tabsStore = useTabsStore()
|
|
|
|
|
const keepAliveStore = useKeepAliveStore()
|
|
|
|
|
|
|
|
|
|
const dictStore = useDictStore()
|
|
|
|
|
const isAutoLogin = ref(false)
|
|
|
|
|
let publicKey: any = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type FormInstance = InstanceType<typeof ElForm>;
|
|
|
|
|
const loginFormRef = ref<FormInstance>()
|
|
|
|
|
const loginRules = reactive({
|
|
|
|
|
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
|
|
|
|
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
|
|
|
|
username: [{required: true, message: '请输入用户名', trigger: 'blur'}],
|
|
|
|
|
password: [{required: true, message: '请输入密码', trigger: 'blur'}],
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
const loginForm = reactive<Login.ReqLoginForm>({
|
|
|
|
|
username: '',
|
|
|
|
|
password: '',
|
|
|
|
|
checked: false,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// login
|
|
|
|
|
@@ -99,10 +106,19 @@ const login = (formEl: FormInstance | undefined) => {
|
|
|
|
|
loading.value = true
|
|
|
|
|
try {
|
|
|
|
|
// 1.执行登录接口
|
|
|
|
|
const { data } = await loginApi({
|
|
|
|
|
...loginForm,
|
|
|
|
|
password: loginForm.password,
|
|
|
|
|
const {data} = await loginApi({
|
|
|
|
|
username: forge.util.encode64(loginForm.username),
|
|
|
|
|
password: isAutoLogin.value ? loginForm.password : encryptPassword(loginForm.password)
|
|
|
|
|
})
|
|
|
|
|
if (loginForm.checked) {
|
|
|
|
|
localStorage.setItem("loginInfo", JSON.stringify({
|
|
|
|
|
username: forge.util.encode64(loginForm.username),
|
|
|
|
|
password: isAutoLogin.value ? loginForm.password : encryptPassword(loginForm.password),
|
|
|
|
|
exp: Date.now() + 1000 * 60 * 60 * 24 * 30
|
|
|
|
|
}))
|
|
|
|
|
} else {
|
|
|
|
|
localStorage.removeItem("loginInfo")
|
|
|
|
|
}
|
|
|
|
|
userStore.setAccessToken(data.accessToken)
|
|
|
|
|
userStore.setRefreshToken(data.refreshToken)
|
|
|
|
|
userStore.setUserInfo(data.userInfo)
|
|
|
|
|
@@ -148,6 +164,33 @@ onMounted(() => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const encryptPassword = (password: string) => {
|
|
|
|
|
const encrypted = publicKey.encrypt(password, 'RSAES-PKCS1-V1_5');
|
|
|
|
|
// 将加密后的数据转换为base64格式以便传输
|
|
|
|
|
return forge.util.encode64(encrypted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onBeforeMount(async () => {
|
|
|
|
|
let loginInfoJSON = localStorage.getItem("loginInfo")
|
|
|
|
|
if (loginInfoJSON) {
|
|
|
|
|
const loginInfo = JSON.parse(loginInfoJSON)
|
|
|
|
|
if (loginInfo.exp < Date.now()) {
|
|
|
|
|
localStorage.removeItem("loginInfo")
|
|
|
|
|
} else {
|
|
|
|
|
isAutoLogin.value = true
|
|
|
|
|
loginForm.username = forge.util.decode64(loginInfo.username)
|
|
|
|
|
loginForm.password = loginInfo.password
|
|
|
|
|
loginForm.checked = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isAutoLogin.value) {
|
|
|
|
|
let {data: publicKeyBase64}:{data:string} = await getPublicKey()
|
|
|
|
|
//将base64格式的公钥转换为Forge可以使用的格式
|
|
|
|
|
const publicKeyDer = forge.util.decode64(publicKeyBase64);
|
|
|
|
|
publicKey = forge.pki.publicKeyFromPem(forge.pki.publicKeyToPem(forge.pki.publicKeyFromAsn1(forge.asn1.fromDer(publicKeyDer))));
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang='scss'>
|
|
|
|
|
|