feat: 字母描红页样式开发基本完成
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
import { NAV_INNER_PX } from '../../utils/navMetrics';
|
||||
|
||||
const HOME_TAB_URL = '/pages/home/home';
|
||||
const TAB_BAR_ROUTES = new Set([
|
||||
'pages/home/home',
|
||||
'pages/age/age',
|
||||
'pages/favorites/favorites',
|
||||
'pages/profile/profile',
|
||||
]);
|
||||
|
||||
Component({
|
||||
options: { multipleSlots: true },
|
||||
properties: {
|
||||
@@ -9,26 +17,53 @@ Component({
|
||||
data: {
|
||||
statusBarHeight: 0,
|
||||
navBlockHeight: 0,
|
||||
showBackButton: false,
|
||||
leftActionType: 'none',
|
||||
},
|
||||
lifetimes: {
|
||||
attached() {
|
||||
const { statusBarHeight } = wx.getWindowInfo();
|
||||
const pages = getCurrentPages();
|
||||
this.setData({
|
||||
statusBarHeight,
|
||||
navBlockHeight: statusBarHeight + NAV_INNER_PX,
|
||||
showBackButton: pages.length > 1,
|
||||
});
|
||||
this.syncLeftAction();
|
||||
},
|
||||
},
|
||||
pageLifetimes: {
|
||||
show() {
|
||||
this.syncLeftAction();
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handleBack() {
|
||||
wx.navigateBack({
|
||||
fail: () => {
|
||||
wx.switchTab({ url: '/pages/home/home' });
|
||||
},
|
||||
});
|
||||
syncLeftAction() {
|
||||
const pages = getCurrentPages();
|
||||
const currentRoute = pages[pages.length - 1]?.route || '';
|
||||
const isTabBarPage = TAB_BAR_ROUTES.has(currentRoute);
|
||||
|
||||
let leftActionType: 'none' | 'back' | 'home' = 'none';
|
||||
|
||||
if (pages.length > 1) {
|
||||
leftActionType = 'back';
|
||||
} else if (!isTabBarPage) {
|
||||
leftActionType = 'home';
|
||||
}
|
||||
|
||||
this.setData({ leftActionType });
|
||||
},
|
||||
|
||||
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 });
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user