feat(unit): 新增单元管理功能及相关接口
- 新增单元的请求和响应VO类,实现分页查询单元列表 - 新增UnitController,提供单元列表查询、添加和删除API接口 - 实现UnitService及其实现类,完成单元相关数据库操作和业务逻辑 - 扩展UnitDOMapper及对应XML,实现单元列表和数量查询功能 - 扩展GradeUnitDOMapper,支持单元与年级关联的插入与删除 - 在enlish-vue中新增单元列表展示、分页、删除及新增对话框功能 - 编写AddUnitDialog组件,实现新增单元UI及逻辑 - 新增unit.js接口封装单元相关的API请求 - 注释掉LessonPlansServiceImpl中的导出Word文档相关代码逻辑调整 - 调整class.vue页面样式和布局,集成单元管理模块并优化查询交互
This commit is contained in:
@@ -0,0 +1,73 @@
|
|||||||
|
package com.yinlihupo.enlish.service.controller;
|
||||||
|
|
||||||
|
import com.yinlihupo.enlish.service.domain.dataobject.UnitDO;
|
||||||
|
import com.yinlihupo.enlish.service.model.vo.unit.AddUnitReqVO;
|
||||||
|
import com.yinlihupo.enlish.service.model.vo.unit.DeleteUnitReqVO;
|
||||||
|
import com.yinlihupo.enlish.service.model.vo.unit.FindUnitListReqVO;
|
||||||
|
import com.yinlihupo.enlish.service.model.vo.unit.FindUnitListRspVO;
|
||||||
|
import com.yinlihupo.enlish.service.service.UnitService;
|
||||||
|
import com.yinlihupo.framework.biz.operationlog.aspect.ApiOperationLog;
|
||||||
|
import com.yinlihupo.framework.common.response.PageResponse;
|
||||||
|
import com.yinlihupo.framework.common.response.Response;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RequestMapping("/unit/")
|
||||||
|
@RestController
|
||||||
|
@Slf4j
|
||||||
|
public class UnitController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UnitService unitService;
|
||||||
|
|
||||||
|
@PostMapping("/list")
|
||||||
|
@ApiOperationLog(description = "查询单元")
|
||||||
|
public PageResponse<FindUnitListRspVO> list(@RequestBody FindUnitListReqVO findUnitListReqVO) {
|
||||||
|
Integer page = findUnitListReqVO.getPage();
|
||||||
|
Integer size = findUnitListReqVO.getSize();
|
||||||
|
Integer unitDOListCount = unitService.findUnitDOListCount();
|
||||||
|
|
||||||
|
List<UnitDO> unitDOList = unitService.findUnitDOList(page, size);
|
||||||
|
List<FindUnitListRspVO> findUnitListRspVOS = unitDOList.stream().map(unitDO -> FindUnitListRspVO.builder()
|
||||||
|
.id(unitDO.getId())
|
||||||
|
.title(unitDO.getTitle())
|
||||||
|
.version(unitDO.getVersion())
|
||||||
|
.createAt(unitDO.getCreateAt())
|
||||||
|
.build()
|
||||||
|
).toList();
|
||||||
|
|
||||||
|
return PageResponse.success(findUnitListRspVOS, page, unitDOListCount, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
@ApiOperationLog(description = "添加单元")
|
||||||
|
public Response<Void> add(@RequestBody AddUnitReqVO addUnitReqVO) {
|
||||||
|
try {
|
||||||
|
unitService.add(addUnitReqVO);
|
||||||
|
|
||||||
|
return Response.success();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
return Response.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete")
|
||||||
|
@ApiOperationLog(description = "删除单元")
|
||||||
|
public Response<String> delete(@RequestBody DeleteUnitReqVO deleteUnitReqVO) {
|
||||||
|
try {
|
||||||
|
unitService.delete(deleteUnitReqVO.getId());
|
||||||
|
|
||||||
|
return Response.success();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
return Response.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,4 +10,8 @@ public interface GradeUnitDOMapper {
|
|||||||
List<Integer> selectUnitIdsByGradeId(@Param("gradeId") Integer gradeId);
|
List<Integer> selectUnitIdsByGradeId(@Param("gradeId") Integer gradeId);
|
||||||
|
|
||||||
GradeUnitDO selectByUnitId(@Param("unitId") Integer unitId);
|
GradeUnitDO selectByUnitId(@Param("unitId") Integer unitId);
|
||||||
|
|
||||||
|
int insert(GradeUnitDO record);
|
||||||
|
|
||||||
|
int deleteByUnitId(@Param("unitId") Integer unitId);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.yinlihupo.enlish.service.domain.mapper;
|
package com.yinlihupo.enlish.service.domain.mapper;
|
||||||
|
|
||||||
import com.yinlihupo.enlish.service.domain.dataobject.UnitDO;
|
import com.yinlihupo.enlish.service.domain.dataobject.UnitDO;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface UnitDOMapper {
|
public interface UnitDOMapper {
|
||||||
int deleteByPrimaryKey(Integer id);
|
int deleteByPrimaryKey(Integer id);
|
||||||
@@ -18,4 +21,8 @@ public interface UnitDOMapper {
|
|||||||
int updateByPrimaryKey(UnitDO record);
|
int updateByPrimaryKey(UnitDO record);
|
||||||
|
|
||||||
UnitDO selectByTitle(String title);
|
UnitDO selectByTitle(String title);
|
||||||
|
|
||||||
|
List<UnitDO> selectUnitDOList(@Param("startIndex") Integer startIndex, @Param("pageSize") Integer pageSize);
|
||||||
|
|
||||||
|
Integer selectUnitDOListCount();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.yinlihupo.enlish.service.model.vo.unit;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class AddUnitReqVO {
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private Integer gradeId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.yinlihupo.enlish.service.model.vo.unit;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class DeleteUnitReqVO {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.yinlihupo.enlish.service.model.vo.unit;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class FindUnitListReqVO {
|
||||||
|
|
||||||
|
private Integer page;
|
||||||
|
private Integer size;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.yinlihupo.enlish.service.model.vo.unit;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class FindUnitListRspVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 年级/单元
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本
|
||||||
|
*/
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime createAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.yinlihupo.enlish.service.service;
|
||||||
|
|
||||||
|
import com.yinlihupo.enlish.service.domain.dataobject.UnitDO;
|
||||||
|
import com.yinlihupo.enlish.service.model.vo.unit.AddUnitReqVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface UnitService {
|
||||||
|
|
||||||
|
List<UnitDO> findUnitDOList(Integer page, Integer size);
|
||||||
|
|
||||||
|
Integer findUnitDOListCount();
|
||||||
|
|
||||||
|
void add(AddUnitReqVO addUnitReqVO);
|
||||||
|
|
||||||
|
void delete(Integer id);
|
||||||
|
}
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
package com.yinlihupo.enlish.service.service.plan;
|
package com.yinlihupo.enlish.service.service.plan;
|
||||||
|
|
||||||
import com.deepoove.poi.XWPFTemplate;
|
|
||||||
import com.deepoove.poi.config.Configure;
|
|
||||||
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
|
||||||
import com.yinlihupo.enlish.service.constant.LessonPlanConstant;
|
import com.yinlihupo.enlish.service.constant.LessonPlanConstant;
|
||||||
import com.yinlihupo.enlish.service.domain.dataobject.*;
|
import com.yinlihupo.enlish.service.domain.dataobject.*;
|
||||||
import com.yinlihupo.enlish.service.domain.mapper.*;
|
import com.yinlihupo.enlish.service.domain.mapper.*;
|
||||||
@@ -11,12 +8,12 @@ import com.yinlihupo.enlish.service.utils.DifyArticleClient;
|
|||||||
import com.yinlihupo.enlish.service.utils.StringToPlanMapUtil;
|
import com.yinlihupo.enlish.service.utils.StringToPlanMapUtil;
|
||||||
import com.yinlihupo.framework.common.util.JsonUtils;
|
import com.yinlihupo.framework.common.util.JsonUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -151,6 +148,8 @@ public class LessonPlansServiceImpl implements LessonPlansService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Map<String, Object> generateWeekendPlans(List<VocabularyBankDO> checkList,
|
private Map<String, Object> generateWeekendPlans(List<VocabularyBankDO> checkList,
|
||||||
int day,
|
int day,
|
||||||
GradeDO gradeDO, UnitDO unitDO, Integer studentId) throws IOException {
|
GradeDO gradeDO, UnitDO unitDO, Integer studentId) throws IOException {
|
||||||
@@ -158,14 +157,14 @@ public class LessonPlansServiceImpl implements LessonPlansService {
|
|||||||
Map<String, Object> data = new HashMap<>();
|
Map<String, Object> data = new HashMap<>();
|
||||||
data.put("title", "第" + day + "天" + "复习" + gradeDO.getTitle() + unitDO.getTitle() + studentId);
|
data.put("title", "第" + day + "天" + "复习" + gradeDO.getTitle() + unitDO.getTitle() + studentId);
|
||||||
data.put("checkList", checkList);
|
data.put("checkList", checkList);
|
||||||
LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
// LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
||||||
Configure config = Configure.builder()
|
// Configure config = Configure.builder()
|
||||||
.bind("checkList", policy)
|
// .bind("checkList", policy)
|
||||||
.build();
|
// .build();
|
||||||
|
//
|
||||||
XWPFTemplate template = XWPFTemplate.compile(planWeekend, config);
|
// XWPFTemplate template = XWPFTemplate.compile(planWeekend, config);
|
||||||
template.render(data);
|
// template.render(data);
|
||||||
template.writeAndClose(new FileOutputStream("C:\\project\\java\\enlish_edu\\enlish\\enlish-service\\src\\main\\resources\\tmp\\word" + "复习" + day + ".docx"));
|
// template.writeAndClose(new FileOutputStream("C:\\project\\java\\enlish_edu\\enlish\\enlish-service\\src\\main\\resources\\tmp\\word" + "复习" + day + ".docx"));
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -229,22 +228,22 @@ public class LessonPlansServiceImpl implements LessonPlansService {
|
|||||||
data.put("articleBans", mapB.get(LessonPlanConstant.ANSWER_KEY_EXPLANATION));
|
data.put("articleBans", mapB.get(LessonPlanConstant.ANSWER_KEY_EXPLANATION));
|
||||||
data.put("articleBtran", mapB.get(LessonPlanConstant.FULL_TRANSLATION));
|
data.put("articleBtran", mapB.get(LessonPlanConstant.FULL_TRANSLATION));
|
||||||
|
|
||||||
LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
// LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
||||||
Configure config = Configure.builder()
|
// Configure config = Configure.builder()
|
||||||
.bind("syncVocabList", policy)
|
// .bind("syncVocabList", policy)
|
||||||
.bind("gapVocabList", policy)
|
// .bind("gapVocabList", policy)
|
||||||
.bind("reviewVocabList", policy)
|
// .bind("reviewVocabList", policy)
|
||||||
.bind("drillRound1", policy)
|
// .bind("drillRound1", policy)
|
||||||
.bind("drillRound2", policy)
|
// .bind("drillRound2", policy)
|
||||||
.bind("drillRound3", policy)
|
// .bind("drillRound3", policy)
|
||||||
.bind("mixedDrill", policy)
|
// .bind("mixedDrill", policy)
|
||||||
.bind("checkList", policy)
|
// .bind("checkList", policy)
|
||||||
.bind("checkListAns", policy)
|
// .bind("checkListAns", policy)
|
||||||
.build();
|
// .build();
|
||||||
|
//
|
||||||
XWPFTemplate template = XWPFTemplate.compile(planWeekday, config);
|
// XWPFTemplate template = XWPFTemplate.compile(planWeekday, config);
|
||||||
template.render(data);
|
// template.render(data);
|
||||||
template.writeAndClose(new FileOutputStream("C:\\project\\java\\enlish_edu\\enlish\\enlish-service\\src\\main\\resources\\tmp\\word" + title + ".docx"));
|
// template.writeAndClose(new FileOutputStream("C:\\project\\java\\enlish_edu\\enlish\\enlish-service\\src\\main\\resources\\tmp\\word" + title + ".docx"));
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.yinlihupo.enlish.service.service.unit;
|
||||||
|
|
||||||
|
import com.yinlihupo.enlish.service.domain.dataobject.GradeUnitDO;
|
||||||
|
import com.yinlihupo.enlish.service.domain.dataobject.UnitDO;
|
||||||
|
import com.yinlihupo.enlish.service.domain.mapper.GradeUnitDOMapper;
|
||||||
|
import com.yinlihupo.enlish.service.domain.mapper.UnitDOMapper;
|
||||||
|
import com.yinlihupo.enlish.service.model.vo.unit.AddUnitReqVO;
|
||||||
|
import com.yinlihupo.enlish.service.service.UnitService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UnitServiceImpl implements UnitService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UnitDOMapper unitDOMapper;
|
||||||
|
@Resource
|
||||||
|
private GradeUnitDOMapper gradeUnitDOMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UnitDO> findUnitDOList(Integer page, Integer size) {
|
||||||
|
return unitDOMapper.selectUnitDOList((page - 1) * size, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer findUnitDOListCount() {
|
||||||
|
return unitDOMapper.selectUnitDOListCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(AddUnitReqVO addUnitReqVO) {
|
||||||
|
|
||||||
|
UnitDO unitDO = UnitDO.builder()
|
||||||
|
.title(addUnitReqVO.getTitle())
|
||||||
|
.createAt(LocalDateTime.now())
|
||||||
|
.build();
|
||||||
|
unitDOMapper.insertSelective(unitDO);
|
||||||
|
|
||||||
|
Integer gradeId = addUnitReqVO.getGradeId();
|
||||||
|
gradeUnitDOMapper.insert(GradeUnitDO.builder().gradeId(gradeId).unitId(unitDO.getId()).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Integer id) {
|
||||||
|
unitDOMapper.deleteByPrimaryKey(id);
|
||||||
|
gradeUnitDOMapper.deleteByUnitId(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,5 +19,13 @@
|
|||||||
where unit_id = #{unitId}
|
where unit_id = #{unitId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<insert id="insert">
|
||||||
|
insert into grade_unit (grade_id, unit_id)
|
||||||
|
values (#{gradeId}, #{unitId})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<delete id="deleteByUnitId">
|
||||||
|
delete from grade_unit
|
||||||
|
where unit_id = #{unitId}
|
||||||
|
</delete>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -91,4 +91,15 @@
|
|||||||
where title = #{title}
|
where title = #{title}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectUnitDOList" resultMap="BaseResultMap">
|
||||||
|
select *
|
||||||
|
from unit
|
||||||
|
limit #{startIndex}, #{pageSize}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectUnitDOListCount" resultType="java.lang.Integer">
|
||||||
|
select count(*)
|
||||||
|
from unit
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
21
enlish-vue/src/api/unit.js
Normal file
21
enlish-vue/src/api/unit.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import axios from "@/axios";
|
||||||
|
|
||||||
|
export function getUnitList(page, size) {
|
||||||
|
return axios.post('/unit/list', {
|
||||||
|
page: page,
|
||||||
|
size: size
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addUnit(name, gradeId) {
|
||||||
|
return axios.post('/unit/add', {
|
||||||
|
title: name,
|
||||||
|
gradeId: gradeId
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteUnit(id) {
|
||||||
|
return axios.post('/unit/delete', {
|
||||||
|
id: id
|
||||||
|
})
|
||||||
|
}
|
||||||
86
enlish-vue/src/layouts/components/AddUnitDialog.vue
Normal file
86
enlish-vue/src/layouts/components/AddUnitDialog.vue
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog v-model="visible" title="新增单元" width="480px" :close-on-click-modal="false">
|
||||||
|
<div class="space-y-4" v-loading="loading">
|
||||||
|
<el-form label-width="80px">
|
||||||
|
<el-form-item label="单元名称">
|
||||||
|
<el-input v-model="name" placeholder="请输入单元名称,如:Unit 1" clearable />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="年级">
|
||||||
|
<el-select v-model="gradeId" placeholder="请选择年级" style="width: 260px">
|
||||||
|
<el-option v-for="g in gradeOptions" :key="g.id" :label="g.title" :value="g.id" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
<template #footer>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<el-button @click="visible = false">取消</el-button>
|
||||||
|
<el-button type="primary" :disabled="!canSubmit" @click="handleSubmit">确定</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, computed, watch } from 'vue'
|
||||||
|
import { getGradeList } from '@/api/grade'
|
||||||
|
import { addUnit } from '@/api/unit'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: { type: Boolean, default: false },
|
||||||
|
defaultGradeId: { type: [Number, String], default: null }
|
||||||
|
})
|
||||||
|
const emit = defineEmits(['update:modelValue', 'success'])
|
||||||
|
|
||||||
|
const visible = computed({
|
||||||
|
get: () => props.modelValue,
|
||||||
|
set: (val) => emit('update:modelValue', val)
|
||||||
|
})
|
||||||
|
|
||||||
|
const loading = ref(false)
|
||||||
|
const name = ref('')
|
||||||
|
const gradeId = ref(null)
|
||||||
|
const gradeOptions = ref([])
|
||||||
|
|
||||||
|
const canSubmit = computed(() => name.value.trim().length > 0 && !!gradeId.value)
|
||||||
|
|
||||||
|
async function fetchGrades() {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const res = await getGradeList(1, 100)
|
||||||
|
const d = res?.data
|
||||||
|
gradeOptions.value = Array.isArray(d?.data) ? d.data : []
|
||||||
|
if (props.defaultGradeId && !gradeId.value) {
|
||||||
|
gradeId.value = Number(props.defaultGradeId)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSubmit() {
|
||||||
|
if (!canSubmit.value) return
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
await addUnit(name.value.trim(), Number(gradeId.value))
|
||||||
|
ElMessage.success('新增单元成功')
|
||||||
|
emit('success')
|
||||||
|
visible.value = false
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
(v) => {
|
||||||
|
if (v) {
|
||||||
|
name.value = ''
|
||||||
|
gradeId.value = props.defaultGradeId ? Number(props.defaultGradeId) : null
|
||||||
|
fetchGrades()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6 lg:col-span-1 lg:row-span-2">
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6 lg:col-span-1 lg:row-span-1">
|
||||||
<div class="text-lg font-semibold mb-4">学生查询</div>
|
<div class="text-lg font-semibold mb-4">学生查询</div>
|
||||||
<div class="flex flex-wrap items-center gap-3 mb-4">
|
<div class="flex flex-wrap items-center gap-3 mb-4">
|
||||||
<el-input v-model="studentName" placeholder="按姓名查询" clearable style="max-width: 220px" />
|
<el-input v-model="studentName" placeholder="按姓名查询" clearable style="max-width: 220px" />
|
||||||
@@ -105,6 +105,40 @@
|
|||||||
<AddGradeDialog v-model="showAddGradeDialog" @success="fetchGrades" />
|
<AddGradeDialog v-model="showAddGradeDialog" @success="fetchGrades" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6" v-loading="unitLoading">
|
||||||
|
<div class="text-lg font-semibold mb-4">单元列表</div>
|
||||||
|
<el-table ref="unitTableRef" :data="units" border class="w-full">
|
||||||
|
<el-table-column prop="id" label="ID" width="80" />
|
||||||
|
<el-table-column prop="title" label="单元名称" min-width="200" />
|
||||||
|
<el-table-column prop="version" label="版本" min-width="120" />
|
||||||
|
<el-table-column prop="createAt" label="创建时间" min-width="160" />
|
||||||
|
<el-table-column label="操作" width="120" fixed="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-button type="danger" size="small" @click.stop="onDeleteUnit(row)">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<div class="mt-4 flex justify-end">
|
||||||
|
<el-pagination
|
||||||
|
background
|
||||||
|
layout="prev, pager, next, sizes, total"
|
||||||
|
:total="unitTotalCount"
|
||||||
|
:page-size="unitPageSize"
|
||||||
|
:current-page="unitPageNo"
|
||||||
|
@current-change="handleUnitPageChange"
|
||||||
|
@size-change="handleUnitSizeChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 flex justify-end">
|
||||||
|
<el-button type="primary" :disabled="!selectedGradeId" @click="showAddUnitDialog = true">新增单元</el-button>
|
||||||
|
</div>
|
||||||
|
<AddUnitDialog
|
||||||
|
v-model="showAddUnitDialog"
|
||||||
|
:default-grade-id="selectedGradeId"
|
||||||
|
@success="fetchUnits"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</el-main>
|
</el-main>
|
||||||
|
|
||||||
@@ -116,12 +150,14 @@
|
|||||||
import Header from '@/layouts/components/Header.vue'
|
import Header from '@/layouts/components/Header.vue'
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { getClassList, deleteClass } from '@/api/class'
|
import { getClassList, deleteClass } from '@/api/class'
|
||||||
import { getGradeList } from '@/api/grade'
|
import { getGradeList, deleteGrade } from '@/api/grade'
|
||||||
import { getStudentList, deleteStudent } from '@/api/student'
|
import { getStudentList, deleteStudent } from '@/api/student'
|
||||||
import ExamGenerateDialog from '@/layouts/components/ExamGenerateDialog.vue'
|
import ExamGenerateDialog from '@/layouts/components/ExamGenerateDialog.vue'
|
||||||
import AddClassDialog from '@/layouts/components/AddClassDialog.vue'
|
import AddClassDialog from '@/layouts/components/AddClassDialog.vue'
|
||||||
import AddGradeDialog from '@/layouts/components/AddGradeDialog.vue'
|
import AddGradeDialog from '@/layouts/components/AddGradeDialog.vue'
|
||||||
import AddStudentDialog from '@/layouts/components/AddStudentDialog.vue'
|
import AddStudentDialog from '@/layouts/components/AddStudentDialog.vue'
|
||||||
|
import { getUnitList, deleteUnit } from '@/api/unit'
|
||||||
|
import AddUnitDialog from '@/layouts/components/AddUnitDialog.vue'
|
||||||
|
|
||||||
const classes = ref([])
|
const classes = ref([])
|
||||||
const pageNo = ref(1)
|
const pageNo = ref(1)
|
||||||
@@ -154,6 +190,14 @@ const selectedStudentIds = ref([])
|
|||||||
const showGenerateDialog = ref(false)
|
const showGenerateDialog = ref(false)
|
||||||
const showAddStudentDialog = ref(false)
|
const showAddStudentDialog = ref(false)
|
||||||
|
|
||||||
|
const units = ref([])
|
||||||
|
const unitPageNo = ref(1)
|
||||||
|
const unitPageSize = ref(10)
|
||||||
|
const unitTotalCount = ref(0)
|
||||||
|
const unitLoading = ref(false)
|
||||||
|
const unitTableRef = ref(null)
|
||||||
|
const showAddUnitDialog = ref(false)
|
||||||
|
|
||||||
async function fetchClasses() {
|
async function fetchClasses() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
@@ -303,9 +347,48 @@ async function onDeleteGrade(row) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchUnits() {
|
||||||
|
unitLoading.value = true
|
||||||
|
try {
|
||||||
|
const res = await getUnitList(unitPageNo.value, unitPageSize.value)
|
||||||
|
const d = res.data
|
||||||
|
units.value = Array.isArray(d.data) ? d.data : []
|
||||||
|
unitTotalCount.value = d.totalCount || 0
|
||||||
|
unitPageNo.value = d.pageNo || unitPageNo.value
|
||||||
|
unitPageSize.value = d.pageSize || unitPageSize.value
|
||||||
|
} finally {
|
||||||
|
unitLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function handleUnitPageChange(p) {
|
||||||
|
unitPageNo.value = p
|
||||||
|
fetchUnits()
|
||||||
|
}
|
||||||
|
function handleUnitSizeChange(s) {
|
||||||
|
unitPageSize.value = s
|
||||||
|
unitPageNo.value = 1
|
||||||
|
fetchUnits()
|
||||||
|
}
|
||||||
|
async function onDeleteUnit(row) {
|
||||||
|
try {
|
||||||
|
const res = await deleteUnit(row.id)
|
||||||
|
const data = res.data
|
||||||
|
console.log(data)
|
||||||
|
if (data.success) {
|
||||||
|
ElMessage.success('删除成功')
|
||||||
|
} else {
|
||||||
|
ElMessage.error(data.message || '删除失败')
|
||||||
|
}
|
||||||
|
await fetchUnits()
|
||||||
|
} catch (e) {
|
||||||
|
ElMessage.error('删除失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchClasses()
|
fetchClasses()
|
||||||
fetchGrades()
|
fetchGrades()
|
||||||
fetchStudents()
|
fetchStudents()
|
||||||
|
fetchUnits()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user