<template>
|
<div class="login-page">
|
<div class="login-shell">
|
<section class="login-brand">
|
<div class="brand-badge">PRODUCT INVENTORY</div>
|
<img :src="brandLogo" alt="brand logo" class="brand-logo" />
|
<h1 class="brand-title">{{ title }}</h1>
|
<p class="brand-copy">
|
统一管理库存、流程与业务数据,让系统入口和后台主界面保持同一套简约视觉语言。
|
</p>
|
<div class="brand-points">
|
<div class="brand-point">
|
<span class="point-dot"></span>
|
<span>清晰的数据入口</span>
|
</div>
|
<div class="brand-point">
|
<span class="point-dot"></span>
|
<span>更轻的界面层次</span>
|
</div>
|
<div class="brand-point">
|
<span class="point-dot"></span>
|
<span>稳定的业务协同体验</span>
|
</div>
|
</div>
|
</section>
|
|
<section class="login-panel">
|
<el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form">
|
<div class="panel-head">
|
<p class="panel-kicker">WELCOME BACK</p>
|
<h2 class="panel-title">登录系统</h2>
|
<p class="panel-subtitle">输入账号和密码进入工作台。</p>
|
</div>
|
|
<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><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
|
</el-input>
|
</el-form-item>
|
|
<div class="login-options">
|
<el-checkbox v-model="loginForm.rememberMe">记住密码</el-checkbox>
|
<router-link v-if="register" class="register-link" :to="'/register'">立即注册</router-link>
|
</div>
|
|
<el-button
|
:loading="loading"
|
size="large"
|
type="primary"
|
class="login-submit"
|
@click.prevent="handleLogin"
|
>
|
<span v-if="!loading">登录</span>
|
<span v-else>登录中...</span>
|
</el-button>
|
</el-form>
|
</section>
|
</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"
|
import brandLogo from "@/assets/logo/logo.png"
|
|
const title = import.meta.env.VITE_APP_TITLE
|
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 codeUrl = ref("")
|
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) {
|
codeUrl.value = "data:image/gif;base64," + res.img
|
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;
|
padding: 32px;
|
background:
|
radial-gradient(circle at top left, rgba(207, 223, 214, 0.95), transparent 30%),
|
radial-gradient(circle at bottom right, rgba(222, 232, 227, 0.9), transparent 28%),
|
linear-gradient(180deg, #f7faf8 0%, #eef2ee 100%);
|
}
|
|
.login-shell {
|
width: min(1120px, 100%);
|
min-height: 680px;
|
display: grid;
|
grid-template-columns: 1.1fr 0.9fr;
|
border: 1px solid rgba(216, 225, 219, 0.9);
|
border-radius: 32px;
|
overflow: hidden;
|
background: rgba(255, 255, 255, 0.76);
|
box-shadow: 0 26px 80px rgba(31, 49, 38, 0.12);
|
backdrop-filter: blur(24px);
|
}
|
|
.login-brand {
|
position: relative;
|
display: flex;
|
flex-direction: column;
|
justify-content: center;
|
padding: 56px 64px;
|
background:
|
linear-gradient(180deg, rgba(244, 248, 245, 0.9), rgba(233, 240, 236, 0.9)),
|
linear-gradient(135deg, rgba(31, 122, 114, 0.05), rgba(255, 255, 255, 0));
|
|
&::after {
|
content: "";
|
position: absolute;
|
inset: 28px;
|
border: 1px solid rgba(31, 122, 114, 0.08);
|
border-radius: 28px;
|
pointer-events: none;
|
}
|
}
|
|
.brand-badge {
|
width: fit-content;
|
padding: 8px 14px;
|
border-radius: 999px;
|
background: rgba(31, 122, 114, 0.1);
|
color: #1f7a72;
|
font-size: 12px;
|
font-weight: 700;
|
letter-spacing: 0.14em;
|
}
|
|
.brand-logo {
|
width: 160px;
|
height: auto;
|
margin: 30px 0 24px;
|
object-fit: contain;
|
}
|
|
.brand-title {
|
margin: 0;
|
font-size: 42px;
|
line-height: 1.12;
|
color: #21313f;
|
letter-spacing: -0.03em;
|
}
|
|
.brand-copy {
|
max-width: 460px;
|
margin: 18px 0 0;
|
font-size: 16px;
|
line-height: 1.75;
|
color: #5f6d7e;
|
}
|
|
.brand-points {
|
margin-top: 34px;
|
display: flex;
|
flex-direction: column;
|
gap: 14px;
|
}
|
|
.brand-point {
|
display: flex;
|
align-items: center;
|
gap: 12px;
|
color: #3d4b59;
|
font-size: 15px;
|
font-weight: 500;
|
}
|
|
.point-dot {
|
width: 10px;
|
height: 10px;
|
border-radius: 50%;
|
background: linear-gradient(135deg, #1f7a72, #5ca39c);
|
box-shadow: 0 0 0 6px rgba(31, 122, 114, 0.08);
|
}
|
|
.login-panel {
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
padding: 40px;
|
background: rgba(255, 255, 255, 0.7);
|
}
|
|
.login-form {
|
width: min(420px, 100%);
|
padding: 38px 34px 34px;
|
border: 1px solid rgba(216, 225, 219, 0.92);
|
border-radius: 28px;
|
background: rgba(255, 255, 255, 0.88);
|
box-shadow: 0 18px 52px rgba(31, 49, 38, 0.1);
|
}
|
|
.panel-head {
|
margin-bottom: 28px;
|
}
|
|
.panel-kicker {
|
margin: 0 0 10px;
|
color: #8a98a8;
|
font-size: 12px;
|
font-weight: 700;
|
letter-spacing: 0.16em;
|
}
|
|
.panel-title {
|
margin: 0;
|
color: #21313f;
|
font-size: 30px;
|
font-weight: 700;
|
}
|
|
.panel-subtitle {
|
margin: 10px 0 0;
|
color: #6b7888;
|
font-size: 14px;
|
}
|
|
.login-options {
|
margin: -4px 0 22px;
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
color: #5f6d7e;
|
}
|
|
.register-link {
|
color: var(--el-color-primary);
|
font-weight: 600;
|
}
|
|
.login-submit {
|
width: 100%;
|
height: 48px;
|
}
|
|
.input-icon {
|
width: 14px;
|
}
|
|
:deep(.el-form-item) {
|
margin-bottom: 22px;
|
}
|
|
:deep(.el-input__wrapper) {
|
min-height: 42px;
|
height: 42px;
|
padding-top: 0;
|
padding-bottom: 0;
|
}
|
|
:deep(.el-input__inner) {
|
height: 42px;
|
line-height: 42px;
|
}
|
|
:deep(.el-checkbox) {
|
color: #5f6d7e;
|
}
|
|
@media (max-width: 960px) {
|
.login-page {
|
padding: 18px;
|
}
|
|
.login-shell {
|
min-height: auto;
|
grid-template-columns: 1fr;
|
}
|
|
.login-brand {
|
padding: 40px 28px 22px;
|
}
|
|
.login-brand::after {
|
inset: 16px;
|
}
|
|
.brand-title {
|
font-size: 32px;
|
}
|
|
.brand-copy {
|
font-size: 14px;
|
}
|
|
.brand-points {
|
margin-top: 24px;
|
}
|
|
.login-panel {
|
padding: 12px 18px 24px;
|
}
|
|
.login-form {
|
width: 100%;
|
padding: 28px 22px 24px;
|
}
|
}
|
</style>
|