前台8项体验修复: 知识库上传自动刷新; 资产PDF归类; Token驾驶舱媒体统计; AI模糊意图澄清选择; ChatPage增加MCP/附件上传/语音; 技能市场安装态修复+清理演示数据; MCP协议应用改名MCP应用; Agent单应用接入(名称/介绍/API Key)

This commit is contained in:
QihuAI Design committed 2026-07-15 10:33:43 +08:00
1 parent 463824480b
commit bc2899ed09
11 files changed
+945 -154

No files matched your search

+34 -19
View File
@@ -392,24 +392,43 @@ const AssetsPage: React.FC = () => {
const [showCreate, setShowCreate] = useState(false);
const navigate = useNavigate();
const fetchAssets = async (category?: string) => {
// 将后端返回的资产标准化:
// 1. 统一 fileType(兼容 file_type 字段)
// 2. 兼容遗留的文档类分类(doc/document 等)与带文件类型但分类异常的资产,
// 统一归入 file 分类,确保它们出现在「文件」页签及其对应的子类型(如 pdf)中。
const VALID_CATEGORIES = ['file', 'novel', 'image', 'video', 'audio', 'custom', 'other'];
const normalizeAsset = (item: any): Asset => {
const rawCat = item.category;
const ft = item.fileType || item.file_type || 'other';
let category = rawCat;
if (!VALID_CATEGORIES.includes(category)) {
category = (ft && ft !== 'other') ? 'file' : 'other';
}
return { ...item, category, fileType: ft };
};
// 一次性拉取当前用户全部资产(分页累加),分类与子类型筛选全部在前端完成,
// 避免后端按 category 过滤时漏掉历史遗留分类(如 doc)的资产。
const fetchAllAssets = async () => {
setLoading(true);
setError(null);
try {
const catParam = category && category !== 'all' ? category : undefined;
const res = await assetsAPI.getAssets(catParam);
// getAssets 返回分页格式 {total, page, page_size, items}
const rawItems = (res.data as any)?.items || res.data || [];
// 标准化资产数据:如果category为空但有fileType,则自动归类为file
const normalizedAssets: Asset[] = rawItems.map((item: any) => ({
...item,
category: item.category || (item.fileType || item.file_type ? 'file' : 'other'),
fileType: item.fileType || item.file_type || 'other',
}));
let all: any[] = [];
let page = 1;
const pageSize = 100;
for (;;) {
const res = await assetsAPI.getAssets({ page, page_size: pageSize });
const data = (res.data as any) || {};
const items: any[] = data.items || [];
const total: number = data.total || 0;
all = all.concat(items);
if (items.length === 0 || all.length >= total) break;
page += 1;
}
const normalized = all.map(normalizeAsset);
// 按id去重
const seen = new Set<string>();
const deduped = normalizedAssets.filter(a => {
const deduped = normalized.filter(a => {
if (seen.has(a.id)) return false;
seen.add(a.id);
return true;
@@ -451,13 +470,9 @@ const AssetsPage: React.FC = () => {
useEffect(() => {
fetchCategories();
fetchAssets();
fetchAllAssets();
}, []);
useEffect(() => {
fetchAssets(activeCategory === 'all' ? undefined : activeCategory);
}, [activeCategory]);
// Filter by sub-category for files
const filtered = (() => {
// 如果是文件分类,先确保只显示文件类资产
@@ -640,7 +655,7 @@ const AssetsPage: React.FC = () => {
{showCreate && (
<CreateAssetModal
onClose={() => setShowCreate(false)}
onCreated={() => fetchAssets(activeCategory === 'all' ? undefined : activeCategory)}
onCreated={() => fetchAllAssets()}
/>
)}
</div>