<template>
|
<div class="login-page">
|
<div class="login-card">
|
<div class="card-header">
|
<div class="logo">
|
<svg-icon icon-class="user" />
|
</div>
|
<h1>客户关系管理系统</h1>
|
<p>高效管理客户资源,驱动业务增长</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"
|
auto-complete="off"
|
placeholder="请输入账号"
|
>
|
<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"
|
auto-complete="off"
|
placeholder="请输入密码"
|
show-password
|
@keyup.enter="handleLogin"
|
>
|
<template #prefix><el-icon><Lock /></el-icon></template>
|
</el-input>
|
</el-form-item>
|
|
<div class="form-options">
|
<el-checkbox v-model="loginForm.rememberMe">记住密码</el-checkbox>
|
<router-link v-if="register" :to="'/register'">立即注册</router-link>
|
</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>
|
</div>
|
|
<div class="bg-pattern">
|
<div class="pattern-item"></div>
|
<div class="pattern-item"></div>
|
<div class="pattern-item"></div>
|
</div>
|
</div>
|
</template>
|
|
<script setup>
|
import { getCodeImg } from "@/api/login"
|
import Cookies from "js-cookie"
|
import { encrypt, decrypt } from "@/utils/jsencrypt"
|
import useUserStore from "@/store/modules/user"
|
|
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 captchaEnabled = ref(true)
|
const register = 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
|
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(() => {
|
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
|
if (captchaEnabled.value) {
|
getCode()
|
}
|
})
|
}
|
})
|
}
|
|
function getCode() {
|
getCodeImg().then((res) => {
|
captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled
|
if (captchaEnabled.value) {
|
loginForm.value.uuid = res.uuid
|
}
|
})
|
}
|
|
function getCookie() {
|
const username = Cookies.get("username")
|
const password = Cookies.get("password")
|
const rememberMe = Cookies.get("rememberMe")
|
loginForm.value = {
|
username: username === undefined ? loginForm.value.username : username,
|
password: password === undefined ? loginForm.value.password : decrypt(password),
|
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
}
|
}
|
|
getCode()
|
getCookie()
|
</script>
|
|
<style lang="scss" scoped>
|
.login-page {
|
min-height: 100vh;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
background: linear-gradient(135deg, var(--el-color-primary-light-9) 0%, var(--el-color-primary-light-8) 50%, var(--el-color-primary-light-9) 100%);
|
position: relative;
|
overflow: hidden;
|
}
|
|
.bg-pattern {
|
position: absolute;
|
top: 0;
|
left: 0;
|
right: 0;
|
bottom: 0;
|
pointer-events: none;
|
|
.pattern-item {
|
position: absolute;
|
border-radius: 50%;
|
background: linear-gradient(135deg, var(--el-color-primary-light-7), var(--el-color-primary-light-9));
|
}
|
|
.pattern-item:nth-child(1) {
|
width: 500px;
|
height: 500px;
|
top: -150px;
|
right: -100px;
|
}
|
|
.pattern-item:nth-child(2) {
|
width: 350px;
|
height: 350px;
|
bottom: -100px;
|
left: -80px;
|
}
|
|
.pattern-item:nth-child(3) {
|
width: 200px;
|
height: 200px;
|
top: 40%;
|
left: 15%;
|
background: linear-gradient(135deg, var(--el-color-primary-light-8), var(--el-color-primary-light-9));
|
}
|
}
|
|
.login-card {
|
width: 420px;
|
padding: 48px 40px;
|
background: rgba(255, 255, 255, 0.95);
|
border-radius: 20px;
|
box-shadow:
|
0 4px 6px -1px rgba(0, 0, 0, 0.05),
|
0 10px 15px -3px rgba(0, 0, 0, 0.08),
|
0 20px 25px -5px rgba(0, 0, 0, 0.05);
|
backdrop-filter: blur(10px);
|
position: relative;
|
z-index: 1;
|
}
|
|
.card-header {
|
text-align: center;
|
margin-bottom: 36px;
|
|
.logo {
|
width: 72px;
|
height: 72px;
|
margin: 0 auto 20px;
|
background: linear-gradient(135deg, var(--el-color-primary) 0%, var(--el-color-primary-light-3) 100%);
|
border-radius: 18px;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
box-shadow: 0 8px 20px var(--el-color-primary-light-5);
|
|
:deep(svg) {
|
width: 36px;
|
height: 36px;
|
color: #fff;
|
}
|
}
|
|
h1 {
|
font-size: 24px;
|
font-weight: 600;
|
color: #1f2937;
|
margin: 0 0 8px;
|
}
|
|
p {
|
font-size: 14px;
|
color: #6b7280;
|
margin: 0;
|
}
|
}
|
|
:deep(.el-form-item) {
|
margin-bottom: 20px;
|
}
|
|
:deep(.el-input__wrapper) {
|
border-radius: 12px;
|
box-shadow: 0 0 0 1px #e5e7eb;
|
padding: 0 16px;
|
height: 48px;
|
transition: all 0.2s;
|
|
&:hover {
|
box-shadow: 0 0 0 1px var(--el-color-primary-light-5);
|
}
|
|
&:focus-within {
|
box-shadow: 0 0 0 2px var(--el-color-primary);
|
}
|
}
|
|
:deep(.el-input__inner) {
|
height: 48px;
|
font-size: 15px;
|
color: #374151;
|
|
&::placeholder {
|
color: #9ca3af;
|
}
|
}
|
|
:deep(.el-input__prefix) {
|
color: #9ca3af;
|
font-size: 18px;
|
}
|
|
.form-options {
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
margin: 8px 0 24px;
|
|
:deep(.el-checkbox__label) {
|
color: #6b7280;
|
font-size: 14px;
|
}
|
|
:deep(.el-checkbox__input.is-checked .el-checkbox__inner) {
|
background-color: var(--el-color-primary);
|
border-color: var(--el-color-primary);
|
}
|
|
a {
|
color: var(--el-color-primary);
|
font-size: 14px;
|
font-weight: 500;
|
text-decoration: none;
|
transition: color 0.2s;
|
|
&:hover {
|
color: var(--el-color-primary-light-3);
|
}
|
}
|
}
|
|
.login-btn {
|
width: 100%;
|
height: 48px;
|
border-radius: 12px;
|
font-size: 16px;
|
font-weight: 500;
|
background: linear-gradient(135deg, var(--el-color-primary) 0%, var(--el-color-primary-light-3) 100%);
|
border: none;
|
box-shadow: 0 4px 14px var(--el-color-primary-light-5);
|
transition: all 0.2s;
|
|
&:hover {
|
transform: translateY(-1px);
|
box-shadow: 0 6px 20px var(--el-color-primary-light-4);
|
}
|
}
|
|
@media (max-width: 480px) {
|
.login-card {
|
width: 90%;
|
padding: 36px 24px;
|
}
|
|
.card-header {
|
h1 {
|
font-size: 20px;
|
}
|
}
|
}
|
</style>
|