tabBar没有点击拦截功能实现,可以使用TabsController自定义页签以及并在其中添加事件进行逻辑判断,可以参考以下demo:export class ButtonInfoModel { index: number = 0; info: string = 'home'; title: string = 'Home'; } const buttonInfo: ButtonInfoModel[] = [{ index: 0, info: 'home', title: 'Home' }, { index: 1, info: 'map', title: 'Map' }, { index: 2, info: 'charging', title: 'Charging' }] @Component export struct Home { @State message: string = 'Home'; build() { Row() { Column() { Text(this.message).fontSize(50).fontWeight(FontWeight.Bold) Text('点击之后无法进入charging页,会跳转map页').fontSize(20).fontWeight(FontWeight.Bold).onClick(() => { buttonInfo[2].info = "map" }) }.width('100%') }.height('100%') } } @Component export struct Map { @State message: string = 'Map'; build() { Row() { Column() { Text(this.message).fontSize(50).fontWeight(FontWeight.Bold) }.width('100%') }.height('100%') } } @Component export struct Charging { @State message: string = 'Charging'; build() { Row() { Column() { Text(this.message).fontSize(50).fontWeight(FontWeight.Bold) }.width('100%') }.height('100%') } } @Entry @Component struct home { @StorageProp('currentBreakpoint') currentBreakpoint: string = 'sm'; @State currentPageIndex: number = 0; @State tabArray: Array<number> = [0, 1, 2] private controller: TabsController = new TabsController() build() { Column() { Tabs({ barPosition: BarPosition.End, controller: this.controller }) { TabContent() { Home() } TabContent() { Map() } TabContent() { Charging() } }.barHeight('0vp').height('94%').vertical(this.currentBreakpoint === 'lg').scrollable(false) this.bottomNavigation() }.justifyContent(FlexAlign.SpaceBetween).backgroundColor("#f1f3f5") } @Builder bottomNavigation() { Row() { ForEach(this.tabArray, (item: number) => { this.BottomNavigation(buttonInfo[item]) }) }.height("50vp").backgroundColor(Color.White).justifyContent(FlexAlign.SpaceAround).width("100%") } @Builder BottomNavigation(button: ButtonInfoModel) { Column({ space: '10vp' }) { Text(button.title) .fontColor(this.currentPageIndex === button.index ? "#0587D7" : "#A5A9AD") .fontWeight(500) .textAlign(TextAlign.Center) .fontSize('10fp') }.alignItems(HorizontalAlign.Center).margin(-20).onClick(() => { if (button.index === 2 && button.info === 'map') { this.controller.changeIndex(1) this.currentPageIndex = 1 } else { this.controller.changeIndex(button.index) this.currentPageIndex = button.index } }) } }
tabBar没有点击拦截功能实现,可以使用TabsController自定义页签以及并在其中添加事件进行逻辑判断,
可以参考以下demo: