步驟導(dǎo)航器組件

2024-01-22 17:27 更新

步驟導(dǎo)航器組件,適用于引導(dǎo)用戶按照步驟完成任務(wù)的導(dǎo)航場景。

說明

該組件從API Version 8開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨標(biāo)記該內(nèi)容的起始版本。

子組件

僅能包含子組件StepperItem

接口

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

參數(shù):

參數(shù)名參數(shù)類型必填參數(shù)描述
indexnumber

設(shè)置步驟導(dǎo)航器當(dāng)前顯示StepperItem的索引值。

默認(rèn)值:0

屬性

事件

名稱描述
onFinish(callback: () => void)步驟導(dǎo)航器最后一個StepperItem的nextLabel被點擊時,并且ItemState屬性為Normal時,觸發(fā)該回調(diào) 。
onSkip(callback: () => void)當(dāng)前顯示的StepperItem狀態(tài)為ItemState.Skip時,nextLabel被點擊時觸發(fā)該回調(diào)。
onChange(callback: (prevIndex?: number, index?: number) => void)

點擊當(dāng)前StepperItem的prevLabel進(jìn)行步驟切換時觸發(fā)該回調(diào);或點擊當(dāng)前StepperItem的nextLabel,當(dāng)前頁面不為步驟導(dǎo)航器最后一個StepperItem且ItemState屬性為Normal時,觸發(fā)該回調(diào)。

- prevIndex:切換前的步驟頁索引值。

- index:切換后的步驟頁(前一頁或者下一頁)索引值。

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

點擊StepperItem的nextLabel切換下一步驟時,當(dāng)前頁面不為步驟導(dǎo)航器最后一個StepperItem且ItemState屬性為Normal時,觸發(fā)該回調(diào)。

- index:當(dāng)前步驟頁索引值。

- pendingIndex:下一步驟頁索引值。

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

點擊StepperItem的prevLabel切換上一步驟時觸發(fā)該回調(diào)。

- index:當(dāng)前步驟頁索引值。

- pendingIndex:上一步驟頁索引值。

示例

  1. // xxx.ets
  2. @Styles function itemStyle () {
  3. .width(336)
  4. .height(621)
  5. .margin({ top: 48, left: 12 })
  6. .borderRadius(24)
  7. .backgroundColor('#FFFFFF')
  8. }
  9. @Extend(Text) function itemTextStyle () {
  10. .fontColor('#182431')
  11. .fontSize(36)
  12. .fontWeight(500)
  13. .opacity(0.4)
  14. .margin({ top: 82, bottom: 40 })
  15. }
  16. @Entry
  17. @Component
  18. struct StepperExample {
  19. @State currentIndex: number = 0
  20. @State firstState: ItemState = ItemState.Normal
  21. @State secondState: ItemState = ItemState.Normal
  22. @State thirdState: ItemState = ItemState.Normal
  23. build() {
  24. Stepper({
  25. index: this.currentIndex
  26. }) {
  27. // 第一個步驟頁
  28. StepperItem() {
  29. Column() {
  30. Text('Page One')
  31. .itemTextStyle()
  32. Button('change status:' + this.firstState)
  33. .backgroundColor('#007dFF')
  34. .onClick(() => {
  35. this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip
  36. })
  37. }.itemStyle()
  38. }
  39. .nextLabel('Next')
  40. .status(this.firstState)
  41. // 第二個步驟頁
  42. StepperItem() {
  43. Column() {
  44. Text('Page Two')
  45. .itemTextStyle()
  46. Button('change status:' + this.secondState)
  47. .backgroundColor('#007dFF')
  48. .onClick(() => {
  49. this.secondState = this.secondState === ItemState.Disabled ? ItemState.Normal : ItemState.Disabled
  50. })
  51. }.itemStyle()
  52. }
  53. .nextLabel('Next')
  54. .prevLabel('Previous')
  55. .status(this.secondState)
  56. // 第三個步驟頁
  57. StepperItem() {
  58. Column() {
  59. Text('Page Three')
  60. .itemTextStyle()
  61. Button('change status:' + this.thirdState)
  62. .backgroundColor('#007dFF')
  63. .onClick(() => {
  64. this.thirdState = this.thirdState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting
  65. })
  66. }.itemStyle()
  67. }
  68. .status(this.thirdState)
  69. // 第四個步驟頁
  70. StepperItem() {
  71. Column() {
  72. Text('Page Four')
  73. .itemTextStyle()
  74. }.itemStyle()
  75. }
  76. }
  77. .backgroundColor('#F1F3F5')
  78. .onFinish(() => {
  79. // 此處可處理點擊最后一頁的Finish時的邏輯,例如路由跳轉(zhuǎn)等
  80. console.info('onFinish')
  81. })
  82. .onSkip(() => {
  83. // 此處可處理點擊跳過時的邏輯,例如動態(tài)修改Stepper的index值使其跳轉(zhuǎn)到某一步驟頁等
  84. console.info('onSkip')
  85. })
  86. .onChange((prevIndex: number, index: number) => {
  87. this.currentIndex = index
  88. })
  89. }
  90. }

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號