bf2251979269335b2d9d2521c0a9c0b4c698c65f.js 5.8 KB

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