2d65cdd1962dfc072a8c3ad8cc9feb8154a8105b.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Component, _decorator, oops, _dec, _class, _crd, ccclass, EventOnAdded, EventOnBeforeRemove, EventOnRemoved, DelegateComponent;
  4. function _reportPossibleCrUseOfoops(extras) {
  5. _reporterNs.report("oops", "../../Oops", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfViewParams(extras) {
  8. _reporterNs.report("ViewParams", "./Defines", _context.meta, extras);
  9. }
  10. return {
  11. setters: [function (_unresolved_) {
  12. _reporterNs = _unresolved_;
  13. }, function (_cc) {
  14. _cclegacy = _cc.cclegacy;
  15. __checkObsolete__ = _cc.__checkObsolete__;
  16. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  17. Component = _cc.Component;
  18. _decorator = _cc._decorator;
  19. }, function (_unresolved_2) {
  20. oops = _unresolved_2.oops;
  21. }],
  22. execute: function () {
  23. _crd = true;
  24. _cclegacy._RF.push({}, "d8f1fGRD7dBzIeBSkOpd/Py", "DelegateComponent", undefined);
  25. /*
  26. * @Author: dgflash
  27. * @Date: 2022-09-01 18:00:28
  28. * @LastEditors: dgflash
  29. * @LastEditTime: 2023-01-09 11:55:03
  30. */
  31. __checkObsolete__(['Component', 'Node', '_decorator']);
  32. ({
  33. ccclass
  34. } = _decorator);
  35. EventOnAdded = "onAdded";
  36. EventOnBeforeRemove = "onBeforeRemove";
  37. EventOnRemoved = "onRemoved";
  38. /** 窗口事件触发组件 */
  39. _export("DelegateComponent", DelegateComponent = (_dec = ccclass('DelegateComponent'), _dec(_class = class DelegateComponent extends Component {
  40. constructor(...args) {
  41. super(...args);
  42. /** 视图参数 */
  43. this.vp = null;
  44. /** 界面关闭回调 - 包括关闭动画播放完(辅助框架内存业务流程使用) */
  45. this.onCloseWindow = null;
  46. }
  47. /** 窗口添加 */
  48. add() {
  49. return new Promise(async (resolve, reject) => {
  50. // 触发窗口组件上添加到父节点后的事件
  51. for (let i = 0; i < this.node.components.length; i++) {
  52. const component = this.node.components[i];
  53. const func = component[EventOnAdded];
  54. if (func) {
  55. if ((await func.call(component, this.vp.params)) == false) {
  56. resolve(false);
  57. return;
  58. }
  59. }
  60. } // 触发外部窗口显示前的事件(辅助实现自定义动画逻辑)
  61. if (typeof this.vp.callbacks.onAdded === "function") {
  62. this.vp.callbacks.onAdded(this.node, this.vp.params);
  63. }
  64. resolve(true);
  65. });
  66. }
  67. /** 删除节点,该方法只能调用一次,将会触发onBeforeRemoved回调 */
  68. remove(isDestroy) {
  69. if (this.vp.valid) {
  70. // 触发窗口移除舞台之前事件
  71. this.applyComponentsFunction(this.node, EventOnBeforeRemove, this.vp.params); // 通知外部对象窗口组件上移除之前的事件(关闭窗口前的关闭动画处理)
  72. if (typeof this.vp.callbacks.onBeforeRemove === "function") {
  73. this.vp.callbacks.onBeforeRemove(this.node, this.onBeforeRemoveNext.bind(this, isDestroy));
  74. } else {
  75. this.removed(this.vp, isDestroy);
  76. }
  77. }
  78. }
  79. /** 窗口关闭前动画处理完后的回调方法,主要用于释放资源 */
  80. onBeforeRemoveNext(isDestroy) {
  81. this.removed(this.vp, isDestroy);
  82. }
  83. /** 窗口组件中触发移除事件与释放窗口对象 */
  84. removed(vp, isDestroy) {
  85. vp.valid = false;
  86. if (vp.callbacks && typeof vp.callbacks.onRemoved === "function") {
  87. vp.callbacks.onRemoved(this.node, vp.params);
  88. } // 界面移除舞台事件
  89. this.onCloseWindow && this.onCloseWindow(vp);
  90. if (isDestroy) {
  91. // 释放界面显示对象
  92. this.node.destroy(); // 释放界面相关资源
  93. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  94. error: Error()
  95. }), oops) : oops).res.release(vp.config.prefab); // oops.log.logView(`【界面管理】释放【${vp.config.prefab}】界面资源`);
  96. } else {
  97. this.node.removeFromParent();
  98. }
  99. }
  100. onDestroy() {
  101. // 触发窗口组件上窗口移除之后的事件
  102. this.applyComponentsFunction(this.node, EventOnRemoved, this.vp.params);
  103. this.vp = null;
  104. }
  105. applyComponentsFunction(node, funName, params) {
  106. for (let i = 0; i < node.components.length; i++) {
  107. const component = node.components[i];
  108. const func = component[funName];
  109. if (func) {
  110. func.call(component, params);
  111. }
  112. }
  113. }
  114. }) || _class));
  115. _cclegacy._RF.pop();
  116. _crd = false;
  117. }
  118. };
  119. });
  120. //# sourceMappingURL=2d65cdd1962dfc072a8c3ad8cc9feb8154a8105b.js.map