当前位置: 首页 > wzjs >正文

网站的虚拟主机到期深圳网页设计兴田德润i简介

网站的虚拟主机到期,深圳网页设计兴田德润i简介,排版设计模板网站,桂林网站建设《HarmonyOSNext弹窗:ComponentContent动态玩转企业级弹窗》 ##Harmony OS Next ##Ark Ts ##教育 本文适用于教育科普行业进行学习,有错误之处请指出我会修改。 🚫 为啥要抛弃CustomDialogController? 传统CustomDialogControl…

《HarmonyOSNext弹窗:ComponentContent动态玩转企业级弹窗》

##Harmony OS Next ##Ark Ts ##教育

本文适用于教育科普行业进行学习,有错误之处请指出我会修改。


🚫 为啥要抛弃CustomDialogController?

传统CustomDialogController简直像块木头!🤖 不能动态创建不支持实时刷新,在复杂场景里卡到窒息!救星来了——用UIContext家的PromptAction.openCustomDialog(),丝滑到飞起!✈️


🎨 两种姿势玩转openCustomDialog

传参方式灵活性UI耦合度适用场景动态更新支持
ComponentContent 🧩⭐⭐⭐⭐⭐解耦!高度定制化弹窗✅ 可用updateCustomDialog
Builder 🔗⭐⭐绑定上下文想用系统默认风格的懒人模式❌ 不支持

💡 本文重点讲解ComponentContent玩法! Builder党请移步👉 openCustomDialog文档


🎭 弹窗模式自由切换

调参小能手isModal

// true:霸道总裁模态框(必须处理才能点别处)  
// false:佛系非模态框(随便点不拦你)  
{ isModal: true } 

⏳ 弹窗生命周期全监控

弹窗从生到死全记录📝:
1️⃣ onWillAppear → 2️⃣ onDidAppear → 3️⃣ onWillDisappear → 4️⃣ onDidDisappear
像追剧一样掌控每个节点!📺


🪄 弹窗操作三连击

🔮 STEP 1:创建ComponentContent
private contentNode = new ComponentContent(  this.ctx,   wrapBuilder(buildText), // 🧱 封装自定义组件  new Params(this.message) // 🎁 传参可缺省  
);

📌 注意:Params能传基础数据类型

🚪 STEP 2:开窗!
// 默认开启完全自定义样式(customStyle=true)  
PromptActionClass.ctx.getPromptAction()  .openCustomDialog(contentNode, options)  .then(() => console.info('弹窗出道成功!🎉'))  .catch((error: BusinessError) => {  console.error(`翻车代码${error.code}|原因:${error.message}💥`);  });  
STEP 3:关窗+清理内存
PromptActionClass.ctx.getPromptAction()  .closeCustomDialog(contentNode)  .then(() => {  console.info('弹窗杀青~👋');  contentNode?.dispose(); // ♻️ 内存清理必做!  })  .catch((error: BusinessError) => { ... }); // 同上  

⚠️ 重点:在弹窗内关闭需封装静态方法(参考下文完整代码)


🔄 动态更新双攻略

📢 更新内容
this.contentNode.update(new Params('新鲜内容')); // 秒变文案!  
🎛️ 更新属性
// 支持属性:alignment|offset|autoCancel|maskColor  
PromptActionClass.ctx.getPromptAction()  .updateCustomDialog(contentNode, {   alignment: DialogAlignment.Bottom // 立刻沉底!  });  

💣 巨坑预警:未设置的属性会变回默认值!
例:初始设置{ alignment: Top, offset: {dx:0,dy:50} } → 更新{ alignment: Bottom } → offset会消失!


🧩 超完整代码示例

📦 PromptAction封装类
// PromptActionClass.ets  
import { BusinessError, ComponentContent, promptAction } from '@kit.ArkUI';  
import { UIContext } from '@ohos.arkui.UIContext';  export class PromptActionClass {  static ctx: UIContext;  static contentNode: ComponentContent<Object>;  static options: promptAction.BaseDialogOptions;  // 三件套配置法✨  static setContext(context: UIContext) { this.ctx = context; }  static setContentNode(node: ComponentContent<Object>) { this.contentNode = node; }  static setOptions(options: promptAction.BaseDialogOptions) { this.options = options; }  // 一键开窗🚀  static openDialog() {  this.ctx.getPromptAction().openCustomDialog(this.contentNode, this.options)  .then(() => console.info('开窗成功! ✨'))  .catch((error: BusinessError) => this.handleError(error, 'Open'));  }  // 安全关窗🔒  static closeDialog() {  this.ctx.getPromptAction().closeCustomDialog(this.contentNode)  .then(() => console.info('关窗完毕~ 👋'))  .catch((error: BusinessError) => this.handleError(error, 'Close'));  }  // 动态更新🔄  static updateDialog(options: promptAction.BaseDialogOptions) {  this.ctx.getPromptAction().updateCustomDialog(this.contentNode, options)  .then(() => console.info('属性更新! 🎛️'))  .catch((error: BusinessError) => this.handleError(error, 'Update'));  }  // 错误处理统一包📦  private static handleError(error: BusinessError, type: string) {  console.error(`${type}弹窗失败❌|代码${error.code}|原因: ${error.message}`);  }  
}  
🖼️ 页面调用实战
// Index.ets  
import { ComponentContent } from '@kit.ArkUI';  
import { PromptActionClass } from './PromptActionClass';  class Params { text: string = ""; constructor(text: string) { this.text = text; } }  @Builder  
function buildText(params: Params) {  Column() {  Text(params.text).fontSize(50).fontWeight(FontWeight.Bold).margin({ bottom: 36 })  Button('Close').onClick(() => PromptActionClass.closeDialog()) // 关键!调用静态方法  }.backgroundColor('#FFF0F0F0')  
}  @Entry  
@Component  
struct Index {  @State message: string = "初始文案";  private ctx: UIContext = this.getUIContext();  private contentNode: ComponentContent<Object> =   new ComponentContent(this.ctx, wrapBuilder(buildText), new Params(this.message));  aboutToAppear(): void {  // 初始化三件套 🧾  PromptActionClass.setContext(this.ctx);  PromptActionClass.setContentNode(this.contentNode);  PromptActionClass.setOptions({ alignment: DialogAlignment.Top, offset: { dx: 0, dy: 50 } });  }  build() {  Row() {  Column() {  // 按钮1:开窗+改属性  Button("开窗并改属性 🎛️")  .margin({ top: 50 })  .onClick(() => {  PromptActionClass.openDialog();  setTimeout(() => PromptActionClass.updateDialog({  alignment: DialogAlignment.Bottom,  offset: { dx: 0, dy: -50 } // 1.5秒后下沉  }), 1500);  })  // 按钮2:开窗+改内容  Button("开窗并改文案 ✏️")  .margin({ top: 50 })  .onClick(() => {  PromptActionClass.openDialog();  setTimeout(() => this.contentNode.update(  new Params('更新后的酷炫文案!')), 1500); // 1.5秒后换字  })  }.width('100%')  }.height('100%')  }  
}  

💎 精华总结表

功能实现方式注意事项
弹窗创建new ComponentContent()Params传参支持基础类型
开启弹窗openCustomDialog(contentNode)默认开启完全自定义样式
关闭弹窗closeCustomDialog(contentNode)必须调用dispose()释放内存!
更新内容contentNode.update(new Params())避开@Reusable/@Link等装饰器
更新属性updateCustomDialog(options)未设置属性会重置为默认值!

⚡ 闪电技巧包

  1. 内存卫士:关窗后必做.dispose(),否则内存泄漏警告!🚨
  2. 防重置术:更新属性时必须重传所有参数,不然会被系统默认值覆盖!
  3. 解耦大法:用ComponentContent替代Builder,和UI界面离婚成功!💔
  4. 异步更新:在setTimeout中调更新方法,避免阻塞动效⏱️

文章转载自:

http://hjQmmX7G.rgxLL.cn
http://CSgAMIEd.rgxLL.cn
http://rE7AHXQn.rgxLL.cn
http://eI6EL8YY.rgxLL.cn
http://lcb6Gwep.rgxLL.cn
http://WXOOeSIt.rgxLL.cn
http://dnDz6Ulr.rgxLL.cn
http://lfl4Ae5T.rgxLL.cn
http://idgaVV5B.rgxLL.cn
http://PXtfrao9.rgxLL.cn
http://nRsW22vP.rgxLL.cn
http://zAR4aIDI.rgxLL.cn
http://IFk8IgYW.rgxLL.cn
http://sCYDxeEe.rgxLL.cn
http://lcUyHDUT.rgxLL.cn
http://bt3yT43o.rgxLL.cn
http://DDfy0R2o.rgxLL.cn
http://s23aQljr.rgxLL.cn
http://ry3KZCyK.rgxLL.cn
http://zazGJwMc.rgxLL.cn
http://t2LXOG3p.rgxLL.cn
http://P2L28Oa5.rgxLL.cn
http://3NekxEps.rgxLL.cn
http://jp3moc6f.rgxLL.cn
http://CjIQzovK.rgxLL.cn
http://bhCHvDVb.rgxLL.cn
http://QnYnDrT4.rgxLL.cn
http://iTW2Pvn8.rgxLL.cn
http://LFihlFYu.rgxLL.cn
http://pq8AfZAf.rgxLL.cn
http://www.dtcms.com/wzjs/734950.html

相关文章:

  • 正能量网站入口不用下载做运营需要具备什么能力
  • 网站视频主持人制作长沙服务好的网络营销
  • 图书馆 网站开发 总结seo怎么做网站排名
  • 全国哪个餐饮品牌的网站做的好做网站的流程分析-图灵吧
  • 网站建设情况自查报告python代码大全
  • 海城网站制作佛山网站制作系统
  • 网站制作软件排行榜泉州教育网站
  • 宿迁大型三合一网站开发网站建设怎么上传不了图片
  • 哪里有html企业网站模板下载怎样下载网站模版
  • 商品网站建设实验记录怎么做电影流量网站
  • 自建导航站wordpress做网站去除视频广告
  • 网站建设倒计时单页源码长沙专业企业建站联系人
  • 5g云网站建设网页制作平台有
  • 文山市住房和城乡建设局网站wordpress协会主题
  • 网站域名登陆地址做历史卷子的网站
  • 我想阻止一个网站要怎么做dedecms 图片网站模板
  • 天津网站搜索排名优化南京关键词优化服务
  • 网站建设结束语seo站群优化
  • 建设网站前台费用石家庄信息门户网站制作费用
  • 南京网站设计制作虚拟主机专用控制面板
  • 美橙网站建设网站搭建空间
  • 网站设计宽屏尺寸南京前十名传媒广告公司
  • 做婚庆的网站有哪些内容网页设计与制作的原则
  • wordpress创建分站点建设银行网站查询业务收费吗
  • 网站被k表现设计类专业哪个专科学校好
  • 要求维护公司做网站整改的函做网站用到的工具
  • 做网站要买什么类型云空间短视频seo排名
  • 网站建设与维护学什么科目完整网站开发流程
  • 企业网企业网站制作北京互联网公司排名
  • 常德网站优化哪家好制作照片