material-dialogs三方框架获取值
使用material-dialogs弹窗,选择了一个item,获取到选择的值在组件外的类中方法onSelected中,怎么把选择的值传给组件中的sex?代码如下:
import { TopNavigationView } from '@ohos/uicomponents/Index';
import { router } from '@kit.ArkUI';
import UserManager from '@ohos/datastory/src/main/ets/datasource/userdata/UserManager';
import { getTeacherSelfInfo } from '../model/AccountMagNetModel';
import { Logger } from '@ohos/utils/Index';
import { CustomDialog1, showToast } from '@ohos/base/Index';
import { GetTeacherDataBean } from '../entity/GetTeacherSelfInfoModel';
import { AccountMagItem } from '../components/AccountMagItem';
import { ClickCallback, DialogAttributeModel, MaterialDialog,
SingleChoiceListener } from '@ohos/material-dialogs';
/***
* 账号管理
*/
@Entry({ routeName: 'AccountMagPage' })
@Component
export struct AccountMagPage {
@State avatarImage: ResourceStr = $r("app.media.head_image")
@State name: string | undefined = ''
@State sex: ResourceStr = $r("app.string.man")
@State identity: ResourceStr = $r("app.string.parent")
@State loginAccount: ResourceStr = ''
@State organizInfo: ResourceStr = ''
@State bindWeChat: ResourceStr = $r('app.string.unbind')
isTeacher = false
@State teacherData: GetTeacherDataBean | undefined = undefined
model: MaterialDialog.Model = new MaterialDialog.Model();
dialogAttribute = new DialogAttributeModel()
@State items: string[] = ['男', '女']
private listenser:SingleChoiceListener = new SingleChoiceListener1()
existDialog() {
this.dialogController.close()
}
dialogController: CustomDialogController = new CustomDialogController({
builder: MaterialDialog({
model: this.model, dialogAttribute: this.dialogAttribute
}),
cancel: this.existDialog,
autoCancel: true,
alignment: DialogAlignment.Center,
customStyle: true
})
aboutToAppear(): void {
this.getAvatarImage();
this.getTeacherInfo();
}
/**
*家长和老师端修改个人信息详情
*/
private getTeacherInfo() {
getTeacherSelfInfo().then(
(data) => {
this.teacherData = data;
this.sex = data.sex
this.identity = data.shenfen
this.loginAccount = data.zhanghao
}
).catch((error: string) => {
Logger.error('changePwd:' + error);
showToast(error);
});
}
/**
*获取基础信息
*/
private getAvatarImage() {
this.name = UserManager.getUserInfo()?.name;
this.isTeacher = UserManager.isTeacher();
if (this.isTeacher) {
const teacherInfo = UserManager.getTeacherInfo();
this.organizInfo = `${teacherInfo.schoolname}/${teacherInfo.gradename}/${teacherInfo.classname}`;
let key = "headerImage/xxx/xxx" + UserManager.getUserInfo()?.UserId + ".jpeg";
const aa: number = Math.floor(Math.random() * 99999999);
this.avatarImage = "http://www.huawei.com/" + key + "?" + aa;
} else {
const studentInfo = UserManager.getStudentInfo();
this.organizInfo = `${studentInfo.schoolName}/${studentInfo.gradeName}/${studentInfo.className}`;
this.avatarImage = studentInfo.headUrl;
}
}
build() {
Scroll() {
Column() {
TopNavigationView({
title: $r('app.string.accountManagement'),
onBackClick: () => {
router.back()
}
})
Column() {
this.textImgItem($r('app.string.avatar'), this.avatarImage)
Divider()
AccountMagItem({
leftText: $r('app.string.name'),
rightText: this.name
})
if (this.sex) {
Divider()
AccountMagItem({
leftText: $r('app.string.sex'),
rightText: this.sex,
rightImg: $r('app.media.qianjin')
}).onClick(() => {
//弹出dialog
this.model.reset()
this.model.listItemsSingleChoice(this.items, 2, true, null, -1, -1, this.listenser)
this.model.positiveButton($r("app.string.sure"), Callback('', 0))
this.model.negativeButton($r("app.string.cancel"), Callback('', 1))
this.model.setStacked(false)
this.dialogController.open()
})
}
Divider()
AccountMagItem({
leftText: $r('app.string.identity'),
rightText: this.identity,
})
AccountMagItem({
leftText: $r('app.string.loginAccount'),
rightText: this.loginAccount,
}).margin({
top: 5
})
this.textOtherGray(5, $r('app.string.organizational'), $r('app.string.more'))
AccountMagItem({
leftText: this.organizInfo,
})
AccountMagItem({
leftText: $r('app.string.infoUpdate'),
rightImg: $r('app.media.qianjin')
}).margin({
top: 15
}).onClick(() => {
})
Divider()
AccountMagItem({
leftText: $r('app.string.bindWeChat'),
rightText: this.bindWeChat,
rightImg: $r('app.media.qianjin')
}).onClick(() => {
})
Button($r('app.string.sign_out'), { type: ButtonType.Capsule, stateEffect: true })
.width('80%')
.height(48)
.backgroundColor($r('app.color.color_primary'))
.margin({
top: 50
})
.onClick(() => {
//TODO:退出账号
})
}
.height('100%')
.width('100%')
.backgroundColor('#cae7e2e2')
}
.height('100%')
.width('100%')
}
}
@Builder
textOtherGray(id: number, leftText: ResourceStr, rightText?: ResourceStr, rightImg?: ResourceStr) {
Row() {
Text(leftText).fontColor(Color.Grey)
Blank();
if (rightText) {
Text(rightText)
.fontColor(Color.Green)
.margin({
right: 10
})
}
if (rightImg) {
Image(rightImg)
.objectFit(ImageFit.Contain)
.width($r('app.float.list_image_margin_right'))
.height($r('app.float.list_image_margin_right'))
}
}
.height(48)
.width('100%')
.alignItems(VerticalAlign.Center)
.padding({
left: 20,
right: 20
})
.onClick(() => {
})
}
@Builder
textImgItem(leftText: ResourceStr, rightImg: ResourceStr) {
Row() {
Text(leftText);
Blank();
Image(rightImg)
.width(60)
.height(60)
.borderRadius(100)
.clip(new Circle({ width: 60, height: 60 }));
}
.height(65)
.width('100%')
.alignItems(VerticalAlign.Center)
.backgroundColor('#ffffff')
.padding({
left: 20,
right: 20
})
.onClick(() => {
})
}
}
class SingleChoiceListener1 implements SingleChoiceListener {
onSelected(value: string, index: number) {
}
}
function Callback(value1: string, type: number): ClickCallback {
let back: ClickCallback = new ClickCallback1(value1, type)
return back
}
class ClickCallback1 implements ClickCallback {
value1: string = ''
type: number = 0
onClick(value?: string) {
if (this.type === 0) {
console.info(this.value1)
} else if (this.type === 1) {
console.info('ClickCallback when the confirm button is clicked')
} else if (this.type === 2) {
} else {
console.info('ClickCallback when the confirm button is clicked')
}
}
constructor(value: string, type: number) {
this.value1 = value
this.type = type
}
}
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
图片剪切的第三方框架
228浏览 • 1回复 待解决
HarmonyOS 依赖的三方框架cordova需要HarmonyOS化
48浏览 • 1回复 待解决
HarmonyOS RN三方框架已经支持了哪些三方库?有没有一个总览?
202浏览 • 1回复 待解决
HarmonyOS 三方框架@ohos/mqtt各个方法如何判断成功
466浏览 • 1回复 待解决
三方框架支持上传到我们自己的仓库吗?
247浏览 • 1回复 待解决
npm上的三方框架如何自行转换为HarmonyOS可以使用的
454浏览 • 1回复 待解决
js开发能引入vant或element-ui 等第三方框架么?
8115浏览 • 1回复 已解决
使用HarmonyOS框架调用Cronet三方库使用问题
1308浏览 • 2回复 待解决
三方的js框架如何移植适配到HarmonyOS中
339浏览 • 0回复 待解决
如何获取可用的三方库
1769浏览 • 1回复 待解决
三方应用如何获取蓝牙mac地址
2253浏览 • 1回复 待解决
三方应用如何获取http代理信息
1762浏览 • 1回复 待解决
鸿蒙有哪些支持的第三方UI框架吗?
3588浏览 • 1回复 待解决
HarmonyOS har包依赖三方库,三方库中的so,无法找到
517浏览 • 1回复 待解决
【三方库移植】怎么在OpneHarmony标准系统上移植三方库
6306浏览 • 1回复 待解决
Retrofit这个开源三方库对应的HarmonyOS三方库地址是什么?
444浏览 • 1回复 待解决
三方应用使用蓝牙功能
991浏览 • 1回复 待解决
鸿蒙宣称欢迎手机三方加入鸿蒙系统?
请问大概多久才可以让三方加入?
8848浏览 • 2回复 待解决
三方相机预览demo开发
891浏览 • 1回复 待解决
HarmonyOS 希望支持三方库WebViewJavascriptBridge
476浏览 • 1回复 待解决
实现弹幕功能的三方库
1090浏览 • 1回复 待解决
图片缓存磁盘,系统是否有图片缓存磁盘的能力或框架,或者有什么推荐的三方图片框架?
221浏览 • 1回复 待解决
第三方应用怎么获取应用签名证书的hash值
2018浏览 • 1回复 待解决
native交叉编译第三方库
210浏览 • 1回复 待解决
开发第三方SDK如何编译?
13544浏览 • 2回复 待解决
请参考以下代码: