feat(course): 支持考试类型资源的选择与上传

- 新增试卷列表获取逻辑,支持考试类型资源展示
- 优化文件上传校验,统一获取文件类型与大小限制
- 调整课程列表请求方法名,增强代码可读性
- 移除冗余的showDialog响应式变量
- 新增自定义考试按钮,区分不同资源类型的上传入口
- 更新文件基础URL配置,使用环境变量动态设置
- 引入试卷相关API模块,支持考试资源操作接口调用
- 扩展useCreateCourseMaps钩子,增加获取试卷列表方法
This commit is contained in:
陈昱达
2025-11-24 19:44:43 +08:00
parent 8d9775b77a
commit f07582d5c1
5 changed files with 166 additions and 32 deletions

91
src/api/modules/paper.js Normal file
View File

@@ -0,0 +1,91 @@
// 试卷
import ajax from "./xajax.js";
// 分页查询,资源归属,试题模式,关键词查询
// pageIndex 第几页
// pageSize 一页展示多少行
//参数:// ownership22级资源归属
// ownership11级资源归属
// ownership33级资源归属paperMode(试卷模式)keyWord(关键词)
const querylist = function (query) {
return ajax.post("/systemapi/xboe/m/exam/paper/querylist", query);
};
// 添加
// ownership22级资源归属
// ownership11级资源归属
// ownership33级资源归属testName(试卷名称),paperType试卷分类
// paperContent(试卷内容) remark 备注 difficulty难度
const save = function (data) {
return ajax.postJson("/systemapi/xboe/m/exam/paper/save", data);
};
// 删除
// id 试卷id
const del = function (id) {
return ajax.get("/systemapi/xboe/m/exam/paper/delete?id=" + id);
};
// 编辑
//当前id// ownership22级资源归属
// ownership11级资源归属
// ownership33级资源归属testName(试卷名称),paperType试卷分类
// paperContent(试卷内容) remark 备注 difficulty难度
const update = function (data) {
return ajax.postJson("/systemapi/xboe/m/exam/paper/update", data);
};
/* 编辑详情 */
const detail = function (id) {
return ajax.get("/systemapi/xboe/m/exam/paper/query?id=" + id);
};
/* 试卷批量导入计算
* num 数目
* score 总分
* diff1 容易的试题数量
* diff2 中等的试题数量
* diff3 困难的试题数量
* type1 单选的试题数量
* type2 单选的试题数量
* type3 单选的试题数量
*/
const batchImportCount = function (data) {
return ajax.postJson("/systemapi/xboe/m/exam/paper/batch-count", data);
};
/**
* 根据生成的试题的id查询所有的试题
* @param {试题的集合array} ids
*/
const batchImportData = function (ids) {
return ajax.postJson("/systemapi/xboe/m/exam/paper/batch-count", ids);
};
/**
* 查询试卷
* @param {pageSize,name} data
*/
const querypaper = function (data) {
return ajax.post("/systemapi/xboe/m/exam/paper/queryPaper", data);
};
/**
* 返回试卷的json内容字符串
* @param {Object} id
*/
const getPaperContent = function (id) {
return ajax.get("/systemapi/xboe/m/exam/paper/paper-content?id=" + id);
};
const newPaperContent = function (id) {
return ajax.get(
"/systemapi/xboe/m/course/content/exam/paper-content?courseExamId=" + id
);
};
export default {
detail,
update,
del,
save,
querylist,
querypaper,
getPaperContent,
newPaperContent,
batchImportCount,
batchImportData,
};

View File

@@ -6,6 +6,7 @@ import {
getPageListByType,
getType,
getMapsItem,
getPaperList,
} from "@/hooks/useCreateCourseMaps";
import apiCourseFile from "@/api/modules/courseFile";
import { useRoute } from "vue-router";
@@ -22,7 +23,6 @@ const props = defineProps({
// 响应式数据
const tableData = ref([]);
const loading = ref(false);
const showDialog = ref(false);
const fileList = ref([]);
// 表单数据
@@ -145,24 +145,49 @@ const handlePreviewItem = (row) => {
// 分页改变处理
const changePagination = (PAGINATION) => {
Object.assign(pagination, PAGINATION);
getVideoList();
getCourseList();
};
// 获取视频列表
const getVideoList = () => {
const getCourseList = () => {
loading.value = true;
const paramsData = {
...form,
pageSize: pagination.pageSize,
pageIndex: pagination.current,
self: true,
};
let paramsData = {};
getPageListByType(paramsData).then((res) => {
loading.value = false;
tableData.value = res.result.list;
pagination.total = res.result.count;
});
switch (props.resType) {
// 考试
case 61:
paramsData = {
keyWord: form.name,
pageSize: pagination.pageSize,
pageIndex: pagination.current,
};
getPaperList(paramsData).then((res) => {
loading.value = false;
tableData.value = res.result.list.map((item) => {
return {
...item,
name: item.testName,
};
});
pagination.total = res.result.count;
});
break;
default:
// 非考试列表
paramsData = {
...form,
pageSize: pagination.pageSize,
pageIndex: pagination.current,
self: true,
};
getPageListByType(paramsData).then((res) => {
loading.value = false;
tableData.value = res.result.list;
pagination.total = res.result.count;
});
break;
}
};
// 上传成功处理
@@ -199,6 +224,10 @@ const handleUploadSuccess = (res, file) => {
// 上传前处理
const handleBeforeUpload = (file) => {
const { fileType, name, uploadSize, uploadSizeName } = getMapsItem(
props.resType
);
if (file.name.lastIndexOf(".") === -1) {
ElMessage({ message: `文件格式不正确!`, type: "error", offset: 100 });
return false;
@@ -208,13 +237,9 @@ const handleBeforeUpload = (file) => {
fileExtension = fileExtension.toLowerCase();
// 校检文件类型
if (
getMapsItem(props.resType).fileType.join(",").indexOf(fileExtension) === -1
) {
if (fileType.join(",").indexOf(fileExtension) === -1) {
ElMessage({
message: `文件格式不正确, 请上传正确格式的${
getMapsItem(props.resType).name
}文件!`,
message: `文件格式不正确, 请上传正确格式的${name}文件!`,
type: "error",
offset: 100,
});
@@ -222,14 +247,11 @@ const handleBeforeUpload = (file) => {
}
// 校检文件大小
if (getMapsItem(props.resType).uploadSize) {
const isLt =
file.size / 1024 / 1024 < getMapsItem(props.resType).uploadSize;
if (uploadSize) {
const isLt = file.size / 1024 / 1024 < uploadSize;
if (!isLt) {
ElMessage({
message: `上传文件大小不能超过 ${
getMapsItem(props.resType).uploadSize
} !`,
message: `上传文件大小不能超过 ${uploadSizeName} !`,
type: "error",
offset: 100,
});
@@ -248,7 +270,7 @@ const handleBeforeUpload = (file) => {
// 生命周期
onMounted(() => {
getVideoList();
getCourseList();
});
</script>
@@ -270,7 +292,10 @@ onMounted(() => {
>上传新{{ getType(props.resType) }}</el-button
>
</el-upload>
<span class="desc ml10"
<el-button v-if="[61].includes(props.resType)" type="primary"
>自定义考试</el-button
>
<span class="desc ml10" v-if="![61].includes(props.resType)"
>文件大小限制{{
getMapsItem(props.resType).uploadSizeName
}},支持的文件类型:{{ getMapsItem(props.resType).fileType.join(",") }}
@@ -283,7 +308,7 @@ onMounted(() => {
v-model="form.name"
clearable
></el-input>
<el-button class="ml10" @click="getVideoList" type="primary"
<el-button class="ml10" @click="getCourseList" type="primary"
>查询</el-button
>
</div>

View File

@@ -1,5 +1,5 @@
import apiCourseFile from "@/api/modules/courseFile";
import apiExamPaper from "@/api/modules/paper";
// const contentTypeMaps = {
// 10: "视频",
// 20: "音频",
@@ -152,3 +152,20 @@ export function getPageListByType(params) {
});
});
}
export function getPaperList(params) {
return new Promise((resolve, reject) => {
apiExamPaper
.querylist(params)
.then((res) => {
if (res.status === 200) {
resolve(res);
} else {
reject(res.message);
}
})
.catch((err) => {
reject(err);
});
});
}

View File

@@ -24,7 +24,7 @@ export function useMediaComponent(props, emit) {
emit("update:dialogVideoForm", { ...localDialogVideoForm.value });
};
const fileBaseUrl = "http://home.hzer.xyz:9960/upload";
const fileBaseUrl = `${process.env.VUE_APP_BOE_API_URL}/upload`;
return {
localDialogVideoForm,

View File

@@ -65,7 +65,8 @@ const courseOperations = {
isNext.value = false;
},
addExam: () => {
console.log("添加考试功能调用");
courseMetadata.resType = 61;
showDialog.value = true;
},
addHomework: () => {
console.log("添加作业功能调用");