UI模块添加数据绑定装饰器

1.添加数据基类,子类自动添加代理,数据变化自动通知
 2.支持同属性多装饰器
This commit is contained in:
gongxh
2025-08-29 15:25:10 +08:00
parent b62a4af8db
commit e48011d941
45 changed files with 1354 additions and 21 deletions

View File

@@ -1,24 +0,0 @@
/**
* @Author: Gongxh
* @Date: 2025-02-17
* @Description: 准备一个数据类
*/
import { GlobalEvent } from "kunpocc-event";
export class DataHelper {
private static _data: Map<string, any> = new Map();
public static getValue<T>(key: string, defaultValue: T): T {
if (this._data.has(key)) {
return this._data.get(key) as T;
}
return defaultValue;
}
public static setValue(key: string, value: any): void {
this._data.set(key, value);
/** 数据改变后发送事件 */
GlobalEvent.send(key);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "1bd1aa0a-5c4d-4425-afaa-2a46c0f02a42",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,62 @@
/**
* @Author: Gongxh
* @Date: 2025-08-19
* @Description:
*/
import { kunpo } from "../../header";
export class Level extends kunpo.DataBase {
private _levelid: number = 1;
private _storey: number = 0;
private _ispassed: boolean = false;
private _data: { min: number, max: number } = { min: 1, max: 100 };
constructor() {
super();
}
public get levelid() { return this._levelid; }
public set levelid(lv: number) { this._levelid = lv; }
public get storey() { return this._storey; }
public set storey(storey: number) { this._storey = storey; }
public get ispassed() { return this._ispassed; }
public set ispassed(bool: boolean) { this._ispassed = bool; }
public get data(): { min: number, max: number } { return this._data; }
public set data(data: { min: number, max: number }) { this._data = data; }
public init(data: any) {
this.data = { min: data.min, max: data.max };
this.refreshMin(data.min);
this.refreshMax(data.max);
this.ispassed = data.ispassed;
this.levelid = data.levelid;
this.storey = data.storey;
}
public refreshLevel(lv: number) {
this.levelid = lv;
}
public refreshStorey(storey: number) {
this.storey = storey;
}
public refreshBool(bool: boolean) {
this.ispassed = bool;
}
public refreshMin(min: number) {
this.data.min = min;
}
public refreshMax(max: number) {
this.data.max = max;
}
}

View File

@@ -2,7 +2,7 @@
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "7340bacc-d167-47e8-a83b-2224c46b7fd0",
"uuid": "632daee7-7c2c-4baf-a4dd-d1a12ad91169",
"files": [],
"subMetas": {},
"userData": {}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "3edce213-52a5-403f-b57f-52da9d7bcbce",
"files": [],
"subMetas": {},
"userData": {}
}