diff --git a/src/api/system/paper/index.ts b/src/api/system/paper/index.ts index 3e635d7..9577aa1 100644 --- a/src/api/system/paper/index.ts +++ b/src/api/system/paper/index.ts @@ -69,7 +69,6 @@ export async function exportPapers(params) { } export async function getPaperDetailByTaskId(paperId) { - return await request.get({ url: '/exam/qu/getPaper' , params:{paperId} }) } @@ -91,4 +90,40 @@ export async function updatePaperStatus(paperId: string, status: number) { data: { paperId, status } // 使用data }) } + +export async function openDown(ids) { + try { + // 1. 将数组转换为逗号分隔的字符串(例如 ["id1", "id2"] → "id1,id2") + const paperIdsParam = ids.join(','); + const res = await request.download({ + url: `/exam/paper/addUpload/${paperIdsParam}`, + }); + // 3. 创建 Blob 并触发下载 + const blob = new Blob([res]); + const url = window.URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + // 使用示例 + const filename = `${getNowTimeString()}.zip`; + link.setAttribute('download', filename); + document.body.appendChild(link); + link.click(); + link.remove(); + window.URL.revokeObjectURL(url); // 释放内存 + } catch (e) { + console.error('下载失败:', e); + throw new Error('下载试卷失败'); + } +} + +function getNowTimeString() { + const now = new Date(); + const Y = now.getFullYear(); + const M = String(now.getMonth() + 1).padStart(2, '0'); + const D = String(now.getDate()).padStart(2, '0'); + const h = String(now.getHours()).padStart(2, '0'); + const m = String(now.getMinutes()).padStart(2, '0'); + const s = String(now.getSeconds()).padStart(2, '0'); + return `${Y}${M}${D}${h}${m}${s}`; +} diff --git a/src/views/paper/question/FileForm.vue b/src/views/paper/question/FileForm.vue index 9c8d72f..d8c092c 100644 --- a/src/views/paper/question/FileForm.vue +++ b/src/views/paper/question/FileForm.vue @@ -192,6 +192,11 @@ --> + + +