export const LOVART_HOME_SIDEBAR_CONFIG_KEY = "lovart_home_sidebar_config"; export const DEFAULT_LOVART_HOME_SIDEBAR_ITEMS = [ { key: "newProject", label: "新建项目", description: "首页左侧顶部的新建项目按钮", }, { key: "home", label: "首页", description: "回到首页主视图", }, { key: "projects", label: "项目列表", description: "打开项目列表视图", }, { key: "profile", label: "个人主页", description: "首页侧边栏个人主页入口", }, { key: "gallery", label: "个人相册", description: "跳转到个人相册", }, { key: "tutorial", label: "视频教程", description: "展示视频教程悬浮面板", }, { key: "imageEditor", label: "图片编辑", description: "打开图片编辑功能", }, { key: "aiCad", label: "AI-CAD", description: "跳转 AI-CAD 页面", }, { key: "agent", label: "风格化", description: "跳转风格化工作区", }, { key: "videoCanvas", label: "视频画布", description: "跳转视频画布页面", }, { key: "flowBoard", label: "流程白板", description: "跳转流程白板页面", }, { key: "productPlanning", label: "商品策划", description: "跳转商品策划页面", }, { key: "toolbox1", label: "工具箱", description: "展示工具箱一链接列表", }, { key: "toolbox2", label: "工具箱2", description: "展示工具箱二链接列表", }, { key: "settings", label: "系统设置", description: "管理员系统设置入口", }, ] as const; export type LovartHomeSidebarItemKey = (typeof DEFAULT_LOVART_HOME_SIDEBAR_ITEMS)[number]["key"]; export type LovartHomeSidebarItemConfig = { label: string; iconUrl: string; enabled: boolean; }; export type LovartHomeSidebarConfig = { items: Record; }; const DEFAULT_ITEMS = DEFAULT_LOVART_HOME_SIDEBAR_ITEMS.reduce( (accumulator, item) => { accumulator[item.key] = { label: item.label, iconUrl: "", enabled: true, }; return accumulator; }, {} as Record ); export const defaultLovartHomeSidebarConfig: LovartHomeSidebarConfig = { items: DEFAULT_ITEMS, }; export function getDefaultLovartHomeSidebarItem( key: LovartHomeSidebarItemKey ): LovartHomeSidebarItemConfig { return defaultLovartHomeSidebarConfig.items[key]; } export function normalizeLovartHomeSidebarConfig( value: unknown ): LovartHomeSidebarConfig { const raw = value && typeof value === "object" && !Array.isArray(value) ? (value as Record) : {}; const rawItems = raw.items && typeof raw.items === "object" && !Array.isArray(raw.items) ? (raw.items as Record) : {}; const items = DEFAULT_LOVART_HOME_SIDEBAR_ITEMS.reduce( (accumulator, item) => { const itemRaw = rawItems[item.key] && typeof rawItems[item.key] === "object" && !Array.isArray(rawItems[item.key]) ? (rawItems[item.key] as Record) : {}; const label = String(itemRaw.label || "") .trim() .slice(0, 32); const iconUrl = String(itemRaw.iconUrl || "") .trim() .slice(0, 2000); accumulator[item.key] = { label: label || item.label, iconUrl, enabled: typeof itemRaw.enabled === "boolean" ? itemRaw.enabled : true, }; return accumulator; }, {} as Record ); return { items }; }