Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
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 = (
|
||||
<Button
|
||||
size='small'
|
||||
theme='borderless'
|
||||
disabled={selectableCount === 0}
|
||||
onClick={isAllSelected ? onClearSelection : onSelectAll}
|
||||
>
|
||||
{isAllSelected ? t('取消全选') : t('全选')}
|
||||
</Button>
|
||||
);
|
||||
|
||||
const formatPicker = (
|
||||
<RadioGroup
|
||||
type='button'
|
||||
size='small'
|
||||
value={format}
|
||||
onChange={(e) => setFormat(e.target.value)}
|
||||
>
|
||||
<Radio value='txt'>{t('文本 TXT')}</Radio>
|
||||
<Radio value='word'>{t('Word 文档')}</Radio>
|
||||
</RadioGroup>
|
||||
);
|
||||
|
||||
const exportBtn = (
|
||||
<Button
|
||||
size='small'
|
||||
theme='solid'
|
||||
type='primary'
|
||||
icon={<Download size={14} />}
|
||||
disabled={selectedCount === 0 || exporting}
|
||||
loading={exporting}
|
||||
onClick={handleExport}
|
||||
>
|
||||
{t('导出')}
|
||||
</Button>
|
||||
);
|
||||
|
||||
const cancelBtn = (
|
||||
<Button
|
||||
size='small'
|
||||
theme='borderless'
|
||||
icon={<X size={14} />}
|
||||
// 导出进行中禁用「取消」——否则 bar 被关闭但 docx 仍在 await 中,
|
||||
// 最终仍会触发一次下载,对用户体感是「我已经取消了为什么还有文件」。
|
||||
disabled={exporting}
|
||||
onClick={onCancel}
|
||||
>
|
||||
{t('取消')}
|
||||
</Button>
|
||||
);
|
||||
|
||||
const countText = (
|
||||
<span className='text-sm font-medium text-gray-700 dark:text-gray-200 whitespace-nowrap'>
|
||||
{t('已选 {{count}} / {{total}} 条', {
|
||||
count: selectedCount,
|
||||
total: selectableCount,
|
||||
})}
|
||||
</span>
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
role='toolbar'
|
||||
aria-label={t('消息导出工具栏')}
|
||||
className='bg-white/95 dark:bg-neutral-800/95 backdrop-blur-sm border border-gray-200/80 dark:border-neutral-700/80 rounded-2xl shadow-lg'
|
||||
>
|
||||
{isMobile ? (
|
||||
<div className='flex flex-col gap-2 px-3 py-2'>
|
||||
<div className='flex items-center justify-between gap-2'>
|
||||
{countText}
|
||||
{formatPicker}
|
||||
</div>
|
||||
<div className='flex items-center justify-between gap-2'>
|
||||
{selectAllBtn}
|
||||
<div className='flex items-center gap-2'>
|
||||
{cancelBtn}
|
||||
{exportBtn}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className='flex items-center gap-3 px-4 py-2'>
|
||||
{countText}
|
||||
{selectAllBtn}
|
||||
<span className='w-px h-5 bg-gray-200 dark:bg-neutral-700' />
|
||||
{formatPicker}
|
||||
{exportBtn}
|
||||
{cancelBtn}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MessageSelectionBar;
|
||||
Reference in New Issue
Block a user