1e41f4b71Sopenharmony_ci# Stepper
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci步骤导航器组件,适用于引导用户按照步骤完成任务的导航场景。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci>  **说明:**
7e41f4b71Sopenharmony_ci>
8e41f4b71Sopenharmony_ci> 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## 子组件
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci仅能包含子组件[StepperItem](ts-basic-components-stepperitem.md)。
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## 接口
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciStepper(value?: { index?: number })
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**参数:**
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填  | 说明 |
27e41f4b71Sopenharmony_ci| ------| -------- | --------------- | -------- |
28e41f4b71Sopenharmony_ci| value | { index?: number }   | 否 | 设置步骤导航器当前显示StepperItem的索引值。<br/>默认值:0<br />从API version 10开始,该参数支持[$$](../../../quick-start/arkts-two-way-sync.md)双向绑定变量。 |
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci## 属性
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci## 事件
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci### onFinish
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_cionFinish(callback: () => void)
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci步骤导航器最后一个StepperItem的nextLabel被点击时,并且ItemState属性为Normal时,触发该回调。
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci### onSkip
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_cionSkip(callback:&nbsp;()&nbsp;=&gt;&nbsp;void)
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci当前显示的StepperItem状态为ItemState.Skip时,nextLabel被点击时触发该回调。
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci### onChange
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_cionChange(callback:&nbsp;(prevIndex:&nbsp;number,&nbsp;index:&nbsp;number)&nbsp;=&gt;&nbsp;void)
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci点击当前StepperItem的prevLabel进行步骤切换时触发该回调;或点击当前StepperItem的nextLabel,当前页面不为步骤导航器最后一个StepperItem且ItemState属性为Normal时,触发该回调。
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci**参数:** 
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci| 参数名    | 类型   | 必填 | 说明                                       |
70e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ------------------------------------------ |
71e41f4b71Sopenharmony_ci| prevIndex | number | 是   | 切换前的步骤页索引值。                     |
72e41f4b71Sopenharmony_ci| index     | number | 是   | 切换后的步骤页(前一页或者下一页)索引值。 |
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci### onNext
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_cionNext(callback:&nbsp;(index:&nbsp;number,&nbsp;pendingIndex:&nbsp;number)&nbsp;=&gt;&nbsp;void)
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci点击StepperItem的nextLabel切换下一步骤时,当前页面不为步骤导航器最后一个StepperItem且ItemState属性为Normal时,触发该回调。
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**参数:** 
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci| 参数名       | 类型   | 必填 | 说明               |
87e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ------------------ |
88e41f4b71Sopenharmony_ci| index        | number | 是   | 当前步骤页索引值。 |
89e41f4b71Sopenharmony_ci| pendingIndex | number | 是   | 下一步骤页索引值。 |
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci### onPrevious
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_cionPrevious(callback:&nbsp;(index:&nbsp;number,&nbsp;pendingIndex:&nbsp;number)&nbsp;=&gt;&nbsp;void)
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci点击StepperItem的prevLabel切换上一步骤时触发该回调。
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci**参数:** 
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci| 参数名       | 类型   | 必填 | 说明               |
104e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ------------------ |
105e41f4b71Sopenharmony_ci| index        | number | 是   | 当前步骤页索引值。 |
106e41f4b71Sopenharmony_ci| pendingIndex | number | 是   | 上一步骤页索引值。 |
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci## 示例
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci```ts
112e41f4b71Sopenharmony_ci// xxx.ets
113e41f4b71Sopenharmony_ci@Styles function itemStyle () {
114e41f4b71Sopenharmony_ci  .width(336)
115e41f4b71Sopenharmony_ci  .height(621)
116e41f4b71Sopenharmony_ci  .margin({ top: 48, left: 12 })
117e41f4b71Sopenharmony_ci  .borderRadius(24)
118e41f4b71Sopenharmony_ci  .backgroundColor('#FFFFFF')
119e41f4b71Sopenharmony_ci}
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci@Extend(Text) function itemTextStyle () {
122e41f4b71Sopenharmony_ci  .fontColor('#182431')
123e41f4b71Sopenharmony_ci  .fontSize(36)
124e41f4b71Sopenharmony_ci  .fontWeight(500)
125e41f4b71Sopenharmony_ci  .opacity(0.4)
126e41f4b71Sopenharmony_ci  .margin({ top: 82, bottom: 40 })
127e41f4b71Sopenharmony_ci}
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci@Entry
130e41f4b71Sopenharmony_ci@Component
131e41f4b71Sopenharmony_cistruct StepperExample {
132e41f4b71Sopenharmony_ci  @State currentIndex: number = 0
133e41f4b71Sopenharmony_ci  @State firstState: ItemState = ItemState.Normal
134e41f4b71Sopenharmony_ci  @State secondState: ItemState = ItemState.Normal
135e41f4b71Sopenharmony_ci  @State thirdState: ItemState = ItemState.Normal
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci  build() {
138e41f4b71Sopenharmony_ci    Stepper({
139e41f4b71Sopenharmony_ci      index: this.currentIndex
140e41f4b71Sopenharmony_ci    }) {
141e41f4b71Sopenharmony_ci      // 第一个步骤页
142e41f4b71Sopenharmony_ci      StepperItem() {
143e41f4b71Sopenharmony_ci        Column() {
144e41f4b71Sopenharmony_ci          Text('Page One')
145e41f4b71Sopenharmony_ci            .itemTextStyle()
146e41f4b71Sopenharmony_ci          Button('change status:' + this.firstState)
147e41f4b71Sopenharmony_ci            .backgroundColor('#007dFF')
148e41f4b71Sopenharmony_ci            .onClick(() => {
149e41f4b71Sopenharmony_ci              this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip
150e41f4b71Sopenharmony_ci            })
151e41f4b71Sopenharmony_ci        }.itemStyle()
152e41f4b71Sopenharmony_ci      }
153e41f4b71Sopenharmony_ci      .nextLabel('Next')
154e41f4b71Sopenharmony_ci      .status(this.firstState)
155e41f4b71Sopenharmony_ci      // 第二个步骤页
156e41f4b71Sopenharmony_ci      StepperItem() {
157e41f4b71Sopenharmony_ci        Column() {
158e41f4b71Sopenharmony_ci          Text('Page Two')
159e41f4b71Sopenharmony_ci            .itemTextStyle()
160e41f4b71Sopenharmony_ci          Button('change status:' + this.secondState)
161e41f4b71Sopenharmony_ci            .backgroundColor('#007dFF')
162e41f4b71Sopenharmony_ci            .onClick(() => {
163e41f4b71Sopenharmony_ci              this.secondState = this.secondState === ItemState.Disabled ? ItemState.Normal : ItemState.Disabled
164e41f4b71Sopenharmony_ci            })
165e41f4b71Sopenharmony_ci        }.itemStyle()
166e41f4b71Sopenharmony_ci      }
167e41f4b71Sopenharmony_ci      .nextLabel('Next')
168e41f4b71Sopenharmony_ci      .prevLabel('Previous')
169e41f4b71Sopenharmony_ci      .status(this.secondState)
170e41f4b71Sopenharmony_ci      // 第三个步骤页
171e41f4b71Sopenharmony_ci      StepperItem() {
172e41f4b71Sopenharmony_ci        Column() {
173e41f4b71Sopenharmony_ci          Text('Page Three')
174e41f4b71Sopenharmony_ci            .itemTextStyle()
175e41f4b71Sopenharmony_ci          Button('change status:' + this.thirdState)
176e41f4b71Sopenharmony_ci            .backgroundColor('#007dFF')
177e41f4b71Sopenharmony_ci            .onClick(() => {
178e41f4b71Sopenharmony_ci              this.thirdState = this.thirdState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting
179e41f4b71Sopenharmony_ci            })
180e41f4b71Sopenharmony_ci        }.itemStyle()
181e41f4b71Sopenharmony_ci      }
182e41f4b71Sopenharmony_ci      .status(this.thirdState)
183e41f4b71Sopenharmony_ci      // 第四个步骤页
184e41f4b71Sopenharmony_ci      StepperItem() {
185e41f4b71Sopenharmony_ci        Column() {
186e41f4b71Sopenharmony_ci          Text('Page Four')
187e41f4b71Sopenharmony_ci            .itemTextStyle()
188e41f4b71Sopenharmony_ci        }.itemStyle()
189e41f4b71Sopenharmony_ci      }
190e41f4b71Sopenharmony_ci    }
191e41f4b71Sopenharmony_ci    .backgroundColor('#F1F3F5')
192e41f4b71Sopenharmony_ci    .onFinish(() => {
193e41f4b71Sopenharmony_ci      // 此处可处理点击最后一页的Finish时的逻辑,例如路由跳转等
194e41f4b71Sopenharmony_ci      console.info('onFinish')
195e41f4b71Sopenharmony_ci    })
196e41f4b71Sopenharmony_ci    .onSkip(() => {
197e41f4b71Sopenharmony_ci      // 此处可处理点击跳过时的逻辑,例如动态修改Stepper的index值使其跳转到某一步骤页等
198e41f4b71Sopenharmony_ci      console.info('onSkip')
199e41f4b71Sopenharmony_ci    })
200e41f4b71Sopenharmony_ci    .onChange((prevIndex?: number, index?: number) => {
201e41f4b71Sopenharmony_ci      if(index){
202e41f4b71Sopenharmony_ci        this.currentIndex = index
203e41f4b71Sopenharmony_ci      }
204e41f4b71Sopenharmony_ci    })
205e41f4b71Sopenharmony_ci  }
206e41f4b71Sopenharmony_ci}
207e41f4b71Sopenharmony_ci```
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci![stepper](figures/stepper.gif)
211e41f4b71Sopenharmony_ci
212