Sfoglia il codice sorgente

feat(题目管理): 添加Excel导入检查接口并优化导入流程

添加checkExcel接口用于先检查Excel文件格式,通过后再调用importExcel接口
将学科字段改为题库类型并更新对应枚举格式化方法
tanshanming 7 mesi fa
parent
commit
31ea08b473
2 ha cambiato i file con 41 aggiunte e 12 eliminazioni
  1. 11 1
      src/api/exam/question/tQuestionApi.js
  2. 30 11
      src/views/exm/question/index.vue

+ 11 - 1
src/api/exam/question/tQuestionApi.js

@@ -10,7 +10,17 @@ export default {
 	importExcel: (file) => {
 		const formData = new FormData()
 		formData.append('file', file)
-		return request('api/admin/question/import', formData, 'post', {
+		return request('api/admin/question/loadExcel', formData, 'post', {
+			headers: {
+				'Content-Type': 'multipart/form-data'
+			}
+		})
+	},
+	// 导入数据检查接口
+	checkExcel: (file) => {
+		const formData = new FormData()
+		formData.append('file', file)
+		return request('api/admin/question/checkExcel', formData, 'post', {
 			headers: {
 				'Content-Type': 'multipart/form-data'
 			}

+ 30 - 11
src/views/exm/question/index.vue

@@ -70,11 +70,11 @@
 		>
 			<a-table-column title="Id" data-index="id" key="id" width="90px" />
 			<a-table-column
-				title="学科"
-				data-index="subjectId"
-				key="subjectId"
+				title="题库类型"
+				data-index="bankType"
+				key="bankType"
 				width="150px"
-				:customRender="subjectFormatter"
+				:customRender="bankTypeFormatter"
 			/>
 			<a-table-column
 				title="题型"
@@ -218,6 +218,10 @@
 		queryParam.pageIndex = 1
 		search()
 	}
+	const bankTypeFormatter = ({ text }) => {
+		const key = Number(text)
+		return enumFormat(bankTypeEnum.value, key)
+	}
 
 	const search = () => {
 		listLoading.value = true
@@ -294,19 +298,34 @@
 	// 处理Excel导入
 	const handleImportExcel = (options) => {
 		const { file } = options
-		const loading = message.loading('正在导入中...', 0)
+		const loading = message.loading('正在检查文件...', 0)
 
+		// 先调用检查接口
 		tQuestionApi
-			.importExcel(file)
-			.then((res) => {
+			.checkExcel(file)
+			.then((checkRes) => {
 				loading()
-				message.success('导入成功')
-				search() // 刷新列表
+				// 检查通过后,再调用导入接口
+				const importLoading = message.loading('正在导入中...', 0)
+
+				return tQuestionApi
+					.importExcel(file)
+					.then((res) => {
+						importLoading()
+						message.success('导入成功')
+						search() // 刷新列表
+					})
+					.catch((error) => {
+						importLoading()
+						message.error('导入失败,请检查Excel文件格式是否正确')
+						console.error('导入失败:', error)
+						throw error // 继续抛出错误以便外层catch捕获
+					})
 			})
 			.catch((error) => {
 				loading()
-				message.error('导入失败,请检查Excel文件格式是否正确')
-				console.error('导入失败:', error)
+				message.error('文件检查失败,请确保Excel格式正确')
+				console.error('检查失败:', error)
 			})
 	}
 </script>