鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之Stepper组件

 鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之Stepper组件

一、操作环境

操作系统:  Windows 10 专业版、IDE:DevEco Studio 3.1、SDK:HarmonyOS 3.1+

二、Stepper组件

鸿蒙(HarmonyOS)仅能包含子组件StepperItem。

子组件

无。

接口

Stepper(value?: { index?: number })

参数
参数名参数类型必填参数描述
indexnumber

设置步骤导航器当前显示StepperItem的索引值。

默认值:0

事件
名称描述
onFinish(callback: () => void)步骤导航器最后一个StepperItem的nextLabel被点击时,并且ItemState属性为Normal时,触发该回调 。
onSkip(callback: () => void)当前显示的StepperItem状态为ItemState.Skip时,nextLabel被点击时触发该回调。
onChange(callback: (prevIndex?: number, index?: number) => void)

点击当前StepperItem的prevLabel进行步骤切换时触发该回调;或点击当前StepperItem的nextLabel,当前页面不为步骤导航器最后一个StepperItem且ItemState属性为Normal时,触发该回调。

- prevIndex:切换前的步骤页索引值。

- index:切换后的步骤页(前一页或者下一页)索引值。

onNext(callback: (index?: number, pendingIndex?: number) => void)

点击StepperItem的nextLabel切换下一步骤时,当前页面不为步骤导航器最后一个StepperItem且ItemState属性为Normal时,触发该回调。

- index:当前步骤页索引值。

- pendingIndex:下一步骤页索引值。

onPrevious(callback: (index?: number, pendingIndex?: number) => void)

点击StepperItem的prevLabel切换上一步骤时触发该回调。

- index:当前步骤页索引值。

- pendingIndex:上一步骤页索引值。

示例

代码
// xxx.ets
@Styles function itemStyle () {
  .width(336)
  .height(621)
  .margin({ top: 48, left: 12 })
  .borderRadius(24)
  .backgroundColor('#FFFFFF')
}

@Extend(Text) function itemTextStyle () {
  .fontColor('#182431')
  .fontSize(36)
  .fontWeight(500)
  .opacity(0.4)
  .margin({ top: 82, bottom: 40 })
}

@Entry
@Component
struct StepperExample {
  @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')
            .itemTextStyle()
          Button('change status:' + this.firstState)
            .backgroundColor('#007dFF')
            .onClick(() => {
              this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip
            })
        }.itemStyle()
      }
      .nextLabel('Next')
      .status(this.firstState)
      // 第二个步骤页
      StepperItem() {
        Column() {
          Text('Page Two')
            .itemTextStyle()
          Button('change status:' + this.secondState)
            .backgroundColor('#007dFF')
            .onClick(() => {
              this.secondState = this.secondState === ItemState.Disabled ? ItemState.Normal : ItemState.Disabled
            })
        }.itemStyle()
      }
      .nextLabel('Next')
      .prevLabel('Previous')
      .status(this.secondState)
      // 第三个步骤页
      StepperItem() {
        Column() {
          Text('Page Three')
            .itemTextStyle()
          Button('change status:' + this.thirdState)
            .backgroundColor('#007dFF')
            .onClick(() => {
              this.thirdState = this.thirdState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting
            })
        }.itemStyle()
      }
      .status(this.thirdState)
      // 第四个步骤页
      StepperItem() {
        Column() {
          Text('Page Four')
            .itemTextStyle()
        }.itemStyle()
      }
    }
    .backgroundColor('#F1F3F5')
    .onFinish(() => {
      // 此处可处理点击最后一页的Finish时的逻辑,例如路由跳转等
      console.info('onFinish')
    })
    .onSkip(() => {
      // 此处可处理点击跳过时的逻辑,例如动态修改Stepper的index值使其跳转到某一步骤页等
      console.info('onSkip')
    })
    .onChange((prevIndex: number, index: number) => {
      this.currentIndex = index
    })
  }
}
图例

你有时间常去我家看看我在这里谢谢你啦...

我家地址:亚丁号

最后送大家一首诗:

山高路远坑深,
大军纵横驰奔,

谁敢横刀立马?
惟有点赞加关注大军。

  • 11
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
非常抱歉,我之前的回答有误,uView2 中没有 `u-stepper` 步进器组件。 不过,你可以使用 `u-number-box` 数字框组件来实现步进器的功能。以下是一个示例: ```vue <template> <u-popup :visible.sync="showPopup" :position="'bottom'"> <div class="popup-header">科技风格页面弹窗</div> <div class="popup-body"> <u-form @submit.prevent="onSubmit"> <u-form-item label="标题"> <u-input v-model="form.title" placeholder="请输入标题"></u-input> </u-form-item> <u-form-item label="下拉列表"> <u-select v-model="form.select" :options="options"></u-select> </u-form-item> <u-form-item label="步进器"> <u-number-box v-model="form.stepper" :min="1" :max="10"></u-number-box> </u-form-item> <u-button type="primary" native-type="submit">确认</u-button> </u-form> </div> </u-popup> </template> <script> export default { data() { return { showPopup: false, form: { title: '', select: '', stepper: 1 }, options: [ { label: '选项1', value: '1' }, { label: '选项2', value: '2' }, { label: '选项3', value: '3' } ] } }, methods: { onSubmit() { // 提交表单 console.log(this.form) // 关闭弹窗 this.showPopup = false } } } </script> <style> .popup-header { font-size: 16px; font-weight: bold; padding: 16px; border-bottom: 1px solid #ddd; } .popup-body { padding: 16px; } </style> ``` 在这个示例中,我们使用了 `u-number-box` 数字框组件来代替步进器,并设置了 `min` 和 `max` 属性来限制数字范围。其他组件的使用方法和上一个示例相同。 再次感谢您的指正,希望这次回答能够帮到您。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

亚丁号

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值