408 lines
9.6 KiB
Vue
408 lines
9.6 KiB
Vue
<template>
|
|
<div class="login-container">
|
|
<div class="loginRoot">
|
|
<div class="login">
|
|
<div class="leftLogo">
|
|
<div class="left-logo-container">
|
|
<img :src="systemLogo" />
|
|
<div class="shortBar"></div>
|
|
<div class="welcome-message">Welcome to log in and use this system platform</div>
|
|
<div class="welcome-label">欢迎登录</div>
|
|
</div>
|
|
</div>
|
|
<div class="rightForm">
|
|
<el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form">
|
|
<div class="title-container">
|
|
<div class="tite-square"></div>
|
|
<div class="title-label">{{ title }}</div>
|
|
</div>
|
|
<el-form-item prop="username">
|
|
<el-input v-model="loginForm.username" type="text" size="large" class="custom-input" auto-complete="off"
|
|
placeholder="账号">
|
|
</el-input>
|
|
</el-form-item>
|
|
<el-form-item prop="password">
|
|
<el-input v-model="loginForm.password" type="password" show-password size="large" class="custom-input"
|
|
auto-complete="off" placeholder="密码" @keyup.enter="handleLogin">
|
|
</el-input>
|
|
</el-form-item>
|
|
<el-form-item prop="code" v-if="captchaEnabled">
|
|
<el-input v-model="loginForm.code" size="large" class="custom-input captcha-input" auto-complete="off"
|
|
placeholder="验证码" @keyup.enter="handleLogin">
|
|
</el-input>
|
|
<div class="login-code">
|
|
<img :src="codeUrl" @click="getCode" class="login-code-img" />
|
|
</div>
|
|
</el-form-item>
|
|
<!-- <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox> -->
|
|
<el-form-item style="width:100%;">
|
|
<el-button :loading="loading" size="large" type="primary" class="myLoginBtn" style="width:100%;"
|
|
@click.prevent="handleLogin">
|
|
<span v-if="!loading">登 录</span>
|
|
<span v-else>登 录 中...</span>
|
|
</el-button>
|
|
<div style="float: right;" v-if="register">
|
|
<router-link class="link-type" :to="'/register'">立即注册</router-link>
|
|
</div>
|
|
</el-form-item>
|
|
</el-form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 底部 -->
|
|
<!-- <div class="el-login-footer">
|
|
<span>Copyright © 2018-2025 ruoyi.vip All Rights Reserved.</span>
|
|
</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 systemLogo from '@/assets/images/systemLogo.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: "admin",
|
|
password: "admin123",
|
|
rememberMe: false,
|
|
code: "",
|
|
uuid: ""
|
|
})
|
|
|
|
const loginRules = {
|
|
username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
|
|
password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
|
|
code: [{ required: true, trigger: "change", 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
|
|
// 勾选了需要记住密码设置在 cookie 中设置记住用户名和密码
|
|
if (loginForm.value.rememberMe) {
|
|
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 })
|
|
} else {
|
|
// 否则移除
|
|
Cookies.remove("username")
|
|
Cookies.remove("password")
|
|
Cookies.remove("rememberMe")
|
|
}
|
|
// 调用action的登录方法
|
|
userStore.login(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-container {
|
|
position: relative;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-image: url("../assets/images/login-background.png");
|
|
background-size: cover;
|
|
}
|
|
|
|
.loginRoot {
|
|
position: absolute;
|
|
top: calc(50% - 290px);
|
|
left: calc(50% - 500px);
|
|
z-index: 2;
|
|
}
|
|
|
|
.login {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
width: 1000px;
|
|
height: 580px;
|
|
border-radius: 6px;
|
|
}
|
|
|
|
.leftLogo {
|
|
width: 500px;
|
|
height: 580px;
|
|
display: flex;
|
|
/* 垂直居中 */
|
|
align-items: center;
|
|
/* 水平居中(可选) */
|
|
justify-content: center;
|
|
background-image: url("../assets/images/login-leftBg.png");
|
|
background-size: cover;
|
|
|
|
|
|
.left-logo-container {
|
|
width: 302px;
|
|
height: 154px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.shortBar {
|
|
width: 40px;
|
|
height: 6px;
|
|
border-radius: 3px 3px 3px 3px;
|
|
background: #ffffff;
|
|
margin: 10px auto 24px auto;
|
|
}
|
|
|
|
.welcome-message {
|
|
margin: 0 auto;
|
|
font-family: Arial;
|
|
font-weight: 400;
|
|
width: 203px;
|
|
height: 29px;
|
|
font-size: 14px;
|
|
text-align: center;
|
|
color: #FFFFFF;
|
|
}
|
|
|
|
.welcome-label {
|
|
padding-top: 12px;
|
|
margin: 0 auto;
|
|
font-family: Alibaba PuHuiTi;
|
|
font-weight: 400;
|
|
width: 66px;
|
|
height: 14px;
|
|
font-size: 14px;
|
|
text-align: center;
|
|
color: #FFFFFF;
|
|
letter-spacing: 1px;
|
|
}
|
|
}
|
|
|
|
.rightForm {
|
|
width: 500px;
|
|
height: 580px;
|
|
display: flex;
|
|
/* 垂直居中 */
|
|
align-items: center;
|
|
background: #ffffff;
|
|
}
|
|
|
|
.tite-square {
|
|
width: 10px;
|
|
height: 10px;
|
|
border-radius: 2px;
|
|
background: #ffc63d;
|
|
margin: 0px 20px 4px 0;
|
|
display: inline-flex;
|
|
}
|
|
|
|
.title-label {
|
|
font-family: Alibaba PuHuiTi;
|
|
font-weight: 500;
|
|
width: 217px;
|
|
height: 32px;
|
|
font-size: 32px;
|
|
text-align: center;
|
|
color: #1A75E6;
|
|
letter-spacing: 2px;
|
|
display: inline-flex;
|
|
}
|
|
|
|
.title-container {
|
|
margin: 0px auto 70px auto;
|
|
text-align: center;
|
|
}
|
|
|
|
:deep(.el-form-item--default) {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
:deep(.el-form-item__error) {
|
|
font-family: Microsoft YaHei;
|
|
font-weight: 400;
|
|
font-size: 16px;
|
|
letter-spacing: 1px;
|
|
}
|
|
|
|
:deep(.el-input .el-input__password) {
|
|
font-size: 18px;
|
|
}
|
|
|
|
// 输入框样式
|
|
.custom-input {
|
|
width: 310px;
|
|
height: 50px;
|
|
border-left: 5px solid #1A75E6;
|
|
font-family: Microsoft YaHei;
|
|
font-weight: 400;
|
|
font-size: 18px;
|
|
text-align: center;
|
|
color: #DCDCDC;
|
|
letter-spacing: 1px;
|
|
|
|
/* Vue 3 方式 */
|
|
:deep(.el-input__wrapper.is-focus) {
|
|
box-shadow: 0 0 0 1px #A6C9FF inset;
|
|
background: #ffffff;
|
|
font-family: Arial;
|
|
font-weight: 400;
|
|
font-size: 18px;
|
|
color: #000000;
|
|
letter-spacing: 1px;
|
|
}
|
|
|
|
:deep(.el-input__wrapper:hover) {
|
|
box-shadow: 0 0 0 1px #A6C9FF inset;
|
|
background: #ffffff;
|
|
font-family: Arial;
|
|
font-weight: 400;
|
|
font-size: 18px;
|
|
color: #000000;
|
|
letter-spacing: 1px;
|
|
}
|
|
|
|
:deep(.el-input__wrapper) {
|
|
background: #f7f7f7;
|
|
border-radius: 0px;
|
|
}
|
|
}
|
|
|
|
.captcha-input {
|
|
:deep(.el-input__inner) {
|
|
position: absolute;
|
|
left: 15px;
|
|
width: 170px;
|
|
}
|
|
}
|
|
|
|
.login-form {
|
|
width: 310px;
|
|
height: 416px;
|
|
margin: 0 auto;
|
|
z-index: 1;
|
|
|
|
.el-input {
|
|
height: 50px;
|
|
--el-input-border-color: transparent;
|
|
|
|
input {
|
|
height: 50px;
|
|
}
|
|
}
|
|
|
|
.input-icon {
|
|
height: 39px;
|
|
width: 18px;
|
|
margin-left: 0px;
|
|
}
|
|
}
|
|
|
|
.login-tip {
|
|
font-size: 13px;
|
|
text-align: center;
|
|
color: #bfbfbf;
|
|
}
|
|
|
|
.login-code {
|
|
width: 33%;
|
|
height: 40px;
|
|
position: absolute;
|
|
right: 22px;
|
|
z-index: 2;
|
|
|
|
img {
|
|
cursor: pointer;
|
|
vertical-align: middle;
|
|
}
|
|
}
|
|
|
|
.myLoginBtn {
|
|
width: 310px;
|
|
height: 50px;
|
|
margin-top: 46px;
|
|
border-radius: 25px 25px 25px 25px;
|
|
background: #1a75e6;
|
|
font-family: Microsoft YaHei;
|
|
font-weight: 400;
|
|
font-size: 24px;
|
|
text-align: center;
|
|
color: #FFFFFF;
|
|
letter-spacing: 1px;
|
|
}
|
|
|
|
.el-login-footer {
|
|
height: 40px;
|
|
line-height: 40px;
|
|
position: fixed;
|
|
bottom: 0;
|
|
width: 100%;
|
|
text-align: center;
|
|
color: #fff;
|
|
font-family: Arial;
|
|
font-size: 12px;
|
|
letter-spacing: 1px;
|
|
}
|
|
|
|
.login-code-img {
|
|
height: 40px;
|
|
padding-left: 12px;
|
|
}
|
|
</style>
|