<template>
|
<div class="login-page">
|
<!-- 左侧插画区 -->
|
<div class="illustration-side">
|
<div class="illustration-content">
|
<div class="scene">
|
<!-- 仓库建筑 -->
|
<div class="warehouse">
|
<div class="building">
|
<div class="roof"></div>
|
<div class="wall">
|
<div class="window"></div>
|
<div class="window"></div>
|
<div class="window"></div>
|
</div>
|
<div class="door"></div>
|
</div>
|
</div>
|
<!-- 卡车 -->
|
<div class="truck">
|
<div class="truck-body"></div>
|
<div class="truck-cab"></div>
|
<div class="wheel wheel-1"></div>
|
<div class="wheel wheel-2"></div>
|
</div>
|
<!-- 箱子 -->
|
<div class="boxes">
|
<div class="box box-1"></div>
|
<div class="box box-2"></div>
|
<div class="box box-3"></div>
|
</div>
|
<!-- 装饰元素 -->
|
<div class="decor-circle c1"></div>
|
<div class="decor-circle c2"></div>
|
<div class="decor-circle c3"></div>
|
</div>
|
<h2>智能供应链管理</h2>
|
<p>高效协同 · 精准管控 · 数据驱动</p>
|
</div>
|
</div>
|
|
<!-- 右侧登录区 -->
|
<div class="login-side">
|
<div class="login-form-box">
|
<div class="form-header">
|
<h3>欢迎回来</h3>
|
<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="用户名"
|
class="login-input"
|
>
|
<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
|
class="login-input"
|
@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>
|
<a href="#" class="forgot-link">忘记密码?</a>
|
</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>
|
</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 { User, Lock } from '@element-plus/icons-vue'
|
|
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 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>
|
// 主题色变量
|
$primary: #1f7a72;
|
$primary-light: #2a9d8f;
|
$primary-lighter: #3abbae;
|
$primary-lightest: #e8f5f3;
|
|
.login-page {
|
min-height: 100vh;
|
display: flex;
|
}
|
|
/* 左侧插画区 */
|
.illustration-side {
|
flex: 1;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
background: linear-gradient(135deg, $primary-lightest 0%, #d4edea 100%);
|
padding: 60px;
|
}
|
|
.illustration-content {
|
text-align: center;
|
|
h2 {
|
font-size: 32px;
|
font-weight: 600;
|
color: $primary;
|
margin: 40px 0 12px 0;
|
}
|
|
p {
|
font-size: 16px;
|
color: $primary-light;
|
margin: 0;
|
}
|
}
|
|
/* CSS 插画场景 */
|
.scene {
|
position: relative;
|
width: 320px;
|
height: 240px;
|
margin: 0 auto;
|
}
|
|
/* 仓库 */
|
.warehouse {
|
position: absolute;
|
bottom: 40px;
|
left: 50%;
|
transform: translateX(-50%);
|
}
|
|
.building {
|
position: relative;
|
width: 140px;
|
height: 100px;
|
}
|
|
.roof {
|
position: absolute;
|
top: 0;
|
left: 50%;
|
transform: translateX(-50%);
|
width: 0;
|
height: 0;
|
border-left: 75px solid transparent;
|
border-right: 75px solid transparent;
|
border-bottom: 40px solid $primary;
|
}
|
|
.wall {
|
position: absolute;
|
bottom: 0;
|
left: 50%;
|
transform: translateX(-50%);
|
width: 120px;
|
height: 70px;
|
background: #fff;
|
border: 3px solid $primary;
|
border-radius: 0 0 4px 4px;
|
display: flex;
|
justify-content: space-around;
|
align-items: center;
|
padding: 0 10px;
|
}
|
|
.window {
|
width: 20px;
|
height: 30px;
|
background: $primary-lightest;
|
border-radius: 2px;
|
}
|
|
.door {
|
position: absolute;
|
bottom: 0;
|
left: 50%;
|
transform: translateX(-50%);
|
width: 30px;
|
height: 45px;
|
background: $primary-light;
|
border-radius: 4px 4px 0 0;
|
}
|
|
/* 卡车 */
|
.truck {
|
position: absolute;
|
bottom: 40px;
|
right: 20px;
|
width: 100px;
|
height: 50px;
|
}
|
|
.truck-body {
|
position: absolute;
|
top: 10px;
|
left: 0;
|
width: 60px;
|
height: 35px;
|
background: $primary;
|
border-radius: 4px;
|
}
|
|
.truck-cab {
|
position: absolute;
|
top: 18px;
|
right: 0;
|
width: 35px;
|
height: 27px;
|
background: $primary-light;
|
border-radius: 0 8px 4px 0;
|
}
|
|
.wheel {
|
position: absolute;
|
bottom: 0;
|
width: 16px;
|
height: 16px;
|
background: $primary;
|
border-radius: 50%;
|
border: 3px solid $primary-light;
|
}
|
|
.wheel-1 {
|
left: 12px;
|
}
|
|
.wheel-2 {
|
right: 8px;
|
}
|
|
/* 箱子 */
|
.boxes {
|
position: absolute;
|
bottom: 40px;
|
left: 30px;
|
}
|
|
.box {
|
position: absolute;
|
border-radius: 3px;
|
}
|
|
.box-1 {
|
width: 35px;
|
height: 35px;
|
background: $primary;
|
bottom: 0;
|
left: 0;
|
}
|
|
.box-2 {
|
width: 30px;
|
height: 30px;
|
background: $primary-light;
|
bottom: 0;
|
left: 40px;
|
}
|
|
.box-3 {
|
width: 28px;
|
height: 28px;
|
background: $primary-lighter;
|
bottom: 38px;
|
left: 5px;
|
}
|
|
/* 装饰圆圈 */
|
.decor-circle {
|
position: absolute;
|
border-radius: 50%;
|
opacity: 0.3;
|
}
|
|
.c1 {
|
width: 80px;
|
height: 80px;
|
background: $primary;
|
top: 20px;
|
left: 30px;
|
}
|
|
.c2 {
|
width: 50px;
|
height: 50px;
|
background: $primary-light;
|
top: 60px;
|
right: 40px;
|
}
|
|
.c3 {
|
width: 35px;
|
height: 35px;
|
background: $primary-lighter;
|
bottom: 100px;
|
left: 20px;
|
}
|
|
/* 右侧登录区 */
|
.login-side {
|
width: 460px;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
background: #fff;
|
padding: 40px;
|
}
|
|
.login-form-box {
|
width: 100%;
|
max-width: 340px;
|
}
|
|
.form-header {
|
margin-bottom: 32px;
|
|
h3 {
|
font-size: 26px;
|
font-weight: 600;
|
color: $primary;
|
margin: 0 0 8px 0;
|
}
|
|
p {
|
font-size: 14px;
|
color: $primary-light;
|
margin: 0;
|
}
|
}
|
|
:deep(.login-input .el-input__wrapper) {
|
background: $primary-lightest;
|
border: 1px solid #d0e5e2;
|
border-radius: 10px;
|
box-shadow: none;
|
padding: 0 16px;
|
height: 48px;
|
|
&:hover {
|
border-color: $primary-light;
|
}
|
|
&:focus-within {
|
border-color: $primary;
|
background: #fff;
|
box-shadow: 0 0 0 3px rgba(31, 122, 114, 0.1);
|
}
|
}
|
|
:deep(.login-input .el-input__inner) {
|
height: 48px;
|
font-size: 15px;
|
color: $primary;
|
|
&::placeholder {
|
color: #8fb5af;
|
}
|
}
|
|
:deep(.login-input .el-input__prefix) {
|
color: $primary-light;
|
margin-right: 10px;
|
}
|
|
.form-options {
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
margin: 16px 0 24px;
|
|
:deep(.el-checkbox__label) {
|
font-size: 14px;
|
color: $primary-light;
|
}
|
|
:deep(.el-checkbox__input.is-checked .el-checkbox__inner) {
|
background-color: $primary;
|
border-color: $primary;
|
}
|
|
:deep(.el-checkbox__input.is-checked + .el-checkbox__label) {
|
color: $primary;
|
}
|
|
.forgot-link {
|
font-size: 14px;
|
color: $primary;
|
text-decoration: none;
|
font-weight: 500;
|
|
&:hover {
|
text-decoration: underline;
|
}
|
}
|
}
|
|
.login-btn {
|
width: 100%;
|
height: 48px;
|
border-radius: 10px;
|
font-size: 16px;
|
font-weight: 500;
|
background: linear-gradient(135deg, $primary 0%, $primary-light 100%);
|
border: none;
|
transition: all 0.2s;
|
|
&:hover {
|
opacity: 0.9;
|
transform: translateY(-1px);
|
box-shadow: 0 6px 20px rgba(31, 122, 114, 0.3);
|
}
|
}
|
|
/* 响应式 */
|
@media (max-width: 900px) {
|
.illustration-side {
|
display: none;
|
}
|
|
.login-side {
|
width: 100%;
|
}
|
}
|
</style>
|