使用Vue3开发学生管理系统模板7 科目信息的实现

字段设计

  • ID
  • name:课程名称,字符串,最大36字符
  • start_time:开设时间,日期类型
  • teacher_total:该科目老师人数,数字类型
  • master_id:负责人ID,字符串,最大36字符
  • master_name:负责人名字,字符串,最大36字符
  • master_phone:负责人电话,字符串,最大20字符

封装JSON数据

[{"id": "1","name": "语文","start_time": "2012-09-09","teacher_total": 8,"master_id": "1","master_name": "张三的老师","master_phone": "18811118888"},{"id": "2","name": "数学","start_time": "2012-09-09","teacher_total": 8,"master_id": "1","master_name": "张三的老师","master_phone": "18811118888"},{"id": "3","name": "英语","start_time": "2012-09-09","teacher_total": 8,"master_id": "1","master_name": "张三的老师","master_phone": "18811118888"}
]

渲染科目信息表格

完整代码:

<script setup>
import {FilterMatchMode} from 'primevue/api';
import {ref, onBeforeMount} from 'vue';
import {useToast} from 'primevue/usetoast';
import teachers from "@/assets/data/teachers.json"
import courses from "@/assets/data/courses.json"// 老师
const teacher = ref({id: "1",name: "张三的老师",phone: "18811118888",age: 33,gender: "男",height: 177,weight: 128,course_id: "1",course_name: "数学",job: "教导处主任",job_age: 5,job_time: "2018-06-09",salary: 12000,detail: "{}"
})const sClass = ref(null) // 选取的老师信息const toast = useToast();const isEdit = ref(false) // 是否为编辑
const teacherDialog = ref(false); // 老师弹窗是否显示
const deleteTeacherDialog = ref(false); // 确认删除老师弹窗是否显示
const deleteTeachersDialog = ref(false); // 批量删除老师弹窗是否显示
const selectedTeachers = ref(null);
const dt = ref(null);
const filters = ref({});
const submitted = ref(false);onBeforeMount(() => {initFilters();
});/*** 打开新增老师的弹窗*/
function openNew() {teacher.value = {id: "1",name: "张三的老师",phone: "18811118888",age: 33,gender: "男",height: 177,weight: 128,course_id: "1",course_name: "数学",job: "教导处主任",job_age: 5,job_time: "2018-06-09",salary: 12000,detail: "{}"};isEdit.value = falsesubmitted.value = false;teacherDialog.value = true;
}/*** 新增老师*/
function addStudentHome() {console.log("新增老师:", sClass.value)teacherDialog.value = false
}const hideDialog = () => {teacherDialog.value = false;submitted.value = false;
};/*** 编辑老师信息* @param data 要编辑的老师信息*/
const editTeacher = (data) => {teacher.value = {...data};console.log(teacher);isEdit.value = trueteacherDialog.value = true;
};/*** 确认删除老师* @param data 要删除的老师信息*/
const confirmDeleteTeacher = (data) => {teacher.value = data;deleteTeacherDialog.value = true;
};/*** 删除老师*/
const deleteTeacher = () => {sClasss = sClasss.filter((val) => val.id !== sClass.value.id);deleteTeacherDialog.value = false;sClass.value = {id: 1,name: "张三的家长",gender: "男",age: "41",phone: "18888887777",student_id: "1",student_sclass_id: "1",student_sclass: "初一(3)班",student_name: "张三",relation: "父子"};toast.add({severity: 'success', summary: '成功', detail: '删除老师', life: 3000});
};const exportCSV = () => {dt.value.exportCSV();
};const confirmDeleteSelected = () => {deleteTeachersDialog.value = true;
};/*** 删除选中的老师*/
const deleteSelectedTeachers = () => {users = users.filter((val) => !selectedTeachers.value.includes(val));deleteTeachersDialog.value = false;selectedTeachers.value = null;toast.add({severity: 'success', summary: '成功', detail: '删除老师', life: 3000});
};/*** 初始化过滤器*/
const initFilters = () => {filters.value = {global: {value: null, matchMode: FilterMatchMode.CONTAINS}};
};
</script><template><div class="grid"><div class="col-12"><div class="card"><!--消息提示--><Toast/><!--顶部工具栏--><Toolbar class="mb-4"><!--左侧--><template v-slot:start><div class="my-2"><Button label="新增" icon="pi pi-plus" class="p-button-success mr-2" @click="openNew"/><Button label="删除" icon="pi pi-trash" class="p-button-danger" @click="confirmDeleteSelected":disabled="!selectedTeachers || !selectedTeachers.length"/></div></template><!--右侧--><template v-slot:end><FileUpload mode="basic" accept="image/*" :maxFileSize="1000000" label="Import" chooseLabel="导入"class="mr-2 inline-block"/><Button label="导出" icon="pi pi-upload" class="p-button-help" @click="exportCSV($event)"/></template></Toolbar><!--数据表格--><DataTableref="dt":value="courses"v-model:selection="selectedTeachers"dataKey="id":paginator="true":rows="10":filters="filters"paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown":rowsPerPageOptions="[5, 10, 25]"currentPageReportTemplate="显示第 {first}-{last} 条数据,共 {totalRecords} 条"responsiveLayout="scroll"><!--表头--><template #header><div class="flex flex-column md:flex-row md:justify-content-between md:align-items-center"><h5 class="m-0">科目管理</h5><span class="block mt-2 md:mt-0 p-input-icon-left"><i class="pi pi-search"/><InputText v-model="filters['global'].value" placeholder="搜索..."/></span></div></template><!--内容--><Column selectionMode="multiple" headerStyle="width: 3rem"></Column><Column field="name" header="名称" :sortable="true"></Column><Column field="start_time" header="开设时间" :sortable="true"></Column><Column field="teacher_total" header="教师人数" :sortable="true"></Column><Column field="master_name" header="负责人" :sortable="true"></Column><Column field="master_phone" header="负责人电话" :sortable="true"></Column><Column><template #body="slotProps"><Button icon="pi pi-pencil" class="p-button-rounded p-button-success mr-2"@click="editTeacher(slotProps.data)"/><Button icon="pi pi-trash" class="p-button-rounded p-button-warning mt-2"@click="confirmDeleteTeacher(slotProps.data)"/></template></Column></DataTable><!--新增弹窗--><Dialog v-model:visible="teacherDialog":style="{ width: '450px' }"header="新增老师":modal="true"class="p-fluid"><div class="field"><label for="name">姓名</label><InputText id="name" v-model.trim="teacher.name"/></div><div class="field"><label for="age">年龄</label><InputText id="age" v-model.trim="teacher.age"/></div><div class="field"><label for="gender">性别</label><InputText id="gender" v-model.trim="teacher.gender"/></div><div class="field"><label for="phone">电话</label><InputText id="phone" v-model.trim="teacher.phone"/></div><div class="field"><label for="height">身高</label><InputText id="height" v-model.trim="teacher.height"/></div><div class="field"><label for="weight">体重</label><InputText id="weight" v-model.trim="teacher.weight"/></div><div class="field"><label for="course">科目</label><InputText id="course" v-model.trim="teacher.course_name"/></div><div class="field"><label for="job">职位</label><InputText id="job" v-model.trim="teacher.job"/></div><div class="field"><label for="job_time">入职时间</label><InputText id="job_time" v-model.trim="teacher.job_time"/></div><div class="field"><label for="salary">工资</label><InputText id="salary" v-model.trim="teacher.salary"/></div><template #footer><Button label="取消" icon="pi pi-times" class="p-button-text" @click="hideDialog"/><Button label="保存" icon="pi pi-check" class="p-button-text" @click="addStudentHome"/></template></Dialog><!--确认删除弹窗--><Dialog v-model:visible="deleteTeacherDialog" :style="{ width: '450px' }" header="Confirm" :modal="true"><div class="flex align-items-center justify-content-center"><i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem"/><span v-if="teacher">您确认要删除 <b>{{ teacher.name }}</b>吗?</span></div><template #footer><Button label="取消" icon="pi pi-times" class="p-button-text" @click="deleteTeacherDialog = false"/><Button label="确认" icon="pi pi-check" class="p-button-text" @click="deleteTeacher"/></template></Dialog><!--批量删除确认弹窗--><Dialog v-model:visible="deleteTeachersDialog" :style="{ width: '450px' }" header="请确认" :modal="true"><div class="flex align-items-center justify-content-center"><i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem"/><span v-if="teacher">删除后无法撤销,您确定要删除吗?</span></div><template #footer><Button label="取消" icon="pi pi-times" class="p-button-text" @click="deleteTeachersDialog = false"/><Button label="确认" icon="pi pi-check" class="p-button-text" @click="deleteSelectedTeachers"/></template></Dialog></div></div></div>
</template>

渲染效果:
在这里插入图片描述

实现科目的增删改查

完整代码:

<script setup>
import {FilterMatchMode} from 'primevue/api';
import {ref, onBeforeMount} from 'vue';
import {useToast} from 'primevue/usetoast';
import teachers from "@/assets/data/teachers.json"
import courses from "@/assets/data/courses.json"// 科目
const course = ref({id: "1",name: "语文",start_time: "2012-09-09",teacher_total: 8,master_id: "1",master_name: "张三的老师",master_phone: "18811118888"
})
// 老师
const teacher = ref({id: "1",name: "张三的老师",phone: "18811118888",age: 33,gender: "男",height: 177,weight: 128,course_id: "1",course_name: "数学",job: "教导处主任",job_age: 5,job_time: "2018-06-09",salary: 12000,detail: "{}"
})const sClass = ref(null) // 选取的老师信息const toast = useToast();const isEdit = ref(false) // 是否为编辑
const teacherDialog = ref(false); // 老师弹窗是否显示
const onDeleteDialog = ref(false); // 确认删除老师弹窗是否显示
const onDeletesDialog = ref(false); // 批量删除老师弹窗是否显示
const selectedTeachers = ref(null);
const dt = ref(null);
const filters = ref({});
const submitted = ref(false);onBeforeMount(() => {initFilters();
});/*** 打开新增的弹窗*/
function openNew() {teacher.value = {id: "1",name: "张三的老师",phone: "18811118888",age: 33,gender: "男",height: 177,weight: 128,course_id: "1",course_name: "数学",job: "教导处主任",job_age: 5,job_time: "2018-06-09",salary: 12000,detail: "{}"};isEdit.value = falsesubmitted.value = false;teacherDialog.value = true;
}/*** 新增*/
function add() {console.log("新增:", sClass.value)teacherDialog.value = false
}const hideDialog = () => {teacherDialog.value = false;submitted.value = false;
};/*** 编辑老师信息* @param data 要编辑的老师信息*/
const editTeacher = (data) => {teacher.value = {...data};console.log(teacher);isEdit.value = trueteacherDialog.value = true;
};/*** 确认删除老师* @param data 要删除的老师信息*/
const confirmDelete = (data) => {teacher.value = data;onDeleteDialog.value = true;
};/*** 删除老师*/
const onDelete = () => {sClasss = sClasss.filter((val) => val.id !== sClass.value.id);onDeleteDialog.value = false;sClass.value = {id: 1,name: "张三的家长",gender: "男",age: "41",phone: "18888887777",student_id: "1",student_sclass_id: "1",student_sclass: "初一(3)班",student_name: "张三",relation: "父子"};toast.add({severity: 'success', summary: '成功', detail: '删除老师', life: 3000});
};const exportCSV = () => {dt.value.exportCSV();
};const confirmDeleteSelected = () => {onDeletesDialog.value = true;
};/*** 删除选中的老师*/
const deleteSelected = () => {users = users.filter((val) => !selectedTeachers.value.includes(val));onDeletesDialog.value = false;selectedTeachers.value = null;toast.add({severity: 'success', summary: '成功', detail: '删除老师', life: 3000});
};/*** 初始化过滤器*/
const initFilters = () => {filters.value = {global: {value: null, matchMode: FilterMatchMode.CONTAINS}};
};
</script><template><div class="grid"><div class="col-12"><div class="card"><!--消息提示--><Toast/><!--顶部工具栏--><Toolbar class="mb-4"><!--左侧--><template v-slot:start><div class="my-2"><Button label="新增" icon="pi pi-plus" class="p-button-success mr-2" @click="openNew"/><Button label="删除" icon="pi pi-trash" class="p-button-danger" @click="confirmDeleteSelected":disabled="!selectedTeachers || !selectedTeachers.length"/></div></template><!--右侧--><template v-slot:end><FileUpload mode="basic" accept="image/*" :maxFileSize="1000000" label="Import" chooseLabel="导入"class="mr-2 inline-block"/><Button label="导出" icon="pi pi-upload" class="p-button-help" @click="exportCSV($event)"/></template></Toolbar><!--数据表格--><DataTableref="dt":value="courses"v-model:selection="selectedTeachers"dataKey="id":paginator="true":rows="10":filters="filters"paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown":rowsPerPageOptions="[5, 10, 25]"currentPageReportTemplate="显示第 {first}-{last} 条数据,共 {totalRecords} 条"responsiveLayout="scroll"><!--表头--><template #header><div class="flex flex-column md:flex-row md:justify-content-between md:align-items-center"><h5 class="m-0">科目管理</h5><span class="block mt-2 md:mt-0 p-input-icon-left"><i class="pi pi-search"/><InputText v-model="filters['global'].value" placeholder="搜索..."/></span></div></template><!--内容--><Column selectionMode="multiple" headerStyle="width: 3rem"></Column><Column field="name" header="名称" :sortable="true"></Column><Column field="start_time" header="开设时间" :sortable="true"></Column><Column field="teacher_total" header="教师人数" :sortable="true"></Column><Column field="master_name" header="负责人" :sortable="true"></Column><Column field="master_phone" header="负责人电话" :sortable="true"></Column><Column><template #body="slotProps"><Button icon="pi pi-pencil" class="p-button-rounded p-button-success mr-2"@click="editTeacher(slotProps.data)"/><Button icon="pi pi-trash" class="p-button-rounded p-button-warning mt-2"@click="confirmDelete(slotProps.data)"/></template></Column></DataTable><!--新增弹窗--><Dialog v-model:visible="teacherDialog":style="{ width: '450px' }"header="新增科目":modal="true"class="p-fluid"><div class="field"><label for="name">名称</label><InputText id="name" v-model.trim="course.name"/></div><div class="field"><label for="start_time">开设时间</label><InputText id="start_time" v-model.trim="course.start_time"/></div><div class="field"><label for="teacher_total">老师人数</label><InputText id="teacher_total" v-model.trim="course.teacher_total"/></div><div class="field"><label for="master">科目负责人</label><Dropdown id="master"  v-model="teacher" :options="teachers" optionLabel="name" placeholder="请选择"/></div><template #footer><Button label="取消" icon="pi pi-times" class="p-button-text" @click="hideDialog"/><Button label="保存" icon="pi pi-check" class="p-button-text" @click="add"/></template></Dialog><!--确认删除弹窗--><Dialog v-model:visible="onDeleteDialog" :style="{ width: '450px' }" header="Confirm" :modal="true"><div class="flex align-items-center justify-content-center"><i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem"/><span v-if="teacher">您确认要删除 <b>{{ teacher.name }}</b>吗?</span></div><template #footer><Button label="取消" icon="pi pi-times" class="p-button-text" @click="onDeleteDialog = false"/><Button label="确认" icon="pi pi-check" class="p-button-text" @click="onDelete"/></template></Dialog><!--批量删除确认弹窗--><Dialog v-model:visible="onDeletesDialog" :style="{ width: '450px' }" header="请确认" :modal="true"><div class="flex align-items-center justify-content-center"><i class="pi pi-exclamation-triangle mr-3" style="font-size: 2rem"/><span v-if="teacher">删除后无法撤销,您确定要删除吗?</span></div><template #footer><Button label="取消" icon="pi pi-times" class="p-button-text" @click="onDeletesDialog = false"/><Button label="确认" icon="pi pi-check" class="p-button-text" @click="deleteSelected"/></template></Dialog></div></div></div>
</template>

渲染效果:
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/314127.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2023最后一天:坚持不渝,未来值得奔赴

2024坚持不渝 又到了2023年的最后一天&#xff0c;最近这一个月多都是恍恍惚惚地&#xff0c;时间过得可真快啊&#xff0c;坐在桌子前&#xff0c;回顾这一年的过往历程~我做的每个选择或者决定&#xff0c;似乎都有支撑它的理由&#xff0c;其带来的后果&#xff0c;无…

Spring Boot整合 EasyExcel 实现复杂 Excel 表格的导入与导出功能

文章目录 1. 简介2. 引入依赖3. 导入功能实现3.1 创建实体类3.2 编写导入 Controller3.3 编写导入页面 4. 导出功能实现4.1 编写导出 Controller4.2 编写导出页面 5. 启动应用 &#x1f388;个人主页&#xff1a;程序员 小侯 &#x1f390;CSDN新晋作者 &#x1f389;欢迎 &…

OpenOCD简介和下载安装(Ubuntu)

文章目录 OpenOCD简介OpenOCD软件模块OpenOCD源码下载OpenOCD安装 OpenOCD简介 OpenOCD&#xff08;Open On-Chip Debugger&#xff09;开放式片上调试器 OpenOCD官网 https://openocd.org/&#xff0c;进入官网点击 About 可以看到OpenOCD最初的设计是由国外一个叫Dominic Ra…

Embedding模型在大语言模型中的重要性

引言 随着大型语言模型的发展&#xff0c;以ChatGPT为首&#xff0c;涌现了诸如ChatPDF、BingGPT、NotionAI等多种多样的应用。公众大量地将目光聚焦于生成模型的进展之快&#xff0c;却少有关注支撑许多大型语言模型应用落地的必不可少的Embedding模型。本文将主要介绍为什么…

Spark魔力:招聘网站数据深度分析系统

Spark魔力&#xff1a;招聘网站数据深度分析系统 简介数据集技术栈功能特点创新点 简介 在本文中&#xff0c;我们将介绍一款基于Spark的招聘网站数据分析系统&#xff0c;该系统使用爬取的前程无忧招聘数据。通过结合Flask、Pandas、PySpark、以及MySQL等技术&#xff0c;实现…

探索 Vue 异步组件的世界:解锁高效开发的秘密(下)

&#x1f90d; 前端开发工程师&#xff08;主业&#xff09;、技术博主&#xff08;副业&#xff09;、已过CET6 &#x1f368; 阿珊和她的猫_CSDN个人主页 &#x1f560; 牛客高级专题作者、在牛客打造高质量专栏《前端面试必备》 &#x1f35a; 蓝桥云课签约作者、已在蓝桥云…

啊哈c语言——逻辑挑战6:奔跑的小人

首先我们来设计这个小人&#xff1a; 将这个小人身体的三部分分为3行来分别表示&#xff1a; 第1行用一个大写字母O表示小人的脑袋。 第2行用左尖括号表示小人的右手&#xff0c;用大写字母H表示小人的身 体&#xff0c;用右尖括号>表示小人的右手。 第3行用两个大写字母…

C++多态性——(1)初识多态

归纳编程学习的感悟&#xff0c; 记录奋斗路上的点滴&#xff0c; 希望能帮到一样刻苦的你&#xff01; 如有不足欢迎指正&#xff01; 共同学习交流&#xff01; &#x1f30e;欢迎各位→点赞 &#x1f44d; 收藏⭐ 留言​&#x1f4dd; 苦难和幸福一样&#xff0c;都是生命盛…

电子邮件地址填写指南:格式与常见问题解答

一个专业的电子邮件地址是一个你只用于工作目的的通信帐户。当你给收件人发送电子邮件时&#xff0c;这是他们最先看到的细节之一。无论你的职位或行业如何&#xff0c;拥有一个专业的电子邮件地址都可以提高你和所在公司的可信度。 在本文中我们解释了专业的电子邮件地址是什么…

计算机网络课程设计-企业网三层架构

&#xff08;单人版&#xff09; 摘 要 本篇报告主要解决了为一家名为西宫的公司网络搭建问题&#xff0c;该网络采用企业网三层架构对完了过进行设计。首先使用以太网中继&#xff0c;主要使用VLAN划分的技术来划定不同部门。使用MSTP对每个组配置生成树&#xff0c;防止交换机…

echarts 折线图根据x轴时间渲染不同颜色的折线

footIm 如上图所示一条折线多种颜色 后端数据返回"data": [ { “dateTime”: “2023-10-11 00:02:10”, “pos”: 6, “curr”: 104.6 }, { “dateTime”: “2023-10-11 00:02:39”, “pos”: 7, “curr”: 104.6 }&#xff0c; …] 我们拿到后端返回的res.data传递给…

采用环形首尾互联互控的雪崩效应极好的Hash算法/杂凑函数RING-512设计原理详解

RING-512密码杂凑算法 黄金龙&#xff08;QQ1435271638&#xff09; 什么是Hash算法&#xff1f; Hash算法&#xff0c;又称为哈希算法、杂凑函数、散列函数、消息摘要算法。它可以将相当长&#xff08;一般不大于2^64Bit&#xff09;的输入数据经过计算生成固定长度的Hash值…