@cc-component/cc-ex-component 1.4.1 → 1.4.3

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
- // this.vmParams = null
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)
@@ -225,19 +225,19 @@ export class ReferenceComponent extends Component {
225
225
  let name = key[0].toLowerCase() + key.substring(1);
226
226
  const type = this.getPropertyType(data.com)
227
227
  let bind_pix = `@Bind`
228
- let event = `,{ event: (self:${className}) => { } }`
228
+ let event = `,{ event: (this:${className}) => { } }`
229
229
  if (type === "YXCollectionView") {
230
230
  event = `, {
231
- layout: (self:${className}) => {
231
+ layout: (this:${className}) => {
232
232
  const layout = new YXFlowLayout();
233
233
  layout.horizontalSpacing = 10;
234
234
  layout.verticalSpacing = 20;
235
235
  layout.itemSize = () => math.size(100, 100);
236
236
  return layout;
237
237
  },
238
- cellForItemAt: (self:${className}, indexPath, collectionView) => {
238
+ cellForItemAt: (this:${className}, indexPath, collectionView) => {
239
239
  const node = collectionView.dequeueReusableCell("cell", indexPath);
240
- //node.getComponent(TableVIewItem).refreshUI(self.viewModel.${name}[indexPath.row])
240
+ //node.getComponent(TableVIewItem).refreshUI(this.viewModel.${name}[indexPath.row])
241
241
  return node;
242
242
  },
243
243
  }`
@@ -246,9 +246,9 @@ export class ReferenceComponent extends Component {
246
246
  } else if (type === "TableView") {
247
247
  event = `, {
248
248
  itemSize: () => math.size(100, 100),
249
- cellForItemAt: (self:${className}, indexPath, collectionView) => {
249
+ cellForItemAt: (this:${className}, indexPath, collectionView) => {
250
250
  const node = collectionView.dequeueReusableCell("cell", indexPath)
251
- //node.getComponent(TableVIewItem).refreshUI(self.viewModel.${name}[indexPath.row])
251
+ //node.getComponent(TableVIewItem).refreshUI(this.viewModel.${name}[indexPath.row])
252
252
  return node
253
253
  },
254
254
  }`
@@ -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 = `
@@ -432,7 +432,7 @@ export class ${className} extends ViewModel(${this.baseWindowName}) {${sx.text}\
432
432
  const typeMap: Record<string, string> = {
433
433
  'Label': 'string',
434
434
  'RichText': 'string',
435
- 'Sprite': 'SpriteFrame',
435
+ 'Sprite': 'SpriteFrame | { bundle: string, path: string }',
436
436
  'Button': 'boolean', // Button 通常绑定激活状态(true/false)
437
437
  'ProgressBar': 'number', // 进度条应为 number (0~1)
438
438
  'Skeleton': 'sp.SkeletonData',
@@ -17,6 +17,7 @@ import { math } from 'cc';
17
17
  import { YXCollectionView, YXIndexPath } from '../lib/collectView/lib_collect/yx-collection-view';
18
18
  import { EventTouch } from 'cc';
19
19
  import { YXPagelayout } from '../lib/collectView/lib_collect/yx-page-layout';
20
+ import { SpriteFrame } from 'cc';
20
21
 
21
22
  interface IBindingData extends ITableViewEvents, IBindingDataEvents {
22
23
  dataPath: string;
@@ -28,32 +29,35 @@ interface IBindingData extends ITableViewEvents, IBindingDataEvents {
28
29
 
29
30
 
30
31
  interface IBindingDataEvents {
31
- reset?: (self: any, value: any, com: Component) => void;
32
- event?: (self: any) => void;
33
- touchStart?: (self: any, event: EventTouch) => void;
34
- touchMove?: (self: any, event: EventTouch) => void;
35
- touchEnd?: (self: any, event: EventTouch) => void;
36
- touchCancel?: (self: any, event: EventTouch) => void;
32
+ reset?: (this: any, value: any, com: Component) => void;
33
+ event?: (this: any) => void;
34
+ /**动态加载spine的 sp.SkeletonData完成 */
35
+ spineFinish?: (this: any) => void;
36
+ touchStart?: (this: any, event: EventTouch) => void;
37
+ touchMove?: (this: any, event: EventTouch) => void;
38
+ touchEnd?: (this: any, event: EventTouch) => void;
39
+ touchCancel?: (this: any, event: EventTouch) => void;
40
+
37
41
  }
38
42
 
39
43
 
40
44
  interface ITableViewEvents {
41
45
  /**列表相关 */
42
- itemSize: (self: any) => Size,
43
- cellForItemAt: (self: any, indexPath: IIndexPath, collectionView: ListView) => Node,
44
- onTouchCellAt?: (self: any, indexPath: IIndexPath) => void
45
- numberOfItems?: (self: any) => number;
46
- moveFinish?: (self: any, indexPath: IIndexPath) => void
46
+ itemSize: (this: any) => Size,
47
+ cellForItemAt: (this: any, indexPath: IIndexPath, collectionView: ListView) => Node,
48
+ onTouchCellAt?: (this: any, indexPath: YXIndexPath) => void
49
+ numberOfItems?: (this: any) => number;
50
+ moveFinish?: (this: any, indexPath: IIndexPath) => void
47
51
 
48
52
  }
49
53
 
50
54
  interface ICollectViewEvents {
51
55
  /**列表相关 */
52
- layout: (self: any) => YXFlowLayout,
53
- cellForItemAt: (self: any, indexPath: YXIndexPath, collectionView: YXCollectionView) => Node
54
- itemSize?: ((self: any, indexPath: YXIndexPath, layout: YXFlowLayout, collectionView: YXCollectionView) => math.Size),
55
- onTouchCellAt?: (self: any, indexPath: YXIndexPath) => void
56
- numberOfItems?: ((self: any, section: number, collectionView: YXCollectionView) => number);
56
+ layout: (this: any) => YXFlowLayout,
57
+ cellForItemAt: (this: any, indexPath: YXIndexPath, collectionView: YXCollectionView) => Node
58
+ itemSize?: ((this: any, indexPath: YXIndexPath, layout: YXFlowLayout, collectionView: YXCollectionView) => math.Size),
59
+ onTouchCellAt?: (this: any, indexPath: YXIndexPath) => void
60
+ numberOfItems?: ((this: any, section: number, collectionView: YXCollectionView) => number);
57
61
  }
58
62
 
59
63
  // 全局存储绑定关系: { className -> { uiProp: dataPath } }
@@ -82,13 +86,11 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
82
86
  * 重载onload 注入更新
83
87
  */
84
88
  target.prototype.onLoad = function () {
85
- onLoad.call(this);
86
89
  const className = target.prototype//js.getClassName(target);
87
90
  if (!bindingMap.has(className)) {
88
91
  bindingMap.set(className, new Map());
89
92
  }
90
93
  this.className = className;
91
- console.log('onLoad我的', this.node.name, this.className)
92
94
  if (!this._bindings) this._bindings = [];
93
95
 
94
96
  const map = bindingMap.get(className)
@@ -109,13 +111,13 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
109
111
  const data = map.get(propertyKey)
110
112
  updateStatus(data, com, value_data, this);
111
113
  }
112
-
113
114
  // 创建实例并转为响应式
114
115
  const vm_data = 'viewModel'
115
116
  const instance = new constructor();
116
117
  this[vm_data] = this._makeReactive(instance, vm_data);
117
-
118
118
  this.onLoadFinish();
119
+ onLoad.call(this);
120
+
119
121
  };
120
122
  };
121
123
 
@@ -137,6 +139,7 @@ export function Bind<T extends Component>(path?: string, param?: IBindingDataEve
137
139
  itemSize: null,
138
140
  cellForItemAt: null,
139
141
  numberOfItems: null,
142
+ spineFinish: param?.spineFinish,
140
143
  touchStart: param?.touchStart,
141
144
  touchMove: param?.touchMove,
142
145
  touchEnd: param?.touchEnd,
@@ -203,6 +206,19 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
203
206
  touch_toggle = 'CALL_TOGGLE_EVENT'
204
207
  touch_editbox = 'CALL_EDITBOX_EVENT'
205
208
  className: any
209
+
210
+ /**ui配置 */
211
+ config: {
212
+ module: string;
213
+ layer: string;
214
+ path: string;
215
+ bundle: string;
216
+ name?: string;/**窗口名称 */
217
+ index?: number;
218
+ is_load_sub?: boolean;
219
+ /**是否记录-不记录可重复打开窗口 */
220
+ is_record?: boolean;
221
+ };
206
222
  // 创建响应式数据
207
223
  _makeReactive<T extends object>(obj: T, pathPrefix: string): T {
208
224
  const self = this as any;
@@ -268,12 +284,15 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
268
284
 
269
285
  }
270
286
 
271
- // protected onLoad(): void {
272
- // super.onLoad()
273
- // console.error('打印名称', js.getClassName(this))
274
- // const className = js.getClassName(this)
275
- // // ecs.getSingleton()
276
- // }
287
+ protected onLoad(): void {
288
+ super.onLoad()
289
+ if (this.config) {
290
+ const module = this.config.module;
291
+ const name = this.config.name.replace('Window', '');
292
+ const manager: any = (js.getClassByName(`${module}Manager`))
293
+ manager.Ins[`${name}Data`] = this.viewModel
294
+ }
295
+ }
277
296
  // 在 withDataBinding 返回的 class 中
278
297
  protected onDestroy(): void {
279
298
  this.unbindViewModel();
@@ -358,7 +377,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
358
377
  const btnCall = (btn) => {
359
378
  tempData.value = btn.node.active
360
379
  self.viewModel[sx] = tempData
361
- data.event?.(self)
380
+ data.event?.call(self)
362
381
  self[`onClick_${sx}`]?.(btn)
363
382
  }
364
383
  com_btn[touch_click] = btnCall
@@ -369,7 +388,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
369
388
  if (data.touchStart && !com_btn[touch_start]) {
370
389
  com_btn.node.off(Node.EventType.TOUCH_START, com_btn[touch_start]);
371
390
  const call_start = (btn) => {
372
- data.touchStart?.(self, btn)
391
+ data.touchStart?.call(self, btn)
373
392
  }
374
393
  com_btn[touch_start] = call_start
375
394
  com_btn.node.on(Node.EventType.TOUCH_START, com_btn[touch_start]);
@@ -378,7 +397,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
378
397
  if (data.touchMove && !com_btn[touch_start]) {
379
398
  com_btn.node.off(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
380
399
  const call_start = (btn) => {
381
- data.touchMove?.(self, btn)
400
+ data.touchMove?.call(self, btn)
382
401
  }
383
402
  com_btn[touch_start] = call_start
384
403
  com_btn.node.on(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
@@ -387,7 +406,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
387
406
  if (data.touchEnd && !com_btn[touch_start]) {
388
407
  com_btn.node.off(Node.EventType.TOUCH_END, com_btn[touch_start]);
389
408
  const call_start = (btn) => {
390
- data.touchEnd?.(self, btn)
409
+ data.touchEnd?.call(self, btn)
391
410
  }
392
411
  com_btn[touch_start] = call_start
393
412
  com_btn.node.on(Node.EventType.TOUCH_END, com_btn[touch_start]);
@@ -396,7 +415,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
396
415
  if (data.touchCancel && !com_btn[touch_start]) {
397
416
  com_btn.node.off(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
398
417
  const call_start = (btn) => {
399
- data.touchCancel?.(self, btn)
418
+ data.touchCancel?.call(self, btn)
400
419
  }
401
420
  com_btn[touch_start] = call_start
402
421
  com_btn.node.on(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
@@ -413,7 +432,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
413
432
  const slideCall = (slider) => {
414
433
  tempData.value = slider.progress
415
434
  self.viewModel[sx] = tempData
416
- data.event?.(self)
435
+ data.event?.call(self)
417
436
  self[`onClick_${sx}`]?.(slider)
418
437
  }
419
438
  com_btn[touch_click] = slideCall
@@ -431,7 +450,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
431
450
  const toggleCall = (toggle) => {
432
451
  tempData.value = toggle.isChecked
433
452
  self.viewModel[sx] = tempData
434
- data.event?.(self)
453
+ data.event?.call(self)
435
454
  self[`onClick_${sx}`]?.(toggle)
436
455
  }
437
456
  com_btn[touch_click] = toggleCall
@@ -449,7 +468,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
449
468
  const ebCall = (editbox: EditBox) => {
450
469
  tempData.value = editbox.textLabel.string
451
470
  self.viewModel[sx] = tempData
452
- data.event?.(self)
471
+ data.event?.call(self)
453
472
  self[`onClick_${sx}`]?.(editbox)
454
473
  }
455
474
  com_btn[touch_click] = ebCall
@@ -468,14 +487,14 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
468
487
  switch (data.type) {
469
488
  case 'cc.Label':
470
489
  if (data.reset) {
471
- data.reset(self, value, com);
490
+ data.reset.call(self, value, com);
472
491
  } else {
473
492
  if (value != undefined && value !== null) (com as Label).string = value?.toString() || '';
474
493
  }
475
494
  break;
476
495
  case 'cc.RichText':
477
496
  if (data.reset) {
478
- data.reset(self, value, com);
497
+ data.reset.call(self, value, com);
479
498
  } else
480
499
  if (value != undefined && value !== null)
481
500
  (com as RichText).string = value?.toString() || '';
@@ -484,34 +503,59 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
484
503
  // 假设 value 是 SpriteFrame 路径或资源
485
504
  // 需要额外处理资源加载逻辑
486
505
  if (data.reset) {
487
- data.reset(self, value, com);
506
+ data.reset.call(self, value, com);
488
507
  } else
489
- if (value != undefined && value !== null) (com as Sprite).spriteFrame = value;
508
+ if (value != undefined && value !== null) {
509
+ if (value instanceof SpriteFrame)
510
+ (com as Sprite).spriteFrame = value;
511
+ else {
512
+ const data = ExComponentModule.EmitGetSprite(value)
513
+ if (data) (com as Sprite).spriteFrame = data;
514
+ else {
515
+ ExComponentModule.EmitLoadSprite(value).then(sprite => { if (com && com.isValid) (com as Sprite).spriteFrame = sprite; }).catch(() => { });
516
+ }
517
+ }
518
+ }
490
519
  break;
491
520
  case 'cc.Button':
492
521
  const com_btn = (com as Button);
493
522
  if (data.reset) {
494
- data.reset(self, value, com);
523
+ data.reset.call(self, value, com);
495
524
  } else
496
525
  com_btn.node.active = value ?? true;
497
526
  break;
498
527
  case 'cc.ProgressBar':
499
528
  if (data.reset) {
500
- data.reset(self, value, com);
529
+ data.reset.call(self, value, com);
501
530
  } else
502
531
  if (value != undefined && value !== null) (com as ProgressBar).progress = Number(value) || 0;
503
532
  break;
504
- case 'cc.Skeleton':
533
+ case 'sp.Skeleton':
505
534
  if (data.reset) {
506
- data.reset(self, value, com);
535
+ data.reset.call(self, value, com);
507
536
  } else
508
- if (value != undefined && value !== null) (com as sp.Skeleton).skeletonData = value
537
+ if (value != undefined && value !== null)
538
+ if (value instanceof sp.SkeletonData)
539
+ (com as sp.Skeleton).skeletonData = value
540
+ else {
541
+ const dataSpine = ExComponentModule.EmitGetSpine(value)
542
+ if (dataSpine) {
543
+ (com as sp.Skeleton).skeletonData = value;
544
+ data.spineFinish.call(self)
545
+ }
546
+ else {
547
+ ExComponentModule.EmitLoadSpine(value).then(sprite => {
548
+ if (sprite) { if (com && com.isValid) (com as sp.Skeleton).skeletonData = sprite; }
549
+ data.spineFinish.call(self)
550
+ }).catch(() => { });
551
+ }
552
+ }
509
553
  break;
510
554
  case 'cc.Slider':
511
555
  {
512
556
  const com_sld = (com as Slider);
513
557
  if (data.reset) {
514
- data.reset(self, value, com);
558
+ data.reset.call(self, value, com);
515
559
  } else
516
560
  if (value != undefined && value !== null) com_sld.progress = Number(value) || 0;
517
561
  }
@@ -520,7 +564,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
520
564
  {
521
565
  const com_tg = (com as Toggle);
522
566
  if (data.reset) {
523
- data.reset(self, value, com);
567
+ data.reset.call(self, value, com);
524
568
  } else
525
569
  if (value != undefined && value !== null) com_tg.isChecked = Boolean(value);
526
570
  }
@@ -529,7 +573,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
529
573
  {
530
574
  const com_eb = (com as EditBox);
531
575
  if (data.reset) {
532
- data.reset(self, value, com);
576
+ data.reset.call(self, value, com);
533
577
  } else
534
578
  if (value != undefined && value !== null) com_eb.string = value?.toString() || '';
535
579
  }
@@ -538,7 +582,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
538
582
  {
539
583
  const com_tgc = (com as ToggleContainer);
540
584
  if (data.reset) {
541
- data.reset(self, value, com);
585
+ data.reset.call(self, value, com);
542
586
  }
543
587
  //事件
544
588
  if (com_tgc.checkEvents.length <= 0) {
@@ -552,7 +596,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
552
596
  tempData.skip = true;
553
597
  tempData.value = com_tgc.toggleItems.indexOf(toggle)
554
598
  self.viewModel[sx] = tempData
555
- data.event?.(self)
599
+ data.event?.call(self)
556
600
  self[`onClick_${sx}`]?.(toggle)
557
601
  }
558
602
  com_tgc.checkEvents.push(clickEventHandler);
@@ -568,7 +612,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
568
612
  {
569
613
 
570
614
  const com_list = (com as TableView);
571
- if (data.reset) { data.reset(self, value, com); }
615
+ if (data.reset) { data.reset.call(self, value, com); }
572
616
 
573
617
  // ✅ 关键:不要缓存 count,而是通过 dataPath 动态取值
574
618
  const getLatestDataLength = () => {
@@ -580,19 +624,19 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
580
624
  com_list.reload()
581
625
  } else {
582
626
  const cellForItemAt = (indexPath: IIndexPath, collectionView: ListView) => {
583
- return data.cellForItemAt(self, indexPath, collectionView);
627
+ return data.cellForItemAt.call(self, indexPath, collectionView);
584
628
  }
585
629
  const numberOfItems = () => {
586
630
  return getLatestDataLength()
587
631
  }
588
632
  const itemSize = () => {
589
- return data.itemSize(self)
633
+ return data.itemSize.call(self)
590
634
  }
591
635
  const moveFinish = (indexPath: IIndexPath) => {
592
- data.moveFinish?.(self, indexPath)
636
+ data.moveFinish?.call(self, indexPath)
593
637
  }
594
638
  const onTouchCellAt = (indexPath: IIndexPath) => {
595
- data.onTouchCellAt?.(self, indexPath)
639
+ data.onTouchCellAt?.call(self, indexPath)
596
640
  }
597
641
 
598
642
  const classView = { cellForItemAt, numberOfItems, itemSize, moveFinish, onTouchCellAt }
@@ -631,7 +675,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
631
675
  // 确定列表内一共需要显示多少条内容
632
676
  // table_collection.isCenterShow = false;//少于宽度,居中显示
633
677
  table_collection.numberOfItems = () => {
634
- const count = data.numberOfItems ? data.numberOfItems(self) : getLatestDataLength()
678
+ const count = data.numberOfItems ? data.numberOfItems.call(self) : getLatestDataLength()
635
679
  if (table_collection.layout instanceof YXPagelayout) {
636
680
  table_collection.layout.dataCount = count
637
681
  return count * 3
@@ -640,13 +684,13 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
640
684
  }
641
685
  }
642
686
  table_collection.cellForItemAt = (indexPath, collectionView) => {
643
- return data.cellForItemAt(self, indexPath, collectionView as any) // 返回这个节点给列表显示
687
+ return data.cellForItemAt.call(self, indexPath, collectionView as any) // 返回这个节点给列表显示
644
688
  }
645
689
 
646
690
  table_collection.onTouchCellAt = (indexPath, collectionView) => {
647
691
  // 通过 getVisibleNode 获取到点击的节点
648
692
  //const cell = collectionView.getVisibleCellNode(indexPath)
649
- data.onTouchCellAt?.(self, indexPath)
693
+ data.onTouchCellAt?.call(self, indexPath)
650
694
  }
651
695
  table_collection.onCellDisplay = (cell, indexPath) => { }
652
696
  table_collection.onCellEndDisplay = (cell, indexPath) => { }
@@ -675,3 +719,4 @@ export function Ref(target: any, propertyKey: string) {
675
719
  const refList = refMap.get(target)
676
720
  refList.push(propertyKey)
677
721
  }
722
+
@@ -1,3 +1,5 @@
1
+ import { sp } from "cc";
2
+ import { SpriteFrame } from "cc";
1
3
  import { Button } from "cc";
2
4
 
3
5
 
@@ -11,6 +13,9 @@ export class ExComponentModule {
11
13
  }
12
14
 
13
15
  param: { click: (comp: Button) => void }
16
+ paramSprite: { loadSprite: (param: { bundle: string, path: string }) => Promise<SpriteFrame>, getSprite: (param: { bundle: string, path: string }) => SpriteFrame }
17
+ paramSpine: { loadSpine: (param: { bundle: string, path: string }) => Promise<sp.SkeletonData>, getSpine: (param: { bundle: string, path: string }) => sp.SkeletonData }
18
+
14
19
  ResetBaseWindow: string = "BaseWindow";
15
20
  static Init() {
16
21
 
@@ -19,16 +24,38 @@ export class ExComponentModule {
19
24
  static OnButtonClick(param: { click: (comp: Button) => void }) {
20
25
  ExComponentModule.Ins.param = param
21
26
  }
22
- static Emit(btn: Button) {
23
- ExComponentModule.Ins.param.click(btn)
24
- }
27
+
25
28
 
26
29
  static ResetBaseWindow(name?: string, isGet?: boolean) {
27
30
  if (!isGet) ExComponentModule.Ins.ResetBaseWindow = name
28
31
  return ExComponentModule.Ins.ResetBaseWindow
29
32
  }
30
33
 
34
+ static OnLoadSprite(param: { loadSprite: (param: { bundle: string, path: string }) => Promise<SpriteFrame>, getSprite: (param: { bundle: string, path: string }) => SpriteFrame }) {
35
+ ExComponentModule.Ins.paramSprite = param
36
+ }
37
+ static OnLoadSpine(param: { loadSpine: (param: { bundle: string, path: string }) => Promise<sp.SkeletonData>, getSpine: (param: { bundle: string, path: string }) => sp.SkeletonData }) {
38
+ ExComponentModule.Ins.paramSpine = param
39
+ }
31
40
 
41
+
42
+ static Emit(btn: Button) {
43
+ ExComponentModule.Ins.param.click(btn)
44
+ }
45
+
46
+ static async EmitLoadSprite(param: any): Promise<SpriteFrame> {
47
+ return ExComponentModule.Ins.paramSprite.loadSprite(param)
48
+ }
49
+ static EmitGetSprite(param: any): SpriteFrame {
50
+ return ExComponentModule.Ins.paramSprite.getSprite(param)
51
+ }
52
+
53
+ static async EmitLoadSpine(param: any): Promise<sp.SkeletonData> {
54
+ return ExComponentModule.Ins.paramSpine.loadSpine(param)
55
+ }
56
+ static EmitGetSpine(param: any): sp.SkeletonData {
57
+ return ExComponentModule.Ins.paramSpine.getSpine(param)
58
+ }
32
59
  }
33
60
  window.ExComponentModule = ExComponentModule;
34
61
 
@@ -1,3 +1,6 @@
1
+ import { SpriteFrame } from "cc";
2
+ import { sp } from "cc";
3
+ import { Sprite } from "cc";
1
4
  import { Button } from "cc";
2
5
  declare global {
3
6
  namespace ExComponentModule {
@@ -5,9 +8,18 @@ declare global {
5
8
  function Init();
6
9
  /**监听所有按钮的点击事件 */
7
10
  function OnButtonClick(param: { click: (comp: Button) => void });
11
+ /**监听加载图片 */
12
+ function OnLoadSprite(param: { loadSprite: (param: { bundle: string, path: string }) => Promise<SpriteFrame>, getSprite: (param: { bundle: string, path: string }) => SpriteFrame });
13
+ function OnLoadSpine(param: { loadSpine: (param: { bundle: string, path: string }) => Promise<sp.SkeletonData>, getSpine: (param: { bundle: string, path: string }) => sp.SkeletonData });
14
+ /**重置基础窗口 */
8
15
  function ResetBaseWindow(name?: string, isGet?: boolean);
9
16
  /**组件:内部使用方法 */
10
17
  function Emit(btn: Button);
11
18
 
19
+ //#region 组件:内部使用方法----------------
20
+ function EmitLoadSprite(param: any): Promise<SpriteFrame>;
21
+ function EmitGetSprite(param: any): SpriteFrame;
22
+ function EmitLoadSpine(param: any): Promise<sp.SkeletonData>;
23
+ function EmitGetSpine(param: any): sp.SkeletonData;
12
24
  }
13
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cc-component/cc-ex-component",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "engine": ">=3.8.6",
5
5
  "description": "系统组件添加常用扩展方法",
6
6
  "main": "index.ts",