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")
  }
}
相关推荐
kirk_wang3 小时前
HarmonyOS 7.0 A2A任务链实战:用getRelatedTasks核对随访材料来源
华为·harmonyos
OH_TPC5 小时前
lottie-turbo 源码解读(一):lottie_bridge 与 Animator——声明式配置到 native 渲染的桥接
harmonyos
钉先生贾6 小时前
HarmonyOS 7.0 空间计算实战 30:退出沉浸视图后,怎样清理临时资源并恢复上下文
华为·harmonyos·空间计算
钉先生贾7 小时前
HarmonyOS 7.0 空间计算实战 28:空间内容加载失败时,怎样提供可完成的二维替代
华为·harmonyos·空间计算
JosieBook8 小时前
【鸿蒙】把一个 Qt 桌面视频编辑器“搬“上鸿蒙 PC:Olive 移植适配全记录
qt·音视频·harmonyos
kirk_wang1 天前
HarmonyOS 7 Text.tailIndents实战:停止条件换版后复核徽标如何不遮住正文
华为·harmonyos
kirk_wang1 天前
HarmonyOS 7 系统选色器实战:HdsColorPicker只管给色值,语义留给业务
华为·harmonyos
OH_TPC1 天前
ImageKnifePro 源码解读(五):Native 渲染节点与 ArkTS 组件——前台下单,后厨做菜
harmonyos
kirk_wang1 天前
HarmonyOS 7.0 AgentCard实战:随访草稿只到待确认,不替用户提交
华为·harmonyos
kirk_wang1 天前
HarmonyOS 7 智慧手势实战:requestSelected为什么不能当训练完成回执
华为·harmonyos