@cc-component/cc-ex-component 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -20,7 +20,7 @@ export class BaseReference extends Component {
|
|
|
20
20
|
onLoadFinish() {
|
|
21
21
|
if (this.vmParams) {
|
|
22
22
|
this.viewModel?.refreshUI(this.vmParams)
|
|
23
|
-
|
|
23
|
+
this.vmParams = null
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -32,11 +32,9 @@ export class BaseReference extends Component {
|
|
|
32
32
|
|
|
33
33
|
refreshUI(vmParams: any) {
|
|
34
34
|
this.vmParams = vmParams;
|
|
35
|
-
if (this.vmParams) {
|
|
35
|
+
if (this.vmParams && this.viewModel) {
|
|
36
36
|
this.viewModel?.refreshUI(this.vmParams)
|
|
37
|
-
/// this.vmParams = null
|
|
38
37
|
}
|
|
39
|
-
|
|
40
38
|
}
|
|
41
39
|
protected onDestroy(): void {
|
|
42
40
|
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import { UIOpacity, tween, Vec3 } from 'cc';
|
|
2
2
|
import { _decorator, Component, Node } from 'cc';
|
|
3
3
|
import { BaseReference } from './BaseReference';
|
|
4
|
-
import { Button } from 'cc';
|
|
5
4
|
const { ccclass, property } = _decorator;
|
|
6
5
|
|
|
7
6
|
@ccclass('BaseWindow')
|
|
8
7
|
export class BaseWindow extends BaseReference {
|
|
9
8
|
maskOpacity: UIOpacity;
|
|
10
9
|
root: Node;
|
|
11
|
-
/**关闭事件-当系统级关闭所有打开的界面时。如果关闭界面时需要执行自己的业务逻辑,使用此属性
|
|
12
|
-
* eventName:关闭方法名称
|
|
13
|
-
* param:参数
|
|
14
|
-
*/
|
|
15
|
-
closeEvent: { eventName: string, param?: any };
|
|
16
10
|
/**参数*/
|
|
17
11
|
param: any;
|
|
18
12
|
/**关闭参数 */
|
|
19
13
|
paramClose: { is_anim?: boolean, param?: any, finish?: Function };
|
|
14
|
+
/**ui配置 */
|
|
15
|
+
config: {
|
|
16
|
+
module: string;
|
|
17
|
+
layer: string;
|
|
18
|
+
path: string;
|
|
19
|
+
bundle: string;
|
|
20
|
+
name?: string;/**窗口名称 */
|
|
21
|
+
index?: number;
|
|
22
|
+
is_load_sub?: boolean;
|
|
23
|
+
/**是否记录-不记录可重复打开窗口 */
|
|
24
|
+
is_record?: boolean;
|
|
25
|
+
};
|
|
20
26
|
|
|
21
27
|
protected onLoad(): void {
|
|
22
28
|
this.maskOpacity = this.node.getChildByName('mask')?.getComponent(UIOpacity)
|
|
@@ -76,6 +82,12 @@ export class BaseWindow extends BaseReference {
|
|
|
76
82
|
})
|
|
77
83
|
.start();
|
|
78
84
|
}
|
|
85
|
+
|
|
86
|
+
/**关闭事件-当系统级关闭所有打开的界面时。如果关闭界面时需要执行自己的业务逻辑,重写此方法
|
|
87
|
+
* eventName:关闭方法名称
|
|
88
|
+
* param:参数
|
|
89
|
+
*/
|
|
90
|
+
closeEvent(): { eventName: string, param?: any } { return null }
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
|
|
@@ -205,7 +205,7 @@ export class ReferenceComponent extends Component {
|
|
|
205
205
|
// const com = this.node.components.find(v => { return v.reference })
|
|
206
206
|
// const match = com.name.match(/<([^>]+)>/);
|
|
207
207
|
// const className = match && match[1] ? match[1] : "any"
|
|
208
|
-
const className = this.node.name
|
|
208
|
+
const className = this.node.name.replace('Window', '');
|
|
209
209
|
let data = `${className}Data`
|
|
210
210
|
let iinterface = `I${className}Data`
|
|
211
211
|
//console.error("[MLogger Error]", className)
|
|
@@ -293,7 +293,7 @@ export class ReferenceComponent extends Component {
|
|
|
293
293
|
let text = ""
|
|
294
294
|
let sx_this = ''
|
|
295
295
|
let sx = ''
|
|
296
|
-
const className = this.node.name
|
|
296
|
+
const className = this.node.name.replace('Window', '');
|
|
297
297
|
|
|
298
298
|
let data = `${className}Data`
|
|
299
299
|
let iinterface = `I${className}Data`
|
|
@@ -366,7 +366,7 @@ const { ccclass, property } = _decorator;
|
|
|
366
366
|
let text = `${importStr}\n`
|
|
367
367
|
text += this.genCodeVmData(false)
|
|
368
368
|
const sx = this.genCodeBind(false, true)
|
|
369
|
-
const className = this.node.name
|
|
369
|
+
const className = this.node.name.replace('Window', '');
|
|
370
370
|
|
|
371
371
|
let iinterface = `I${className}Data`
|
|
372
372
|
const onload = `
|
package/assets/core/ViewModel.ts
CHANGED
|
@@ -82,13 +82,11 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
|
|
|
82
82
|
* 重载onload 注入更新
|
|
83
83
|
*/
|
|
84
84
|
target.prototype.onLoad = function () {
|
|
85
|
-
onLoad.call(this);
|
|
86
85
|
const className = target.prototype//js.getClassName(target);
|
|
87
86
|
if (!bindingMap.has(className)) {
|
|
88
87
|
bindingMap.set(className, new Map());
|
|
89
88
|
}
|
|
90
89
|
this.className = className;
|
|
91
|
-
console.log('onLoad我的', this.node.name, this.className)
|
|
92
90
|
if (!this._bindings) this._bindings = [];
|
|
93
91
|
|
|
94
92
|
const map = bindingMap.get(className)
|
|
@@ -109,13 +107,13 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
|
|
|
109
107
|
const data = map.get(propertyKey)
|
|
110
108
|
updateStatus(data, com, value_data, this);
|
|
111
109
|
}
|
|
112
|
-
|
|
113
110
|
// 创建实例并转为响应式
|
|
114
111
|
const vm_data = 'viewModel'
|
|
115
112
|
const instance = new constructor();
|
|
116
113
|
this[vm_data] = this._makeReactive(instance, vm_data);
|
|
117
|
-
|
|
118
114
|
this.onLoadFinish();
|
|
115
|
+
onLoad.call(this);
|
|
116
|
+
|
|
119
117
|
};
|
|
120
118
|
};
|
|
121
119
|
|
|
@@ -203,6 +201,19 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
203
201
|
touch_toggle = 'CALL_TOGGLE_EVENT'
|
|
204
202
|
touch_editbox = 'CALL_EDITBOX_EVENT'
|
|
205
203
|
className: any
|
|
204
|
+
|
|
205
|
+
/**ui配置 */
|
|
206
|
+
config: {
|
|
207
|
+
module: string;
|
|
208
|
+
layer: string;
|
|
209
|
+
path: string;
|
|
210
|
+
bundle: string;
|
|
211
|
+
name?: string;/**窗口名称 */
|
|
212
|
+
index?: number;
|
|
213
|
+
is_load_sub?: boolean;
|
|
214
|
+
/**是否记录-不记录可重复打开窗口 */
|
|
215
|
+
is_record?: boolean;
|
|
216
|
+
};
|
|
206
217
|
// 创建响应式数据
|
|
207
218
|
_makeReactive<T extends object>(obj: T, pathPrefix: string): T {
|
|
208
219
|
const self = this as any;
|
|
@@ -268,12 +279,13 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
268
279
|
|
|
269
280
|
}
|
|
270
281
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
282
|
+
protected onLoad(): void {
|
|
283
|
+
super.onLoad()
|
|
284
|
+
const module = this.config.module;
|
|
285
|
+
const name = this.config.name.replace('Window', '');
|
|
286
|
+
const manager: any = (js.getClassByName(`${module}Manager`))
|
|
287
|
+
manager.Ins[`${name}Data`] = this.viewModel
|
|
288
|
+
}
|
|
277
289
|
// 在 withDataBinding 返回的 class 中
|
|
278
290
|
protected onDestroy(): void {
|
|
279
291
|
this.unbindViewModel();
|