feat(admin): 综合大题页签增加 Excel 模板下载与批量导入(R73)
api/admin.js 新增 importBigQuestionsExcel(silent:true,错误提示由调用方统一给出,避免同族双弹)。 Admin.vue 大题工具栏新增「下载Excel模板」「Excel批量导入」两按钮 + 隐藏 file input, 复用既有 safeDownload 与 ref 模式;按钮 title 明确提示「先下载模板、按模板列填写、 组别以当前选中组别为准」,解决测试人员找不到模板入口的问题。
This commit is contained in:
@@ -148,6 +148,21 @@ export function importQuestionsExcel(group, formData) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 综合大题 Excel 批量导入(R73)
|
||||
* 首 sheet 为数据表(表头在第 1 行),可携带「填写说明」sheet
|
||||
* @param {string} group - 组别标识(zhongzhi / gaozhi)
|
||||
* @param {FormData} formData - 包含 Excel 文件的 FormData(字段名 file)
|
||||
* @returns {Promise} { imported, skipped, errors: [{ row, message }] }
|
||||
*/
|
||||
export function importBigQuestionsExcel(group, formData) {
|
||||
// silent: true —— 与 importQuestionsExcel 同口径:错误提示由调用方统一给出,避免同族双弹
|
||||
return request.post(`/admin/big-questions/${group}/import-excel`, formData, {
|
||||
timeout: 300000,
|
||||
silent: true,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传 Word 答题模板
|
||||
* @param {string} group - 组别标识
|
||||
|
||||
@@ -224,6 +224,21 @@
|
||||
<el-input v-model="bigSearch" placeholder="搜索大题标题/题干" clearable size="small" class="search-input" />
|
||||
<el-button type="primary" v-guard="() => openBigDialog(null)">新增大题</el-button>
|
||||
<el-button size="small" type="info" plain :loading="bigQuestionsLoading" @click="fetchBigQuestions">刷新</el-button>
|
||||
<el-divider direction="vertical" />
|
||||
<el-button
|
||||
size="small"
|
||||
type="info"
|
||||
plain
|
||||
title="下载综合大题导入模板,模板内含「填写说明」页:列名含义、状态说明、常见被拒原因"
|
||||
v-guard="() => downloadBigQuestionTpl()"
|
||||
>下载Excel模板</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
type="success"
|
||||
title="请先下载模板,按模板列填写后再导入。组别以当前选中的组别为准,表格里的组别会被忽略"
|
||||
v-guard="() => triggerBigExcelImport()"
|
||||
>Excel批量导入</el-button>
|
||||
<input ref="bigExcelFileInput" type="file" accept=".xlsx,.xls" style="display:none" @change="onBigExcelFileChange" />
|
||||
<el-button
|
||||
size="small"
|
||||
type="warning"
|
||||
@@ -2521,6 +2536,43 @@ async function downloadQuestionTpl() {
|
||||
})
|
||||
}
|
||||
|
||||
// ==================== 综合大题 Excel 导入 / 模板(R73) ====================
|
||||
const bigExcelFileInput = ref(null)
|
||||
|
||||
function triggerBigExcelImport() {
|
||||
if (bigExcelFileInput.value) bigExcelFileInput.value.click()
|
||||
}
|
||||
|
||||
async function onBigExcelFileChange(e) {
|
||||
const file = e.target.files && e.target.files[0]
|
||||
if (!file) return
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
try {
|
||||
const res = await adminApi.importBigQuestionsExcel(questionGroup.value, formData)
|
||||
const r = res || {}
|
||||
ElMessage.success(`导入完成:成功 ${r.imported || 0} 道,跳过 ${r.skipped || 0} 道`)
|
||||
if (r.errors && r.errors.length) {
|
||||
console.warn('综合大题导入跳过明细:', r.errors)
|
||||
ElMessage.warning(`有 ${r.errors.length} 行被跳过,详见控制台`)
|
||||
}
|
||||
fetchBigQuestions()
|
||||
} catch (err) {
|
||||
const msg = (err && err.response && err.response.data && err.response.data.message)
|
||||
|| (err && err.message) || '未知错误'
|
||||
ElMessage.error('综合大题导入失败:' + msg)
|
||||
} finally {
|
||||
e.target.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadBigQuestionTpl() {
|
||||
// 同 downloadQuestionTpl:safeDownload 自带 HTTP 状态 + content-type 双重校验
|
||||
await safeDownload(`/api/admin/big-questions/${questionGroup.value}/template`, {
|
||||
fallbackName: `综合大题导入模板_${questionGroup.value}.xlsx`,
|
||||
})
|
||||
}
|
||||
|
||||
// 考生答题记录
|
||||
const examSubmissions = ref([])
|
||||
const examSubmissionsLoading = ref(false)
|
||||
|
||||
Reference in New Issue
Block a user