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")
  }
}
相关推荐
OH_TPC2 小时前
@ohos/grpc 源码解读(一):一次 RPC 调用的三层之旅——ArkTS、NAPI 与 nghttp2 帧处理全链路
harmonyos
NJPJI_Yang2 小时前
鸿蒙操作系统使用 Navigation 实现页面路由与栈管理实战(本文已在AtomGit仓库开源)
华为·开源·harmonyos
程序猿追2 小时前
HarmonyOS 7 饮水倒计时归零以后,怎样核对系统收到提醒
华为·harmonyos
黑臂麒麟3 小时前
【鸿蒙心迹】React Native 鸿蒙平板形态适配实战:键盘避让、挖孔安全区与主从栏切换
react native·harmonyos·响应式设计·平板·rnon
黑臂麒麟3 小时前
React Native 鸿蒙升级 RNOH 0.84 实战:TurboModule 注册方式怎么迁
react native·harmonyos·rnoh·turbomodule
xiongmosy3 小时前
越过“规模临界点”之后:余承东给鸿蒙定的下一站,是“走向世界”
华为·harmonyos
程序猿追4 小时前
HarmonyOS 7 记账图表里,金额没变的交通条为什么变短了
华为·harmonyos
万物智能信息科技5 小时前
CAN总线协议解析和驱动开发—【万物智能之开源鸿蒙OpenHarmony系统实战开发系列教程】
驱动开发·嵌入式硬件·华为·开源·harmonyos·鸿蒙
熊猫钓鱼>_>10 小时前
从零手写 2048:HarmonyOS ArkTS 声明式游戏的工程化实战【鸿蒙心迹】
华为·ai·华为云·ai编程·harmonyos·openharmony·鸿蒙心迹
程序猿追15 小时前
HarmonyOS 7 月历翻页后,月底的便签该跟哪一天
harmonyos