35380ae2d70e9940a652d7a7c737d1533052fd2c.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, GameComponent, VM, _dec, _dec2, _class, _crd, ccclass, help, executionOrder, VMParent;
  4. function _reportPossibleCrUseOfGameComponent(extras) {
  5. _reporterNs.report("GameComponent", "../../module/common/GameComponent", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfVM(extras) {
  8. _reporterNs.report("VM", "./ViewModel", _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. _decorator = _cc._decorator;
  18. }, function (_unresolved_2) {
  19. GameComponent = _unresolved_2.GameComponent;
  20. }, function (_unresolved_3) {
  21. VM = _unresolved_3.VM;
  22. }],
  23. execute: function () {
  24. _crd = true;
  25. _cclegacy._RF.push({}, "15ccciO+ZRH476sPKD/LvB7", "VMParent", undefined);
  26. __checkObsolete__(['Component', '_decorator']);
  27. ({
  28. ccclass,
  29. help,
  30. executionOrder
  31. } = _decorator);
  32. /**
  33. * 提供VM环境,控制旗下所有VM节点
  34. * 一般用于 非全局的 VM绑定,VM 环境与 组件紧密相连
  35. * (Prefab 模式绑定)
  36. * VMParent 必须必其他组件优先执行
  37. * v0.1 修复bug ,现在可以支持 Parent 嵌套 (但是注意性能问题,不要频繁嵌套)
  38. */
  39. _export("default", VMParent = (_dec = executionOrder(-1), _dec2 = help('https://gitee.com/dgflash/oops-framework/wikis/pages?sort_id=12037729&doc_id=2873565'), ccclass(_class = _dec(_class = _dec2(_class = class VMParent extends (_crd && GameComponent === void 0 ? (_reportPossibleCrUseOfGameComponent({
  40. error: Error()
  41. }), GameComponent) : GameComponent) {
  42. constructor() {
  43. super(...arguments);
  44. /** 绑定的标签,可以通过这个tag 获取 当前的 vm 实例 */
  45. this.tag = '_temp';
  46. /** 需要绑定的私有数据 */
  47. this.data = {};
  48. /**VM 管理 */
  49. this.VM = _crd && VM === void 0 ? (_reportPossibleCrUseOfVM({
  50. error: Error()
  51. }), VM) : VM;
  52. }
  53. /**
  54. * [注意]不能直接覆盖此方法,如果需要覆盖。
  55. * 只能在该方法内部调用父类的实现
  56. * ```ts
  57. * onLoad(){
  58. * super.onLoad();
  59. * }
  60. * ```
  61. *
  62. */
  63. onLoad() {
  64. if (this.data == null) return;
  65. this.tag = '_temp' + '<' + this.node.uuid.replace('.', '') + '>';
  66. (_crd && VM === void 0 ? (_reportPossibleCrUseOfVM({
  67. error: Error()
  68. }), VM) : VM).add(this.data, this.tag); // log(VM['_mvs'],this.tag)
  69. //搜寻所有节点:找到 watch path
  70. var comps = this.getVMComponents(); // console.group();
  71. for (var i = 0; i < comps.length; i++) {
  72. var comp = comps[i];
  73. this.replaceVMPath(comp, this.tag);
  74. } // console.groupEnd()
  75. this.onBind();
  76. }
  77. /**在 onLoad 完成 和 start() 之前调用,你可以在这里进行初始化数据等操作 */
  78. onBind() {}
  79. /**在 onDestroy() 后调用,此时仍然可以获取绑定的 data 数据*/
  80. onUnBind() {}
  81. replaceVMPath(comp, tag) {
  82. // @ts-ignore
  83. var path = comp['watchPath']; // @ts-ignore
  84. if (comp['templateMode'] == true) {
  85. // @ts-ignore
  86. var pathArr = comp['watchPathArr'];
  87. if (pathArr) {
  88. for (var i = 0; i < pathArr.length; i++) {
  89. var _path = pathArr[i];
  90. pathArr[i] = _path.replace('*', tag);
  91. }
  92. }
  93. } else {
  94. // VMLabel
  95. // 遇到特殊 path 就优先替换路径
  96. if (path.split('.')[0] === '*') {
  97. // @ts-ignore
  98. comp['watchPath'] = path.replace('*', tag);
  99. }
  100. }
  101. }
  102. /** 未优化的遍历节点,获取VM 组件 */
  103. getVMComponents() {
  104. var comps = this.node.getComponentsInChildren('VMBase');
  105. var parents = this.node.getComponentsInChildren('VMParent').filter(v => v.uuid !== this.uuid); // 过滤掉自己
  106. //过滤掉不能赋值的parent
  107. var filters = [];
  108. parents.forEach(node => {
  109. filters = filters.concat(node.getComponentsInChildren('VMBase'));
  110. });
  111. comps = comps.filter(v => filters.indexOf(v) < 0);
  112. return comps;
  113. }
  114. /**
  115. * [注意]不能覆盖此方法,如果需要覆盖。
  116. * 需要在该方法内部调用父类的实现,再定义自己的方法
  117. * ```ts
  118. * onDestroy(){
  119. * super.onDestroy();
  120. * }
  121. * ```
  122. */
  123. onDestroy() {
  124. this.onUnBind(); // 解除全部引用
  125. (_crd && VM === void 0 ? (_reportPossibleCrUseOfVM({
  126. error: Error()
  127. }), VM) : VM).remove(this.tag);
  128. this.data = null;
  129. super.onDestroy();
  130. }
  131. }) || _class) || _class) || _class));
  132. _cclegacy._RF.pop();
  133. _crd = false;
  134. }
  135. };
  136. });
  137. //# sourceMappingURL=35380ae2d70e9940a652d7a7c737d1533052fd2c.js.map