2 changed files with 1473 additions and 197 deletions
@ -1,225 +1,537 @@ |
|||
<template> |
|||
<div class="login"> |
|||
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> |
|||
<h3 class="title">{{title}}</h3> |
|||
<el-form-item prop="username"> |
|||
<el-input |
|||
v-model="loginForm.username" |
|||
type="text" |
|||
auto-complete="off" |
|||
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="密码" |
|||
@keyup.enter.native="handleLogin" |
|||
> |
|||
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> |
|||
</el-input> |
|||
</el-form-item> |
|||
<el-form-item prop="code" v-if="captchaEnabled"> |
|||
<el-input |
|||
v-model="loginForm.code" |
|||
auto-complete="off" |
|||
placeholder="验证码" |
|||
style="width: 63%" |
|||
@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 class="page-container"> |
|||
<!-- 登录主容器 --> |
|||
<div class="login-wrapper"> |
|||
<!-- 系统logo+名称 --> |
|||
<div class="system-info"> |
|||
<div class="logo-box"> |
|||
<i class="el-icon-location logo-icon"></i> |
|||
</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="medium" |
|||
type="primary" |
|||
style="width:100%;" |
|||
@click.native.prevent="handleLogin" |
|||
<h1 class="system-title">多人联网演示系统</h1> |
|||
</div> |
|||
|
|||
<!-- 登录卡片 --> |
|||
<div class="login-card"> |
|||
<!-- 登录/注册切换标签 --> |
|||
<div class="tab-container"> |
|||
<button |
|||
@click="switchTab('login')" |
|||
:class="{ 'tab-active': activeTab === 'login' }" |
|||
class="tab-item" |
|||
> |
|||
<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> |
|||
<i class="el-icon-user mr-1"></i> 登录 |
|||
</button> |
|||
<button |
|||
@click="switchTab('register')" |
|||
:class="{ 'tab-active': activeTab === 'register' }" |
|||
class="tab-item" |
|||
> |
|||
<i class="el-icon-edit mr-1"></i> 注册 |
|||
</button> |
|||
</div> |
|||
|
|||
<!-- 表单容器 --> |
|||
<div class="form-container"> |
|||
<!-- 登录表单 --> |
|||
<div v-if="activeTab === 'login'"> |
|||
<!-- 账号输入 --> |
|||
<div class="form-item"> |
|||
<label class="form-label">账号</label> |
|||
<div class="input-wrapper"> |
|||
<i class="el-icon-user input-icon"></i> |
|||
<input |
|||
type="text" |
|||
v-model="form.username" |
|||
placeholder="请输入账号" |
|||
class="form-input" |
|||
> |
|||
</div> |
|||
</div> |
|||
|
|||
<!-- 密码输入 --> |
|||
<div class="form-item"> |
|||
<div class="pwd-label-wrapper"> |
|||
<label class="form-label">密码</label> |
|||
<a href="#" class="forgot-pwd">忘记密码?</a> |
|||
</div> |
|||
<div class="input-wrapper"> |
|||
<i class="el-icon-lock input-icon"></i> |
|||
<input |
|||
:type="showPwd ? 'text' : 'password'" |
|||
v-model="form.password" |
|||
placeholder="请输入密码" |
|||
class="form-input" |
|||
> |
|||
<i |
|||
@click="togglePwd" |
|||
:class="showPwd ? 'el-icon-view' : 'el-icon-hide'" |
|||
class="toggle-pwd-icon" |
|||
></i> |
|||
</div> |
|||
</div> |
|||
|
|||
<!-- 记住密码 + 自动登录 --> |
|||
<div class="checkbox-group"> |
|||
<label class="checkbox-item"> |
|||
<input type="checkbox" checked class="checkbox"> |
|||
<span>记住密码</span> |
|||
</label> |
|||
<label class="checkbox-item"> |
|||
<input type="checkbox" class="checkbox"> |
|||
<span>自动登录</span> |
|||
</label> |
|||
</div> |
|||
|
|||
<!-- 登录按钮 --> |
|||
<button |
|||
@click="handleLogin" |
|||
:class="{ 'login-btn-disabled': isLogging }" |
|||
class="login-btn" |
|||
> |
|||
{{ isLogging ? '登录中...' : '登录系统' }} |
|||
</button> |
|||
</div> |
|||
|
|||
<!-- 注册表单 --> |
|||
<div v-else-if="activeTab === 'register'"> |
|||
<!-- 账号输入 --> |
|||
<div class="form-item"> |
|||
<label class="form-label">账号</label> |
|||
<div class="input-wrapper"> |
|||
<i class="el-icon-user input-icon"></i> |
|||
<input |
|||
type="text" |
|||
v-model="form.username" |
|||
placeholder="请输入账号" |
|||
class="form-input" |
|||
> |
|||
</div> |
|||
</div> |
|||
|
|||
<!-- 密码输入 --> |
|||
<div class="form-item"> |
|||
<label class="form-label">密码</label> |
|||
<div class="input-wrapper"> |
|||
<i class="el-icon-lock input-icon"></i> |
|||
<input |
|||
:type="showPwd ? 'text' : 'password'" |
|||
v-model="form.password" |
|||
placeholder="请输入密码" |
|||
class="form-input" |
|||
> |
|||
<i |
|||
@click="togglePwd" |
|||
:class="showPwd ? 'el-icon-view' : 'el-icon-hide'" |
|||
class="toggle-pwd-icon" |
|||
></i> |
|||
</div> |
|||
</div> |
|||
|
|||
<!-- 确认密码输入 --> |
|||
<div class="form-item"> |
|||
<label class="form-label">确认密码</label> |
|||
<div class="input-wrapper"> |
|||
<i class="el-icon-lock input-icon"></i> |
|||
<input |
|||
:type="showConfirmPwd ? 'text' : 'password'" |
|||
v-model="form.confirmPassword" |
|||
placeholder="请确认密码" |
|||
class="form-input" |
|||
> |
|||
<i |
|||
@click="toggleConfirmPwd" |
|||
:class="showConfirmPwd ? 'el-icon-view' : 'el-icon-hide'" |
|||
class="toggle-pwd-icon" |
|||
></i> |
|||
</div> |
|||
</div> |
|||
|
|||
<!-- 权限等级 --> |
|||
<div class="form-item"> |
|||
<label class="form-label">权限等级</label> |
|||
<select |
|||
v-model="form.role" |
|||
class="form-select" |
|||
> |
|||
<option value="user">普通用户</option> |
|||
<option value="host">主持人</option> |
|||
<option value="admin">管理员</option> |
|||
</select> |
|||
</div> |
|||
|
|||
<!-- 注册按钮 --> |
|||
<button |
|||
@click="handleRegister" |
|||
:class="{ 'login-btn-disabled': isRegistering }" |
|||
class="login-btn" |
|||
> |
|||
{{ isRegistering ? '注册中...' : '注册账号' }} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
</el-form-item> |
|||
</el-form> |
|||
<!-- 底部 --> |
|||
<div class="el-login-footer"> |
|||
<span>{{ footerContent }}</span> |
|||
</div> |
|||
|
|||
<!-- 底部版权/提示 --> |
|||
<div class="copyright"> |
|||
<p>© 2026 多人联网演示系统 | 支持Windows/国产化系统互通</p> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import { getCodeImg } from "@/api/login" |
|||
import Cookies from "js-cookie" |
|||
import { encrypt, decrypt } from '@/utils/jsencrypt' |
|||
import defaultSettings from '@/settings' |
|||
import axios from 'axios'; |
|||
|
|||
export default { |
|||
name: "Login", |
|||
name: 'Login', |
|||
data() { |
|||
return { |
|||
title: process.env.VUE_APP_TITLE, |
|||
footerContent: defaultSettings.footerContent, |
|||
codeUrl: "", |
|||
loginForm: { |
|||
username: "admin", |
|||
password: "admin123", |
|||
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 |
|||
activeTab: 'login', |
|||
showPwd: false, |
|||
showConfirmPwd: false, |
|||
isLogging: false, |
|||
isRegistering: false, |
|||
// 表单数据 |
|||
form: { |
|||
username: '', |
|||
password: '', |
|||
confirmPassword: '', |
|||
role: 'user' // 默认普通用户 |
|||
} |
|||
} |
|||
}, |
|||
created() { |
|||
this.getCode() |
|||
this.getCookie() |
|||
}, |
|||
methods: { |
|||
getCode() { |
|||
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 |
|||
} |
|||
}) |
|||
switchTab(tab) { |
|||
this.activeTab = tab; |
|||
}, |
|||
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) |
|||
} |
|||
togglePwd() { |
|||
this.showPwd = !this.showPwd; |
|||
}, |
|||
toggleConfirmPwd() { |
|||
this.showConfirmPwd = !this.showConfirmPwd; |
|||
}, |
|||
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(()=>{}) |
|||
// 跳转选择房间 |
|||
this.$router.push({ path: this.redirect || "/selectRoom" }).catch(()=>{}) |
|||
}).catch(() => { |
|||
this.loading = false |
|||
if (this.captchaEnabled) { |
|||
this.getCode() |
|||
} |
|||
}) |
|||
} |
|||
}) |
|||
if (this.isLogging) return; |
|||
this.isLogging = true; |
|||
// 直接跳转到selectRoom界面,忽略密码验证 |
|||
setTimeout(() => { |
|||
this.$router.push('/selectRoom'); |
|||
this.isLogging = false; |
|||
}, 500); |
|||
}, |
|||
async handleRegister() { |
|||
if (this.isRegistering) return; |
|||
|
|||
// 表单验证 |
|||
if (!this.form.username || !this.form.password || !this.form.confirmPassword) { |
|||
alert('请填写所有必填字段'); |
|||
return; |
|||
} |
|||
|
|||
if (this.form.password !== this.form.confirmPassword) { |
|||
alert('两次输入的密码不一致'); |
|||
return; |
|||
} |
|||
|
|||
this.isRegistering = true; |
|||
|
|||
try { |
|||
const response = await axios.post('http://localhost:3002/api/users/register', { |
|||
username: this.form.username, |
|||
password: this.form.password, |
|||
role: this.form.role |
|||
}); |
|||
|
|||
this.isRegistering = false; |
|||
alert('注册成功,请登录'); |
|||
this.switchTab('login'); |
|||
// 清空表单 |
|||
this.form = { |
|||
username: '', |
|||
password: '', |
|||
confirmPassword: '', |
|||
role: 'user' |
|||
}; |
|||
} catch (error) { |
|||
this.isRegistering = false; |
|||
alert(error.response?.data?.message || '注册失败,请重试'); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<style rel="stylesheet/scss" lang="scss" scoped> |
|||
.login { |
|||
<style scoped> |
|||
/* 全局页面样式 */ |
|||
.page-container { |
|||
background-color: #F9FAFB; /* 原 neutral 色值 */ |
|||
min-height: 100vh; |
|||
display: flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
padding: 16px; |
|||
color: #333842; /* 原 dark 色值 */ |
|||
font-family: Inter, system-ui, sans-serif; |
|||
} |
|||
|
|||
/* 登录主容器 */ |
|||
.login-wrapper { |
|||
width: 100%; |
|||
max-width: 320px; |
|||
} |
|||
|
|||
/* 系统信息(logo+名称) */ |
|||
.system-info { |
|||
text-align: center; |
|||
margin-bottom: 24px; |
|||
display: flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
gap: 12px; |
|||
} |
|||
|
|||
.logo-box { |
|||
display: inline-block; |
|||
width: 48px; |
|||
height: 48px; |
|||
background-color: #165DFF; /* 原 primary 色值 */ |
|||
border-radius: 50%; |
|||
display: flex; |
|||
align-items: center; |
|||
height: 100%; |
|||
background-image: url("../assets/images/login-background.jpg"); |
|||
background-size: cover; |
|||
justify-content: center; |
|||
margin-bottom: 0; |
|||
} |
|||
|
|||
.logo-icon { |
|||
color: white; |
|||
font-size: 24px; |
|||
} |
|||
|
|||
.system-title { |
|||
font-size: 20px; |
|||
font-weight: 600; |
|||
color: #333842; |
|||
margin: 0; |
|||
} |
|||
|
|||
.system-desc { |
|||
font-size: 12px; |
|||
color: #9CA3AF; /* 原 gray-500 色值 */ |
|||
margin-top: 4px; |
|||
} |
|||
|
|||
/* 登录卡片 */ |
|||
.login-card { |
|||
background-color: white; |
|||
border-radius: 8px; |
|||
box-shadow: 0 4px 12px rgba(22, 93, 255, 0.08); |
|||
overflow: hidden; |
|||
} |
|||
.title { |
|||
margin: 0px auto 30px auto; |
|||
|
|||
/* 标签容器 */ |
|||
.tab-container { |
|||
display: flex; |
|||
border-bottom: 1px solid #E5E7EB; /* 原 gray-200 色值 */ |
|||
} |
|||
|
|||
.tab-item { |
|||
flex: 1; |
|||
padding: 12px 0; |
|||
font-size: 14px; |
|||
text-align: center; |
|||
color: #707070; |
|||
background: transparent; |
|||
border: none; |
|||
cursor: pointer; |
|||
color: #333842; |
|||
transition: color 0.2s; |
|||
} |
|||
|
|||
.tab-item:hover { |
|||
color: #165DFF; /* 原 primary 色值 */ |
|||
} |
|||
|
|||
.tab-active { |
|||
border-bottom: 2px solid #165DFF; |
|||
color: #165DFF; |
|||
font-weight: 500; |
|||
} |
|||
|
|||
/* 表单容器 */ |
|||
.form-container { |
|||
padding: 24px; |
|||
} |
|||
|
|||
.form-item { |
|||
margin-bottom: 16px; |
|||
} |
|||
|
|||
.form-item:last-of-type { |
|||
margin-bottom: 20px; |
|||
} |
|||
|
|||
.form-label { |
|||
display: block; |
|||
font-size: 12px; |
|||
font-weight: 500; |
|||
margin-bottom: 4px; |
|||
color: #71717A; /* 原 gray-600 色值 */ |
|||
} |
|||
|
|||
.login-form { |
|||
/* 房间选择下拉框 */ |
|||
.form-select { |
|||
width: 100%; |
|||
padding: 8px 12px; |
|||
border: 1px solid #E5E7EB; |
|||
border-radius: 6px; |
|||
background: #ffffff; |
|||
width: 400px; |
|||
padding: 25px 25px 5px 25px; |
|||
z-index: 1; |
|||
.el-input { |
|||
height: 38px; |
|||
input { |
|||
height: 38px; |
|||
} |
|||
} |
|||
.input-icon { |
|||
height: 39px; |
|||
width: 14px; |
|||
margin-left: 2px; |
|||
} |
|||
font-size: 14px; |
|||
outline: none; |
|||
transition: border-color 0.2s; |
|||
} |
|||
.login-tip { |
|||
font-size: 13px; |
|||
text-align: center; |
|||
color: #bfbfbf; |
|||
} |
|||
.login-code { |
|||
width: 33%; |
|||
height: 38px; |
|||
float: right; |
|||
img { |
|||
cursor: pointer; |
|||
vertical-align: middle; |
|||
} |
|||
|
|||
.form-select:focus { |
|||
border-color: #165DFF; |
|||
} |
|||
|
|||
/* 输入框容器 */ |
|||
.input-wrapper { |
|||
position: relative; |
|||
} |
|||
|
|||
.form-input { |
|||
width: 100%; |
|||
padding: 8px 12px 8px 36px; |
|||
border: 1px solid #E5E7EB; |
|||
border-radius: 6px; |
|||
font-size: 14px; |
|||
outline: none; |
|||
transition: border-color 0.2s; |
|||
} |
|||
|
|||
.form-input:focus { |
|||
border-color: #165DFF; |
|||
} |
|||
|
|||
.input-icon { |
|||
position: absolute; |
|||
left: 12px; |
|||
top: 50%; |
|||
transform: translateY(-50%); |
|||
color: #9CA3AF; /* 原 gray-400 色值 */ |
|||
} |
|||
|
|||
/* 密码标签行 */ |
|||
.pwd-label-wrapper { |
|||
display: flex; |
|||
justify-content: space-between; |
|||
align-items: center; |
|||
margin-bottom: 4px; |
|||
} |
|||
|
|||
.forgot-pwd { |
|||
font-size: 12px; |
|||
color: #165DFF; |
|||
text-decoration: none; |
|||
} |
|||
|
|||
.forgot-pwd:hover { |
|||
text-decoration: underline; |
|||
} |
|||
|
|||
/* 密码显隐图标 */ |
|||
.toggle-pwd-icon { |
|||
position: absolute; |
|||
right: 12px; |
|||
top: 50%; |
|||
transform: translateY(-50%); |
|||
color: #9CA3AF; |
|||
cursor: pointer; |
|||
} |
|||
|
|||
/* 复选框组 */ |
|||
.checkbox-group { |
|||
display: flex; |
|||
align-items: center; |
|||
font-size: 12px; |
|||
margin-bottom: 24px; |
|||
} |
|||
|
|||
.checkbox-item { |
|||
display: flex; |
|||
align-items: center; |
|||
cursor: pointer; |
|||
margin-right: 16px; |
|||
} |
|||
|
|||
.checkbox { |
|||
margin-right: 4px; |
|||
color: #165DFF; |
|||
} |
|||
.el-login-footer { |
|||
height: 40px; |
|||
line-height: 40px; |
|||
position: fixed; |
|||
bottom: 0; |
|||
|
|||
/* 登录按钮 */ |
|||
.login-btn { |
|||
width: 100%; |
|||
background-color: #165DFF; |
|||
color: white; |
|||
padding: 8px 0; |
|||
border: none; |
|||
border-radius: 6px; |
|||
font-size: 14px; |
|||
font-weight: 500; |
|||
cursor: pointer; |
|||
transition: background-color 0.2s; |
|||
} |
|||
|
|||
.login-btn:hover { |
|||
background-color: rgba(22, 93, 255, 0.9); |
|||
} |
|||
|
|||
.login-btn-disabled { |
|||
opacity: 0.8; |
|||
cursor: not-allowed; |
|||
} |
|||
|
|||
/* 其他登录方式 */ |
|||
.other-login { |
|||
text-align: center; |
|||
color: #fff; |
|||
font-family: Arial; |
|||
margin-top: 24px; |
|||
} |
|||
|
|||
.other-login-desc { |
|||
font-size: 12px; |
|||
letter-spacing: 1px; |
|||
color: #9CA3AF; |
|||
margin-bottom: 12px; |
|||
} |
|||
|
|||
.other-login-btns { |
|||
display: flex; |
|||
justify-content: center; |
|||
gap: 16px; |
|||
} |
|||
|
|||
.other-login-btn { |
|||
width: 32px; |
|||
height: 32px; |
|||
border-radius: 50%; |
|||
background-color: #E8F3FF; /* 原 secondary 色值 */ |
|||
border: none; |
|||
color: #165DFF; |
|||
display: flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
cursor: pointer; |
|||
transition: all 0.2s; |
|||
} |
|||
|
|||
.other-login-btn:hover { |
|||
background-color: #165DFF; |
|||
color: white; |
|||
} |
|||
.login-code-img { |
|||
height: 38px; |
|||
|
|||
/* 版权信息 */ |
|||
.copyright { |
|||
text-align: center; |
|||
margin-top: 16px; |
|||
font-size: 12px; |
|||
color: #9CA3AF; |
|||
} |
|||
</style> |
|||
|
|||
File diff suppressed because it is too large
Loading…
Reference in new issue