Browse Source

登录界面和房间选择

lbj
sd 3 months ago
parent
commit
8a18dfd0b7
  1. 682
      ruoyi-ui/src/views/login.vue
  2. 988
      ruoyi-ui/src/views/selectRoom/index.vue

682
ruoyi-ui/src/views/login.vue

@ -1,225 +1,537 @@
<template> <template>
<div class="login"> <div class="page-container">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> <!-- 登录主容器 -->
<h3 class="title">{{title}}</h3> <div class="login-wrapper">
<el-form-item prop="username"> <!-- 系统logo+名称 -->
<el-input <div class="system-info">
v-model="loginForm.username" <div class="logo-box">
type="text" <i class="el-icon-location logo-icon"></i>
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> </div>
</el-form-item> <h1 class="system-title">多人联网演示系统</h1>
<el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox> </div>
<el-form-item style="width:100%;">
<el-button <!-- 登录卡片 -->
:loading="loading" <div class="login-card">
size="medium" <!-- 登录/注册切换标签 -->
type="primary" <div class="tab-container">
style="width:100%;" <button
@click.native.prevent="handleLogin" @click="switchTab('login')"
:class="{ 'tab-active': activeTab === 'login' }"
class="tab-item"
> >
<span v-if="!loading"> </span> <i class="el-icon-user mr-1"></i> 登录
<span v-else> 中...</span> </button>
</el-button> <button
<div style="float: right;" v-if="register"> @click="switchTab('register')"
<router-link class="link-type" :to="'/register'">立即注册</router-link> :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> </div>
</el-form-item> </div>
</el-form>
<!-- 底部 --> <!-- 底部版权/提示 -->
<div class="el-login-footer"> <div class="copyright">
<span>{{ footerContent }}</span> <p>© 2026 多人联网演示系统 | 支持Windows/国产化系统互通</p>
</div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { getCodeImg } from "@/api/login" import axios from 'axios';
import Cookies from "js-cookie"
import { encrypt, decrypt } from '@/utils/jsencrypt'
import defaultSettings from '@/settings'
export default { export default {
name: "Login", name: 'Login',
data() { data() {
return { return {
title: process.env.VUE_APP_TITLE, activeTab: 'login',
footerContent: defaultSettings.footerContent, showPwd: false,
codeUrl: "", showConfirmPwd: false,
loginForm: { isLogging: false,
username: "admin", isRegistering: false,
password: "admin123", //
rememberMe: false, form: {
code: "", username: '',
uuid: "" password: '',
}, confirmPassword: '',
loginRules: { role: 'user' //
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.getCode()
this.getCookie()
},
methods: { methods: {
getCode() { switchTab(tab) {
getCodeImg().then(res => { this.activeTab = tab;
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() { togglePwd() {
const username = Cookies.get("username") this.showPwd = !this.showPwd;
const password = Cookies.get("password") },
const rememberMe = Cookies.get('rememberMe') toggleConfirmPwd() {
this.loginForm = { this.showConfirmPwd = !this.showConfirmPwd;
username: username === undefined ? this.loginForm.username : username,
password: password === undefined ? this.loginForm.password : decrypt(password),
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
}
}, },
handleLogin() { handleLogin() {
this.$refs.loginForm.validate(valid => { if (this.isLogging) return;
if (valid) { this.isLogging = true;
this.loading = true // selectRoom
if (this.loginForm.rememberMe) { setTimeout(() => {
Cookies.set("username", this.loginForm.username, { expires: 30 }) this.$router.push('/selectRoom');
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 }) this.isLogging = false;
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 }) }, 500);
} else { },
Cookies.remove("username") async handleRegister() {
Cookies.remove("password") if (this.isRegistering) return;
Cookies.remove('rememberMe')
} //
this.$store.dispatch("Login", this.loginForm).then(() => { if (!this.form.username || !this.form.password || !this.form.confirmPassword) {
// this.$router.push({ path: this.redirect || "/" }).catch(()=>{}) alert('请填写所有必填字段');
// return;
this.$router.push({ path: this.redirect || "/selectRoom" }).catch(()=>{}) }
}).catch(() => {
this.loading = false if (this.form.password !== this.form.confirmPassword) {
if (this.captchaEnabled) { alert('两次输入的密码不一致');
this.getCode() 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> </script>
<style rel="stylesheet/scss" lang="scss" scoped> <style scoped>
.login { /* 全局页面样式 */
.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; display: flex;
align-items: center;
justify-content: 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; align-items: center;
height: 100%; justify-content: center;
background-image: url("../assets/images/login-background.jpg"); margin-bottom: 0;
background-size: cover; }
.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; 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; border-radius: 6px;
background: #ffffff; font-size: 14px;
width: 400px; outline: none;
padding: 25px 25px 5px 25px; transition: border-color 0.2s;
z-index: 1;
.el-input {
height: 38px;
input {
height: 38px;
}
}
.input-icon {
height: 39px;
width: 14px;
margin-left: 2px;
}
} }
.login-tip {
font-size: 13px; .form-select:focus {
text-align: center; border-color: #165DFF;
color: #bfbfbf; }
}
.login-code { /* 输入框容器 */
width: 33%; .input-wrapper {
height: 38px; position: relative;
float: right; }
img {
cursor: pointer; .form-input {
vertical-align: middle; 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; .login-btn {
position: fixed;
bottom: 0;
width: 100%; 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; text-align: center;
color: #fff; margin-top: 24px;
font-family: Arial; }
.other-login-desc {
font-size: 12px; 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> </style>

988
ruoyi-ui/src/views/selectRoom/index.vue

File diff suppressed because it is too large
Loading…
Cancel
Save