Files
workspace/code/fms/fms-vue/src/utils/lucideIcons.ts
T
2026-08-10 17:22:36 +08:00

22 lines
649 B
TypeScript

import * as LucideIcons from "@lucide/vue"
let iconMap: Record<string, any> | null = null
function loadIcons() {
if (iconMap) return
const map: Record<string, any> = {}
for (const [key, component] of Object.entries(LucideIcons)) {
if (key !== "default" && key !== "createLucideIcon" && typeof key === "string" && key.charAt(0) === key.charAt(0).toUpperCase()) {
map[key] = component
}
}
iconMap = map
}
/** 同步获取图标组件,传入 null/空字符串时返回 null */
export function getIcon(name?: string | null) {
if (!iconMap) loadIcons()
if (!name || !iconMap) return null
return iconMap[name] || null
}