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")
  }
}
相关推荐
前端不太难19 小时前
鸿蒙 App 的“无状态 System”设计
华为·状态模式·harmonyos
UnicornDev21 小时前
【Flutter x HarmonyOS 6】魔方计时APP——计时逻辑实现
flutter·华为·harmonyos·鸿蒙·鸿蒙系统
AlbertZein1 天前
ImageKnifePro 源码解读:鸿蒙图片加载框架全貌
harmonyos
AlbertZein1 天前
鸿蒙工程化:build-profile.json5 逐字段解析
harmonyos
weixin_417197051 天前
DeepSeek V4绑定华为:一场飞行中换引擎的国产算力革命
人工智能·华为
前端技术2 天前
鸿蒙ArkTS 自定义底部导航栏(Tabs+@Builder 极简实现)
harmonyos·鸿蒙
Swift社区2 天前
为什么“页面跳转”在鸿蒙 PC 上是错误设计?
华为·harmonyos
熬夜敲代码的小N2 天前
鸿蒙PC开发者必备!GitNext深度测评:一站式Git管理工具
git·华为·harmonyos
秋の本名2 天前
第一章 鸿蒙生态架构与开发理念
华为·wpf·harmonyos
Ww.xh2 天前
鸿蒙系统中HTML与Vue集成方案
vue.js·html·harmonyos