perf: 优化依赖与首屏加载
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
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 from 'react';
|
||||
import { Avatar } from '@douyinfe/semi-ui';
|
||||
import { Bot as FastGPT, Image as Jimeng } from 'lucide-react';
|
||||
import OpenAI from '@lobehub/icons/es/OpenAI';
|
||||
import Claude from '@lobehub/icons/es/Claude';
|
||||
import Gemini from '@lobehub/icons/es/Gemini';
|
||||
import Moonshot from '@lobehub/icons/es/Moonshot';
|
||||
import Zhipu from '@lobehub/icons/es/Zhipu';
|
||||
import Qwen from '@lobehub/icons/es/Qwen';
|
||||
import DeepSeek from '@lobehub/icons/es/DeepSeek';
|
||||
import Minimax from '@lobehub/icons/es/Minimax';
|
||||
import Wenxin from '@lobehub/icons/es/Wenxin';
|
||||
import Spark from '@lobehub/icons/es/Spark';
|
||||
import Midjourney from '@lobehub/icons/es/Midjourney';
|
||||
import Hunyuan from '@lobehub/icons/es/Hunyuan';
|
||||
import Cohere from '@lobehub/icons/es/Cohere';
|
||||
import Cloudflare from '@lobehub/icons/es/Cloudflare';
|
||||
import Ai360 from '@lobehub/icons/es/Ai360';
|
||||
import Yi from '@lobehub/icons/es/Yi';
|
||||
import Jina from '@lobehub/icons/es/Jina';
|
||||
import Mistral from '@lobehub/icons/es/Mistral';
|
||||
import XAI from '@lobehub/icons/es/XAI';
|
||||
import Ollama from '@lobehub/icons/es/Ollama';
|
||||
import Doubao from '@lobehub/icons/es/Doubao';
|
||||
import Suno from '@lobehub/icons/es/Suno';
|
||||
import Xinference from '@lobehub/icons/es/Xinference';
|
||||
import OpenRouter from '@lobehub/icons/es/OpenRouter';
|
||||
import Dify from '@lobehub/icons/es/Dify';
|
||||
import Coze from '@lobehub/icons/es/Coze';
|
||||
import SiliconCloud from '@lobehub/icons/es/SiliconCloud';
|
||||
import Kling from '@lobehub/icons/es/Kling';
|
||||
import Perplexity from '@lobehub/icons/es/Perplexity';
|
||||
import Replicate from '@lobehub/icons/es/Replicate';
|
||||
|
||||
const LobeIconsMap = {
|
||||
OpenAI,
|
||||
Claude,
|
||||
Gemini,
|
||||
Moonshot,
|
||||
Zhipu,
|
||||
Qwen,
|
||||
DeepSeek,
|
||||
Minimax,
|
||||
Wenxin,
|
||||
Spark,
|
||||
Midjourney,
|
||||
Hunyuan,
|
||||
Cohere,
|
||||
Cloudflare,
|
||||
Ai360,
|
||||
Yi,
|
||||
Jina,
|
||||
Mistral,
|
||||
XAI,
|
||||
Ollama,
|
||||
Doubao,
|
||||
Suno,
|
||||
Xinference,
|
||||
OpenRouter,
|
||||
Dify,
|
||||
Coze,
|
||||
SiliconCloud,
|
||||
FastGPT,
|
||||
Kling,
|
||||
Jimeng,
|
||||
Perplexity,
|
||||
Replicate,
|
||||
};
|
||||
|
||||
export default function LobeHubIcon({ iconName, size = 14 }) {
|
||||
if (typeof iconName === 'string') iconName = iconName.trim();
|
||||
// 如果没有图标名称,返回 Avatar
|
||||
if (!iconName) {
|
||||
return <Avatar size='extra-extra-small'>?</Avatar>;
|
||||
}
|
||||
|
||||
// 解析组件路径与点号链式属性
|
||||
const segments = String(iconName).split('.');
|
||||
const baseKey = segments[0];
|
||||
const BaseIcon = LobeIconsMap[baseKey];
|
||||
|
||||
let IconComponent = undefined;
|
||||
let propStartIndex = 1;
|
||||
|
||||
if (BaseIcon && segments.length > 1 && BaseIcon[segments[1]]) {
|
||||
IconComponent = BaseIcon[segments[1]];
|
||||
propStartIndex = 2;
|
||||
} else {
|
||||
IconComponent = LobeIconsMap[baseKey];
|
||||
propStartIndex = 1;
|
||||
}
|
||||
|
||||
// 失败兜底
|
||||
if (
|
||||
!IconComponent ||
|
||||
(typeof IconComponent !== 'function' && typeof IconComponent !== 'object')
|
||||
) {
|
||||
const firstLetter = String(iconName).charAt(0).toUpperCase();
|
||||
return <Avatar size='extra-extra-small'>{firstLetter}</Avatar>;
|
||||
}
|
||||
|
||||
// 解析点号链式属性,形如:key={...}、key='...'、key="..."、key=123、key、key=true/false
|
||||
const props = {};
|
||||
|
||||
const parseValue = (raw) => {
|
||||
if (raw == null) return true;
|
||||
let v = String(raw).trim();
|
||||
// 去除一层花括号包裹
|
||||
if (v.startsWith('{') && v.endsWith('}')) {
|
||||
v = v.slice(1, -1).trim();
|
||||
}
|
||||
// 去除引号
|
||||
if (
|
||||
(v.startsWith('"') && v.endsWith('"')) ||
|
||||
(v.startsWith("'") && v.endsWith("'"))
|
||||
) {
|
||||
return v.slice(1, -1);
|
||||
}
|
||||
// 布尔
|
||||
if (v === 'true') return true;
|
||||
if (v === 'false') return false;
|
||||
// 数字
|
||||
if (/^-?\d+(?:\.\d+)?$/.test(v)) return Number(v);
|
||||
// 其他原样返回字符串
|
||||
return v;
|
||||
};
|
||||
|
||||
for (let i = propStartIndex; i < segments.length; i++) {
|
||||
const seg = segments[i];
|
||||
if (!seg) continue;
|
||||
const eqIdx = seg.indexOf('=');
|
||||
if (eqIdx === -1) {
|
||||
props[seg.trim()] = true;
|
||||
continue;
|
||||
}
|
||||
const key = seg.slice(0, eqIdx).trim();
|
||||
const valRaw = seg.slice(eqIdx + 1).trim();
|
||||
props[key] = parseValue(valRaw);
|
||||
}
|
||||
|
||||
// 兼容第二参数 size,若字符串中未显式指定 size,则使用函数入参
|
||||
if (props.size == null && size != null) props.size = size;
|
||||
|
||||
return <IconComponent {...props} />;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
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 assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
|
||||
const filename = new URL('./LobeHubIcon.jsx', import.meta.url);
|
||||
const { code } = await transformWithEsbuild(
|
||||
await readFile(filename, 'utf8'),
|
||||
filename.pathname,
|
||||
{ loader: 'jsx', format: 'cjs', jsx: 'transform', target: 'node22' },
|
||||
);
|
||||
const Mono = () => null;
|
||||
const Color = () => null;
|
||||
const Avatar = () => null;
|
||||
const module = { exports: {} };
|
||||
runInNewContext(code, {
|
||||
module,
|
||||
exports: module.exports,
|
||||
require(name) {
|
||||
if (name === 'react') return React;
|
||||
if (name === '@douyinfe/semi-ui') return { Avatar: 'avatar' };
|
||||
if (name === 'lucide-react') return { Bot: Mono, Image: Mono };
|
||||
assert.ok(name.startsWith('@lobehub/icons/es/'), name);
|
||||
return Object.assign(Mono, { Color, Avatar });
|
||||
},
|
||||
});
|
||||
const render = module.exports.default;
|
||||
|
||||
test('brand icon keeps the selected variant and configured props', () => {
|
||||
const icon = render({
|
||||
iconName: "OpenAI.Avatar.type={'platform'}.shape='square'.size=24",
|
||||
size: 14,
|
||||
});
|
||||
assert.equal(icon.type, Avatar);
|
||||
assert.equal(icon.props.type, 'platform');
|
||||
assert.equal(icon.props.shape, 'square');
|
||||
assert.equal(icon.props.size, 24);
|
||||
});
|
||||
|
||||
test('brand icon preserves color and default size', () => {
|
||||
const icon = render({ iconName: 'Claude.Color' });
|
||||
assert.equal(icon.type, Color);
|
||||
assert.equal(icon.props.size, 14);
|
||||
});
|
||||
|
||||
test('empty and unknown brand names preserve the fallback avatar', () => {
|
||||
for (const [iconName, letter] of [
|
||||
[null, '?'],
|
||||
['', '?'],
|
||||
['UnknownBrand', 'U'],
|
||||
]) {
|
||||
const icon = render({ iconName });
|
||||
assert.equal(icon.type, 'avatar');
|
||||
assert.equal(icon.props.children, letter);
|
||||
}
|
||||
});
|
||||
|
||||
test('base icons and lucide compatibility brands remain supported', () => {
|
||||
for (const iconName of ['OpenAI', 'FastGPT', 'Jimeng']) {
|
||||
const icon = render({ iconName, size: 20 });
|
||||
assert.equal(icon.type, Mono);
|
||||
assert.equal(icon.props.size, 20);
|
||||
}
|
||||
});
|
||||
@@ -17,9 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import HeaderBar from './headerbar';
|
||||
import { Layout } from '@douyinfe/semi-ui';
|
||||
import SiderBar from './SiderBar';
|
||||
import App from '../../App';
|
||||
import { ToastContainer } from 'react-toastify';
|
||||
import React, {
|
||||
@@ -49,7 +47,11 @@ import { useLocation } from 'react-router-dom';
|
||||
import { applyTheme, setPresetOverrides } from '../../helpers/theme';
|
||||
// 用户问卷功能已禁用
|
||||
// import UserSurveyModal from '../common/modals/UserSurveyModal';
|
||||
import NewUserGiftModal from '../common/modals/NewUserGiftModal';
|
||||
const HeaderBar = lazy(() => import('./headerbar'));
|
||||
const SiderBar = lazy(() => import('./SiderBar'));
|
||||
const NewUserGiftModal = lazy(
|
||||
() => import('../common/modals/NewUserGiftModal'),
|
||||
);
|
||||
|
||||
// 懒加载客服浮窗组件 - 非核心功能,延迟加载
|
||||
const CustomerServiceFloat = lazy(() => import('../customer-service'));
|
||||
@@ -355,10 +357,12 @@ const PageLayout = () => {
|
||||
zIndex: 100,
|
||||
}}
|
||||
>
|
||||
<HeaderBar
|
||||
onMobileMenuToggle={() => setDrawerOpen((prev) => !prev)}
|
||||
drawerOpen={drawerOpen}
|
||||
/>
|
||||
<Suspense fallback={null}>
|
||||
<HeaderBar
|
||||
onMobileMenuToggle={() => setDrawerOpen((prev) => !prev)}
|
||||
drawerOpen={drawerOpen}
|
||||
/>
|
||||
</Suspense>
|
||||
{/* 跑马灯公告 - 固定在导航栏正下方;认证页不展示(与 hasMarquee 的高度计算保持一致) */}
|
||||
{!isAuthPage && <Marquee />}
|
||||
</Header>
|
||||
@@ -406,12 +410,14 @@ const PageLayout = () => {
|
||||
: undefined,
|
||||
}}
|
||||
>
|
||||
<SiderBar
|
||||
forceExpanded={siderForceExpanded}
|
||||
onNavigate={() => {
|
||||
if (isMobile) setDrawerOpen(false);
|
||||
}}
|
||||
/>
|
||||
<Suspense fallback={null}>
|
||||
<SiderBar
|
||||
forceExpanded={siderForceExpanded}
|
||||
onNavigate={() => {
|
||||
if (isMobile) setDrawerOpen(false);
|
||||
}}
|
||||
/>
|
||||
</Suspense>
|
||||
</Sider>
|
||||
)}
|
||||
<Layout
|
||||
@@ -470,11 +476,15 @@ const PageLayout = () => {
|
||||
/> */}
|
||||
|
||||
{/* 新用户注册赠送额度弹窗 */}
|
||||
<NewUserGiftModal
|
||||
visible={showGiftModal}
|
||||
onClose={() => setShowGiftModal(false)}
|
||||
quota={giftQuota}
|
||||
/>
|
||||
{showGiftModal && (
|
||||
<Suspense fallback={null}>
|
||||
<NewUserGiftModal
|
||||
visible={showGiftModal}
|
||||
onClose={() => setShowGiftModal(false)}
|
||||
quota={giftQuota}
|
||||
/>
|
||||
</Suspense>
|
||||
)}
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -18,7 +18,6 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import * as XLSX from 'xlsx';
|
||||
import { Modal, Button, Checkbox, Radio, RadioGroup } from '@douyinfe/semi-ui';
|
||||
import { CheckSquare, Eraser, FileSpreadsheet, X } from 'lucide-react';
|
||||
import {
|
||||
@@ -232,7 +231,7 @@ const UsageLogsExportModal = ({
|
||||
// 不用可能过期的 logCount 来禁用按钮(避免编辑筛选未查询时被误禁用)
|
||||
const pageNoData = scope === 'page' && pageCount === 0;
|
||||
|
||||
const buildSheet = (rows, fields, header) => {
|
||||
const buildSheet = (XLSX, rows, fields, header) => {
|
||||
const aoa = [header, ...rows.map((r) => fields.map((f) => f.value(r, t)))];
|
||||
const ws = XLSX.utils.aoa_to_sheet(aoa);
|
||||
ws['!cols'] = fields.map((f) => ({ wch: f.width || 14 }));
|
||||
@@ -267,10 +266,11 @@ const UsageLogsExportModal = ({
|
||||
return;
|
||||
}
|
||||
const header = fields.map((f) => t(f.label));
|
||||
const XLSX = await import('xlsx');
|
||||
const wb = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(
|
||||
wb,
|
||||
buildSheet(rows, fields, header),
|
||||
buildSheet(XLSX, rows, fields, header),
|
||||
t('消耗明细'),
|
||||
);
|
||||
XLSX.writeFile(wb, buildExportFilename());
|
||||
|
||||
+80
-180
@@ -17,81 +17,46 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { lazy, Suspense } from 'react';
|
||||
import i18next from 'i18next';
|
||||
// React 18-compatible LobeHub icons lack these brands; use generic icons.
|
||||
import { Lock, Bot as FastGPT, Image as Jimeng } from 'lucide-react';
|
||||
import { Modal, Tag, Typography, Avatar } from '@douyinfe/semi-ui';
|
||||
import { Modal, Tag, Typography } from '@douyinfe/semi-ui';
|
||||
import { copy, getCurrencySymbol, showSuccess } from './utils';
|
||||
import { visit } from 'unist-util-visit';
|
||||
import {
|
||||
OpenAI,
|
||||
Claude,
|
||||
Gemini,
|
||||
Moonshot,
|
||||
Zhipu,
|
||||
Qwen,
|
||||
DeepSeek,
|
||||
Minimax,
|
||||
Wenxin,
|
||||
Spark,
|
||||
Midjourney,
|
||||
Hunyuan,
|
||||
Cohere,
|
||||
Cloudflare,
|
||||
Ai360,
|
||||
Yi,
|
||||
Jina,
|
||||
Mistral,
|
||||
XAI,
|
||||
Ollama,
|
||||
Doubao,
|
||||
Suno,
|
||||
Xinference,
|
||||
OpenRouter,
|
||||
Dify,
|
||||
Coze,
|
||||
SiliconCloud,
|
||||
Kling,
|
||||
Perplexity,
|
||||
Replicate,
|
||||
} from '@lobehub/icons';
|
||||
import OpenAI from '@lobehub/icons/es/OpenAI/components/Mono';
|
||||
import Claude from '@lobehub/icons/es/Claude/components/Color';
|
||||
import Gemini from '@lobehub/icons/es/Gemini/components/Color';
|
||||
import Moonshot from '@lobehub/icons/es/Moonshot/components/Mono';
|
||||
import Zhipu from '@lobehub/icons/es/Zhipu/components/Color';
|
||||
import Qwen from '@lobehub/icons/es/Qwen/components/Color';
|
||||
import DeepSeek from '@lobehub/icons/es/DeepSeek/components/Color';
|
||||
import Minimax from '@lobehub/icons/es/Minimax/components/Color';
|
||||
import Wenxin from '@lobehub/icons/es/Wenxin/components/Color';
|
||||
import Spark from '@lobehub/icons/es/Spark/components/Color';
|
||||
import Midjourney from '@lobehub/icons/es/Midjourney/components/Mono';
|
||||
import Hunyuan from '@lobehub/icons/es/Hunyuan/components/Color';
|
||||
import Cohere from '@lobehub/icons/es/Cohere/components/Color';
|
||||
import Cloudflare from '@lobehub/icons/es/Cloudflare/components/Color';
|
||||
import Ai360 from '@lobehub/icons/es/Ai360/components/Color';
|
||||
import Yi from '@lobehub/icons/es/Yi/components/Color';
|
||||
import Jina from '@lobehub/icons/es/Jina/components/Mono';
|
||||
import Mistral from '@lobehub/icons/es/Mistral/components/Color';
|
||||
import XAI from '@lobehub/icons/es/XAI/components/Mono';
|
||||
import Ollama from '@lobehub/icons/es/Ollama/components/Mono';
|
||||
import Doubao from '@lobehub/icons/es/Doubao/components/Color';
|
||||
import Suno from '@lobehub/icons/es/Suno/components/Mono';
|
||||
import Xinference from '@lobehub/icons/es/Xinference/components/Color';
|
||||
import OpenRouter from '@lobehub/icons/es/OpenRouter/components/Mono';
|
||||
import Dify from '@lobehub/icons/es/Dify/components/Color';
|
||||
import Coze from '@lobehub/icons/es/Coze/components/Mono';
|
||||
import SiliconCloud from '@lobehub/icons/es/SiliconCloud/components/Color';
|
||||
import Kling from '@lobehub/icons/es/Kling/components/Color';
|
||||
import Perplexity from '@lobehub/icons/es/Perplexity/components/Color';
|
||||
import Replicate from '@lobehub/icons/es/Replicate/components/Mono';
|
||||
|
||||
// 创建图标映射表,避免使用 import * 导致整个库被打包
|
||||
// 只包含实际在库中存在的图标
|
||||
const LobeIconsMap = {
|
||||
OpenAI,
|
||||
Claude,
|
||||
Gemini,
|
||||
Moonshot,
|
||||
Zhipu,
|
||||
Qwen,
|
||||
DeepSeek,
|
||||
Minimax,
|
||||
Wenxin,
|
||||
Spark,
|
||||
Midjourney,
|
||||
Hunyuan,
|
||||
Cohere,
|
||||
Cloudflare,
|
||||
Ai360,
|
||||
Yi,
|
||||
Jina,
|
||||
Mistral,
|
||||
XAI,
|
||||
Ollama,
|
||||
Doubao,
|
||||
Suno,
|
||||
Xinference,
|
||||
OpenRouter,
|
||||
Dify,
|
||||
Coze,
|
||||
SiliconCloud,
|
||||
FastGPT,
|
||||
Kling,
|
||||
Jimeng,
|
||||
Perplexity,
|
||||
Replicate,
|
||||
};
|
||||
// Full Avatar/Text/Combine variants are loaded only when configured icons render.
|
||||
const LobeHubIcon = lazy(() => import('../components/common/LobeHubIcon'));
|
||||
|
||||
import {
|
||||
LayoutDashboard,
|
||||
@@ -205,12 +170,12 @@ export const getModelCategories = (() => {
|
||||
},
|
||||
anthropic: {
|
||||
label: 'Anthropic',
|
||||
icon: <Claude.Color />,
|
||||
icon: <Claude />,
|
||||
filter: (model) => model.model_name.toLowerCase().includes('claude'),
|
||||
},
|
||||
gemini: {
|
||||
label: 'Gemini',
|
||||
icon: <Gemini.Color />,
|
||||
icon: <Gemini />,
|
||||
filter: (model) =>
|
||||
model.model_name.toLowerCase().includes('gemini') ||
|
||||
model.model_name.toLowerCase().includes('gemma') ||
|
||||
@@ -230,7 +195,7 @@ export const getModelCategories = (() => {
|
||||
},
|
||||
zhipu: {
|
||||
label: t('智谱'),
|
||||
icon: <Zhipu.Color />,
|
||||
icon: <Zhipu />,
|
||||
filter: (model) =>
|
||||
model.model_name.toLowerCase().includes('chatglm') ||
|
||||
model.model_name.toLowerCase().includes('glm-') ||
|
||||
@@ -239,29 +204,29 @@ export const getModelCategories = (() => {
|
||||
},
|
||||
qwen: {
|
||||
label: t('通义千问'),
|
||||
icon: <Qwen.Color />,
|
||||
icon: <Qwen />,
|
||||
filter: (model) => model.model_name.toLowerCase().includes('qwen'),
|
||||
},
|
||||
deepseek: {
|
||||
label: 'DeepSeek',
|
||||
icon: <DeepSeek.Color />,
|
||||
icon: <DeepSeek />,
|
||||
filter: (model) => model.model_name.toLowerCase().includes('deepseek'),
|
||||
},
|
||||
minimax: {
|
||||
label: 'MiniMax',
|
||||
icon: <Minimax.Color />,
|
||||
icon: <Minimax />,
|
||||
filter: (model) =>
|
||||
model.model_name.toLowerCase().includes('abab') ||
|
||||
model.model_name.toLowerCase().includes('minimax'),
|
||||
},
|
||||
baidu: {
|
||||
label: t('文心一言'),
|
||||
icon: <Wenxin.Color />,
|
||||
icon: <Wenxin />,
|
||||
filter: (model) => model.model_name.toLowerCase().includes('ernie'),
|
||||
},
|
||||
xunfei: {
|
||||
label: t('讯飞星火'),
|
||||
icon: <Spark.Color />,
|
||||
icon: <Spark />,
|
||||
filter: (model) => model.model_name.toLowerCase().includes('spark'),
|
||||
},
|
||||
midjourney: {
|
||||
@@ -271,12 +236,12 @@ export const getModelCategories = (() => {
|
||||
},
|
||||
tencent: {
|
||||
label: t('腾讯混元'),
|
||||
icon: <Hunyuan.Color />,
|
||||
icon: <Hunyuan />,
|
||||
filter: (model) => model.model_name.toLowerCase().includes('hunyuan'),
|
||||
},
|
||||
cohere: {
|
||||
label: 'Cohere',
|
||||
icon: <Cohere.Color />,
|
||||
icon: <Cohere />,
|
||||
filter: (model) =>
|
||||
model.model_name.toLowerCase().includes('command') ||
|
||||
model.model_name.toLowerCase().includes('c4ai-') ||
|
||||
@@ -284,12 +249,12 @@ export const getModelCategories = (() => {
|
||||
},
|
||||
cloudflare: {
|
||||
label: 'Cloudflare',
|
||||
icon: <Cloudflare.Color />,
|
||||
icon: <Cloudflare />,
|
||||
filter: (model) => model.model_name.toLowerCase().includes('@cf/'),
|
||||
},
|
||||
ai360: {
|
||||
label: t('360智脑'),
|
||||
icon: <Ai360.Color />,
|
||||
icon: <Ai360 />,
|
||||
filter: (model) => model.model_name.toLowerCase().includes('360'),
|
||||
},
|
||||
jina: {
|
||||
@@ -299,7 +264,7 @@ export const getModelCategories = (() => {
|
||||
},
|
||||
mistral: {
|
||||
label: 'Mistral AI',
|
||||
icon: <Mistral.Color />,
|
||||
icon: <Mistral />,
|
||||
filter: (model) =>
|
||||
model.model_name.toLowerCase().includes('mistral') ||
|
||||
model.model_name.toLowerCase().includes('codestral') ||
|
||||
@@ -319,12 +284,12 @@ export const getModelCategories = (() => {
|
||||
},
|
||||
doubao: {
|
||||
label: t('豆包'),
|
||||
icon: <Doubao.Color />,
|
||||
icon: <Doubao />,
|
||||
filter: (model) => model.model_name.toLowerCase().includes('doubao'),
|
||||
},
|
||||
yi: {
|
||||
label: t('零一万物'),
|
||||
icon: <Yi.Color />,
|
||||
icon: <Yi />,
|
||||
filter: (model) => model.model_name.toLowerCase().includes('yi'),
|
||||
},
|
||||
};
|
||||
@@ -355,64 +320,64 @@ export function getChannelIcon(channelType) {
|
||||
return <Ollama size={iconSize} />;
|
||||
case 14: // Anthropic Claude
|
||||
case 33: // AWS Claude
|
||||
return <Claude.Color size={iconSize} />;
|
||||
return <Claude size={iconSize} />;
|
||||
case 41: // Vertex AI
|
||||
return <Gemini.Color size={iconSize} />;
|
||||
return <Gemini size={iconSize} />;
|
||||
case 34: // Cohere
|
||||
return <Cohere.Color size={iconSize} />;
|
||||
return <Cohere size={iconSize} />;
|
||||
case 39: // Cloudflare
|
||||
return <Cloudflare.Color size={iconSize} />;
|
||||
return <Cloudflare size={iconSize} />;
|
||||
case 43: // DeepSeek
|
||||
return <DeepSeek.Color size={iconSize} />;
|
||||
return <DeepSeek size={iconSize} />;
|
||||
case 15: // 百度文心千帆
|
||||
case 46: // 百度文心千帆V2
|
||||
return <Wenxin.Color size={iconSize} />;
|
||||
return <Wenxin size={iconSize} />;
|
||||
case 17: // 阿里通义千问
|
||||
return <Qwen.Color size={iconSize} />;
|
||||
return <Qwen size={iconSize} />;
|
||||
case 18: // 讯飞星火认知
|
||||
return <Spark.Color size={iconSize} />;
|
||||
return <Spark size={iconSize} />;
|
||||
case 16: // 智谱 ChatGLM
|
||||
case 26: // 智谱 GLM-4V
|
||||
return <Zhipu.Color size={iconSize} />;
|
||||
return <Zhipu size={iconSize} />;
|
||||
case 24: // Google Gemini
|
||||
case 11: // Google PaLM2
|
||||
return <Gemini.Color size={iconSize} />;
|
||||
return <Gemini size={iconSize} />;
|
||||
case 47: // Xinference
|
||||
return <Xinference.Color size={iconSize} />;
|
||||
return <Xinference size={iconSize} />;
|
||||
case 25: // Moonshot
|
||||
return <Moonshot size={iconSize} />;
|
||||
case 27: // Perplexity
|
||||
return <Perplexity.Color size={iconSize} />;
|
||||
return <Perplexity size={iconSize} />;
|
||||
case 20: // OpenRouter
|
||||
return <OpenRouter size={iconSize} />;
|
||||
case 19: // 360 智脑
|
||||
return <Ai360.Color size={iconSize} />;
|
||||
return <Ai360 size={iconSize} />;
|
||||
case 23: // 腾讯混元
|
||||
return <Hunyuan.Color size={iconSize} />;
|
||||
return <Hunyuan size={iconSize} />;
|
||||
case 31: // 零一万物
|
||||
return <Yi.Color size={iconSize} />;
|
||||
return <Yi size={iconSize} />;
|
||||
case 35: // MiniMax
|
||||
return <Minimax.Color size={iconSize} />;
|
||||
return <Minimax size={iconSize} />;
|
||||
case 37: // Dify
|
||||
return <Dify.Color size={iconSize} />;
|
||||
return <Dify size={iconSize} />;
|
||||
case 38: // Jina
|
||||
return <Jina size={iconSize} />;
|
||||
case 40: // SiliconCloud
|
||||
return <SiliconCloud.Color size={iconSize} />;
|
||||
return <SiliconCloud size={iconSize} />;
|
||||
case 42: // Mistral AI
|
||||
return <Mistral.Color size={iconSize} />;
|
||||
return <Mistral size={iconSize} />;
|
||||
case 45: // 字节火山方舟、豆包通用
|
||||
return <Doubao.Color size={iconSize} />;
|
||||
return <Doubao size={iconSize} />;
|
||||
case 48: // xAI
|
||||
return <XAI size={iconSize} />;
|
||||
case 49: // Coze
|
||||
return <Coze size={iconSize} />;
|
||||
case 50: // 可灵 Kling
|
||||
return <Kling.Color size={iconSize} />;
|
||||
return <Kling size={iconSize} />;
|
||||
case 51: // 即梦 Jimeng
|
||||
return <Jimeng size={iconSize} />;
|
||||
case 54: // 豆包视频 Doubao Video
|
||||
return <Doubao.Color size={iconSize} />;
|
||||
return <Doubao size={iconSize} />;
|
||||
case 56: // Replicate
|
||||
return <Replicate size={iconSize} />;
|
||||
case 8: // 自定义渠道
|
||||
@@ -436,80 +401,15 @@ export function getChannelIcon(channelType) {
|
||||
* @returns {JSX.Element} - 对应的图标组件或 Avatar
|
||||
*/
|
||||
export function getLobeHubIcon(iconName, size = 14) {
|
||||
if (typeof iconName === 'string') iconName = iconName.trim();
|
||||
// 如果没有图标名称,返回 Avatar
|
||||
if (!iconName) {
|
||||
return <Avatar size='extra-extra-small'>?</Avatar>;
|
||||
}
|
||||
|
||||
// 解析组件路径与点号链式属性
|
||||
const segments = String(iconName).split('.');
|
||||
const baseKey = segments[0];
|
||||
const BaseIcon = LobeIconsMap[baseKey];
|
||||
|
||||
let IconComponent = undefined;
|
||||
let propStartIndex = 1;
|
||||
|
||||
if (BaseIcon && segments.length > 1 && BaseIcon[segments[1]]) {
|
||||
IconComponent = BaseIcon[segments[1]];
|
||||
propStartIndex = 2;
|
||||
} else {
|
||||
IconComponent = LobeIconsMap[baseKey];
|
||||
propStartIndex = 1;
|
||||
}
|
||||
|
||||
// 失败兜底
|
||||
if (
|
||||
!IconComponent ||
|
||||
(typeof IconComponent !== 'function' && typeof IconComponent !== 'object')
|
||||
) {
|
||||
const firstLetter = String(iconName).charAt(0).toUpperCase();
|
||||
return <Avatar size='extra-extra-small'>{firstLetter}</Avatar>;
|
||||
}
|
||||
|
||||
// 解析点号链式属性,形如:key={...}、key='...'、key="..."、key=123、key、key=true/false
|
||||
const props = {};
|
||||
|
||||
const parseValue = (raw) => {
|
||||
if (raw == null) return true;
|
||||
let v = String(raw).trim();
|
||||
// 去除一层花括号包裹
|
||||
if (v.startsWith('{') && v.endsWith('}')) {
|
||||
v = v.slice(1, -1).trim();
|
||||
}
|
||||
// 去除引号
|
||||
if (
|
||||
(v.startsWith('"') && v.endsWith('"')) ||
|
||||
(v.startsWith("'") && v.endsWith("'"))
|
||||
) {
|
||||
return v.slice(1, -1);
|
||||
}
|
||||
// 布尔
|
||||
if (v === 'true') return true;
|
||||
if (v === 'false') return false;
|
||||
// 数字
|
||||
if (/^-?\d+(?:\.\d+)?$/.test(v)) return Number(v);
|
||||
// 其他原样返回字符串
|
||||
return v;
|
||||
};
|
||||
|
||||
for (let i = propStartIndex; i < segments.length; i++) {
|
||||
const seg = segments[i];
|
||||
if (!seg) continue;
|
||||
const eqIdx = seg.indexOf('=');
|
||||
if (eqIdx === -1) {
|
||||
props[seg.trim()] = true;
|
||||
continue;
|
||||
}
|
||||
const key = seg.slice(0, eqIdx).trim();
|
||||
const valRaw = seg.slice(eqIdx + 1).trim();
|
||||
props[key] = parseValue(valRaw);
|
||||
}
|
||||
|
||||
// 兼容第二参数 size,若字符串中未显式指定 size,则使用函数入参
|
||||
if (props.size == null && size != null) props.size = size;
|
||||
|
||||
return <IconComponent {...props} />;
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<span style={{ display: 'inline-block', width: size, height: size }} />
|
||||
}
|
||||
>
|
||||
<LobeHubIcon iconName={iconName} size={size} />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
// 颜色列表
|
||||
|
||||
+19
-21
@@ -31,18 +31,16 @@ import { useActualTheme } from '../../context/Theme';
|
||||
import { marked } from 'marked';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
Moonshot,
|
||||
OpenAI,
|
||||
Zhipu,
|
||||
Claude,
|
||||
Gemini,
|
||||
Wenxin,
|
||||
Spark,
|
||||
DeepSeek,
|
||||
Qwen,
|
||||
Midjourney,
|
||||
} from '@lobehub/icons';
|
||||
import Moonshot from '@lobehub/icons/es/Moonshot/components/Mono';
|
||||
import OpenAI from '@lobehub/icons/es/OpenAI/components/Mono';
|
||||
import Zhipu from '@lobehub/icons/es/Zhipu/components/Color';
|
||||
import Claude from '@lobehub/icons/es/Claude/components/Color';
|
||||
import Gemini from '@lobehub/icons/es/Gemini/components/Color';
|
||||
import Wenxin from '@lobehub/icons/es/Wenxin/components/Color';
|
||||
import Spark from '@lobehub/icons/es/Spark/components/Color';
|
||||
import DeepSeek from '@lobehub/icons/es/DeepSeek/components/Color';
|
||||
import Qwen from '@lobehub/icons/es/Qwen/components/Color';
|
||||
import Midjourney from '@lobehub/icons/es/Midjourney/components/Mono';
|
||||
import {
|
||||
Cpu,
|
||||
Server,
|
||||
@@ -299,15 +297,15 @@ const Home = () => {
|
||||
// 模型列表
|
||||
const modelIcons = [
|
||||
{ Icon: OpenAI, name: 'OpenAI' },
|
||||
{ Icon: Claude.Color, name: 'Claude' },
|
||||
{ Icon: Gemini.Color, name: 'Gemini' },
|
||||
{ Icon: Claude, name: 'Claude' },
|
||||
{ Icon: Gemini, name: 'Gemini' },
|
||||
{ Icon: Midjourney, name: 'Midjourney' },
|
||||
{ Icon: Qwen.Color, name: 'Qwen' },
|
||||
{ Icon: DeepSeek.Color, name: 'DeepSeek' },
|
||||
{ Icon: Zhipu.Color, name: 'ChatGLM' },
|
||||
{ Icon: Qwen, name: 'Qwen' },
|
||||
{ Icon: DeepSeek, name: 'DeepSeek' },
|
||||
{ Icon: Zhipu, name: 'ChatGLM' },
|
||||
{ Icon: Moonshot, name: 'Moonshot' },
|
||||
{ Icon: Spark.Color, name: 'Spark' },
|
||||
{ Icon: Wenxin.Color, name: 'Wenxin' },
|
||||
{ Icon: Spark, name: 'Spark' },
|
||||
{ Icon: Wenxin, name: 'Wenxin' },
|
||||
];
|
||||
|
||||
// Enterprise Style CSS
|
||||
@@ -498,10 +496,10 @@ const Home = () => {
|
||||
<OpenAI size={24} />
|
||||
</div>
|
||||
<div className='w-12 h-12 rounded-xl bg-white dark:bg-slate-800 flex items-center justify-center shadow-md border border-slate-200 dark:border-slate-700 hover:scale-110 transition-transform'>
|
||||
<Claude.Color size={24} />
|
||||
<Claude size={24} />
|
||||
</div>
|
||||
<div className='w-12 h-12 rounded-xl bg-white dark:bg-slate-800 flex items-center justify-center shadow-md border border-slate-200 dark:border-slate-700 hover:scale-110 transition-transform'>
|
||||
<Gemini.Color size={24} />
|
||||
<Gemini size={24} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -18,7 +18,6 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useEffect, useState, useMemo, useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import * as XLSX from 'xlsx';
|
||||
import {
|
||||
RefreshCw,
|
||||
Receipt,
|
||||
@@ -161,7 +160,7 @@ const EXPORT_FIELDS = [
|
||||
];
|
||||
|
||||
// 将选中字段组装成一个 worksheet(含表头、列宽)
|
||||
function buildWorksheet(rows, fields, header) {
|
||||
function buildWorksheet(XLSX, rows, fields, header) {
|
||||
const aoa = [header, ...rows.map((r) => fields.map((f) => f.value(r)))];
|
||||
const ws = XLSX.utils.aoa_to_sheet(aoa);
|
||||
ws['!cols'] = fields.map((f) => ({ wch: f.width || 14 }));
|
||||
@@ -455,6 +454,7 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
|
||||
}
|
||||
|
||||
const header = fields.map((f) => t(f.label));
|
||||
const XLSX = await import('xlsx');
|
||||
const wb = XLSX.utils.book_new();
|
||||
|
||||
if (exportMode === 'perUser') {
|
||||
@@ -535,7 +535,7 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
|
||||
);
|
||||
|
||||
for (const { name, rows } of groups.values()) {
|
||||
const ws = buildWorksheet(rows, fields, header);
|
||||
const ws = buildWorksheet(XLSX, rows, fields, header);
|
||||
XLSX.utils.book_append_sheet(
|
||||
wb,
|
||||
ws,
|
||||
@@ -544,7 +544,7 @@ const OrgLogs = ({ orgId, orgRole, isDeptManager = false }) => {
|
||||
}
|
||||
} else {
|
||||
// 汇总:所有记录放在一个 sheet 页
|
||||
const ws = buildWorksheet(allLogs, fields, header);
|
||||
const ws = buildWorksheet(XLSX, allLogs, fields, header);
|
||||
XLSX.utils.book_append_sheet(
|
||||
wb,
|
||||
ws,
|
||||
|
||||
Reference in New Issue
Block a user