33 lines
1.5 KiB
TypeScript
33 lines
1.5 KiB
TypeScript
/**
|
||
* 移动端底栏配置的单一事实源:
|
||
* 与后端 service.MobileTabKeys 保持一致;管理面板、MobileTabBar、公共设置 normalize 共用。
|
||
* 配置为有序数组,数组顺序即前台底栏展示顺序;配置为空/非法回落默认集合。
|
||
*
|
||
* MOBILE_TABS = 白名单(同时是管理面板排序基准),含全部可选 key;
|
||
* DEFAULT_MOBILE_TABS = 缺省启用集合,是白名单的子集(snippets 默认关闭,需管理员手动开启)。
|
||
*/
|
||
|
||
export const MOBILE_TABS = ["home", "library", "snippets", "compose", "messages", "me"] as const;
|
||
|
||
export type MobileTabKey = (typeof MOBILE_TABS)[number];
|
||
|
||
/** 底栏默认启用配置(白名单子集:snippets 默认不启用,移动端入口由首页导航抽屉承担) */
|
||
export const DEFAULT_MOBILE_TABS: MobileTabKey[] = ["home", "library", "compose", "messages", "me"];
|
||
|
||
/** 配置子集解析:去空白、去重、只留白名单内元素;结果为空视为非法,回落默认集合 */
|
||
export function normalizeMobileTabs(raw: unknown): MobileTabKey[] {
|
||
if (!Array.isArray(raw)) return [...DEFAULT_MOBILE_TABS];
|
||
const seen = new Set<string>();
|
||
const out: MobileTabKey[] = [];
|
||
for (const item of raw) {
|
||
const key = String(item ?? "")
|
||
.trim()
|
||
.toLowerCase();
|
||
if (!key || seen.has(key)) continue;
|
||
if (!(MOBILE_TABS as readonly string[]).includes(key)) continue;
|
||
seen.add(key);
|
||
out.push(key as MobileTabKey);
|
||
}
|
||
return out.length > 0 ? out : [...DEFAULT_MOBILE_TABS];
|
||
}
|