/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
// 多选导出:底部悬浮操作条。展示型组件,状态由父级(Playground/index.jsx)持有。
import React, { useState } from 'react';
import { Button, RadioGroup, Radio } from '@douyinfe/semi-ui';
import { Download, X } from 'lucide-react';
import { useTranslation } from 'react-i18next';
const MessageSelectionBar = ({
selectedCount = 0,
selectableCount = 0,
isAllSelected = false,
onSelectAll,
onClearSelection,
onExport,
onCancel,
isMobile = false,
}) => {
const { t } = useTranslation();
const [exporting, setExporting] = useState(false);
const [format, setFormat] = useState('txt');
const handleExport = async () => {
if (selectedCount === 0 || exporting) return;
setExporting(true);
try {
await onExport?.(format);
} finally {
setExporting(false);
}
};
const selectAllBtn = (
);
const formatPicker = (
setFormat(e.target.value)}
>
{t('文本 TXT')}{t('Word 文档')}
);
const exportBtn = (
}
disabled={selectedCount === 0 || exporting}
loading={exporting}
onClick={handleExport}
>
{t('导出')}
);
const cancelBtn = (
}
// 导出进行中禁用「取消」——否则 bar 被关闭但 docx 仍在 await 中,
// 最终仍会触发一次下载,对用户体感是「我已经取消了为什么还有文件」。
disabled={exporting}
onClick={onCancel}
>
{t('取消')}
);
const countText = (
{t('已选 {{count}} / {{total}} 条', {
count: selectedCount,
total: selectableCount,
})}
);
return (