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")
  }
}
相关推荐
●VON4 小时前
BodyAR 会话管理深度剖析:ARConfig 参数全解与生命周期最佳实践
华为·harmonyos·鸿蒙·新特性
●VON4 小时前
BodyAR 骨骼可视化渲染:Shape + Line + Circle 打造优雅的 AR 骨架叠加层
华为·ar·harmonyos·鸿蒙·新特性
anyup4 小时前
【最全鸿蒙】uni-app 转鸿蒙:从打包失败到商店上架成功全过程
前端·uni-app·harmonyos
●VON5 小时前
鸿蒙NEXT新特性:HdsTabs悬浮页签栏barFloatingStyle完全入门指南
华为·harmonyos·鸿蒙·新特性
互联网散修5 小时前
鸿蒙自定义安全键盘开发实战:Canvas 精密布局与安全交互
harmonyos·自定义键盘
nashane5 小时前
HarmonyOS 6学习:麦克风“抢戏”打断音频?AudioSession焦点避坑指南
学习·音视频·harmonyos
大雷神5 小时前
第05篇|窗口与安全区:AppStorage 如何保存宽高、状态栏和暗色模式
harmonyos
GLAB-Mary6 小时前
苏州华为培训哪家好?
华为·hcip
深开鸿6 小时前
开源鸿蒙机器人操作系统M-Robots OS 2.0重磅发布
机器人·开源·harmonyos
意图共鸣6 小时前
意图共鸣科技发布《认知智能白皮书》:从华为“逻辑折叠”看认知架构(CA)的“感知-仲裁”解耦设计
科技·华为·架构