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

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>