前端代码迁移

main
xuao 2 weeks ago
parent 4e752336cd
commit 1df730f466

@ -3,6 +3,8 @@ package com.ruoyi.course.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.course.common.R;
import com.ruoyi.course.domain.Classroom;
import com.ruoyi.course.domain.vo.ClassroomQueryVO;
@ -33,7 +35,7 @@ import java.util.Map;
@RequestMapping("/course/classroom")
@Tag(name = "教室管理", description = "教室相关的CRUD操作和分配管理")
@Slf4j
public class ClassroomController {
public class ClassroomController extends BaseController {
@Autowired
private IClassroomService classroomService;
@ -124,9 +126,10 @@ public class ClassroomController {
@ApiResponse(responseCode = "200", description = "查询成功")
})
@GetMapping("/list")
public R<List<Classroom>> listClassrooms() {
public TableDataInfo listTeachers() {
startPage();
List<Classroom> list = classroomService.list();
return R.ok(list, "查询成功");
return getDataTable(list);
}
@Operation(summary = "分页查询教室列表", description = "根据条件分页查询教室列表")

@ -3,15 +3,17 @@ package com.ruoyi.course.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.course.common.R;
import com.ruoyi.course.domain.Clazz;
import com.ruoyi.course.domain.vo.ClassQueryVO;
import com.ruoyi.course.service.IClazzService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.ruoyi.course.common.R;
import com.ruoyi.course.domain.Clazz;
import com.ruoyi.course.domain.vo.ClassQueryVO;
import com.ruoyi.course.service.IClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
@ -27,10 +29,10 @@ import java.util.List;
@RestController
@RequestMapping("/course/clazz")
@Tag(name = "班级管理", description = "班级相关的CRUD操作")
public class ClazzController {
public class ClazzController extends BaseController {
@Autowired
private IClazzService classService;
private IClazzService clazzService;
@Operation(summary = "新增班级", description = "创建一个新的班级")
@ApiResponses(value = {
@ -39,7 +41,7 @@ public class ClazzController {
})
@PostMapping("/add")
public R<Boolean> addClass(@RequestBody Clazz clazz) {
boolean success = classService.save(clazz);
boolean success = clazzService.save(clazz);
return success ? R.ok(true, "新增成功") : R.error("新增失败");
}
@ -53,7 +55,7 @@ public class ClazzController {
public R<Boolean> deleteClass(
@Parameter(description = "班级ID", required = true, example = "1")
@PathVariable Long id) {
boolean success = classService.removeById(id);
boolean success = clazzService.removeById(id);
return success ? R.ok(true, "删除成功") : R.error("删除失败");
}
@ -69,7 +71,7 @@ public class ClazzController {
return R.paramError("请选择要删除的数据");
}
boolean success = classService.removeByIds(ids);
boolean success = clazzService.removeByIds(ids);
return success ? R.ok(true, "批量删除成功") : R.error("批量删除失败");
}
@ -89,7 +91,7 @@ public class ClazzController {
// 设置更新时间
clazz.setUpdateTime(LocalDateTime.now());
boolean success = classService.updateById(clazz);
boolean success = clazzService.updateById(clazz);
return success ? R.ok(true, "修改成功") : R.error("修改失败");
}
@ -102,7 +104,7 @@ public class ClazzController {
public R<Clazz> getClassById(
@Parameter(description = "班级ID", required = true, example = "1")
@PathVariable Long id) {
Clazz clazz = classService.getById(id);
Clazz clazz = clazzService.getById(id);
if (clazz == null) {
return R.notFound("班级不存在");
}
@ -114,9 +116,10 @@ public class ClazzController {
@ApiResponse(responseCode = "200", description = "查询成功")
})
@GetMapping("/list")
public R<List<Clazz>> listClasses() {
List<Clazz> list = classService.list();
return R.ok(list, "查询成功");
public TableDataInfo listTeachers() {
startPage();`
List<Clazz> list = clazzService.list();
return getDataTable(list);
}
@Operation(summary = "分页查询班级列表", description = "根据条件分页查询班级列表")
@ -156,7 +159,7 @@ public class ClazzController {
wrapper.orderByDesc(Clazz::getCreateTime);
// 执行分页查询
IPage<Clazz> result = classService.page(page, wrapper);
IPage<Clazz> result = clazzService.page(page, wrapper);
return R.ok(result, "查询成功");
}
@ -175,47 +178,14 @@ public class ClazzController {
Page<Clazz> page = new Page<>(pageNum, pageSize);
IPage<Clazz> result = classService.page(page);
IPage<Clazz> result = clazzService.page(page);
return R.ok(result, "查询成功");
}
@Operation(summary = "根据状态查询班级", description = "根据班级状态查询班级列表")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "查询成功"),
@ApiResponse(responseCode = "400", description = "参数错误")
})
@GetMapping("/listByStatus/{status}")
public R<List<Clazz>> listByStatus(
@Parameter(description = "班级状态", required = true, example = "1")
@PathVariable Integer status) {
LambdaQueryWrapper<Clazz> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Clazz::getStatus, status);
wrapper.orderByDesc(Clazz::getCreateTime);
List<Clazz> list = classService.list(wrapper);
return R.ok(list, "查询成功");
}
@Operation(summary = "根据年级和状态查询", description = "根据年级和班级状态查询班级列表")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "查询成功")
})
@GetMapping("/listByGradeAndStatus")
public R<List<Clazz>> listByGradeAndStatus(
@Parameter(description = "年级", required = true, example = "2023级")
@RequestParam String grade,
@Parameter(description = "状态", required = true, example = "1")
@RequestParam Integer status) {
LambdaQueryWrapper<Clazz> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Clazz::getGrade, grade);
wrapper.eq(Clazz::getStatus, status);
wrapper.orderByDesc(Clazz::getCreateTime);
List<Clazz> list = classService.list(wrapper);
return R.ok(list, "查询成功");
}
@ -231,7 +201,7 @@ public class ClazzController {
if (status != null) {
wrapper.eq(Clazz::getStatus, status);
}
Long count = classService.count(wrapper);
Long count = clazzService.count(wrapper);
return R.ok(count, "查询成功");
}

@ -3,13 +3,15 @@ package com.ruoyi.course.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.course.common.R;
import com.ruoyi.course.domain.Course;
import com.ruoyi.course.domain.vo.CourseQueryVO;
import com.ruoyi.course.service.ICourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
@ -23,9 +25,9 @@ import java.util.List;
* </p>
*/
@RestController
@RequestMapping("/course/course")
@RequestMapping("/course/courses")
@Api(tags = "课程管理")
public class CourseController {
public class CourseController extends BaseController {
@Autowired
private ICourseService courseService;
@ -81,9 +83,10 @@ public class CourseController {
@ApiOperation("查询所有课程")
@GetMapping("/list")
public R<List<Course>> listCourses() {
public TableDataInfo listTeachers() {
startPage();
List<Course> list = courseService.list();
return R.ok(list, "查询成功");
return getDataTable(list);
}
@ApiOperation("分页查询课程列表")

@ -3,13 +3,15 @@ package com.ruoyi.course.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.course.common.R;
import com.ruoyi.course.domain.Student;
import com.ruoyi.course.domain.vo.StudentQueryVO;
import com.ruoyi.course.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
@ -28,7 +30,7 @@ import java.util.List;
@RestController
@RequestMapping("/course/student")
@Api(tags = "学生管理")
public class StudentController {
public class StudentController extends BaseController {
@Autowired
private IStudentService studentService;
@ -84,9 +86,10 @@ public class StudentController {
@ApiOperation("查询所有学生")
@GetMapping("/list")
public R<List<Student>> listStudents() {
public TableDataInfo listStudents() {
startPage();
List<Student> list = studentService.list();
return R.ok(list, "查询成功");
return getDataTable(list);
}
@ApiOperation("分页查询学生列表")

@ -3,17 +3,19 @@ package com.ruoyi.course.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.course.common.R;
import com.ruoyi.course.common.TeacherTimetableResponse;
import com.ruoyi.course.domain.Teacher;
import com.ruoyi.course.domain.vo.TeacherQueryVO;
import com.ruoyi.course.service.ITeacherService;
import com.ruoyi.course.service.impl.TeacherScheduleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
@ -29,7 +31,7 @@ import java.util.List;
@RestController
@RequestMapping("/course/teacher")
@Tag(name = "教师管理", description = "教师相关的CRUD操作和课表管理")
public class TeacherController {
public class TeacherController extends BaseController {
@Autowired
private ITeacherService teacherService;
@ -116,9 +118,10 @@ public class TeacherController {
@ApiResponse(responseCode = "200", description = "查询成功")
})
@GetMapping("/list")
public R<List<Teacher>> listTeachers() {
public TableDataInfo listTeachers() {
startPage();
List<Teacher> list = teacherService.list();
return R.ok(list, "查询成功");
return getDataTable(list);
}
@Operation(summary = "分页查询教师列表", description = "根据条件分页查询教师列表")

@ -48,7 +48,6 @@ public class Student implements Serializable {
private GradeEnum grade;
@ApiModelProperty(value = "已选选修课ID列表JSON数组")
private String selectedElectiveIds;

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询课程列表
export function listCourse(query) {
return request({
url: '/course/course/list',
url: '/course/courses/list',
method: 'get',
params: query
})
@ -12,7 +12,7 @@ export function listCourse(query) {
// 查询课程分页列表
export function pageCourse(query) {
return request({
url: '/course/course/page',
url: '/course/courses/page',
method: 'get',
params: query
})
@ -21,7 +21,7 @@ export function pageCourse(query) {
// 查询课程详细
export function getCourse(id) {
return request({
url: '/course/course/' + id,
url: '/course/courses/' + id,
method: 'get'
})
}
@ -29,7 +29,7 @@ export function getCourse(id) {
// 新增课程
export function addCourse(data) {
return request({
url: '/course/course',
url: '/course/courses',
method: 'post',
data: data
})
@ -38,7 +38,7 @@ export function addCourse(data) {
// 修改课程
export function updateCourse(data) {
return request({
url: '/course/course',
url: '/course/courses',
method: 'put',
data: data
})
@ -47,7 +47,7 @@ export function updateCourse(data) {
// 删除课程
export function delCourse(id) {
return request({
url: '/course/course/' + id,
url: '/course/courses/' + id,
method: 'delete'
})
}
@ -55,7 +55,7 @@ export function delCourse(id) {
// 批量删除课程
export function batchDeleteCourse(ids) {
return request({
url: '/course/course/batch',
url: '/course/courses/batch',
method: 'delete',
data: ids
})
@ -64,7 +64,7 @@ export function batchDeleteCourse(ids) {
// 导出课程
export function exportCourse(query) {
return request({
url: '/course/course/export',
url: '/course/courses/export',
method: 'get',
params: query
})

@ -161,7 +161,50 @@ export const dynamicRoutes = [
meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
}
]
}
}
// {
// path: '/course', // 一级路由路径
// component: Layout,
// redirect: '/course/classroom', // 默认重定向到教室管理
// meta: { title: '课程管理', icon: 'education' }, // 侧边栏显示"课程管理"使用education图标
// children: [
// {
// path: 'classroom', // 二级路由路径: /course/classroom
// component: () => import('@/views/course/classroom/index'), // 对应views目录下的教室管理组件
// name: 'Classroom', // 路由名称,必须唯一
// meta: { title: '教室管理', icon: 'classroom' }, // 侧边栏显示"教室管理"使用classroom图标
// permissions: ['course:classroom:list'] // 需要的权限标识
// },
// {
// path: 'clazz', // 二级路由路径: /course/clazz
// component: () => import('@/views/course/clazz/index'), // 对应views目录下的班级管理组件
// name: 'Clazz', // 路由名称,必须唯一
// meta: { title: '班级管理', icon: 'tree' }, // 侧边栏显示"班级管理"使用tree图标
// permissions: ['course:clazz:list'] // 需要的权限标识
// },
// {
// path: 'courses', // 二级路由路径: /course/courses
// component: () => import('@/views/course/courses/index'), // 对应views目录下的课程管理组件
// name: 'Course', // 路由名称,必须唯一
// meta: { title: '课程管理', icon: 'list' }, // 侧边栏显示"课程管理"使用list图标
// permissions: ['course:courses:list'] // 需要的权限标识
// },
// {
// path: 'student', // 二级路由路径: /course/student
// component: () => import('@/views/course/student/index'), // 对应views目录下的学生管理组件
// name: 'Student', // 路由名称,必须唯一
// meta: { title: '学生管理', icon: 'user' }, // 侧边栏显示"学生管理"使用user图标
// permissions: ['course:student:list'] // 需要的权限标识
// },
// {
// path: 'teacher', // 二级路由路径: /course/teacher
// component: () => import('@/views/course/teacher/index'), // 对应views目录下的教师管理组件
// name: 'Teacher', // 路由名称,必须唯一
// meta: { title: '教师管理', icon: 'peoples' }, // 侧边栏显示"教师管理"使用peoples图标
// permissions: ['course:teacher:list'] // 需要的权限标识
// }
// ]
// }
]
// 防止连续点击多次路由报错

@ -54,7 +54,7 @@
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['course:classroom:add']"
v-hasPermi="['courses:classroom:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
@ -65,7 +65,7 @@
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['course:classroom:remove']"
v-hasPermi="['courses:classroom:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
@ -75,7 +75,7 @@
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['course:classroom:export']"
v-hasPermi="['courses:classroom:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
@ -136,14 +136,14 @@
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['course:classroom:edit']"
v-hasPermi="['courses:classroom:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['course:classroom:remove']"
v-hasPermi="['courses:classroom:remove']"
>删除</el-button>
</template>
</el-table-column>

@ -51,7 +51,7 @@
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['course:clazz:add']"
v-hasPermi="['courses:clazz:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
@ -62,7 +62,7 @@
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['course:clazz:remove']"
v-hasPermi="['courses:clazz:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
@ -72,7 +72,7 @@
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['course:clazz:export']"
v-hasPermi="['courses:clazz:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
@ -124,14 +124,14 @@
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['course:clazz:edit']"
v-hasPermi="['courses:clazz:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['course:clazz:remove']"
v-hasPermi="['courses:clazz:remove']"
>删除</el-button>
</template>
</el-table-column>

@ -52,7 +52,7 @@
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['api:course:add']"
v-hasPermi="['course:courses:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
@ -63,7 +63,7 @@
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['api:course:remove']"
v-hasPermi="['course:courses:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
@ -73,7 +73,7 @@
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['api:course:export']"
v-hasPermi="['course:courses:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
@ -137,14 +137,14 @@
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['course:course:edit']"
v-hasPermi="['course:courses:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['course:course:remove']"
v-hasPermi="['course:courses:remove']"
>删除</el-button>
</template>
</el-table-column>
@ -273,7 +273,7 @@
</template>
<script>
import { listCourse, getCourse, delCourse, addCourse, updateCourse, exportCourse } from "@/api/course/course"
import { listCourse, getCourse, delCourse, addCourse, updateCourse, exportCourse } from "@/api/course/courses"
export default {
name: "Course",

@ -42,7 +42,7 @@
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['course:student:add']"
v-hasPermi="['courses:student:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
@ -53,7 +53,7 @@
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['course:student:remove']"
v-hasPermi="['courses:student:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
@ -63,7 +63,7 @@
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['course:student:export']"
v-hasPermi="['courses:student:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
@ -76,15 +76,19 @@
<el-table-column label="姓名" align="center" prop="name" width="100" :show-overflow-tooltip="true" />
<el-table-column label="年级" align="center" prop="grade" width="80">
<template slot-scope="scope">
<el-tag size="small">{{ scope.row.grade }}</el-tag>
<el-tag size="small">{{ formatGrade(scope.row.grade) }}</el-tag>
</template>
</el-table-column>
<el-table-column label="班级" align="center" prop="className" width="120" :show-overflow-tooltip="true" />
<el-table-column label="已选选修课" align="center" prop="selectedElectiveNames" min-width="250" :show-overflow-tooltip="true">
<el-table-column label="班级" align="center" prop="classId" width="120">
<template slot-scope="scope">
<div v-if="scope.row.selectedElectiveNames && scope.row.selectedElectiveNames !== '[]'">
{{ formatCourseNames(scope.row.selectedElectiveNames) }}
</div>
{{ getClassName(scope.row.classId) }}
</template>
</el-table-column>
<el-table-column label="已选选修课" align="center" min-width="250">
<template slot-scope="scope">
<span v-if="scope.row.selectedElectiveIds" class="text-gray">
{{ formatCourseNames(scope.row.selectedElectiveIds) }}
</span>
<span v-else class="text-gray">无选修课</span>
</template>
</el-table-column>
@ -223,7 +227,7 @@
<script>
import { listStudent, getStudent, delStudent, addStudent, updateStudent, exportStudent } from "@/api/course/student"
import { listClazz } from "@/api/course/clazz"
import { listCourse } from "@/api/course/course"
import { listCourse } from "@/api/course/courses"
export default {
name: "Student",
@ -310,11 +314,12 @@ export default {
computed: {
//
filteredClasses() {
if (!this.form.grade) return []
if (!this.form.grade || !Array.isArray(this.classList)) return []
return this.classList.filter(cls => cls.grade === this.form.grade)
},
//
filteredElectiveCourses() {
if (!Array.isArray(this.electiveCourses)) return []
if (!this.form.grade) return this.electiveCourses
// ""
@ -329,59 +334,151 @@ export default {
this.getCourseList()
},
methods: {
/** 格式化年级显示 */
formatGrade(grade) {
const gradeMap = {
'FRESHMAN': '高一',
'SOPHOMORE': '高二',
'JUNIOR': '高三'
}
return gradeMap[grade] || grade
},
/** 根据班级ID获取班级名称 */
getClassName(classId) {
if (!this.classList.length) return `班级${classId}`
const cls = this.classList.find(c => c.id === classId)
return cls ? cls.className : `班级${classId}`
},
/** 格式化选修课名称显示 */
formatCourseNames(ids) {
if (!ids || !this.allCourses.length) return '无选修课'
// ids
let idArray = []
try {
if (typeof ids === 'string') {
idArray = JSON.parse(ids)
} else if (Array.isArray(ids)) {
idArray = ids
}
} catch (e) {
console.error('解析选修课ID失败:', e)
return '选修课数据异常'
}
if (!idArray.length) return '无选修课'
const names = idArray.map(id => {
const course = this.allCourses.find(c => c.id === id)
return course ? course.courseName : `课程${id}`
})
return names.join('、')
},
/** 查询学生列表 */
getList() {
this.loading = true
console.log('发送查询请求,参数:', this.queryParams)
listStudent(this.queryParams).then(response => {
this.studentList = response.rows
this.total = response.total
console.log('学生列表API返回:', response) //
if (response.code === 200 || response.success) {
//
// response.data
this.studentList = response.rows
// total
//
this.total = this.studentList.length
console.log('设置的学生数据:', this.studentList)
console.log('总数:', this.total)
} else {
this.$modal.msgError(response.msg || "获取学生列表失败")
this.studentList = []
this.total = 0
}
this.loading = false
}).catch(error => {
console.error('获取学生列表失败:', error)
this.$modal.msgError("获取学生列表失败")
this.loading = false
this.studentList = []
this.total = 0
})
},
/** 获取班级列表 */
getClassList() {
this.classLoading = true
listClazz().then(response => {
this.classList = response || []
if (response.code === 200) {
// API
// response.data response.rows
this.classList = response.data || response.rows || []
} else {
this.$modal.msgError(response.msg || "获取班级列表失败")
this.classList = []
}
this.classLoading = false
if (this.classList.length === 0) {
this.$modal.msgWarning("暂无班级数据,请先在班级管理中配置班级")
}
}).catch(() => {
}).catch(error => {
console.error('获取班级列表失败:', error)
this.classList = []
this.classLoading = false
this.$modal.msgWarning("获取班级列表失败,请联系管理员配置班级数据")
})
},
/** 获取选修课列表 */
/** 获取课程列表 */
getCourseList() {
this.courseLoading = true
listCourse().then(response => {
this.allCourses = response || []
//
this.electiveCourses = this.allCourses.filter(course => course.courseType === '选修') || []
if (response.code === 200) {
// API
// response.data response.rows
this.allCourses = response.data || response.rows || []
//
this.electiveCourses = this.allCourses.filter(course =>
course.courseType === '选修'
) || []
} else {
this.$modal.msgError(response.msg || "获取课程列表失败")
this.allCourses = []
this.electiveCourses = []
}
this.courseLoading = false
if (this.electiveCourses.length === 0) {
this.$modal.msgWarning("暂无选修课数据,请先在课程管理中配置选修课")
}
}).catch(() => {
}).catch(error => {
console.error('获取课程列表失败:', error)
this.allCourses = []
this.electiveCourses = []
this.courseLoading = false
this.$modal.msgWarning("获取课程列表失败,请联系管理员配置课程数据")
})
},
//
handleGradeChange() {
this.form.classId = null
},
//
cancel() {
this.open = false
this.reset()
},
//
reset() {
this.form = {
@ -398,54 +495,73 @@ export default {
this.$refs.form.resetFields()
}
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm")
if (this.$refs.queryForm) {
this.$refs.queryForm.resetFields()
}
this.handleQuery()
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
this.open = true
this.title = "添加学生"
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset()
const id = row.id || this.ids
getStudent(id).then(response => {
const data = response.data
if (response.code === 200) {
const data = response.data || {}
// ID
let electiveIds = []
try {
if (data.selectedElectiveIds) {
electiveIds = JSON.parse(data.selectedElectiveIds)
// ID
let electiveIds = []
try {
if (data.selectedElectiveIds) {
if (typeof data.selectedElectiveIds === 'string') {
electiveIds = JSON.parse(data.selectedElectiveIds)
} else if (Array.isArray(data.selectedElectiveIds)) {
electiveIds = data.selectedElectiveIds
}
}
} catch (e) {
console.error('解析选修课ID失败:', e)
}
} catch (e) {
console.error('解析选修课ID失败:', e)
}
this.form = {
...data,
selectedElectiveIds: electiveIds
}
this.form = {
...data,
selectedElectiveIds: electiveIds
}
this.open = true
this.title = "修改学生"
this.open = true
this.title = "修改学生"
} else {
this.$modal.msgError(response.msg || "获取学生信息失败")
}
}).catch(error => {
console.error('获取学生信息失败:', error)
this.$modal.msgError("获取学生信息失败")
})
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
@ -457,57 +573,110 @@ export default {
}
if (this.form.id != null) {
//
updateStudent(submitData).then(response => {
this.$modal.msgSuccess("修改成功")
this.open = false
this.getList()
if (response.code === 200) {
this.$modal.msgSuccess("修改成功")
this.open = false
this.getList()
} else {
this.$modal.msgError(response.msg || "修改失败")
}
}).catch(error => {
console.error('修改失败:', error)
this.$modal.msgError("修改失败")
})
} else {
//
addStudent(submitData).then(response => {
this.$modal.msgSuccess("新增成功")
this.open = false
this.getList()
if (response.code === 200) {
this.$modal.msgSuccess("新增成功")
this.open = false
this.getList()
} else {
this.$modal.msgError(response.msg || "新增失败")
}
}).catch(error => {
console.error('新增失败:', error)
this.$modal.msgError("新增失败")
})
}
}
})
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids
this.$modal.confirm('是否确认删除学生名称为"' + (row.name || ids) + '"的数据项?').then(() => {
return delStudent(ids)
}).then(() => {
this.getList()
this.$modal.msgSuccess("删除成功")
this.ids = []
}).catch(() => {})
}).then(response => {
if (response.code === 200) {
this.getList()
this.$modal.msgSuccess("删除成功")
this.ids = []
} else {
this.$modal.msgError(response.msg || "删除失败")
}
}).catch(error => {
console.error('删除失败:', error)
this.$modal.msgError("删除失败")
})
},
/** 导出按钮操作 */
handleExport() {
this.$modal.confirm('是否确认导出所有学生数据项?').then(() => {
this.exportLoading = true
return exportStudent(this.queryParams)
}).then(response => {
this.$download.name(response, "学生数据.xlsx")
// 使Blob
if (response instanceof Blob) {
const blob = new Blob([response], { type: 'application/vnd.ms-excel' })
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)
downloadElement.href = href
downloadElement.download = "学生数据.xlsx"
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
this.$modal.msgSuccess("导出成功")
} else {
this.$modal.msgError("导出失败,返回格式不正确")
}
this.exportLoading = false
}).catch(error => {
console.error('导出失败:', error)
this.$modal.msgError("导出失败")
this.exportLoading = false
}).catch(() => {})
})
},
/** 格式化课程名称显示 */
formatCourseNames(idsStr) {
try {
const ids = JSON.parse(idsStr)
if (!ids || !ids.length) return '无选修课'
const names = ids.map(id => {
const course = this.allCourses.find(c => c.id === id)
return course ? course.courseName : `课程${id}`
})
return names.join('、')
} catch (e) {
return idsStr
/** 格式化时间 */
parseTime(time) {
if (!time) return ''
//
if (typeof time === 'string') {
return time
}
//
const date = new Date(time)
if (isNaN(date.getTime())) {
return time
}
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const hour = String(date.getHours()).padStart(2, '0')
const minute = String(date.getMinutes()).padStart(2, '0')
const second = String(date.getSeconds()).padStart(2, '0')
return `${year}-${month}-${day} ${hour}:${minute}:${second}`
}
}
}
@ -529,4 +698,5 @@ export default {
padding: 20px;
text-align: center;
}
</style>

@ -127,14 +127,14 @@
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['course:teacher:edit']"
v-hasPermi="['courses:teacher:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['course:teacher:remove']"
v-hasPermi="['courses:teacher:remove']"
>删除</el-button>
</template>
</el-table-column>

Loading…
Cancel
Save