@cc-component/cc-ex-component 1.4.0 → 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
|
@@ -57,10 +57,10 @@ interface ICollectViewEvents {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// 全局存储绑定关系: { className -> { uiProp: dataPath } }
|
|
60
|
-
const bindingMap = new Map<
|
|
60
|
+
const bindingMap = new Map<any, Map<string, IBindingData>>();
|
|
61
61
|
const baseData = 'viewModel'
|
|
62
62
|
const skip = "$"
|
|
63
|
-
export const refMap: Map<
|
|
63
|
+
export const refMap: Map<any, string[]> = new Map();
|
|
64
64
|
|
|
65
65
|
// const comType = {
|
|
66
66
|
// "cc.Sprite": typeof Sprite,
|
|
@@ -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
|
-
|
|
86
|
-
const className = js.getClassName(target);
|
|
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)
|
|
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
|
|
|
@@ -130,7 +128,7 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
|
|
|
130
128
|
export function Bind<T extends Component>(path?: string, param?: IBindingDataEvents) {
|
|
131
129
|
const dataPath = baseData + '.' + path;
|
|
132
130
|
return function (target: any, propertyKey: string) {
|
|
133
|
-
const className =
|
|
131
|
+
const className = target.constructor.prototype
|
|
134
132
|
const data: IBindingData = {
|
|
135
133
|
propertyKey: propertyKey,
|
|
136
134
|
dataPath: dataPath, type: className, reset: param?.reset, event: param?.event,
|
|
@@ -152,7 +150,7 @@ export function Bind<T extends Component>(path?: string, param?: IBindingDataEve
|
|
|
152
150
|
export function BindTable<T extends Component>(dataPath: string, param?: ITableViewEvents) {
|
|
153
151
|
dataPath = baseData + '.' + dataPath;
|
|
154
152
|
return function (target: any, propertyKey: string) {
|
|
155
|
-
const className =
|
|
153
|
+
const className = target
|
|
156
154
|
const data: IBindingData = {
|
|
157
155
|
propertyKey: propertyKey,
|
|
158
156
|
|
|
@@ -171,8 +169,7 @@ export function BindTable<T extends Component>(dataPath: string, param?: ITableV
|
|
|
171
169
|
export function BindCollect<T extends Component>(dataPath: string, param?: ICollectViewEvents) {
|
|
172
170
|
dataPath = baseData + '.' + dataPath;
|
|
173
171
|
return function (target: any, propertyKey: string) {
|
|
174
|
-
const className =
|
|
175
|
-
|
|
172
|
+
const className = target
|
|
176
173
|
const data: IBindingData = {
|
|
177
174
|
propertyKey: propertyKey,
|
|
178
175
|
dataPath: dataPath, type: null,
|
|
@@ -203,7 +200,20 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
203
200
|
touch_slide = 'CALL_SLIDE_EVENT'
|
|
204
201
|
touch_toggle = 'CALL_TOGGLE_EVENT'
|
|
205
202
|
touch_editbox = 'CALL_EDITBOX_EVENT'
|
|
206
|
-
className:
|
|
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
|
+
};
|
|
207
217
|
// 创建响应式数据
|
|
208
218
|
_makeReactive<T extends object>(obj: T, pathPrefix: string): T {
|
|
209
219
|
const self = this as any;
|
|
@@ -251,7 +261,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
251
261
|
if (fullPath === dataPath) {
|
|
252
262
|
const com = this[uiProp]
|
|
253
263
|
if (com) {
|
|
254
|
-
const classname =
|
|
264
|
+
const classname = this.constructor.prototype
|
|
255
265
|
const data = bindingMap.get(classname).get(uiProp)
|
|
256
266
|
const value = this._getNestedValue(this, data.dataPath);
|
|
257
267
|
updateStatus(data, com, value, this)
|
|
@@ -269,6 +279,13 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
269
279
|
|
|
270
280
|
}
|
|
271
281
|
|
|
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
|
+
}
|
|
272
289
|
// 在 withDataBinding 返回的 class 中
|
|
273
290
|
protected onDestroy(): void {
|
|
274
291
|
this.unbindViewModel();
|
|
@@ -666,8 +683,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
|
|
|
666
683
|
|
|
667
684
|
// 定义装饰器
|
|
668
685
|
export function Ref(target: any, propertyKey: string) {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
const refList = refMap.get(className)
|
|
686
|
+
if (!refMap.has(target)) { refMap.set(target, []) }
|
|
687
|
+
const refList = refMap.get(target)
|
|
672
688
|
refList.push(propertyKey)
|
|
673
689
|
}
|