import { getNavInnerPx } from '../../utils/navMetrics'; const HOME_TAB_URL = '/pages/home/home'; const HOME_ROUTE = 'pages/home/home'; const TAB_BAR_ROUTES = new Set([ HOME_ROUTE, 'pages/category/category', 'pages/age/age', 'pages/favorites/favorites', 'pages/profile/profile', ]); Component({ options: { multipleSlots: true }, properties: { title: { type: String, value: '' }, background: { type: String, value: '' }, }, data: { statusBarHeight: 0, navInnerHeight: 44, navBlockHeight: 0, leftActionType: 'none' as 'none' | 'back' | 'home' | 'brand', /** 仅首页(Tab 根页)在 logo 旁展示「涂鸦丫」;其余主 Tab 只展示 logo */ showBrandName: false, }, lifetimes: { attached() { const { statusBarHeight } = wx.getWindowInfo(); const navInnerHeight = getNavInnerPx(); this.setData({ statusBarHeight, navInnerHeight, navBlockHeight: statusBarHeight + navInnerHeight, }); this.syncLeftAction(); }, }, pageLifetimes: { show() { this.syncLeftAction(); }, }, methods: { syncLeftAction() { const pages = getCurrentPages(); const currentRoute = pages[pages.length - 1]?.route || ''; const isTabBarPage = TAB_BAR_ROUTES.has(currentRoute); let leftActionType: 'none' | 'back' | 'home' | 'brand' = 'none'; const showBrandName = currentRoute === HOME_ROUTE; if (pages.length > 1) { leftActionType = 'back'; } else if (!isTabBarPage) { leftActionType = 'home'; } else { // 五个主 Tab 根页:仅展示品牌区(左 logo;首页另见 showBrandName) leftActionType = 'brand'; } this.setData({ leftActionType, showBrandName }); }, handleLeftAction() { if (this.data.leftActionType === 'back') { wx.navigateBack({ fail: () => { wx.switchTab({ url: HOME_TAB_URL }); }, }); return; } if (this.data.leftActionType === 'home') { wx.switchTab({ url: HOME_TAB_URL }); } }, }, });