import { FileDown,ListPlus,Loader2,Plus,Upload,X } from 'lucide-react'; import React from 'react'; import { createPortal } from 'react-dom'; import type { Card } from '../api'; import type { CardBatchModalProps } from '../types'; // BatchCardImportModal 负责卡密批量创建和单组库存追加的交互界面。 export const BatchCardImportModal: React.FC = ({ dataCards, downloadCardTemplate, ...state }) => { // handleFileChange 保存用户选择的批量导入文件。 const handleFileChange = (event: React.ChangeEvent) => { state.setBatchFile(event.target.files?.[0] || null); }; // handleAppendContentChange 更新追加文本并保留原始换行,预览由 Hook 派生。 const handleAppendContentChange = (event: React.ChangeEvent) => { state.setAppendContent(event.target.value); }; // handleTargetChange 切换追加库存目标卡密组。 const handleTargetChange = (event: React.ChangeEvent) => { state.setAppendTargetId(event.target.value); }; // handleClose 关闭弹窗并取消当前批量请求。 const handleClose = () => state.closeBatchModal(); // handleCreateTab 切换到批量创建页签。 const handleCreateTab = () => state.setBatchTab('create'); // handleAppendTab 切换到库存追加页签。 const handleAppendTab = () => state.setBatchTab('append'); // handleRetryCreate 重试最近一次批量创建。 const handleRetryCreate = () => void state.handleRetryBatchCreate(); // handleRetryAppend 重试最近一次库存追加。 const handleRetryAppend = () => void state.handleRetryBatchAppend(); // completedBatchResult 只保留包含逐行统计的成功批量结果。 const completedBatchResult = state.batchResult && 'rows' in state.batchResult ? state.batchResult : null; // renderCardOption 渲染追加目标卡密组的下拉选项。 const renderCardOption = (card: Card) => ; // handleSubmitCreate 提交批量创建请求。 const handleSubmitCreate = () => void state.handleBatchCreate(); // handleSubmitAppend 提交批量追加请求。 const handleSubmitAppend = () => void state.handleBatchAppend(); if (!state.showBatchModal) return null; return createPortal(

批量导入卡密

{state.batchTab === 'create' ? (
上传表格,每行一个卡密组。表头:名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值。 类型填 text/data/image;data 类型的“内容”按行存卡密(CSV 单元格内换行需用引号包裹)。
{state.batchResult?.error && (
{state.batchResult.error}
)} {completedBatchResult && (
共 {completedBatchResult.total} 行 · 成功 {completedBatchResult.created} · 失败 {completedBatchResult.failed}
{completedBatchResult.failed > 0 && (
{completedBatchResult.rows.filter( // row 是批量结果中的单行处理记录。 row => !row.success, ).map( // row 是待展示失败说明的单行结果。 row => (
第 {row.row_no} 行「{row.name}」:{row.error}
), )}
)}
)}
) : (
{dataCards.length === 0 ? (
暂无 data(批量卡密)类型的卡密组,请先创建一个再充卡密。
) : ( <>