import { IconAppFinance, IconAppClothes } from "@/components/iconfont"; export interface SubAppItem { id: string; title: string; icon: any; group: string; description?: string; } type HeaderItem = { type: "header"; title: string; }; type GroupItem = { type: "group"; title: string; data: SubAppItem[]; }; export type AppListItem = HeaderItem | GroupItem; export const SUB_APPS: SubAppItem[] = [ { id: "/money/home", title: "记账", icon: IconAppFinance, group: "J", description: "记录日常收支,管理你的每一笔钱", }, { id: "/clothes/home", title: "衣服搭配", icon: IconAppClothes, group: "Y", description: "帮你整理每日穿搭灵感", }, ]; export function getGroupedApps(keyword?: string): AppListItem[] { let list = SUB_APPS; if (keyword && keyword.trim()) { const lower = keyword.toLowerCase(); list = SUB_APPS.filter((item) => item.title.toLowerCase().includes(lower)); } const map: Record = {}; list.forEach((item) => { if (!map[item.group]) map[item.group] = []; map[item.group].push(item); }); const sortedKeys = Object.keys(map).sort((a, b) => { if (a === "#") return 1; if (b === "#") return -1; return a.localeCompare(b); }); const data: AppListItem[] = []; sortedKeys.forEach((key) => { data.push({ type: "header", title: key }); data.push({ type: "group", title: key, data: map[key] }); }); return data; }