使用vue3实现页面学生成绩录入系统

实现的功能如下:

  • 输入框为空提示
  • 数据添加
  • 平均分计算
  • 总分计算
  • 姓名搜索

代码如下

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>实验二</title>
		<link rel="stylesheet" href="../实验二/css/实验二.css">
		<script type="text/javascript"  src="../实验二/js/vue.global.prod.js" charset="utf-8"></script>
	</head>
	<body>
		<div id="app">
			<h3>学生成绩录入系统</h3>
			<div class="inputInfo">
				<label for="studentName">姓名:</label>
				<input type="text" id="studentName" placeholder="请输入学生的姓名......" v-model="newStudent.stuName" />
			</div>
			<div class="inputInfo">
				<label for="studentID">学号:</label>
				<input type="text" id="studentID" placeholder="请输入学生的学号......" v-model="newStudent.stuID" />
			</div>
			<div class="inputInfo">
				<label for="studentScore_One">课程一(HTML5应用开发):</label>
				<input type="number" id="studentScore_One" placeholder="请输入课程成绩......" v-model.number="newStudent.scoreOne" />
			</div>
			<div class="inputInfo">
				<label for="studentScore_Two">课程二(JavaScript程序设计):</label>
				<input type="number" id="studentScore_Two" placeholder="请输入课程成绩......" v-model.number="newStudent.scoreTwo" />
			</div>
			<div class="inputInfo">
				<label for="studentScore_Three">课程三(前端框架(Vue.js)应用开发):</label>
				<input type="number" id="studentScore_Three" placeholder="请输入课程成绩......" v-model.number="newStudent.scoreThree" />
			</div>
			<button class="btnStyle createBtn" @click="createNewStudent()">添加学生成绩</button>
			
			<hr />
			<!-- 学生信息列表 -->
			<h3>学生成绩列表</h3>
			<div class="optionBtn">
				<button class="btnStyle averageBtn" @click="averageThree()">显示课程三的平均值</button>
				<button class="btnStyle averageBtn" @click="averageTotal()">显示个人课程平均分</button>
			</div>
			<table class="studentList">
				<thead>
					<tr>
						<td>姓名</td>
						<td>学号</td>
						<td>课程一<br />(HTML5应用开发)</td>
						<td>课程二<br />(JavaScript程序设计)</td>
						<td><a href="javascript:void(0)" @click="sortScoreThree()">课程三<br />(前端框架(Vue.js)应用开发)↑</a></td>
						<td>个人课程<br />总分</td>
						<td>个人课程<br />平均分</td>
						<td>操作</td>
					</tr>
				</thead>
				<tbody>
					<tr v-for="(student,index) in students">
						<td>{{student.stuName}}</td>
						<td>{{student.stuID}}</td>
						<td>{{student.scoreOne}}</td>
						<td>{{student.scoreTwo}}</td>
						<td>{{student.scoreThree}}</td>
						<td>{{scoreTotal(index)}}</td>
						<td>{{student.scoreAverage}}</td>
						<td>
							<button class="btnStyle deleteBtn" @click="deleteStudent(index)">删除</button>
						</td>
					</tr>
					<tr class="lastTr">
						<td>平均分</td>
						<td>/</td>
						<td></td>
						<td></td>
						<td>{{averageThreeCourse}}</td>
						<td>/</td>
						<td>/</td>
						<td>/</td>
					</tr>
				</tbody>
			</table>
			<div class="searchInfo">
				按姓名搜索:<input type="text" v-model="search" />
				<button class="btnStyle searchBtn" @click="filteredStudents()">搜索</button>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		const app = Vue.createApp({
			data(){
				return{
					students:[{
						stuName:"远航",
						stuID:"22010230900",
						scoreOne:"88",
						scoreTwo:"99",
						scoreThree:"22",
						scoreAverage:''
					},
					{
						stuName:"小航",
						stuID:"22010230900",
						scoreOne:"18",
						scoreTwo:"29",
						scoreThree:"32",
						scoreAverage:''
					}],
					newStudent:{stuName:'',stuID:'',scoreOne:'',scoreTwo:'',scoreThree:'',scoreAverage:''},
					search:'',
					averageThreeCourse:0,
					courseNum:3
				}
			},
			methods: {
					createNewStudent(){
						if(this.newStudent.stuName ===""){
							alert("姓名不能为空!")
							return
						}
						if(this.newStudent.stuID ===""){
							alert("学号不能为空!")
							return
						}
						if(this.newStudent.scoreOne ===""){
							alert("课程一不能为空!")
							return
						}
						if(this.newStudent.scoreTwo ===""){
							alert("课程二不能为空!")
							return
						}
						if(this.newStudent.scoreThree ===""){
							alert("课程二不能为空!")
							return
							
						}
						this.students.unshift(this.newStudent)
						// 添加完成后清空输入框
						this.newStudent = {stuName:'',stuID:'',scoreOne:'',scoreTwo:'',scoreThree:''}
						
					},
					averageThree(){
						var ever_class3_sum = 0
						for(var i=0;i<this.students.length;i++){
							ever_class3_sum += parseInt(this.students[i].scoreThree)
						}
						this.averageThreeCourse = ever_class3_sum/this.students.length
					},
					averageTotal(){
						for(var i = 0;i<this.students.length;i++){
							 this.students[i].scoreAverage = (this.scoreTotal(i)/this.courseNum).toFixed(2)
						}
					},
					sortScoreThree(){
						// console.log(this.students.sort(function(a ,b){
						// 	return a.scoreThree > b.scoreThree
						// }))
						this.students.reverse(function(a,b){
							return a.scoreThree > b.scoreThree
						})
						
					},
					scoreTotal(index){
						sum =  Number(this.students[index].scoreOne) + Number(this.students[index].scoreTwo) + Number(this.students[index].scoreThree)
						return sum
					},
					deleteStudent(index){
						this.students.splice(index, 1)
					},
					// 还未做完?搜索为空回显原来数据
					filteredStudents(){
						window.localStorage.setItem
						search = this.search
						if(search.length == 0){
							console.log(12)
							this.newSearchStudent = this.students.slice()
							console.log(this.newSearchStudent)
							return "success"
						}
						app.students = this.students.filter(function(item){
							return item.stuName.match(search)
						})
						
					}
				},
		}).mount('#app')
	</script>
</html>

效果图如下:
在这里插入图片描述

css

* {
	margin: 0px;
	padding: 0px;
	font-size: 18px;
}
h3 {
	text-align: center;
	margin: 20px 0px;
	font-size: 36px;
}
.inputInfo {
	width: 800px;
	margin: 0px auto;
	margin-bottom: 18px;
}
.inputInfo input[type="text"],
.inputInfo input[type="number"]{
	width: 800px;
	height: 32px;
	border-radius: 4px;
	padding-left: 6px;
}
.inputInfo input[type="radio"]{
	margin-right: 6px;
	margin-left: 6px;
}
.inputInfo select {
	width: 100px;
	height: 32px;
	border-radius: 4px;
}
.btnStyle {
	display: block;
	padding: 6px 12px;
	text-align: center;
	white-space: nowrap;
	vertical-align: middle;
	cursor: pointer;
	color: white;
	border: 1px solid transparent;
	border-radius: 8px;
	margin: 0px auto;
	margin-bottom: 20px;
}
.createBtn {
	background-color: #d9534f;
	border-color: #d43f3a;
}
.optionBtn {
	width: 800px;
	margin: 0px auto;
}
.optionBtn>button {
	display: inline-block;
	margin-left: 10px;
}
.averageBtn,
.sortBtn{
	background-color: #E5E5E5;
	border-color: #E5E5E5;
	color: #333;
	margin: 20px auto;
}
.studentList{
	width: 1200px;
	margin: 0px auto;
	border-collapse:collapse;
}
.studentList thead tr td {
	background-color: #6495ED;
}
.studentList thead tr td>a{
	font-size: 20px;
	text-decoration: none;
	color: #333;
}
.lastTr{
	font-size: 20px;
	font-weight: bold;
}
.studentList td {
	height: 60px;
	text-align: center;
	border: 1px solid #ddd;
	font-size: 20px;
}
.deleteBtn{
	background-color: #428bca;
	border-color: #357ebd;
	margin: 0px auto;
}
.searchBtn {
	background-color: #5bc0de;
	border-color: #46b8da;
	height: 20px;
	margin: 0px 10px;
	font-size: 14px;
}
.searchInfo {
	width: 800px;
	height: 50px;
	margin: 0px auto;
	line-height: 50px;
	font-size: 20px;
}
.searchInfo>input {
	height: 28px;
	border-radius: 4px;
	padding-left: 6px;
}
.searchInfo>button {
	height: 34px;
	font-size: 20px;
	line-height: 20px;
	display: inline-block;
}

js使用的是VUE3

vue.global.prod.js

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Spring Boot是一个开源的Java开发框架,而Vue是一个用于构建用户界面的JavaScript框架。如果要开发一个成绩录入系统,可以使用Spring Boot作为后端框架,Vue作为前端框架。 在Spring Boot中,可以使用Spring MVC来处理HTTP请求和响应。可以创建一个后端的REST API,用于接收成绩录入的请求。可以定义一个成绩实体类,包含学生姓名、科目、分数等属性,使用JPA进行数据库操作,将成绩信息保存到数据库中。 在Vue中,可以使用Vue Router进行路由管理,创建不同的路由来展示不同的页面。可以创建一个录入成绩的表单页面使用Vue的双向数据绑定来实时更新页面上的数据。当用户输入完成绩并点击提交按钮时,可以使用Vue的AJAX请求将数据发送到后端的REST API。 在前后端交互方面,可以使用JSON格式来传输数据。后端将收到的成绩数据进行处理,并保存到数据库中。可以使用Spring Boot的数据校验功能来验证数据的合法性,例如检查分数是否为有效值。 在前端页面上,可以使用Vue的表格组件来展示保存在数据库中的成绩数据。可以使用Vue的过滤功能来对成绩数据进行排序和筛选。可以根据需求添加其他功能,例如编辑成绩、删除成绩等。 总结而言,使用Spring Boot和Vue可以快速开发一个成绩录入系统。Spring Boot提供了后端支持,处理请求和数据库操作,而Vue则提供了前端支持,处理用户界面和数据展示。通过合理地设计和组织代码,可以实现一个功能完善的成绩录入系统

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值