fix: 组件复用
This commit is contained in:
		
							parent
							
								
									edf7e07f6f
								
							
						
					
					
						commit
						628671d9d9
					
				| @ -6,8 +6,6 @@ export default struct ConfirmDialog { | |||||||
|   private controller?: CustomDialogController; |   private controller?: CustomDialogController; | ||||||
|   onConfirm: () => void = () => { |   onConfirm: () => void = () => { | ||||||
|   }; |   }; | ||||||
|   onCancel?: () => void = () => { |  | ||||||
|   }; |  | ||||||
| 
 | 
 | ||||||
|   build() { |   build() { | ||||||
|     Column() { |     Column() { | ||||||
| @ -22,11 +20,7 @@ export default struct ConfirmDialog { | |||||||
|         BtnComponent({ |         BtnComponent({ | ||||||
|           text: "取消", |           text: "取消", | ||||||
|         }).onClick(() => { |         }).onClick(() => { | ||||||
|           if (!this.onCancel) { |           this.controller?.close(); | ||||||
|             this.controller?.close(); |  | ||||||
|             return; |  | ||||||
|           } |  | ||||||
|           this.onCancel && this.onCancel(); |  | ||||||
|         }) |         }) | ||||||
| 
 | 
 | ||||||
|         BtnComponent().onClick(() => { |         BtnComponent().onClick(() => { | ||||||
|  | |||||||
| @ -9,7 +9,7 @@ | |||||||
| import dayTs from '../../utils/Date' | import dayTs from '../../utils/Date' | ||||||
| import router from '@ohos.router' | import router from '@ohos.router' | ||||||
| import common from '@ohos.app.ability.common' | import common from '@ohos.app.ability.common' | ||||||
| import BtnComponent from './Button' | import ConfirmDialog from './ConfirmDialog' | ||||||
| 
 | 
 | ||||||
| @Component | @Component | ||||||
| export default struct HeaderComponent { | export default struct HeaderComponent { | ||||||
| @ -25,7 +25,12 @@ export default struct HeaderComponent { | |||||||
|   @BuilderParam |   @BuilderParam | ||||||
|   logoExpansionBuilder?: () => void = this.customBuilder |   logoExpansionBuilder?: () => void = this.customBuilder | ||||||
|   exitDialogController: CustomDialogController = new CustomDialogController({ |   exitDialogController: CustomDialogController = new CustomDialogController({ | ||||||
|     builder: exitDialogComponent(), |     builder: ConfirmDialog({ | ||||||
|  |       text: "是否确认退出程序?", | ||||||
|  |       onConfirm: () => { | ||||||
|  |         (getContext(this) as common.UIAbilityContext).terminateSelf() | ||||||
|  |       } | ||||||
|  |     }), | ||||||
|     customStyle: true |     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