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")
  }
}
相关推荐
世人万千丶5 分钟前
桌面便签小应用 - HarmonyOS ArkUI 开发实战-TextArea与Flex布局-PC版本
华为·harmonyos·鸿蒙·鸿蒙系统
慧海灵舟8 分钟前
AGenUI 鸿蒙端实战踩坑录:从 Column 布局消失到异步组件宽度为 0
华为·harmonyos
yuegu77736 分钟前
HarmonyOS应用<节气通>开发第33篇:状态管理实战
华为·harmonyos
YM52e1 小时前
买菜计算器小应用 - HarmonyOS ArkUI 开发实战-PC版本
学习·华为·harmonyos·鸿蒙·鸿蒙系统
阿捏利1 小时前
系列总览-鸿蒙科普系列完全指南
华为·harmonyos
小雨下雨的雨2 小时前
HarmonyOS ArkUI训练营入门-组件掌握系列-Animation 动画效果实现-PC版本
学习·华为·harmonyos·鸿蒙
yuegu7772 小时前
HarmonyOS应用<节气通>开发第32篇:ArkTS语法快速入门——从TypeScript到声明式UI的完整指南
harmonyos
2601_962072553 小时前
李梦娇常识4600问|题库|打印版
sql·华为od·华为·c#·华为云·.net·harmonyos
伶俜663 小时前
鸿蒙原生应用实战(十九)ArkUI 喝水提醒 App:定时通知 + 每日记录 + 统计图表
华为·harmonyos
风华圆舞4 小时前
Flutter + 鸿蒙 Intents Kit:页面直达能力的完整接入方案
flutter·ui·华为·harmonyos