From 28fa2099ad37d92576ee1e533a12b9babd815bdb Mon Sep 17 00:00:00 2001 From: zyh Date: Fri, 29 Aug 2025 23:55:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=89=B9=E6=AC=A1=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=AF=B9=E8=AF=9D=E6=A1=86=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E7=94=9F=E6=88=90=E7=9A=84=E5=85=91=E6=8D=A2?= =?UTF-8?q?=E7=A0=81Excel=E6=96=87=E4=BB=B6=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/links/LinkGenerate.vue | 182 +++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) diff --git a/src/views/links/LinkGenerate.vue b/src/views/links/LinkGenerate.vue index 6239047..fe9e81b 100644 --- a/src/views/links/LinkGenerate.vue +++ b/src/views/links/LinkGenerate.vue @@ -432,6 +432,42 @@ + + +
+
+ +
+

生成成功!

+

批次ID: {{ batchDownloadDialog.batchId }}

+

共生成 {{ batchDownloadDialog.count }} 个兑换码

+

是否立即下载本次生成的兑换码Excel文件?

+
+
+
+ + +
+ { // 刷新列表 await refreshList() + // 弹出批次下载对话框 + if (result && result.batchId && result.codeNos && result.codeNos.length > 0) { + showBatchDownloadDialog(result.batchId, result.codeNos.length) + } + // 重置表单 resetForm() @@ -938,6 +987,76 @@ const closeBatchDeleteByStatusDialog = () => { batchDeleteFormRef.value?.resetFields() } +// 批次下载对话框相关方法 +const showBatchDownloadDialog = (batchId, count) => { + batchDownloadDialog.visible = true + batchDownloadDialog.batchId = batchId + batchDownloadDialog.count = count + batchDownloadDialog.downloading = false +} + +const closeBatchDownloadDialog = () => { + batchDownloadDialog.visible = false + batchDownloadDialog.batchId = '' + batchDownloadDialog.count = 0 + batchDownloadDialog.downloading = false +} + +const downloadCurrentBatch = async () => { + try { + batchDownloadDialog.downloading = true + + // 根据批次ID筛选当前批次的数据 + const currentBatchData = linkList.value.filter(item => + item.batchId === batchDownloadDialog.batchId + ) + + if (currentBatchData.length === 0) { + ElMessage.warning('未找到当前批次的数据,请刷新列表后重试') + return + } + + // 准备导出数据 + const headers = [ + { key: 'codeNo', label: '兑换码' }, + { key: 'batchId', label: '批次ID' }, + { key: 'quantity', label: '数量' }, + { key: 'times', label: '次数' }, + { key: 'totalPoints', label: '总积分' }, + { key: 'statusDesc', label: '状态' }, + { key: 'remainingTime', label: '剩余时间' }, + { key: 'linkUrl', label: '链接地址' }, + { key: 'expireAt', label: '过期时间' }, + { key: 'createdAt', label: '创建时间' } + ] + + const data = currentBatchData.map(item => ({ + ...item, + remainingTime: item.isExpired ? '已过期' : (item.remainingSeconds > 0 ? formatRemainingTime(item.remainingSeconds) : '-'), + linkUrl: generateLinkUrl(item.codeNo), + expireAt: formatDateTime(item.expireAt), + createdAt: formatDateTime(item.createdAt) + })) + + // 生成文件名 + const filename = `批次${batchDownloadDialog.batchId}_兑换码_${currentBatchData.length}个_${new Date().toISOString().split('T')[0]}.xlsx` + + // 导出Excel + exportExcelUtil(data, headers, filename) + + ElMessage.success(`成功导出批次 ${batchDownloadDialog.batchId} 的 ${currentBatchData.length} 个兑换码`) + + // 关闭对话框 + closeBatchDownloadDialog() + + } catch (error) { + console.error('批次下载失败:', error) + ElMessage.error('下载失败,请重试') + } finally { + batchDownloadDialog.downloading = false + } +} + const handleBatchDeleteByStatus = async () => { try { // 表单验证 @@ -1465,6 +1584,69 @@ onUnmounted(() => { } } +/* 批次下载对话框样式 */ +.batch-download-dialog { + text-align: center; +} + +.download-content { + padding: 20px 0; +} + +.download-info { + display: flex; + flex-direction: column; + align-items: center; + gap: 16px; +} + +.info-icon { + font-size: 48px; + color: #409eff; +} + +.info-text { + text-align: center; +} + +.info-text h4 { + margin: 0 0 16px 0; + font-size: 18px; + color: #303133; + font-weight: 600; +} + +.info-text p { + margin: 8px 0; + font-size: 14px; + color: #606266; + line-height: 1.5; +} + +.info-text strong { + color: #409eff; + font-weight: 600; +} + +@media (max-width: 768px) { + .batch-download-dialog :deep(.el-dialog) { + width: 90% !important; + margin: 0 auto !important; + } + + .info-icon { + font-size: 40px; + } + + .info-text h4 { + font-size: 16px; + } + + .info-text p { + font-size: 13px; + } +} + @media (max-width: 480px) { .link-generate { padding: 8px;