diff --git a/entry/src/main/ets/pages/compontents/ConfirmDialog.ets b/entry/src/main/ets/pages/compontents/ConfirmDialog.ets index e7c384b..cb2c0c0 100644 --- a/entry/src/main/ets/pages/compontents/ConfirmDialog.ets +++ b/entry/src/main/ets/pages/compontents/ConfirmDialog.ets @@ -6,8 +6,6 @@ export default struct ConfirmDialog { private controller?: CustomDialogController; onConfirm: () => void = () => { }; - onCancel?: () => void = () => { - }; build() { Column() { @@ -22,11 +20,7 @@ export default struct ConfirmDialog { BtnComponent({ text: "取消", }).onClick(() => { - if (!this.onCancel) { - this.controller?.close(); - return; - } - this.onCancel && this.onCancel(); + this.controller?.close(); }) BtnComponent().onClick(() => { diff --git a/entry/src/main/ets/pages/compontents/Header.ets b/entry/src/main/ets/pages/compontents/Header.ets index 1d55f46..1969e31 100644 --- a/entry/src/main/ets/pages/compontents/Header.ets +++ b/entry/src/main/ets/pages/compontents/Header.ets @@ -9,7 +9,7 @@ import dayTs from '../../utils/Date' import router from '@ohos.router' import common from '@ohos.app.ability.common' -import BtnComponent from './Button' +import ConfirmDialog from './ConfirmDialog' @Component export default struct HeaderComponent { @@ -25,7 +25,12 @@ export default struct HeaderComponent { @BuilderParam logoExpansionBuilder?: () => void = this.customBuilder exitDialogController: CustomDialogController = new CustomDialogController({ - builder: exitDialogComponent(), + builder: ConfirmDialog({ + text: "是否确认退出程序?", + onConfirm: () => { + (getContext(this) as common.UIAbilityContext).terminateSelf() + } + }), customStyle: true }) @@ -99,38 +104,4 @@ export default struct HeaderComponent { } } -@CustomDialog -struct exitDialogComponent { - private controller?: CustomDialogController; - - build() { - Column() { - Text("提示信息").fontSize(26).margin({ - top: 40 - }).fontWeight(FontWeight.Bold) - Row() { - Text("是否确认退出程序?").fontSize(28) - }.margin({ - top: 100, - bottom: 90 - }) - - Row() { - BtnComponent({ - text: "取消" - }).onClick(() => { - this.controller?.close() - }) - BtnComponent().onClick(() => { - (getContext(this) as common.UIAbilityContext).terminateSelf() - }) - } - } - .backgroundImage($r("app.media.km_open")) - .backgroundImageSize({ - width: "100%", - height: "100%" - }).width(800).height(400) - } -}