HarmonyOS-UIAbitity-StepperItem——【坚果派-红目香薰】

举报
红目香薰 发表于 2024/03/31 18:25:39 2024/03/31
【摘要】 ​ 摘要作者:红目香薰团队:坚果派 团队介绍:坚果派由坚果创建,团队拥有12个华为HDE以及若干其他领域的三十余位万粉博主运营。 StepperItem用作Stepper组件的页面子组件。子组件支持单个子组件。接口StepperItem()属性参数名参数类型默认值参数描述prevLabelstring-当步骤导航器大于一页,除第一页默认值都为"返回"。nextLabelstring-步骤导航...

 

摘要

作者:红目香薰
团队:坚果派
团队介绍:坚果派由坚果创建,团队拥有12个华为HDE以及若干其他领域的三十余位万粉博主运营。 

StepperItem

用作Stepper组件的页面子组件。

子组件

支持单个子组件。

接口

StepperItem()

属性

参数名

参数类型

默认值

参数描述

prevLabel

string

-

当步骤导航器大于一页,除第一页默认值都为"返回"。

nextLabel

string

-

步骤导航器大于一页时,最后一页默认值为"开始",其余页默认值为"下一步"。

status

ItemState

ItemState.Normal

步骤导航器元素的状态。

ItemState枚举说明

名称

描述

Normal

正常状态,右侧文本按钮正常显示,可点击进入下一个StepperItem。

Disabled

不可用状态,右侧文本按钮灰度显示,不可点击进入下一个StepperItem。

Waiting

等待状态,右侧文本按钮不显示,使用等待进度条,不可点击进入下一个StepperItem。

Skip

跳过状态,表示跳过当前步骤, 进入下一个StepperItem。

示例代码

@Entry
@Component
struct Index {
  @State currentIndex: number = 0;
  @State firstState: ItemState = ItemState.Normal;
  @State secondState: ItemState = ItemState.Normal;
  @State thirdState: ItemState = ItemState.Normal;

  build() {
    Stepper({
      index: this.currentIndex
    }) {
      // 第一个步骤页
      StepperItem() {
        Column() {
          Text('Page One')
            .fontSize(35)
            .fontColor(Color.Blue)
            .lineHeight(50)
            .margin({ top: 250, bottom: 50 })
          Button('change status:' + this.firstState)
            .onClick(() => {
              this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip;
            })
        }.width('100%')
      }
      .nextLabel('Next')
      .status(this.firstState)
      // 第二个步骤页
      StepperItem() {
        Column() {
          Text('Page Two')
            .fontSize(35)
            .fontColor(Color.Blue)
            .lineHeight(50)
            .margin({ top: 250, bottom: 50 })
          Button('change status:' + this.secondState)
            .onClick(() => {
              this.secondState = this.secondState === ItemState.Disabled ? ItemState.Normal : ItemState.Disabled;
            })
        }.width('100%')
      }
      .nextLabel('Next')
      .prevLabel('Previous')
      .status(this.secondState)
      // 第三个步骤页
      StepperItem() {
        Column() {
          Text('Page Three')
            .fontSize(35)
            .fontColor(Color.Blue)
            .lineHeight(50)
            .margin({ top: 250, bottom: 50 })
          Button('change status:' + this.thirdState)
            .onClick(() => {
              this.thirdState = this.thirdState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting;
            })
        }.width('100%')
      }
      .status(this.thirdState)
      // 第四个步骤页
      StepperItem() {
        Text('Page four')
          .fontSize(35)
          .fontColor(Color.Blue)
          .width('100%')
          .textAlign(TextAlign.Center)
          .lineHeight(50)
          .margin({ top: 250 })
      }
      .nextLabel('Finish')
    }
    .onFinish(() => {
      // 此处可处理点击最后一页的Finish时的逻辑,例如路由跳转等
      console.info('onFinish');
    })
    .onSkip(() => {
      // 此处可处理点击跳过时的逻辑,例如动态修改Stepper的index值使其跳转到某一步骤页等
      console.info('onSkip');
    })
    .onChange((prevIndex: number, index: number) => {
      this.currentIndex = index;
    })
  }
}

实际效果:

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。