import React from 'react';
// ─── 公共接口 ───────────────────────────────────────────────
export interface DbIconProps {
size?: number;
color?: string;
}
const IconFrame: React.FC<{
size: number;
children: React.ReactNode;
}> = ({ size, children }) => (
{children}
);
// ─── 默认色表 ───────────────────────────────────────────────
const DB_DEFAULT_COLORS: Record = {
mysql: '#00758F',
mariadb: '#003545',
oceanbase: '#0052CC',
postgres: '#336791',
redis: '#DC382D',
mongodb: '#47A248',
elasticsearch: '#FEC514',
jvm: '#1677FF',
kingbase: '#1890FF',
dameng: '#E6002D',
oracle: '#F80000',
sqlserver: '#CC2927',
clickhouse: '#FFBF00',
sqlite: '#003B57',
duckdb: '#FFC107',
vastbase: '#0066CC',
opengauss: '#2446A8',
highgo: '#00A86B',
iris: '#1F6FEB',
tdengine: '#2962FF',
diros: '#0050B3',
starrocks: '#00A6A6',
sphinx: '#2F5D62',
custom: '#888888',
};
export const getDbDefaultColor = (type: string): string =>
DB_DEFAULT_COLORS[type?.toLowerCase()] || DB_DEFAULT_COLORS.custom;
// ─── 有品牌 SVG 文件的数据库类型(文件在 /db-icons/ 下) ────
const BRAND_SVG_TYPES = new Set([
'mysql', 'mariadb', 'postgres', 'redis', 'mongodb', 'clickhouse', 'sqlite',
'diros', 'sphinx', 'duckdb', 'sqlserver', 'elasticsearch',
]);
/** 品牌 SVG 图标:用
加载 /db-icons/*.svg */
const BrandSvgIcon: React.FC<{ type: string; size: number; color?: string }> = ({ type, size, color }) => {
const bgColor = color || getDbDefaultColor(type);
return (
);
};
// ─── 彩色标签图标(fallback) ──────────────────────────────
/** 通用彩色标签:填充背景 + 白色粗体缩写 */
const ColorBadge: React.FC<{ size: number; color: string; label: string }> = ({ size, color, label }) => {
const textSize = label.length <= 2 ? size * 0.48 : size * 0.38;
return (
);
};
// ─── 各数据库图标 ───────────────────────────────────────────
// 有品牌 SVG 的数据库
const MySQLIcon: React.FC = ({ size = 16, color }) => (
);
const MariaDBIcon: React.FC = ({ size = 16, color }) => (
);
const OceanBaseIcon: React.FC = ({ size = 16, color }) => (
);
const PostgresIcon: React.FC = ({ size = 16, color }) => (
);
const RedisIcon: React.FC = ({ size = 16, color }) => (
);
const MongoDBIcon: React.FC = ({ size = 16, color }) => (
);
const ClickHouseIcon: React.FC = ({ size = 16, color }) => (
);
const SQLiteIcon: React.FC = ({ size = 16, color }) => (
);
// 无品牌 SVG → 彩色文字标签
const OracleIcon: React.FC = ({ size = 16, color }) => (
);
const SQLServerIcon: React.FC = ({ size = 16, color }) => (
);
const DorisIcon: React.FC = ({ size = 16, color }) => (
);
const StarRocksIcon: React.FC = ({ size = 16, color }) => (
);
const SphinxIcon: React.FC = ({ size = 16, color }) => (
);
const DuckDBIcon: React.FC = ({ size = 16, color }) => (
);
const KingBaseIcon: React.FC = ({ size = 16, color }) => (
);
const DamengIcon: React.FC = ({ size = 16, color }) => (
);
const VastBaseIcon: React.FC = ({ size = 16, color }) => (
);
const OpenGaussIcon: React.FC = ({ size = 16, color }) => (
);
const HighGoIcon: React.FC = ({ size = 16, color }) => (
);
const IrisIcon: React.FC = ({ size = 16, color }) => (
);
const TDengineIcon: React.FC = ({ size = 16, color }) => (
);
const JVMIcon: React.FC = ({ size = 16, color }) => (
);
const ElasticsearchIcon: React.FC = ({ size = 16, color }) => (
);
/** Custom — 齿轮图标 */
const CustomIcon: React.FC = ({ size = 16, color }) => {
const c = color || DB_DEFAULT_COLORS.custom;
return (
);
};
// ─── 图标注册表 ─────────────────────────────────────────────
const DorisIconFallback: React.FC = ({ size = 16, color }) => (
);
const SphinxIconFallback: React.FC = ({ size = 16, color }) => (
);
const DB_ICON_MAP: Record> = {
mysql: MySQLIcon,
mariadb: MariaDBIcon,
oceanbase: OceanBaseIcon,
diros: DorisIcon,
starrocks: StarRocksIcon,
sphinx: SphinxIcon,
postgres: PostgresIcon,
redis: RedisIcon,
mongodb: MongoDBIcon,
jvm: JVMIcon,
kingbase: KingBaseIcon,
dameng: DamengIcon,
oracle: OracleIcon,
sqlserver: SQLServerIcon,
clickhouse: ClickHouseIcon,
sqlite: SQLiteIcon,
duckdb: DuckDBIcon,
vastbase: VastBaseIcon,
opengauss: OpenGaussIcon,
highgo: HighGoIcon,
iris: IrisIcon,
tdengine: TDengineIcon,
elasticsearch: ElasticsearchIcon,
custom: CustomIcon,
};
/** 可选图标类型列表(用于图标选择器 UI) */
export const DB_ICON_TYPES: string[] = [
'mysql', 'mariadb', 'oceanbase', 'postgres', 'redis', 'mongodb', 'jvm',
'oracle', 'sqlserver', 'sqlite', 'duckdb', 'clickhouse', 'starrocks',
'kingbase', 'dameng', 'vastbase', 'opengauss', 'highgo', 'iris', 'tdengine', 'elasticsearch', 'custom',
];
/** 该类型是否有品牌 SVG 文件 */
export const hasBrandSvg = (type: string): boolean => BRAND_SVG_TYPES.has(type?.toLowerCase());
/** 获取数据库图标 React 节点 */
export const getDbIcon = (type: string, color?: string, size?: number): React.ReactNode => {
const key = (type || 'custom').toLowerCase();
const Component = DB_ICON_MAP[key] || CustomIcon;
return ;
};
/** 获取数据库图标显示名称(中文) */
export const getDbIconLabel = (type: string): string => {
const labels: Record = {
mysql: 'MySQL', mariadb: 'MariaDB', oceanbase: 'OceanBase', postgres: 'PostgreSQL',
redis: 'Redis', mongodb: 'MongoDB', jvm: 'JVM',
oracle: 'Oracle',
sqlserver: 'SQL Server', clickhouse: 'ClickHouse', sqlite: 'SQLite',
starrocks: 'StarRocks',
duckdb: 'DuckDB', kingbase: '金仓', dameng: '达梦',
vastbase: 'VastBase', opengauss: 'OpenGauss', highgo: '瀚高', iris: 'InterSystems IRIS', tdengine: 'TDengine',
elasticsearch: 'Elasticsearch',
custom: '自定义',
};
return labels[type?.toLowerCase()] || type;
};
/** 预设颜色列表 */
export const PRESET_ICON_COLORS: string[] = [
'#336791', '#00758F', '#DC382D', '#47A248', '#F80000',
'#CC2927', '#1890FF', '#E6002D', '#FFBF00', '#2962FF',
'#00A86B', '#0066CC', '#FF6B35', '#7C3AED',
];