Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
@@ -0,0 +1,191 @@
/*
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
*/
import React, { useState, useEffect } from 'react';
import { Modal, Select, Typography, Spin } from '@douyinfe/semi-ui';
import { API, showError } from '../../../../helpers';
const { Text } = Typography;
const BatchCategoryModal = ({
visible,
onClose,
selectedModels,
onConfirm,
t,
}) => {
const [selectedCategories, setSelectedCategories] = useState([]);
const [loading, setLoading] = useState(false);
const [categoriesLoading, setCategoriesLoading] = useState(false);
const [level1Categories, setLevel1Categories] = useState([]);
const [level2Categories, setLevel2Categories] = useState([]);
// 加载分类数据
const loadCategories = async () => {
setCategoriesLoading(true);
try {
const res = await API.get('/api/model_categories/flat');
const { success, data, message } = res.data;
if (success) {
const categoriesData = data || [];
// 分离一级和二级分类,只保留启用的分类
const level1 = categoriesData.filter(
(cat) => cat.parent_id === 0 && cat.status === 1,
);
const level2 = categoriesData.filter(
(cat) => cat.parent_id !== 0 && cat.status === 1,
);
setLevel1Categories(level1);
setLevel2Categories(level2);
} else {
showError(message || t('加载分类失败'));
}
} catch (error) {
showError(t('加载分类失败: ') + error.message);
} finally {
setCategoriesLoading(false);
}
};
// 当弹窗打开时加载分类
useEffect(() => {
if (visible) {
loadCategories();
}
}, [visible]);
const handleConfirm = async () => {
if (selectedCategories.length === 0) return;
setLoading(true);
try {
await onConfirm(selectedCategories);
setSelectedCategories([]);
onClose();
} finally {
setLoading(false);
}
};
const handleClose = () => {
setSelectedCategories([]);
onClose();
};
// 按一级分类分组二级分类
const groupedCategories = level1Categories
.map((level1) => {
const children = level2Categories.filter(
(level2) => level2.parent_id === level1.id,
);
return {
label: level1.category_name,
children: children.map((cat) => ({
label: cat.category_name,
value: cat.category_key,
})),
};
})
.filter((group) => group.children.length > 0); // 只显示有子分类的一级分类
return (
<Modal
title={t('批量设置模型分类')}
visible={visible}
onCancel={handleClose}
onOk={handleConfirm}
okText={t('确定')}
cancelText={t('取消')}
confirmLoading={loading}
okButtonProps={{ disabled: selectedCategories.length === 0 }}
>
<Spin spinning={categoriesLoading}>
<div className='space-y-4'>
<Text>
{t('已选择 {{count}} 个模型', { count: selectedModels.length })}
</Text>
<div className='mt-4'>
<Text strong style={{ display: 'block', marginBottom: '8px' }}>
{t('选择分类(可多选)')}:
</Text>
<Select
value={selectedCategories}
onChange={setSelectedCategories}
placeholder={
categoriesLoading
? t('加载中...')
: t('请选择一个或多个模型分类')
}
style={{ width: '100%' }}
multiple
maxTagCount={3}
showClear
disabled={categoriesLoading}
filter
>
{groupedCategories.map((group) => (
<Select.OptGroup key={group.label} label={group.label}>
{group.children.map((option) => (
<Select.Option key={option.value} value={option.value}>
{option.label}
</Select.Option>
))}
</Select.OptGroup>
))}
</Select>
<Text
type='tertiary'
size='small'
style={{ display: 'block', marginTop: '8px' }}
>
{t('提示:只显示二级分类,按一级分类分组')}
</Text>
</div>
{selectedModels.length > 0 && (
<div className='mt-4 p-3 bg-gray-50 dark:bg-gray-800 rounded'>
<Text type='secondary' size='small'>
{t('将为以下模型设置分类')}:
</Text>
<div className='mt-2 max-h-40 overflow-y-auto'>
{selectedModels.slice(0, 10).map((model, index) => (
<div key={model.id} className='text-sm py-1'>
• {model.model_name}
</div>
))}
{selectedModels.length > 10 && (
<Text type='tertiary' size='small'>
{t('...还有 {{count}} 个', {
count: selectedModels.length - 10,
})}
</Text>
)}
</div>
</div>
)}
</div>
</Spin>
</Modal>
);
};
export default BatchCategoryModal;