fix: 重构退出按钮
This commit is contained in:
		
							parent
							
								
									6ecd1057fb
								
							
						
					
					
						commit
						20c91c90a9
					
				| @ -8,7 +8,6 @@ | ||||
|  */ | ||||
| import dayTs from '../../utils/Date' | ||||
| import router from '@ohos.router' | ||||
| import Prompt from '@system.prompt' | ||||
| import common from '@ohos.app.ability.common' | ||||
| 
 | ||||
| @Component | ||||
| @ -24,6 +23,10 @@ export default struct HeaderComponent { | ||||
|   // 扩充Logo后面区域 | ||||
|   @BuilderParam | ||||
|   logoExpansionBuilder?: () => void = this.customBuilder | ||||
|   exitDialogController: CustomDialogController = new CustomDialogController({ | ||||
|     builder: exitDialogComponent(), | ||||
|     customStyle: true | ||||
|   }) | ||||
| 
 | ||||
|   @Builder | ||||
|   customBuilder() { | ||||
| @ -84,23 +87,8 @@ export default struct HeaderComponent { | ||||
|               }, router.RouterMode.Single); | ||||
|             }) | ||||
|             Image($r('app.media.btn_back')).height(100).onClick(() => { | ||||
|               Prompt.showDialog({ | ||||
|                 title: "提示", | ||||
|                 message: "确定要退出吗?", | ||||
|                 buttons: [ | ||||
|                   { | ||||
|                     text: '取消', | ||||
|                     color: '#666666' | ||||
|                   }, | ||||
|                   { | ||||
|                     text: '退出', | ||||
|                     color: '#666666' | ||||
|                   } | ||||
|                 ], | ||||
|                 success: () => { | ||||
|                   (getContext(this) as common.UIAbilityContext).terminateSelf() | ||||
|                 } | ||||
|               }) | ||||
|               this.exitDialogController.open() | ||||
| 
 | ||||
|             }) | ||||
|           } | ||||
|         } | ||||
| @ -110,3 +98,61 @@ export default struct HeaderComponent { | ||||
|     .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 | ||||
|     }) | ||||
|   } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								entry/src/main/resources/base/media/nor_btn.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								entry/src/main/resources/base/media/nor_btn.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 34 KiB | 
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user