1e41f4b71Sopenharmony_ci# ExceptionPrompt 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciThe exception prompt component is used to show an error message when an error arises. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci> **NOTE** 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> This component is supported since API version 11. Updates will be marked with a superscript to indicate their earliest API version. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci## Modules to Import 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci```ts 15e41f4b71Sopenharmony_ciimport { ExceptionPrompt, PromptOptions, MarginType } from '@kit.ArkUI' 16e41f4b71Sopenharmony_ci``` 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## Child Components 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciNot supported 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci## Attributes 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ciThe [universal attributes](ts-universal-attributes-size.md) are not supported. 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci## ExceptionPrompt 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciExceptionPrompt({ options: PromptOptions, onTipClick?: ()=>void, onActionTextClick?: ()=>void }) 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**Decorator**: @Component 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Parameters** 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Decorator| Description| 41e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 42e41f4b71Sopenharmony_ci| options | [PromptOptions](#promptoptions) | Yes| \@Prop | Exception prompt configuration.| 43e41f4b71Sopenharmony_ci| onTipClick | ()=>void | No| - | Callback invoked when the prompt text on the left is clicked.| 44e41f4b71Sopenharmony_ci| onActionTextClick | ()=>void | No| - | Callback invoked when the icon on the right is clicked.| 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci## PromptOptions 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ciDefines the exception prompt options. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 55e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 56e41f4b71Sopenharmony_ci| icon | [ResourceStr](ts-types.md#resourcestr) | No| Icon of the exception prompt.| 57e41f4b71Sopenharmony_ci| tip | [ResourceStr](ts-types.md#resourcestr) | No| Text content of the exception prompt.<br>By default, the following text resources are provided:<br>1. **ohos_network_not_connected**: displayed when no Internet connection.<br>2. **ohos_network_connected_unstable**: displayed when the Internet connection is unstable.<br>3. **ohos_unstable_connect_server**: displayed when the server fails to be connected.<br>4. **ohos_custom_network_tips_left**: displayed when an Internet connection is available but the location fails to be obtained.| 58e41f4b71Sopenharmony_ci| marginType | [MarginType](#margintype) | Yes| Margin type of the exception prompt.| 59e41f4b71Sopenharmony_ci| actionText | [ResourceStr](ts-types.md#resourcestr) | No| Text of the icon on the right of the exception prompt.| 60e41f4b71Sopenharmony_ci| marginTop | [Dimension](ts-types.md#dimension10) | Yes| Top margin of the exception prompt.| 61e41f4b71Sopenharmony_ci| isShown | boolean | No| Whether the exception prompt is displayed.<br>**true**: The exception prompt is displayed.<br>**false**: The exception prompt is displayed.| 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci## MarginType 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ciDefines the margin type. 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci| Name| Value| Description| 72e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 73e41f4b71Sopenharmony_ci| DEFAULT_MARGIN | 0 | Default margin:<br>Margin 1: referenced from **ohos_id_card_margin_start**.<br>Margin 2: referenced from **ohos_id_card_margin_end**.| 74e41f4b71Sopenharmony_ci| FIT_MARGIN | 1 | Adaptable margin:<br> Margin 1: referenced from **ohos_id_max_padding_start**.<br> Margin 2: referenced from **ohos_id_max_padding_end**.| 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci## Events 77e41f4b71Sopenharmony_ciThe [universal events](ts-universal-events-click.md) are supported. 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci## Example 80e41f4b71Sopenharmony_ci### Example 1 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci```ts 83e41f4b71Sopenharmony_ciimport { ExceptionPrompt, PromptOptions, MarginType } from '@kit.ArkUI' 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci@Entry 86e41f4b71Sopenharmony_ci@Component 87e41f4b71Sopenharmony_cistruct Index { 88e41f4b71Sopenharmony_ci @State options: PromptOptions = { 89e41f4b71Sopenharmony_ci icon: $r('sys.media.ohos_ic_public_fail'), 90e41f4b71Sopenharmony_ci tip: 'Error', 91e41f4b71Sopenharmony_ci marginType: MarginType.DEFAULT_MARGIN, 92e41f4b71Sopenharmony_ci actionText: 'Set network', 93e41f4b71Sopenharmony_ci marginTop: 80, 94e41f4b71Sopenharmony_ci isShown:true 95e41f4b71Sopenharmony_ci } 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci build() { 98e41f4b71Sopenharmony_ci Column() { 99e41f4b71Sopenharmony_ci ExceptionPrompt({ 100e41f4b71Sopenharmony_ci options: this.options, 101e41f4b71Sopenharmony_ci onTipClick: () => { 102e41f4b71Sopenharmony_ci // Click the text on the left to change into the connecting state 103e41f4b71Sopenharmony_ci }, 104e41f4b71Sopenharmony_ci onActionTextClick: () => { 105e41f4b71Sopenharmony_ci // Click Set Network to open the Set network pop-up interface 106e41f4b71Sopenharmony_ci }, 107e41f4b71Sopenharmony_ci }) 108e41f4b71Sopenharmony_ci } 109e41f4b71Sopenharmony_ci } 110e41f4b71Sopenharmony_ci} 111e41f4b71Sopenharmony_ci``` 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci### Example 2 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci```ts 118e41f4b71Sopenharmony_ciimport { ExceptionPrompt, PromptOptions, MarginType } from '@kit.ArkUI' 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci@CustomDialog 121e41f4b71Sopenharmony_cistruct CustomDialogExample { 122e41f4b71Sopenharmony_ci @Link textValue: string 123e41f4b71Sopenharmony_ci @Link inputValue: string 124e41f4b71Sopenharmony_ci @State options: PromptOptions = { 125e41f4b71Sopenharmony_ci icon: $r('app.media.ic_public_fail'), 126e41f4b71Sopenharmony_ci tip: 'Error', 127e41f4b71Sopenharmony_ci marginType: MarginType.DEFAULT_MARGIN, 128e41f4b71Sopenharmony_ci actionText: 'Settings', 129e41f4b71Sopenharmony_ci marginTop: 5, 130e41f4b71Sopenharmony_ci isShown: true 131e41f4b71Sopenharmony_ci } 132e41f4b71Sopenharmony_ci cancel: () => void = () => {} 133e41f4b71Sopenharmony_ci confirm: () => void = () => {} 134e41f4b71Sopenharmony_ci controller: CustomDialogController 135e41f4b71Sopenharmony_ci // You can pass in multiple other controllers in the CustomDialog to open one or more other CustomDialogs in the CustomDialog. In this case, you must place the controller pointing to the self behind all controllers. 136e41f4b71Sopenharmony_ci build() { 137e41f4b71Sopenharmony_ci Column() { 138e41f4b71Sopenharmony_ci ExceptionPrompt({ 139e41f4b71Sopenharmony_ci options: this.options, 140e41f4b71Sopenharmony_ci }) 141e41f4b71Sopenharmony_ci TextInput({ placeholder: '', text: this.textValue }).margin({top:70}).height(60).width('90%') 142e41f4b71Sopenharmony_ci .onChange((value: string) => { 143e41f4b71Sopenharmony_ci this.textValue = value 144e41f4b71Sopenharmony_ci }) 145e41f4b71Sopenharmony_ci Text('Are you sure you want to change the text?').fontSize(16).margin({ bottom: 10 }) 146e41f4b71Sopenharmony_ci Flex({ justifyContent: FlexAlign.SpaceAround }) { 147e41f4b71Sopenharmony_ci Button('No') 148e41f4b71Sopenharmony_ci .onClick(() => { 149e41f4b71Sopenharmony_ci this.controller.close() 150e41f4b71Sopenharmony_ci this.cancel() 151e41f4b71Sopenharmony_ci }).backgroundColor(0xffffff).fontColor(Color.Black) 152e41f4b71Sopenharmony_ci Button('OK') 153e41f4b71Sopenharmony_ci .onClick(() => { 154e41f4b71Sopenharmony_ci this.inputValue = this.textValue 155e41f4b71Sopenharmony_ci this.controller.close() 156e41f4b71Sopenharmony_ci this.confirm() 157e41f4b71Sopenharmony_ci }).backgroundColor(0xffffff).fontColor(Color.Red) 158e41f4b71Sopenharmony_ci }.margin({ bottom: 10 }) 159e41f4b71Sopenharmony_ci } 160e41f4b71Sopenharmony_ci } 161e41f4b71Sopenharmony_ci} 162e41f4b71Sopenharmony_ci@Entry 163e41f4b71Sopenharmony_ci@Component 164e41f4b71Sopenharmony_cistruct Index1 { 165e41f4b71Sopenharmony_ci @State ButtonText: string = '' 166e41f4b71Sopenharmony_ci @State MAP_HEIGHT: string = '30%' 167e41f4b71Sopenharmony_ci @State duration: number = 2500 168e41f4b71Sopenharmony_ci @State tips: string = '' 169e41f4b71Sopenharmony_ci @State actionText: string = '' 170e41f4b71Sopenharmony_ci controller: TextInputController = new TextInputController() 171e41f4b71Sopenharmony_ci cancel: () => void = () => {} 172e41f4b71Sopenharmony_ci confirm: () => void = () => {} 173e41f4b71Sopenharmony_ci @State options: PromptOptions = { 174e41f4b71Sopenharmony_ci icon: $r('app.media.ic_public_fail'), 175e41f4b71Sopenharmony_ci tip: '', 176e41f4b71Sopenharmony_ci marginType: MarginType.DEFAULT_MARGIN, 177e41f4b71Sopenharmony_ci actionText: '', 178e41f4b71Sopenharmony_ci marginTop: 80, 179e41f4b71Sopenharmony_ci isShown: true 180e41f4b71Sopenharmony_ci } 181e41f4b71Sopenharmony_ci @State textValue: string = '' 182e41f4b71Sopenharmony_ci @State inputValue: string = 'click me' 183e41f4b71Sopenharmony_ci dialogController: CustomDialogController | undefined = new CustomDialogController({ 184e41f4b71Sopenharmony_ci builder: CustomDialogExample({ 185e41f4b71Sopenharmony_ci cancel: this.onCancel, 186e41f4b71Sopenharmony_ci confirm: this.onAccept, 187e41f4b71Sopenharmony_ci textValue: $textValue, 188e41f4b71Sopenharmony_ci inputValue: $inputValue 189e41f4b71Sopenharmony_ci }), 190e41f4b71Sopenharmony_ci cancel: this.existApp, 191e41f4b71Sopenharmony_ci autoCancel: true, 192e41f4b71Sopenharmony_ci alignment: DialogAlignment.Bottom, 193e41f4b71Sopenharmony_ci offset: { dx: 0, dy: -20 }, 194e41f4b71Sopenharmony_ci gridCount: 4, 195e41f4b71Sopenharmony_ci customStyle: false 196e41f4b71Sopenharmony_ci }) 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci aboutToDisappear() { 199e41f4b71Sopenharmony_ci this.dialogController = undefined // Set dialogController to undefined. 200e41f4b71Sopenharmony_ci } 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci onCancel() { 203e41f4b71Sopenharmony_ci console.info('Callback when the first button is clicked') 204e41f4b71Sopenharmony_ci } 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci onAccept() { 207e41f4b71Sopenharmony_ci console.info('Callback when the second button is clicked') 208e41f4b71Sopenharmony_ci } 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci existApp() { 211e41f4b71Sopenharmony_ci console.info('Click the callback in the blank area') 212e41f4b71Sopenharmony_ci } 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci build() { 215e41f4b71Sopenharmony_ci Column() { 216e41f4b71Sopenharmony_ci Button('Click Me') 217e41f4b71Sopenharmony_ci .width('30%') 218e41f4b71Sopenharmony_ci .margin({top:420}) 219e41f4b71Sopenharmony_ci .zIndex(999) 220e41f4b71Sopenharmony_ci .onClick(()=>{ 221e41f4b71Sopenharmony_ci if (this.dialogController != undefined) { 222e41f4b71Sopenharmony_ci this.dialogController.open() 223e41f4b71Sopenharmony_ci } 224e41f4b71Sopenharmony_ci }) 225e41f4b71Sopenharmony_ci } 226e41f4b71Sopenharmony_ci .height('100%') 227e41f4b71Sopenharmony_ci .width('100%') 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci } 230e41f4b71Sopenharmony_ci} 231e41f4b71Sopenharmony_ci``` 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci 234