Skip to content

shellTabConfig

解析与管理应用壳层 Tab 配置(page-config displays.*.tabs),含运行时过滤、Tabbar 项构建与路由高亮匹配。

产品展示配置 统一通过 GET /page-config 获取;管理端还原壳层 Tab 使用 POST /page-config/displays/reset(填入编辑器,仍需保存)。

导入

typescript
import {
  buildShellMobileTabbarItems,
  buildShellNavTabbarItems,
  filterShellTabsForRuntime,
  findShellDesktopFooterTab,
  isShellMineTab,
  isShellTabHideTabbar,
  parseShellTabsFromDisplays,
  resolveActiveShellTabKey,
  resolveShellTabRouteTarget,
  shellTabMatchesRoute,
  toShellTabbarItem,
} from '@zengchaowu/shared/functions/shell/shellTabConfig'

ChatShellTabConfig 等类型仍从 @zengchaowu/shared/types/chat-shell-tab-config 导出(与 ShellTabConfig 同构)。

函数签名

typescript
class ShellTabsConfigError extends Error

function parseShellTabsFromDisplays(
  displays: unknown,
  options?: ParseShellTabsOptions,
): ShellTabConfig[]
function filterShellTabsForRuntime(
  tabs: ShellTabConfig[],
  opts: { isElectron: boolean },
): ShellTabConfig[]
function buildShellNavTabbarItems(tabs: ShellTabConfig[]): ShellNavTabbarItem[]
function buildShellMobileTabbarItems(tabs: ShellTabConfig[]): ShellTabbarItem[]
function resolveShellTabRouteTarget(
  tab: ShellTabConfig,
): { name: string } | { path: string } | null
function shellTabMatchesRoute(
  tab: ShellTabConfig,
  route: { name?: string | symbol | null; path?: string },
): boolean
function resolveActiveShellTabKey(
  tabs: ShellTabConfig[],
  route: { name?: string | symbol | null; path?: string },
): string
function isShellTabHideTabbar(tabs: ShellTabConfig[], activeKey: string): boolean
function findShellDesktopFooterTab(tabs: ShellTabConfig[]): ShellTabConfig | undefined
function isShellMineTab(tab: { key?: string; useMineAvatar?: boolean }): boolean
function toShellTabbarItem(tab: ShellTabConfig): ShellTabbarItem

工作原理

  1. parseShellTabsFromDisplays:从 displays 指定键(默认 chatShell.tabs)读取并归一化;无效时抛出 ShellTabsConfigError
  2. filterShellTabsForRuntime:按 electronOnly 等条件过滤。
  3. buildShellNavTabbarItems / buildShellMobileTabbarItems:宽屏侧栏与移动端底栏项。
  4. shellTabMatchesRoute / resolveActiveShellTabKey:按 routeName / prefix / related 匹配,无硬编码 key。