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")
  }
}
相关推荐
猫林老师2 小时前
Flutter for HarmonyOS 开发指南(一):环境搭建与项目创建
flutter·华为·harmonyos
爱笑的眼睛114 小时前
HarmonyOS通知消息分类管理的深度实践与架构解析
华为·harmonyos
爱笑的眼睛115 小时前
HarmonyOS Menu组件深度自定义:突破默认样式的创新实践
华为·harmonyos
赵得C7 小时前
人工智能的未来之路:华为全栈技术链与AI Agent应用实践
人工智能·华为
虚伪的空想家8 小时前
华为A800I A2 arm64架构鲲鹏920cpu的ubuntu22.04 tls配置直通的grub配置
ubuntu·华为·架构·虚拟化·kvm·npu·国产化适配
编码追梦人8 小时前
仓颉语言:全栈开发新利器,从服务端到鸿蒙的深度解析与实践
jvm·华为·harmonyos
爱笑的眼睛118 小时前
HarmonyOS输入法框架(IMF)深度解析:构建跨设备智能输入体验
华为·harmonyos
特立独行的猫a8 小时前
鸿蒙应用状态管理新方案:AppStorageV2与PersistenceV2深度详解
华为·harmonyos·状态管理·appstoragev2·persistencev2
奔跑的露西ly9 小时前
【HarmonyOS NEXT】Navigation路由导航
华为·harmonyos
坚果的博客10 小时前
Cordova 开发鸿蒙应用完全指南
华为·harmonyos