1e41f4b71Sopenharmony_ci# DownloadFileButton 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci下载文件按钮,通过点击该下载按钮,可以获取到当前应用在Download公共目录中所属的存储路径。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci> **说明:** 7e41f4b71Sopenharmony_ci> 8e41f4b71Sopenharmony_ci> 该组件从API Version 12开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## 导入模块 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci``` 13e41f4b71Sopenharmony_ciimport { DownloadFileButton } from '@kit.ArkUI' 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## 子组件 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci无 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci## 属性 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci支持[通用属性](ts-universal-attributes-size.md)。 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci## DownloadFileButton 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ciDownloadbutton(contentOptions?:DownloadContentOptions, styleOptions?:DownloadStyleOptions) 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci下载文件按钮组件,默认显示图标和文字。 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**装饰器类型:**@Component 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**系统能力**: SystemCapability.ArkUI.ArkUI.Full 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci**参数:** 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 装饰器类型 | 说明 | 39e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ | ---- | ---------- | -------------------------------- | 40e41f4b71Sopenharmony_ci| contentOptions | [DownloadContentOptions](#downloadcontentoptions) | 否 | @State | 创建包含指定元素内容的下载按钮。 | 41e41f4b71Sopenharmony_ci| styleOptions | [DownloadStyleOptions](#downloadstyleoptions) | 否 | @State | 创建包含指定元素样式的下载按钮。 | 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci## DownloadContentOptions 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci下载文件按钮中显示的内容。 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci**系统能力**: SystemCapability.ArkUI.ArkUI.Full 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 52e41f4b71Sopenharmony_ci| ---- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 53e41f4b71Sopenharmony_ci| icon | [DownloadIconStyle](#downloadiconstyle) | 否 | 设置下载按钮的图标风格<br/>不传入该参数表示没有图标,icon和text至少存在一个。 | 54e41f4b71Sopenharmony_ci| text | [DownloadDescription](#downloaddescription) | 否 | 设置下载按钮的文本描述<br/>不传入该参数表示没有文字描述,icon和text至少存在一个。 | 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci## DownloadStyleOptions 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci下载文件按钮中图标和文字的样式。 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci**系统能力**: SystemCapability.ArkUI.ArkUI.Full 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 65e41f4b71Sopenharmony_ci| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 66e41f4b71Sopenharmony_ci| iconSize | Dimension | 否 | 下载控件上图标的尺寸。<br/>默认值:16vp | 67e41f4b71Sopenharmony_ci| layoutDirection | [DownloadLayoutDirection](#downloadlayoutdirection) | 否 | 下载控件上图标和文字分布的方向。<br/>默认值:DownloadLayoutDirection.HORIZONTAL | 68e41f4b71Sopenharmony_ci| fontSize | Dimension | 否 | 下载控件上文字的尺寸。<br/>默认值:16fp | 69e41f4b71Sopenharmony_ci| fontStyle | FontStyle | 否 | 下载控件上文字的样式。<br/>默认值:FontStyle.Normal | 70e41f4b71Sopenharmony_ci| fontWeight | number \| FontWeight \| string | 否 | 下载控件上文字粗细。<br/>默认值:FontWeight.Medium | 71e41f4b71Sopenharmony_ci| fontFamily | string \| Resource | 否 | 下载控件上文字的字体。<br/>默认字体:'HarmonyOS Sans' | 72e41f4b71Sopenharmony_ci| fontColor | ResourceColor | 否 | 下载控件上文字的颜色。<br/>默认值:#ffffffff | 73e41f4b71Sopenharmony_ci| iconColor | ResourceColor | 否 | 下载控件上图标的颜色。<br/>默认值:#ffffffff | 74e41f4b71Sopenharmony_ci| textIconSpace | Dimension | 否 | 下载控件中图标和文字的间距。<br/>默认值:4vp | 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci## DownloadIconStyle 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci下载文件按钮中图标的风格。 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**系统能力**: SystemCapability.ArkUI.ArkUI.Full 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 85e41f4b71Sopenharmony_ci| ----------- | ---- | -------------------------- | 86e41f4b71Sopenharmony_ci| FULL_FILLED | 1 | 下载按钮展示填充样式图标。 | 87e41f4b71Sopenharmony_ci| LINES | 2 | 下载按钮展示线条样式图标。 | 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci## DownloadDescription 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci下载按钮中文字的内容。 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci**系统能力**: SystemCapability.ArkUI.ArkUI.Full 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 100e41f4b71Sopenharmony_ci| ------------------- | ---- | -------------------------------- | 101e41f4b71Sopenharmony_ci| DOWNLOAD | 1 | 下载按钮的文字描述为“下载”。 | 102e41f4b71Sopenharmony_ci| DOWNLOAD_FILE | 2 | 下载按钮的文字描述为“下载文件”。 | 103e41f4b71Sopenharmony_ci| SAVE | 3 | 下载按钮的文字描述为“保存”。 | 104e41f4b71Sopenharmony_ci| SAVE_IMAGE | 4 | 下载按钮的文字描述为“保存图片”。 | 105e41f4b71Sopenharmony_ci| SAVE_FILE | 5 | 下载按钮的文字描述为“保存文件”。 | 106e41f4b71Sopenharmony_ci| DOWNLOAD_AND_SHARE | 6 | 下载按钮的文字描述为“下载分享”。 | 107e41f4b71Sopenharmony_ci| RECEIVE | 7 | 下载按钮的文字描述为“接收”。 | 108e41f4b71Sopenharmony_ci| CONTINUE_TO_RECEIVE | 8 | 下载按钮的文字描述为“继续接收”。 | 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci## DownloadLayoutDirection 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci下载文件按钮中图标和文字的排列方式。 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci**系统能力**: SystemCapability.ArkUI.ArkUI.Full 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 121e41f4b71Sopenharmony_ci| ---------- | ---- | ------------------------------------------ | 122e41f4b71Sopenharmony_ci| HORIZONTAL | 0 | 下载控件上图标和文字分布的方向为水平排列。 | 123e41f4b71Sopenharmony_ci| VERTICAL | 1 | 下载控件上图标和文字分布的方向为垂直排列。 | 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci## 事件 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci支持[通用事件](ts-universal-events-click.md)。 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci## 示例 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci``` 132e41f4b71Sopenharmony_ciimport { picker } from '@kit.CoreFileKit'; 133e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 134e41f4b71Sopenharmony_ciimport { DownloadFileButton, DownloadLayoutDirection } from '@kit.ArkUI'; 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci@Entry 137e41f4b71Sopenharmony_ci@Component 138e41f4b71Sopenharmony_cistruct Index { 139e41f4b71Sopenharmony_ci build() { 140e41f4b71Sopenharmony_ci Column() { 141e41f4b71Sopenharmony_ci DownloadFileButton({ 142e41f4b71Sopenharmony_ci contentOptions: { 143e41f4b71Sopenharmony_ci // icon: DownloadIconStyle.FULL_FILLED, 144e41f4b71Sopenharmony_ci // text: DownloadDescription.DOWNLOAD 145e41f4b71Sopenharmony_ci }, 146e41f4b71Sopenharmony_ci styleOptions: { 147e41f4b71Sopenharmony_ci iconSize: '16vp', 148e41f4b71Sopenharmony_ci layoutDirection: DownloadLayoutDirection.HORIZONTAL, 149e41f4b71Sopenharmony_ci fontSize: '16vp', 150e41f4b71Sopenharmony_ci fontStyle: FontStyle.Normal, 151e41f4b71Sopenharmony_ci fontWeight: FontWeight.Medium, 152e41f4b71Sopenharmony_ci fontFamily: 'HarmonyOS Sans', 153e41f4b71Sopenharmony_ci fontColor: '#ffffffff', 154e41f4b71Sopenharmony_ci iconColor: '#ffffffff', 155e41f4b71Sopenharmony_ci textIconSpace: '4vp' 156e41f4b71Sopenharmony_ci } 157e41f4b71Sopenharmony_ci }) 158e41f4b71Sopenharmony_ci .backgroundColor('#007dff') 159e41f4b71Sopenharmony_ci .borderStyle(BorderStyle.Dotted) 160e41f4b71Sopenharmony_ci .borderWidth(0) 161e41f4b71Sopenharmony_ci .borderColor('') 162e41f4b71Sopenharmony_ci .borderRadius('24vp') 163e41f4b71Sopenharmony_ci .position({ x: 0, y: 0 }) 164e41f4b71Sopenharmony_ci .markAnchor({ x: 0, y: 0 }) 165e41f4b71Sopenharmony_ci .offset({ x: 0, y: 0 }) 166e41f4b71Sopenharmony_ci .constraintSize({}) 167e41f4b71Sopenharmony_ci .padding({ 168e41f4b71Sopenharmony_ci top: '12vp', 169e41f4b71Sopenharmony_ci bottom: '12vp', 170e41f4b71Sopenharmony_ci left: '24vp', 171e41f4b71Sopenharmony_ci right: '24vp' 172e41f4b71Sopenharmony_ci }) 173e41f4b71Sopenharmony_ci .onClick(() => { 174e41f4b71Sopenharmony_ci this.downloadAction(); 175e41f4b71Sopenharmony_ci }) 176e41f4b71Sopenharmony_ci } 177e41f4b71Sopenharmony_ci } 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci downloadAction() { 180e41f4b71Sopenharmony_ci try { 181e41f4b71Sopenharmony_ci const document = new picker.DocumentSaveOptions(); 182e41f4b71Sopenharmony_ci document.pickerMode = picker.DocumentPickerMode.DOWNLOAD; 183e41f4b71Sopenharmony_ci new picker.DocumentViewPicker().save(document, (err: BusinessError, result: Array<string>) => { 184e41f4b71Sopenharmony_ci if (err) { 185e41f4b71Sopenharmony_ci return; 186e41f4b71Sopenharmony_ci } 187e41f4b71Sopenharmony_ci console.info(`downloadAction result: ${JSON.stringify(result)}`); 188e41f4b71Sopenharmony_ci }); 189e41f4b71Sopenharmony_ci } catch (e) { 190e41f4b71Sopenharmony_ci } 191e41f4b71Sopenharmony_ci } 192e41f4b71Sopenharmony_ci} 193e41f4b71Sopenharmony_ci``` 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci 196