<template>
|
<div class="login">
|
<LoginBrand />
|
|
<main class="login-panel">
|
<div class="login-card">
|
<div class="login-card__header">
|
<img :src="logo" alt="健齿齿科器材" class="login-card__logo" />
|
<h2 class="login-card__title">欢迎登录</h2>
|
<p class="login-card__subtitle">开启您的数字化工作台</p>
|
</div>
|
|
<el-form ref="loginRef" :model="loginForm" :rules="loginRules">
|
<el-form-item prop="username">
|
<el-input
|
v-model="loginForm.username"
|
type="text"
|
size="large"
|
maxlength="30"
|
auto-complete="off"
|
placeholder="请输入用户名"
|
@keyup.enter="handleLogin"
|
>
|
<template #prefix><el-icon><User /></el-icon></template>
|
</el-input>
|
</el-form-item>
|
|
<el-form-item prop="password">
|
<el-input
|
v-model="loginForm.password"
|
type="password"
|
size="large"
|
maxlength="20"
|
auto-complete="off"
|
placeholder="请输入密码"
|
show-password
|
@keyup.enter="handleLogin"
|
>
|
<template #prefix><el-icon><Lock /></el-icon></template>
|
</el-input>
|
</el-form-item>
|
|
<div class="login-card__options">
|
<el-checkbox v-model="loginForm.rememberMe">记住账号</el-checkbox>
|
<span class="login-card__link" @click="handleForgot">忘记密码?</span>
|
</div>
|
|
<el-button
|
:loading="loading"
|
size="large"
|
type="primary"
|
class="login-btn"
|
@click.prevent="handleLogin"
|
>
|
<span v-if="!loading">登 录</span>
|
<span v-else>登 录 中...</span>
|
</el-button>
|
</el-form>
|
|
<p class="login-card__foot">健齿科技 · 服务全国</p>
|
</div>
|
</main>
|
</div>
|
</template>
|
|
<script setup>
|
import Cookies from "js-cookie"
|
import { encrypt, decrypt } from "@/utils/jsencrypt"
|
import useUserStore from '@/store/modules/user'
|
import LoginBrand from './login/components/LoginBrand.vue'
|
import logo from '@/assets/login/JCCKLogo.png'
|
|
const userStore = useUserStore()
|
const route = useRoute()
|
const router = useRouter()
|
const { proxy } = getCurrentInstance()
|
|
const loginForm = ref({
|
username: "",
|
password: "",
|
rememberMe: false,
|
})
|
|
const loginRules = {
|
username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
|
password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
|
}
|
|
const loading = ref(false)
|
const redirect = ref(undefined)
|
|
watch(route, (newRoute) => {
|
redirect.value = newRoute.query && newRoute.query.redirect
|
}, { immediate: true })
|
|
function handleLogin() {
|
proxy.$refs.loginRef.validate(valid => {
|
if (valid) {
|
loading.value = true
|
// 勾选了需要记住密码设置在 cookie 中设置记住用户名和密码
|
Cookies.set("username", loginForm.value.username, { expires: 30 })
|
Cookies.set("password", encrypt(loginForm.value.password), { expires: 30 })
|
Cookies.set("rememberMe", loginForm.value.rememberMe, { expires: 30 })
|
userStore.loginCheckFactory(loginForm.value).then(res => {
|
const query = route.query
|
const otherQueryParams = Object.keys(query).reduce((acc, cur) => {
|
if (cur !== "redirect") {
|
acc[cur] = query[cur]
|
}
|
return acc
|
}, {})
|
router.push({ path: redirect.value || "/", query: otherQueryParams })
|
}).catch(() => {
|
loading.value = false
|
})
|
}
|
})
|
}
|
|
function handleForgot() {
|
proxy.$modal.msg("请联系系统管理员重置密码")
|
}
|
|
function getCookie() {
|
const username = Cookies.get("username")
|
const password = Cookies.get("password")
|
const rememberMe = Cookies.get("rememberMe")
|
loginForm.value = {
|
...loginForm.value,
|
username: username === undefined ? loginForm.value.username : username,
|
password: password === undefined ? loginForm.value.password : decrypt(password),
|
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
}
|
}
|
|
getCookie()
|
</script>
|
|
<style lang='scss' scoped>
|
.login {
|
display: flex;
|
height: 100%;
|
min-height: 100vh;
|
background: var(--app-bg, #f4f6f9);
|
}
|
|
.login-panel {
|
flex: 1;
|
min-width: 0;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
padding: 24px;
|
background: linear-gradient(180deg, #f6f8fd 0%, #eef2f9 100%);
|
}
|
|
.login-card {
|
width: 100%;
|
max-width: 400px;
|
padding: 40px 44px 28px;
|
box-sizing: border-box;
|
background: #fff;
|
border-radius: var(--app-radius-lg, 14px);
|
box-shadow: 0 12px 40px rgba(16, 42, 96, 0.08);
|
|
.el-form-item {
|
margin-bottom: 22px;
|
}
|
}
|
|
.login-card__header {
|
text-align: center;
|
margin-bottom: 30px;
|
}
|
|
.login-card__logo {
|
height: 40px;
|
object-fit: contain;
|
}
|
|
.login-card__title {
|
margin: 18px 0 0;
|
font-size: 22px;
|
font-weight: 700;
|
color: var(--app-text, #1d2129);
|
letter-spacing: 2px;
|
}
|
|
.login-card__subtitle {
|
margin: 8px 0 0;
|
font-size: 13px;
|
color: var(--app-text-tertiary, #86909c);
|
}
|
|
.login-card__options {
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
margin: -4px 0 20px;
|
font-size: 14px;
|
}
|
|
.login-card__link {
|
color: var(--app-primary, #2c51d9);
|
font-size: 14px;
|
cursor: pointer;
|
transition: color var(--app-transition, 0.2s);
|
|
&:hover {
|
color: var(--app-primary-hover, #4a6cf0);
|
}
|
}
|
|
.login-btn {
|
width: 100%;
|
height: 46px;
|
border: none;
|
border-radius: 10px;
|
font-size: 16px;
|
font-weight: 600;
|
letter-spacing: 6px;
|
background: linear-gradient(90deg, #2c51d9 0%, #4a6cf0 100%);
|
box-shadow: 0 8px 20px rgba(44, 81, 217, 0.28);
|
transition: filter var(--app-transition, 0.2s), transform var(--app-transition, 0.2s);
|
|
&:hover,
|
&:focus {
|
filter: brightness(1.08);
|
}
|
|
&:active {
|
transform: translateY(1px);
|
}
|
}
|
|
.login-card__foot {
|
margin: 34px 0 0;
|
text-align: center;
|
font-size: 12px;
|
letter-spacing: 4px;
|
color: #b6c0cf;
|
}
|
|
// 输入框统一样式
|
:deep(.el-input__wrapper) {
|
border-radius: 10px;
|
padding: 5px 14px;
|
box-shadow: 0 0 0 1px var(--app-border, #e8ecf1) inset;
|
transition: box-shadow var(--app-transition, 0.2s);
|
|
&:hover {
|
box-shadow: 0 0 0 1px var(--app-text-tertiary, #86909c) inset;
|
}
|
|
&.is-focus {
|
box-shadow: 0 0 0 1.5px var(--app-primary, #2c51d9) inset;
|
}
|
}
|
|
@media (max-width: 480px) {
|
.login-panel {
|
padding: 20px 16px;
|
background: #fff;
|
}
|
|
.login-card {
|
padding: 28px 24px 20px;
|
box-shadow: none;
|
}
|
}
|
</style>
|