CustomDialogView.ets 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import promptAction from '@ohos.promptAction';
  2. @CustomDialog
  3. export struct CustomDialogView {
  4. @Link visible: boolean;
  5. controller: CustomDialogController;
  6. // 弹窗交互事件参数,点击确认和取消按钮时的回调函数
  7. onCancel?: () => void;
  8. onConfirm?: () => void;
  9. @Prop text: ResourceStr
  10. build() {
  11. Column() {
  12. Text(this.text)
  13. .fontSize($r('app.integer.custom_dialog_content_font_size'))
  14. .fontColor(Color.Black)
  15. .padding({ top: $r('app.integer.ohos_id_card_padding_start') })
  16. Row() {
  17. Button($r('app.string.custom_dialog_cancel'))
  18. .backgroundColor($r('app.color.ohos_id_color_background'))
  19. .fontColor($r('app.color.ohos_id_color_emphasize'))
  20. .fontSize($r('app.integer.custom_dialog_content_font_size'))
  21. .width($r('app.integer.custom_dialog_button_width'))
  22. .onClick(() => {
  23. this.visible = false;
  24. this.onCancel?.();
  25. })
  26. Button($r('app.string.custom_dialog_confirm'))
  27. .backgroundColor($r('app.color.ohos_id_color_background'))
  28. .fontColor($r('app.color.ohos_id_color_emphasize'))
  29. .fontSize($r('app.integer.custom_dialog_content_font_size'))
  30. .width($r('app.integer.custom_dialog_button_width'))
  31. .onClick(() => {
  32. if (this.onConfirm) {
  33. this.onConfirm()
  34. }
  35. })
  36. }
  37. .justifyContent(FlexAlign.Center)
  38. }
  39. .borderRadius($r('app.integer.ohos_id_corner_radius_default_m'))
  40. .justifyContent(FlexAlign.SpaceAround)
  41. .backgroundColor($r('app.color.ohos_id_color_background'))
  42. .height($r('app.integer.custom_dialog_column_height'))
  43. .width($r('app.integer.custom_dialog_column_width'))
  44. }
  45. }