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")
  }
}
相关推荐
小冷爱学习!7 小时前
华为动态路由-OSPF-完全末梢区域
服务器·网络·华为
2501_904447748 小时前
华为发力中端,上半年nova14下半年nova15,大力普及原生鸿蒙
华为·智能手机·django·scikit-learn·pygame
MarkHD9 小时前
第十八天 WebView深度优化指南
华为·harmonyos
塞尔维亚大汉9 小时前
OpenHarmony(鸿蒙南向)——平台驱动开发【MIPI CSI】
harmonyos·领域驱动设计
别说我什么都不会10 小时前
鸿蒙轻内核M核源码分析系列十五 CPU使用率CPUP
操作系统·harmonyos
feiniao865111 小时前
2025年华为手机解锁BL的方法
华为·智能手机
塞尔维亚大汉12 小时前
OpenHarmony(鸿蒙南向)——平台驱动开发【I3C】
harmonyos·领域驱动设计
VVVVWeiYee12 小时前
BGP配置华为——路径优选验证
运维·网络·华为·信息与通信
今阳13 小时前
鸿蒙开发笔记-6-装饰器之@Require装饰器,@Reusable装饰器
android·app·harmonyos
余多多_zZ14 小时前
鸿蒙初学者学习手册(HarmonyOSNext_API14)_组件截图(@ohos.arkui.componentSnapshot (组件截图) )
学习·华为·harmonyos·鸿蒙·鸿蒙系统