69 lines
1.7 KiB
Plaintext
69 lines
1.7 KiB
Plaintext
@CustomDialog
|
|
export struct SexSelectedSheet {
|
|
controller:CustomDialogController;
|
|
|
|
@State sexNameArr:Array<string> = ['男','女'];
|
|
@Prop selectedSex:number = 0;
|
|
|
|
// 添加回调函数属性
|
|
private sexSelected: (index: number) => void = () => {};
|
|
|
|
// 修改构造函数
|
|
constructor(controller: CustomDialogController, sexSelected: (index: number) => void) {
|
|
super();
|
|
this.controller = controller;
|
|
this.sexSelected = sexSelected;
|
|
}
|
|
|
|
build() {
|
|
Column() {
|
|
// 操作按钮区域
|
|
Row({space:70}) {
|
|
Button('取消')
|
|
.layoutWeight(1)
|
|
.backgroundColor(Color.Transparent)
|
|
.fontColor($r('app.color.main_color'))
|
|
.backgroundColor(Color.White)
|
|
.width(80)
|
|
.onClick(() => {
|
|
this.controller.close()
|
|
})
|
|
|
|
Text('请选择性别')
|
|
.fontSize(15)
|
|
.fontColor('#666666')
|
|
|
|
Button('确定')
|
|
.layoutWeight(1)
|
|
.backgroundColor(Color.Transparent)
|
|
.fontColor($r('app.color.main_color'))
|
|
.backgroundColor(Color.White)
|
|
.width(80)
|
|
.onClick(() => {
|
|
this.controller.close()
|
|
this.sexSelected(this.selectedSex);
|
|
})
|
|
}
|
|
.height(40)
|
|
|
|
TextPicker({
|
|
range:this.sexNameArr,
|
|
})
|
|
.canLoop(false)
|
|
.selectedTextStyle({
|
|
color: '#007AFF',
|
|
font: { size: 20, weight: FontWeight.Medium }
|
|
})
|
|
.onChange((name: string | string[], index: number | number[]) => {
|
|
// 处理单列选择场景
|
|
if (typeof index === "number") {
|
|
this.selectedSex = index;
|
|
}
|
|
})
|
|
}
|
|
.width('100%')
|
|
.height(240)
|
|
.backgroundColor(Color.White)
|
|
}
|
|
}
|