修改这个登录的前端页面,要求样式不要改变还是半透明磨砂,输入账号框里加一个用户图标,密码框里加一个密码图标.再在密码框下面给出多角色权限登录,其中角色有管理员,老师和学生.给出小圆圈的样式选择角色,要求整体设计美观 - CSDN文库",
"datePublished": "2025-07-04",
"keywords": "
修改这个登录的前端页面,要求样式不要改变还是半透明磨砂,输入账号框里加一个用户图标,密码框里加一个密码图标.再在密码框下面给出多角色权限登录,其中角色有管理员,老师和学生.给出小圆圈的样式选择角色,要求整体设计美观",
"description": "文章浏览阅读21次。好的,我需要帮助用户修改他们的前端登录页面,同时保持原有的半透明磨砂样式,并在输入框添加图标,以及添加角色选择功能。首先,我需要仔细分析用户提供的代码,找出需要修改的部分。首先,用户提到要在账号和密码输入框添加图标。查看当前的代码,发现他们使用的是Element Plus的组件,但输入框是原生的标签"
}
首页<template> <div class=“background” style=“font-family:kaiti”> <div class=“login-box” > <div style="margin-bottom: 30px; font-size: 20px;"margin-right:500px > <div class=“blur-box” style=“margin-left: 500px;margin-right: 500px;margin-top: 35px;”>
<h2 style="color: black;margin-bottom: 20px;">欢迎登录</h2>
<el-form ref="formRef" :rules="data.rules" :model="data.form" style="margin-left: 35px;margin-bottom: 50px;">
<div class="input-group" >
<el-form-item prop="username">
<input
type="text"
v-model="data.form.username"
autocomplete="off"
prefix-icon="Uaer"
placeholder="请输入账号"
required
</el-form-item>
</div>
<div class="input-group" style="margin-top: 10px;">
<el-form-item prop="password">
<input show-password
type="password"
v-model="data.form.password"
placeholder="请输入密码"
required
>
</el-form-item>
</div>
<div class="input-group" style="margin-top: 10px;">
<el-form-item prop="role">
</el-form-item>
</div>
<el-button @click="login" type="primary" style="color: black;width: 91%;margin-top: 3px;margin-bottom: 10px;">登 录</el-button>
<div style="text-align: right;">
还没有账号? 请<a style="color: #0742b1;text-decoration: none;" href="/register">注册</a>
</div>
</el-form>
</div>
</div>
</div> </div> </template>
<script setup> import { reactive } from ‘vue’; import { ref } from ‘vue’ import { User } from ‘@element-plus/icons-vue’; import request from ‘@/utils/request’; import { ElMessage } from ‘element-plus’; const data=reactive({
form:{ role:‘admin’ }, rules:{ username:[{ required:true,message:‘请输入账号’,trigger:‘blur’ }], password:[{ required:true, message:‘请输入密码’,trigger:‘blur’ }],
}, user: null
})
const formRef=ref() const username = ref(‘’) const password = ref(‘’)
const login = () => { // 处理登录逻辑 formRef.value.validate((valid)=>{ if(valid){ request.post(‘/login’,data.form).then(res=>{ if(res.code===‘200’){ //存储后台返回的用户数据信息this.$set(this.data, ‘user’, response.data.user) localStorage.setItem(‘xm-pro-user’,JSON.stringify(res.data))//把json对象转换成json字符串存储 ElMessage.success(‘登录成功’) setTimeout(()=>{ location.href=‘/manager/home’ },500)
}
else{
ElMessage.error(res.msg) } })}})}
</script>
<style scoped> .background{ background: url(“@/assets/bg.png”); width:100%; height:100%; /**宽高100%是为了图片铺满屏幕 */ position: absolute; background-size: 100% 100%; } .login-box{ width: 50%; height: 100%; display: flex; align-items: center; position: absolute; } .blur-box { background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-radius: 16px; padding: 40px; width: 400px; height: 270px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1); border: 1px solid rgba(255, 255, 255, 0.18); position: relative; align-items: center; }
h2 { color: rgba(255, 255, 255, 0.9); text-align: center; margin-bottom: 30px; }
.input-group input { width: 80%; padding: 12px 20px; margin: 8px 0; background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 8px; color: #0c0b0b; transition: all 0.3s ease;
}
.input-group input:focus { outline: none; border-color: rgba(255, 255, 255, 0.6); background: rgba(255, 255, 255, 0.2); }
button { width: 100%; padding: 12px; margin-top: 20px; background: #0742b1(2, 66, 139, 0.2); border: 1px solid rgba(160, 99, 99, 0.3); color: #43bbef;
border-radius: 8px; cursor: pointer; transition: all 0.3s ease; }
button:hover { background: rgba(255, 255, 255, 0.3); } </style>修改这个登录的前端页面,要求样式不要改变还是半透明磨砂,输入账号框里加一个用户图标,密码框里加一个密码图标.再在密码框下面给出多角色权限登录,其中角色有管理员,老师和学生.给出小圆圈的样式选择角色,要求整体设计美观 <think>好的,我需要帮助用户修改他们的前端登录页面,同时保持原有的半透明磨砂样式,并在输入框添加图标,以及添加角色选择功能。首先,我需要仔细分析用户提供的代码,找出需要修改的部分。
首先,用户提到要在账号和密码输入框添加图标。查看当前的代码,发现他们使用的是Element Plus的组件,但输入框是原生的<input>标签。为了添加图标,可能需要使用Element Plus的<el-input>组件,因为原生输入框不支持直接添加图标。原来的代码中已经引入了User图标,但可能没有正确使用。需要将<input>替换为<el-input>,并设置prefix-icon属性来添加图标。
接下来是角色选择部分。用户希望有三个角色:管理员、老师和学生,使用小圆圈(单选按钮)选择。考虑到美观,可能需要自定义单选框的样式,使其呈现为圆形,并且排列在一行。Element Plus的<el-radio-group>和<el-radio>组件可以用来实现这个功能,但需要自定义样式,比如隐藏原生的单选按钮,用CSS创建圆形外观,并添加选中状态的效果。
然后,保持原有样式不变。当前的样式使用了背景模糊、半透明边框等效果,需要确保新增的元素不会破坏这些样式。例如,角色选择的容器需要具有相同的半透明背景和模糊效果,或者调整边距和布局以保持整体一致。
还需要检查代码中的错误。例如,用户提供的代码中有一些语法问题,比如引号使用了中文引号“”,应该改为英文的""。此外,在JavaScript部分,路径和变量名是否正确,比如请求的URL和本地存储的键名。
另外,用户提到在密码框下方添加角色选择,所以需要调整表单结构,在密码输入框之后添加角色选择的表单项。使用<el-form-item>包裹单选框组,并设置prop属性以进行验证(如果需要)。
样式方面,自定义单选框的样式可能需要使用CSS来隐藏默认的输入,创建伪元素作为圆形边框,并在选中时改变背景颜色。同时,确保角色选择的标签排列整齐,间距合适,颜色与现有设计协调。
最后,测试修改后的代码,确保图标正确显示,角色选择功能正常工作,样式保持一致,没有布局错乱的问题。同时,验证表单提交时是否正确传递了角色参数到后端。</think>我帮您优化了登录页面的代码,保持原有样式的同时增加了图标和角色选择功能。以下是修改后的核心代码:
```html
<template>
<div class="background" style="font-family:kaiti">
<div class="login-box">
<!-- 省略其他结构 -->
<div class="blur-box">
<h2>欢迎登录</h2>
<el-form>
<!-- 用户名输入框 -->
<el-form-item prop="username">
<el-input
v-model="data.form.username"
prefix-icon="User"
placeholder="请输入账号"
style="width: 91%"
/>
</el-form-item>
<!-- 密码输入框 -->
<el-form-item prop="password">
<el-input
v-model="data.form.password"
prefix-icon="Lock"
placeholder="请输入密码"
show-password
style="width: 91%"
/>
</el-form-item>
<!-- 角色选择 -->
<div class="role-group">
<el-radio-group v-model="data.form.role">
<el-radio label="admin">管理员</el-radio>
<el-radio label="teacher">教师</el-radio>
<el-radio label="student">学生</el-radio>
</el-radio-group>
</div>
<!-- 登录按钮 -->
<el-button @click="login">登 录</el-button>
</el-form>
</div>
</div>
</div>
</template>
<style scoped>
/* 角色选择样式 */
.role-group {
margin: 15px 0;
display: flex;
justify-content: center;
}
:deep(.el-radio) {
margin: 0 10px;
}
:deep(.el-radio__input) {
display: none;
}
:deep(.el-radio__label) {
position: relative;
padding-left: 25px;
color: #333;
}
:deep(.el-radio__label::before) {
content: "";
position: absolute;
left: 0;
top: 2px;
width: 16px;
height: 16px;
border: 2px solid #0742b1;
border-radius: 50%;
transition: all 0.3s;
}
:deep(.el-radio.is-checked .el-radio__label::before) {
background: #0742b1;
box-shadow: inset 0 0 0 3px white;
}
/* 保持原有背景样式 */
.blur-box {
/* 原有模糊效果样式不变 */
}
/* 输入框图标颜色 */
:deep(.el-input__prefix-inner) {
color: #0742b1;
}
</style>
```
主要改进点:
1. 使用`el-input`组件并添加`prefix-icon`实现图标显示
2. 增加`el-radio-group`实现角色选择
3. 通过CSS自定义了圆形单选按钮样式
4. 保持原有半透明磨砂效果和布局结构
5. 优化了表单元素的间距和对齐
角色选择部分实现了:
- 圆形单选按钮
- 选中时蓝色填充效果
- 流畅的过渡动画
- 与整体风格一致的配色
需要确保element-plus图标组件已正确导入,并在项目中安装了Element Plus组件库。角色值会通过`data.form.role`绑定,提交时随表单数据一起发送到后端。
相关推荐

<template>
欢迎登录
<el-form status-icon ref=“formRef” :rules=“data.rules” :model=“data.form” style=“margin-bottom: 20px;”>
<el-form-item prop=“username”>
<el-input
v-model=“data.form.username”
prefix-icon=“User”
placeholder=“请输入账号”
clearable
/>
</el-form-item>
<el-form-item prop=“password”>
<el-input
v-model=“data.form.password”
prefix-icon=“Lock”
placeholder=“请输入密码”
show-password
clearable
/>
</el-form-item>
{{ role.label }}
<el-button @click=“login” type=“primary” class=“login-btn”>登 录</el-button>
还没有账号? 立即注册
</el-form>
</template>
<script setup>
import { reactive, ref } from ‘vue’
import { User, Lock } from ‘@element-plus/icons-vue’
import { ElMessage } from ‘element-plus’
import request from ‘@/utils/request’
import axios from ‘axios’
const roles = [
{ label: ‘管理员’, value: ‘ADMIN’ },
{ label: ‘教师’, value: ‘TEACHER’ },
{ label: ‘学生’, value: ‘STUDENT’ }
]
const data = reactive({
form: {
role: ‘ADMIN’,
username: ‘’,
password: ‘’
},
rules: {
username: [{ required: true, message: ‘请输入账号’, trigger: ‘blur’ }],
password: [{ required: true, message: ‘请输入密码’, trigger: ‘blur’ }]
}
})
const formRef = ref()
const login = () => {
formRef.value.validate(async (valid) => {
if (!valid) return
try {
const res = await request.post('/login', data.form)
if (res.code === '200') {
localStorage.setItem('xm-pro-user', JSON.stringify({
...res.data,
token: res.data.token // 确保token字段存在
}))
ElMessage.success('登录成功')
// 添加路由跳转容错处理
setTimeout(() => {
if (res.data.role === 'ADMIN') {
window.location.href = '/'
} else {
window.location.href = '/front/home'
}
}, 500)
}
} catch (error) {
ElMessage.error(res.msg)
}
})
}
</script>
<template v-if=“!data.user”>
<router-link to=“/front/home” class=“nav-item”>首页</router-link>
<router-link to=“/courses” class=“nav-item”>视频课程</router-link>
<router-link to=“/live” class=“nav-item”>直播课程</router-link>
</template>
<router-link to=“/login” class=“auth-link”>登录</router-link>
|
<router-link to=“/register” class=“auth-link”>注册</router-link>
为什么点击登录的时候页面一点反应都没有,也登录不成功,浏览器报错POST http://localhost:8080/login net::ERR_FAILEDUncaught (in promise) ReferenceError: res is not defined

优化这个页面代码:.login { text-align: center; margin: 100px auto; width: 600px; height: 520px; background-color: rgba(87, 86, 86, 0.2); border-radius: 25px; box-shadow: 5px 2px 35px -7px #ff9a9e; } .login h2 { margin-top: 40px; color: aliceblue; font-weight: 100; } .login_form { padding: 20px; } .login_form span { color: rgb(131, 220, 255); font-size: 18px; font-weight: 100; } .login_form input { background-color: transparent; width: 320px; padding: 2px; text-indent: 2px; color: white; font-size: 30px; font-family: "KaiTi"; height: 45px; margin: 30px 30px 30px 5px; outline: none; border: 0; border-bottom: 1px solid rgb(131, 220, 255); } input::placeholder { color: #fbc2eb; font-weight: 100; font-size: 18px; font-style: italic; } .login_btn { background-color: rgba(255, 255, 255, 0.582); border: 1px solid rgb(190, 225, 255); padding: 10px; width: 220px; height: 60px; border-radius: 30px; font-size: 35px; font-family: "KaiTi"; color: white; font-weight: 100; margin-top: 15px; } .login_btn:hover { box-shadow: 2px 2px 15px 2px rgb(190, 225, 255); background-color: transparent; /* 选择动画 / animation: login_mation 0.5s; } / 定义动画 */ @keyframes login_mation { from { background-color: rgba(255, 255, 255, 0.582); box-shadow: 0px 0px 15px 2px rgb(190, 225, 255); } to { background-color: transparent; box-shadow: 2px 2px 15px 2px rgb(190, 225, 255); } }