HarmonyOS 请问怎么拦截Tabs点击
底部导航栏,点击后跳转到登录页面,未登录状态返回,Tabs应该还选中上一个,而不是选中当前怎么写拦截,登录成功后再刷新当前选中当前Tabs。
/**
 * 业务bufen
 */
@Builder
view() {
  Stack() {
    if (this.currentBreakpoint === BreakpointTypeEnum.LG) {
      Image($r('app.media.app_icon'))
        .width(CommonConstants.FULL_PERCENT)
        .height(CommonConstants.FULL_PERCENT)
    }
    Flex({direction: this.currentBreakpoint === BreakpointTypeEnum.LG ? FlexDirection.RowReverse : FlexDirection.Column,}) {
      Tabs({ index: this.currentIndex, barPosition: this.currentBreakpoint === BreakpointTypeEnum.LG ?BarPosition.Start : BarPosition.End }) {
        ForEach(TabsInfo2, (item: TabBarOption, index: number) => {
          TabContent() {
            this.TabContent_views(index)
          }
          .tabBar(this.BottomTabBuilder(item))
        }, (item: TabBarOption) => JSON.stringify(item))
      }
      .barWidth(this.currentBreakpoint === BreakpointTypeEnum.LG ? '96vp': CommonConstants.FULL_PERCENT)
      .barHeight(this.currentBreakpoint === BreakpointTypeEnum.LG ? CommonConstants.FULL_PERCENT : ((deviceInfo.deviceType === CommonConstants.DEVICE_TYPES[0] ? 35 : 35 + 44)))
      .barBackgroundColor('#FFFFFF')
      .barMode(this.currentBreakpoint === BreakpointTypeEnum.LG ? BarMode.Scrollable : BarMode.Fixed,{ nonScrollableLayoutStyle: LayoutStyle.ALWAYS_CENTER })
      .vertical(this.currentBreakpoint === BreakpointTypeEnum.LG)
      .scrollable(false)
      .onAnimationStart((index: number, targetIndex: number, event: TabsAnimationEvent) => {
        this.currentIndex = targetIndex;
        this.lottieController();
      })
      .onChange((index) => {
        let aaaa = index
      })
      .onTabBarClick((index) => {
        let aaaa = index
      })
    }
    .width(CommonConstants.FULL_PERCENT)
    .height(CommonConstants.FULL_PERCENT)
    .backgroundColor((this.currentBreakpoint === BreakpointTypeEnum.LG && this.currentIndex === TabBarType.index5) ? '#00FFFFFF' : '#F1F3F5')
  }
}
@Builder
TabContent_views(index:number) {
  if (index===TabBarType.index1) {
    PageNav({
      changeFontSize: this.changeFontSize,
      fontSizeText: this.fontSizeText,
    })
  }
  if (index===TabBarType.index2) {
  }
  if (index===TabBarType.index3) {
  }
  if (index===TabBarType.index4) {
    if (this.isLogged) {
      PageIndex5WebView1({
        url: 'https://developer.huawei.com/consumer/cn/hdc/hdc2023/ticket/101677813051874334/?ha_source=HDCminisite&ha_sourceId=89000360',
        webViewController: $webViewController,
        changeFontSize: this.changeFontSize,
        fontSizeText: this.fontSizeText,
      })
    }
  }
  if (index===TabBarType.index5) {
  }
}
@Builder
BottomTabBuilder(tabBarOption: TabBarOption) {
  Column() {
     Canvas(tabBarOption.canvasRenderingContext)
      .width('35vp')
      .height('35vp')
      .onReady(() => {
        lottie.loadAnimation({
          container: tabBarOption.canvasRenderingContext,
          renderer: 'canvas',
          loop: false,
          autoplay: false,
          name: tabBarOption.name,
          path: tabBarOption.path,
        });
        this.lottieController();
      })
    Text(tabBarOption.title)
      .fontSize('15fp')
      .margin({ top: '4vp' })
      .fontWeight(600)
      .fontColor(tabBarOption.id === this.currentIndex ? '#0A59F7' : '#99000000')
  }
  .padding({bottom: deviceInfo.deviceType === CommonConstants.DEVICE_TYPES[0] ? 0 : 24})
  .height(this.currentBreakpoint === BreakpointTypeEnum.LG ? 80 : CommonConstants.FULL_PERCENT)
  .width(CommonConstants.FULL_PERCENT)
  .justifyContent(FlexAlign.Center)
}
lottieController(): void {
  // 自定义设置组件3-需要登录才能查看bufen
  if (((this.currentIndex === TabBarType.index4) && (!this.isLogged))) {
  this.routerController.push({
    url: RouterMap.LoginIndex,
    param: new Object({ query1: "1", query2: '2' }),
    lifecycle: {
      onShown: () => {
        console.info("other page in home");
      },
      onReady: () => {
      },
      onHidden: () => {
        if (this.isLogged) {
          WindowUtil.updateStatusBarColor(getContext(this), false);
          lottie.stop();
          lottie.play(TabsInfo2[this.currentIndex].name);
        }
      },
    }
  })
  return
}
// 自定义 我的组件bufen
if (this.currentIndex === TabBarType.index5) {
  WindowUtil.updateStatusBarColor(getContext(this), true);
  lottie.stop();
  lottie.play(TabsInfo2[this.currentIndex].name);
  return
}
// 未登录bufen
WindowUtil.updateStatusBarColor(getContext(this), false);
lottie.stop();
lottie.play(TabsInfo2[this.currentIndex].name);
}
        HarmonyOS
      
        赞
        
 收藏 0
 回答 1
 
        待解决
        
相关问题
 HarmonyOS toggle 点击拦截 
1571浏览  • 1回复 待解决
Slider拦截点击事件失败 
1101浏览  • 1回复 待解决
HarmonyOS Popup会拦截页面点击事件 
892浏览  • 1回复 待解决
HarmonyOS  网页如何拦截所有的点击跳转事件 
927浏览  • 1回复 待解决
HarmonyOS  web组件怎么拦截请求 
1408浏览  • 1回复 待解决
HarmonyOS 怎么拦截返回键盘 
1343浏览  • 1回复 待解决
HarmonyOS Toggle组件怎么拦截? 
1708浏览  • 1回复 待解决
HarmonyOS createWindow 创建的 window 遮挡拦截了点击事件 
1651浏览  • 1回复 待解决
HarmonyOS Tabs怎么隐藏bar 
1558浏览  • 1回复 待解决
HarmonyOS 点击tabs如何跳转到二级页面 
1627浏览  • 1回复 待解决
HarmonyOS 在AOP中可以拦截到onClick点击事件吗? 
899浏览  • 1回复 待解决
HarmonyOS Tabs怎么实现预加载 
1542浏览  • 1回复 待解决
#鸿蒙通关秘籍#如何在Tabs组件中拦截内容即将改变的事件? 
906浏览  • 1回复 待解决
HarmonyOS Tabs展示完毕后,修改数据源后,Tabs内容无法刷新,请问如何处理 
938浏览  • 1回复 待解决
HarmonyOS 全模态怎么拦截系统返回键 
862浏览  • 1回复 待解决
HarmonyOS Tabs怎么与text同行显示? 
1420浏览  • 1回复 待解决
HarmonyOS Tabs组件怎么动态添加TabContent 
1353浏览  • 1回复 待解决
HarmonyOS tabs的tabBar怎么居左 
1501浏览  • 1回复 待解决
flutter webview插件,拦截不到非用户点击跳转的URL 
1729浏览  • 1回复 待解决
HarmonyOS  tabs快速点击会出现多个tab同时亮的情况 
898浏览  • 1回复 待解决
Tablist 点击超出部分的tab触发点击事件 但是整个列表会自动跳回到最前面 请问怎么解决? 
6124浏览  • 1回复 待解决
HarmonyOS  怎么取消Tabs的滑动回弹效果? 
1677浏览  • 1回复 待解决
HarmonyOS Tabs 的bar 怎么设置对齐左边 
3835浏览  • 1回复 待解决
HarmonyOS  http.createHttp怎么加拦截器 
802浏览  • 1回复 待解决
HarmonyOS  怎么设置Tabs组件预加载TabContent 
1466浏览  • 1回复 待解决





















暂时没有tabBar点击拦截功能实现,可以使用TabsController自定义页签以及并在其中添加事件进行逻辑判断,参考demo如下: