interface TabBarLike { setData(data: { selected: number }, callback?: () => void): void } /** 同步自定义 tabBar 的选中项。页面在 onShow 中调用,保证从二级页返回时状态正确。 */ export function syncTabBar(target: unknown, index: number): void { const host = target as { getTabBar?: () => TabBarLike | undefined } if (typeof host.getTabBar !== 'function') return const tabBar = host.getTabBar() if (!tabBar) return tabBar.setData({ selected: index }) }