fix: 组件复用
This commit is contained in:
parent
edf7e07f6f
commit
628671d9d9
@ -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(() => {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user