@cc-component/cc-ex-component 2.0.7 → 2.0.8

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.
@@ -72,6 +72,7 @@ interface ICollectViewEvents {
72
72
  const bindingMap = new Map<any, Map<string, IBindingData>>();
73
73
  const bindingMapFunc = new Map<any, Map<string, string>>();
74
74
  const bindingMapView = new Map<any, { key: string, manager: any }>();
75
+ const bindingMapClick = new Map<any, Map<string, { func: string, subSx: string, subFunc: string }>>();
75
76
 
76
77
  const baseData = 'viewModel'
77
78
  const skip = "func"
@@ -186,6 +187,18 @@ export function Bind<T extends Component>(path?: string, param?: IBindingDataEve
186
187
  bindingMap.get(className)!.set(propertyKey, data);
187
188
  };
188
189
  }
190
+ export function BindClick(propertyName: string, funcName?: string) {
191
+ return function (target: any, propertyKey: string) {
192
+ const className = target.constructor.prototype
193
+ if (!bindingMapClick.has(className)) { bindingMapClick.set(className, new Map()); }
194
+ const data = bindingMapClick.get(className)
195
+ if (!data.has(propertyKey)) { data.set(propertyKey, { func: '', subFunc: '', subSx: '' }) }
196
+ const sub = data.get(propertyKey)
197
+ sub.func = propertyKey
198
+ sub.subSx = `${propertyName}`
199
+ sub.subFunc = `${funcName ?? propertyKey}`
200
+ };
201
+ }
189
202
 
190
203
  export function BindFunc(path?: string) {
191
204
  return function (target: any, propertyKey: string) {
@@ -409,6 +422,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
409
422
  onLoadFinished() {
410
423
  this.refreshFuncName()
411
424
  this.bindData(true)
425
+ this.bindClick();
412
426
  }
413
427
 
414
428
  managerData() {
@@ -424,7 +438,22 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
424
438
  // this.offTouch()
425
439
  }
426
440
 
427
-
441
+ bindClick() {
442
+ const data = bindingMapClick.get(this.className)
443
+ if (data) {
444
+ const self = this;
445
+ for (const [key, value] of data) {
446
+ const subObj = this[value.subSx]
447
+ if (subObj) {
448
+ const oriFunc = this[value.subSx][value.subFunc]
449
+ this[value.subSx][value.subFunc] = function (...args) {
450
+ oriFunc.apply(this, args)
451
+ self[value.func](args)
452
+ }
453
+ }
454
+ }
455
+ }
456
+ }
428
457
  bindData(isBind: boolean) {
429
458
  const name = js.getClassName(this)
430
459
  const managerData = bindingMapView.get(name)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cc-component/cc-ex-component",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "engine": ">=3.8.6",
5
5
  "description": "系统组件添加常用扩展方法",
6
6
  "main": "index.ts",