中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
选择收货地址Button的实现
微信扫码分享
// ChooseAddress.ets import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @Entry @Component struct Index { build() { Row() { Column() { // 声明FunctionalButton FunctionalButton({ params: { // OpenType.CHOOSE_ADDRESS表示Button为选择收货地址类型 openType: functionalButtonComponentManager.OpenType.CHOOSE_ADDRESS, label: '选择收货地址', // 调整Button样式 styleOption: { bgColor: functionalButtonComponentManager.ColorType.DEFAULT, size: functionalButtonComponentManager.SizeType.DEFAULT, plain: false, disabled: false, loading: false, hoverClass: functionalButtonComponentManager.HoverClassType.HOVER_CLASS, hoverStartTime: 0, hoverStayTime: 0, styleConfig: new functionalButtonComponentManager.ButtonConfig() .fontSize(20) .fontColor(Color.Black) } }, // OpenType为“CHOOSE_ADDRESS”时,回调必须选择“onChooseAddress” controller: new functionalButtonComponentManager.FunctionalButtonController() .onChooseAddress((err, data) => { if (err) { // 错误日志处理 hilog.error(0x0000, "testTag", "error: %{public}d %{public}s", err.code, err.message); return; } // 成功日志处理 hilog.info(0x0000, "testTag", "succeeded in choosing address"); // 获取Address info let userName: string = data.userName; let mobileNumber: string = data.mobileNumber as string; let countryCode: string = data.countryCode as string; let provinceName: string = data.provinceName as string; let cityName: string = data.cityName as string; let districtName: string = data.districtName as string; let streetName: string = data.streetName as string; let detailedAddress: string = data.detailedAddress; }) }) }.width('100%') }.height('100%') } }