smart-bid-web/src/views/login.vue

415 lines
9.2 KiB
Vue
Raw Normal View History

2025-10-16 09:33:10 +08:00
<template>
<div class="login">
2025-10-17 09:21:34 +08:00
<div class="login-container">
<div class="login-header">
<h1 class="main-title">
<img src="../assets/logo/logo.png" alt="logo" class="logo"/>
<span>智能投标系统</span>
</h1>
<h2 class="sub-title">欢迎登录 welcome to login in</h2>
</div>
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
<el-form-item prop="username">
2025-10-16 09:33:10 +08:00
<el-input
2025-10-17 09:21:34 +08:00
v-model="loginForm.username"
type="text"
2025-10-16 09:33:10 +08:00
auto-complete="off"
2025-10-17 09:21:34 +08:00
placeholder="请输入用户名"
>
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
</el-input>
</el-form-item>
<el-form-item prop="password">
<el-input
v-model="loginForm.password"
type="password"
auto-complete="off"
placeholder="请输入登录密码"
2025-10-16 09:33:10 +08:00
@keyup.enter.native="handleLogin"
>
2025-10-17 09:21:34 +08:00
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
2025-10-16 09:33:10 +08:00
</el-input>
2025-10-17 09:21:34 +08:00
</el-form-item>
<el-form-item prop="code" v-if="captchaEnabled">
<div class="code-wrapper">
<el-input
v-model="loginForm.code"
auto-complete="off"
placeholder="验证码"
@keyup.enter.native="handleLogin"
>
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
</el-input>
<div class="login-code">
<img :src="codeUrl" @click="getCode" class="login-code-img"/>
</div>
2025-10-16 09:33:10 +08:00
</div>
2025-10-17 09:21:34 +08:00
</el-form-item>
<div class="form-options">
<el-checkbox v-model="loginForm.rememberMe">记住密码</el-checkbox>
<a href="#" class="forgot-password">忘记密码</a>
2025-10-16 09:33:10 +08:00
</div>
2025-10-17 09:21:34 +08:00
<el-form-item style="width:100%;">
<el-button
:loading="loading"
size="medium"
type="primary"
style="width:100%;"
@click.native.prevent="handleLogin"
>
<span v-if="!loading">登录</span>
<span v-else> 中...</span>
</el-button>
</el-form-item>
</el-form>
</div>
2025-10-16 09:33:10 +08:00
</div>
</template>
<script>
import { getCodeImg } from "@/api/login"
import Cookies from "js-cookie"
import { encrypt, decrypt } from '@/utils/jsencrypt'
import { getSystemConfigApi } from '@/utils/systemConfig'
export default {
name: "Login",
data() {
return {
title: process.env.VUE_APP_TITLE,
codeUrl: "",
loginForm: {
username: "",
password: "",
rememberMe: false,
code: "",
uuid: ""
},
loginRules: {
username: [
{ required: true, trigger: "blur", message: "请输入您的账号" }
],
password: [
{ required: true, trigger: "blur", message: "请输入您的密码" }
],
code: [{ required: true, trigger: "change", message: "请输入验证码" }]
},
loading: false,
// 验证码开关
captchaEnabled: true,
// 注册开关
register: false,
redirect: undefined
}
},
watch: {
$route: {
handler: function(route) {
this.redirect = route.query && route.query.redirect
},
immediate: true
}
},
created() {
this.getSystemConfig()
this.getCode()
this.getCookie()
},
methods: {
async getSystemConfig(){
await getSystemConfigApi();
},
async getCode() {
await getCodeImg().then(res => {
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
if (this.captchaEnabled) {
this.codeUrl = "data:image/gif;base64," + res.img
this.loginForm.uuid = res.uuid
}
})
},
getCookie() {
const username = Cookies.get("username")
const password = Cookies.get("password")
const rememberMe = Cookies.get('rememberMe')
this.loginForm = {
username: username === undefined ? this.loginForm.username : username,
password: password === undefined ? this.loginForm.password : decrypt(password),
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
}
},
handleLogin() {
this.$refs.loginForm.validate(valid => {
if (valid) {
this.loading = true
if (this.loginForm.rememberMe) {
Cookies.set("username", this.loginForm.username, { expires: 30 })
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 })
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 })
} else {
Cookies.remove("username")
Cookies.remove("password")
Cookies.remove('rememberMe')
}
this.$store.dispatch("Login", this.loginForm).then(() => {
this.$router.push({ path: this.redirect || "/" }).catch(()=>{})
}).catch(() => {
this.loading = false
if (this.captchaEnabled) {
this.getCode()
}
})
}
})
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss">
.login {
display: flex;
justify-content: center;
align-items: center;
2025-10-17 09:21:34 +08:00
height: 100vh;
2025-10-16 09:33:10 +08:00
background: #fff;
background-image: url("../assets/images/login-background.jpg");
background-repeat: no-repeat;
2025-10-17 09:21:34 +08:00
background-position: center center;
// background-size: contain;
2025-10-16 09:33:10 +08:00
position: relative;
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 0;
}
}
2025-10-17 09:21:34 +08:00
.login-container {
width: 100%;
max-width: 480px;
padding: 0 20px;
2025-10-16 09:33:10 +08:00
z-index: 1;
}
2025-10-17 09:21:34 +08:00
.login-header {
text-align: center;
margin-bottom: 40px;
2025-10-16 09:33:10 +08:00
2025-10-17 09:21:34 +08:00
.main-title {
font-size: 32px;
font-weight: 700;
color: #060F2E;
margin-bottom: 12px;
letter-spacing: 1px;
}
.sub-title {
font-size: 18px;
color: #666;
font-weight: 500;
margin: 0;
2025-10-16 09:33:10 +08:00
}
2025-10-17 09:21:34 +08:00
}
.login-form {
border-radius: 16px;
background: #ffffff;
width: 100%;
padding: 40px 35px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
border: 1px solid rgba(0, 0, 0, 0.05);
2025-10-16 09:33:10 +08:00
.el-input {
2025-10-17 09:21:34 +08:00
height: 48px;
2025-10-16 09:33:10 +08:00
margin: 8px 0;
position: relative;
.el-input__inner {
2025-10-17 09:21:34 +08:00
height: 48px;
2025-10-16 09:33:10 +08:00
border-radius: 8px;
2025-10-17 09:21:34 +08:00
border: 1px solid #e1e5e9;
padding-left: 45px;
font-size: 15px;
2025-10-16 09:33:10 +08:00
transition: all 0.3s ease;
2025-10-17 09:21:34 +08:00
background: #f9fafb;
2025-10-16 09:33:10 +08:00
&:focus {
border-color: #1E6BFF;
2025-10-17 09:21:34 +08:00
box-shadow: 0 0 0 3px rgba(30, 107, 255, 0.1);
2025-10-16 09:33:10 +08:00
background: #ffffff;
}
&:hover {
2025-10-17 09:21:34 +08:00
border-color: #c0c4cc;
background: #ffffff;
2025-10-16 09:33:10 +08:00
}
}
.el-input__prefix {
position: absolute;
2025-10-17 09:21:34 +08:00
left: 15px;
2025-10-16 09:33:10 +08:00
top: 50%;
transform: translateY(-50%);
z-index: 1;
}
}
.input-icon {
2025-10-17 09:21:34 +08:00
height: 18px;
width: 18px;
2025-10-16 09:33:10 +08:00
margin-left: 0;
color: #999;
transition: color 0.3s ease;
position: absolute;
top: 50%;
left: 12px;
transform: translateY(-50%);
}
.el-form-item {
2025-10-17 09:21:34 +08:00
margin-bottom: 24px;
2025-10-16 09:33:10 +08:00
}
.el-checkbox {
.el-checkbox__label {
color: #666;
font-size: 14px;
}
.el-checkbox__input.is-checked .el-checkbox__inner {
background-color: #1E6BFF;
border-color: #1E6BFF;
}
}
.el-button {
2025-10-17 09:21:34 +08:00
height: 48px;
2025-10-16 09:33:10 +08:00
border-radius: 8px;
font-size: 16px;
font-weight: 600;
background: linear-gradient(135deg, #0A57E7 0%, #1E6BFF 100%);
border: none;
transition: transform 0.2s ease, box-shadow 0.2s ease;
will-change: transform;
&:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(30, 107, 255, 0.35);
}
&:active {
transform: translateY(0);
box-shadow: 0 2px 6px rgba(30, 107, 255, 0.25);
}
}
2025-10-17 09:21:34 +08:00
}
.form-options {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 25px;
2025-10-16 09:33:10 +08:00
2025-10-17 09:21:34 +08:00
.forgot-password {
2025-10-16 09:33:10 +08:00
color: #1E6BFF;
text-decoration: none;
font-size: 14px;
transition: color 0.3s ease;
&:hover {
color: #0A57E7;
text-decoration: underline;
}
}
}
.code-wrapper {
display: flex;
2025-10-17 09:21:34 +08:00
gap: 12px;
2025-10-16 09:33:10 +08:00
align-items: center;
.el-input {
flex: 1;
}
}
.login-code {
width: 120px;
2025-10-17 09:21:34 +08:00
height: 48px;
2025-10-16 09:33:10 +08:00
border-radius: 8px;
overflow: hidden;
2025-10-17 09:21:34 +08:00
border: 1px solid #e1e5e9;
2025-10-16 09:33:10 +08:00
cursor: pointer;
transition: all 0.3s ease;
flex-shrink: 0;
&:hover {
border-color: #1E6BFF;
transform: scale(1.02);
}
img {
cursor: pointer;
vertical-align: middle;
width: 100%;
height: 100%;
object-fit: cover;
}
}
.login-code-img {
2025-10-17 09:21:34 +08:00
height: 48px;
2025-10-16 09:33:10 +08:00
}
// 响应式优化
@media (max-width: 768px) {
.login {
2025-10-17 09:21:34 +08:00
padding: 20px;
}
.login-container {
padding: 0;
2025-10-16 09:33:10 +08:00
}
.login-form {
2025-10-17 09:21:34 +08:00
padding: 30px 25px;
2025-10-16 09:33:10 +08:00
}
2025-10-17 09:21:34 +08:00
.login-header {
.main-title {
font-size: 28px;
}
.sub-title {
font-size: 16px;
}
2025-10-16 09:33:10 +08:00
}
}
@media (max-width: 480px) {
.login-form {
2025-10-17 09:21:34 +08:00
padding: 25px 20px;
2025-10-16 09:33:10 +08:00
}
2025-10-17 09:21:34 +08:00
.login-header {
.main-title {
font-size: 24px;
}
.sub-title {
font-size: 15px;
}
2025-10-16 09:33:10 +08:00
}
}
2025-10-17 09:21:34 +08:00
.logo{
width: 56px;
height: 65px;
}
</style>