HarmonyOS引导页登陆页以及tabbar的代码说明2

效果




修改的页具有下拉刷新功能,实现了分页

引导页代码:

@Component

struct SkipButton 这里是自定义模块。onPageShow是页面显示后则进入一个定时任务。到3秒后则进行跳转到'pages/LoginPage',当页面onPageHide时,则删除自动任务。这其本是上javascript的语法。

typescript 复制代码
import router from '@ohos.router';
@Entry
@Component
struct SplashScreenPage {
  @State pageShowTime: number = 0;
  @State intervalID: number = 0;
  build() {
    Column() {
      Stack({ alignContent: Alignment.TopStart }) {
        Image($r('app.media.splash'))
          .width('100%')
          .height('100%')
        AdvertiseIcon()
        SkipButton({ secondsCount: (2 - this.pageShowTime) })
      }
      .layoutWeight(1)
      .width('100%')

    }
    .alignItems(HorizontalAlign.Start)
    .width('100%')
    .height('100%')
  }

  /**
   * When the SplashScreenPage is displayed, switch to the next page after 3 seconds.
   */
  onPageShow() {
    this.intervalID = setInterval(() => {
      this.pageShowTime += 1;
      if (this.pageShowTime > 3) {
        router.pushUrl({
          url: 'pages/LoginPage'
        });
      }
    }, 1000);
  }

  /**
   * When the SplashScreenPage is hide, clear interval.
   */
  onPageHide() {
    clearInterval(this.intervalID);
  }
}

@Component
struct SkipButton {
  @Prop secondsCount: number;
  build() {
    Flex({
      direction: FlexDirection.Row,
      justifyContent: FlexAlign.End
    }) {
      Text("跳过 "+(this.secondsCount>0?this.secondsCount.toString():'0'))
        .backgroundColor(Color.White)
        .borderRadius(14)
        .fontColor(Color.Black)
        .width('72vp')
        .height("28vp")
        .fontSize('15fp')
        .margin({
          right:'16vp',
          top: '12vp'
        })
        .textAlign(TextAlign.Center)
        .border({ width:1 })
        .borderColor(Color.Black)
        .onClick(() => {
          router.replaceUrl({
            url: 'pages/LoginPage'
          });
        })
    }
  }
}

@Component
struct AdvertiseIcon {
  build() {
    Flex({
      direction: FlexDirection.Column,
      justifyContent: FlexAlign.End
    }) {
      Image($r('app.media.ic_advertise'))
        .objectFit(ImageFit.Contain)
        .width("28vp")
        .height("16vp")
    }
    .margin("16vp")
  }
}
相关推荐
达子6661 小时前
第25章_HarmonyOs开发图解之 电话服务
华为·harmonyos
懿路向前2 小时前
【HarmonyOS学习笔记】2026-08-05 | 端插件卡片绑定与跨上下文判断
笔记·学习·ai编程·harmonyos
程序员黑豆5 小时前
鸿蒙应用开发:V1与V2版本数据持久化实战教程
前端·harmonyos
程序员黑豆9 小时前
鸿蒙开发 Navigation 路由教程:从入门到实战
前端·harmonyos
HarmonyOS_SDK16 小时前
借助AR Engine人脸识别与跟踪能力,直播不露脸也生动
harmonyos
程序员黑豆18 小时前
鸿蒙应用开发 @BuilderParam 使用教程:实现灵活的 UI 插槽
前端·harmonyos
HMS Core19 小时前
基于人体骨骼点识别与跟踪,实现低时延体感游戏
游戏·华为·harmonyos
凡泰AI19 小时前
APP同时覆盖了iOS、安卓和鸿蒙,如何选择混合开发架构才能减少重复建设,提高功能上线效率~
android·ios·harmonyos·mpaas·uni·小程序容器
XR12345678819 小时前
政府办公楼网络搭建方案对比:信锐、华为、华三选型指南
网络·华为
达子66619 小时前
第23章_HarmonyOs开发图解之 WLAN
华为·harmonyos