perf: 优化依赖与首屏加载
This commit is contained in:
+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>
|
||||
);
|
||||
}
|
||||
|
||||
// 颜色列表
|
||||
|
||||
Reference in New Issue
Block a user