fix: 重构退出按钮

This commit is contained in:
wangzhongjie 2025-06-12 15:48:29 +08:00
parent 6ecd1057fb
commit 20c91c90a9
2 changed files with 64 additions and 18 deletions

View File

@ -8,7 +8,6 @@
*/ */
import dayTs from '../../utils/Date' import dayTs from '../../utils/Date'
import router from '@ohos.router' import router from '@ohos.router'
import Prompt from '@system.prompt'
import common from '@ohos.app.ability.common' import common from '@ohos.app.ability.common'
@Component @Component
@ -24,6 +23,10 @@ export default struct HeaderComponent {
// 扩充Logo后面区域 // 扩充Logo后面区域
@BuilderParam @BuilderParam
logoExpansionBuilder?: () => void = this.customBuilder logoExpansionBuilder?: () => void = this.customBuilder
exitDialogController: CustomDialogController = new CustomDialogController({
builder: exitDialogComponent(),
customStyle: true
})
@Builder @Builder
customBuilder() { customBuilder() {
@ -84,23 +87,8 @@ export default struct HeaderComponent {
}, router.RouterMode.Single); }, router.RouterMode.Single);
}) })
Image($r('app.media.btn_back')).height(100).onClick(() => { Image($r('app.media.btn_back')).height(100).onClick(() => {
Prompt.showDialog({ this.exitDialogController.open()
title: "提示",
message: "确定要退出吗?",
buttons: [
{
text: '取消',
color: '#666666'
},
{
text: '退出',
color: '#666666'
}
],
success: () => {
(getContext(this) as common.UIAbilityContext).terminateSelf()
}
})
}) })
} }
} }
@ -110,3 +98,61 @@ export default struct HeaderComponent {
.height(100) .height(100)
} }
} }
@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)
}
}
@Component
struct BtnComponent {
@State text: string = "确认"
build() {
Row() {
Text(this.text).fontColor("#F4EEE7").fontSize(28)
}
.backgroundImage($r("app.media.nor_btn"))
.backgroundImageSize({
width: "100%",
height: "100%"
})
.width(200)
.height(80)
.justifyContent(FlexAlign.Center)
.alignItems(VerticalAlign.Center)
.margin({
left: 20
})
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB