1e41f4b71Sopenharmony_ci# ProgressButton
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci文本下载按钮,可显示具体下载进度。
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci> **说明:**
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> 该组件从API Version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci## 导入模块
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ciimport { ProgressButton } from '@kit.ArkUI'
16e41f4b71Sopenharmony_ci```
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci## 属性
19e41f4b71Sopenharmony_ci支持[通用属性](ts-universal-attributes-size.md)
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## ProgressButton
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ciProgressButton({progress: number, content: string, progressButtonWidth?: Length, clickCallback: () => void, enable: boolean})
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**装饰器类型:**\@Component
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 装饰器类型 | 说明 |
32e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
33e41f4b71Sopenharmony_ci| progress | number | 是 | \@Prop | 下载按钮的当前进度值。 |
34e41f4b71Sopenharmony_ci| content | string | 是 | \@Prop | 下载按钮的文本。 |
35e41f4b71Sopenharmony_ci| progressButtonWidth | [Length](ts-types.md#length) | 否 | - | 下载按钮的宽度。<br/>默认值:44。 |
36e41f4b71Sopenharmony_ci| clickCallback | () =&gt; void | 是 | - | 下载按钮的点击回调。 |
37e41f4b71Sopenharmony_ci| enable | boolean | 是 | \@Prop | 下载按钮是否可以点击。<br> enable为true时,表示可以点击。<br> enable为false时,表示不可点击。 |
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci## 事件
40e41f4b71Sopenharmony_ci支持[通用事件](ts-universal-events-click.md)
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci## 示例
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci```ts
45e41f4b71Sopenharmony_ciimport { ProgressButton } from '@kit.ArkUI'
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci@Entry
48e41f4b71Sopenharmony_ci@Component
49e41f4b71Sopenharmony_cistruct Index {
50e41f4b71Sopenharmony_ci  @State halfProgress: number = 0
51e41f4b71Sopenharmony_ci  @State smallProgress: number = 0
52e41f4b71Sopenharmony_ci  @State bigProgress: number = 0
53e41f4b71Sopenharmony_ci  @State textState1: string = ''
54e41f4b71Sopenharmony_ci  @State isRunning1: boolean = false
55e41f4b71Sopenharmony_ci  @State enableState1: boolean = true
56e41f4b71Sopenharmony_ci  @State progressState: Visibility = Visibility.None
57e41f4b71Sopenharmony_ci  @State ButtonState: Visibility = Visibility.Visible
58e41f4b71Sopenharmony_ci  @State buttonText: string = '下载'
59e41f4b71Sopenharmony_ci  @State buttonEnable: boolean = true
60e41f4b71Sopenharmony_ci  @State isEnd: boolean = false
61e41f4b71Sopenharmony_ci  build() {
62e41f4b71Sopenharmony_ci    Column({space: 20}) {
63e41f4b71Sopenharmony_ci      Text('下载按钮')
64e41f4b71Sopenharmony_ci      Button(this.buttonText)
65e41f4b71Sopenharmony_ci        .fontSize($r('sys.float.ohos_id_text_size_button3'))
66e41f4b71Sopenharmony_ci        .fontWeight(FontWeight.Medium)
67e41f4b71Sopenharmony_ci        .fontColor($r('sys.color.ohos_id_color_emphasize'))
68e41f4b71Sopenharmony_ci        .padding({left: 8, right: 8})
69e41f4b71Sopenharmony_ci        .opacity(this.buttonEnable? 1: 0.4)
70e41f4b71Sopenharmony_ci        .enabled(this.buttonEnable)
71e41f4b71Sopenharmony_ci        .height(28)
72e41f4b71Sopenharmony_ci        .borderRadius(14)
73e41f4b71Sopenharmony_ci        .width(60)
74e41f4b71Sopenharmony_ci        .backgroundColor($r("sys.color.ohos_id_color_button_normal"))
75e41f4b71Sopenharmony_ci        .onClick(() => {
76e41f4b71Sopenharmony_ci          if(!this.isEnd) {
77e41f4b71Sopenharmony_ci            this.buttonText = '等待中'
78e41f4b71Sopenharmony_ci            let timer1 = setInterval(() => {
79e41f4b71Sopenharmony_ci              this.progressState = Visibility.Visible
80e41f4b71Sopenharmony_ci              this.ButtonState = Visibility.None
81e41f4b71Sopenharmony_ci              clearInterval(timer1)
82e41f4b71Sopenharmony_ci              this.isRunning1 = true
83e41f4b71Sopenharmony_ci              let timer = setInterval(() => {
84e41f4b71Sopenharmony_ci                if (this.isRunning1) {
85e41f4b71Sopenharmony_ci                  if (this.halfProgress === 100) {
86e41f4b71Sopenharmony_ci                    this.isEnd = true
87e41f4b71Sopenharmony_ci                  } else {
88e41f4b71Sopenharmony_ci                    this.halfProgress++
89e41f4b71Sopenharmony_ci                    if (this.halfProgress === 100) {
90e41f4b71Sopenharmony_ci                      this.textState1 = '安装中'
91e41f4b71Sopenharmony_ci                      this.enableState1 = false
92e41f4b71Sopenharmony_ci                      this.ButtonState = Visibility.Visible
93e41f4b71Sopenharmony_ci                      this.progressState = Visibility.None
94e41f4b71Sopenharmony_ci                      this.buttonEnable = false
95e41f4b71Sopenharmony_ci                      this.buttonText = '安装中'
96e41f4b71Sopenharmony_ci                      let timer2 = setInterval(() => {
97e41f4b71Sopenharmony_ci                        this.buttonText = '打开'
98e41f4b71Sopenharmony_ci                        this.buttonEnable = true
99e41f4b71Sopenharmony_ci                        this.isEnd = true
100e41f4b71Sopenharmony_ci                        clearInterval(timer2)
101e41f4b71Sopenharmony_ci                      }, 2000)
102e41f4b71Sopenharmony_ci                    }
103e41f4b71Sopenharmony_ci                    console.info('x progress++ = ' + this.halfProgress)
104e41f4b71Sopenharmony_ci                  }
105e41f4b71Sopenharmony_ci                } else {
106e41f4b71Sopenharmony_ci                  console.info('x isRunning = ' + false)
107e41f4b71Sopenharmony_ci                  clearInterval(timer)
108e41f4b71Sopenharmony_ci                }
109e41f4b71Sopenharmony_ci              }, 100)
110e41f4b71Sopenharmony_ci            }, 2000)
111e41f4b71Sopenharmony_ci          }
112e41f4b71Sopenharmony_ci        }).visibility(this.ButtonState)
113e41f4b71Sopenharmony_ci      ProgressButton({
114e41f4b71Sopenharmony_ci        progress: this.halfProgress,
115e41f4b71Sopenharmony_ci        progressButtonWidth: "60",
116e41f4b71Sopenharmony_ci        content: this.textState1,
117e41f4b71Sopenharmony_ci        enable: this.enableState1,
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci        clickCallback: () => {
120e41f4b71Sopenharmony_ci          if (this.isRunning1 && this.halfProgress < 100) {
121e41f4b71Sopenharmony_ci            this.textState1 = '继续'
122e41f4b71Sopenharmony_ci          }
123e41f4b71Sopenharmony_ci          this.isRunning1 = !this.isRunning1
124e41f4b71Sopenharmony_ci          let timer = setInterval(() => {
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci            if (this.isRunning1) {
127e41f4b71Sopenharmony_ci              if (this.halfProgress === 100) {
128e41f4b71Sopenharmony_ci              } else {
129e41f4b71Sopenharmony_ci                this.halfProgress++
130e41f4b71Sopenharmony_ci                if (this.halfProgress === 100) {
131e41f4b71Sopenharmony_ci                  this.textState1 = '安装中'
132e41f4b71Sopenharmony_ci                  this.enableState1 = false
133e41f4b71Sopenharmony_ci                  this.ButtonState = Visibility.Visible
134e41f4b71Sopenharmony_ci                  this.progressState = Visibility.None
135e41f4b71Sopenharmony_ci                  this.buttonEnable = false
136e41f4b71Sopenharmony_ci                  this.buttonText = '安装中'
137e41f4b71Sopenharmony_ci                  let timer2 = setInterval(() => {
138e41f4b71Sopenharmony_ci                    this.buttonText = '打开'
139e41f4b71Sopenharmony_ci                    this.buttonEnable = true
140e41f4b71Sopenharmony_ci                    this.isEnd = true
141e41f4b71Sopenharmony_ci                    clearInterval(timer2)
142e41f4b71Sopenharmony_ci                  },2000)
143e41f4b71Sopenharmony_ci                }
144e41f4b71Sopenharmony_ci                console.info('x progress++ = ' + this.halfProgress)
145e41f4b71Sopenharmony_ci              }
146e41f4b71Sopenharmony_ci            } else {
147e41f4b71Sopenharmony_ci              console.info('x isRunning = ' + false)
148e41f4b71Sopenharmony_ci              clearInterval(timer)
149e41f4b71Sopenharmony_ci            }
150e41f4b71Sopenharmony_ci          }, 100)
151e41f4b71Sopenharmony_ci        }
152e41f4b71Sopenharmony_ci      }).visibility(this.progressState)
153e41f4b71Sopenharmony_ci    }.alignItems(HorizontalAlign.Center).width('100%')
154e41f4b71Sopenharmony_ci  }
155e41f4b71Sopenharmony_ci}
156e41f4b71Sopenharmony_ci```
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci![zh-cn_image_0000001664713029](figures/zh-cn_image_0000001664713029.png)
160