87 lines
1.5 KiB
TypeScript
87 lines
1.5 KiB
TypeScript
/**
|
|
* 数据类基类
|
|
* 提供数据类的生命周期管理和基础功能
|
|
*/
|
|
export class BaseData {
|
|
|
|
/** 是否已初始化 */
|
|
protected _isInitialized: boolean = false;
|
|
|
|
/** 是否已销毁 */
|
|
protected _isDestroyed: boolean = false;
|
|
|
|
/** 数据ID */
|
|
protected _dataId: string = '';
|
|
|
|
/**
|
|
* 构造方法
|
|
*/
|
|
constructor() {
|
|
|
|
}
|
|
|
|
/**
|
|
* 初始化数据
|
|
* @param dataId 数据ID
|
|
*/
|
|
public init(dataId?: string): void{
|
|
if (this._isInitialized) return;
|
|
this._isInitialized = true;
|
|
if (dataId) {
|
|
this._dataId = dataId;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 重置数据到初始状态
|
|
*/
|
|
public reset(): void{
|
|
|
|
}
|
|
|
|
/**
|
|
* 清空数据内容
|
|
*/
|
|
public clear(): void{
|
|
|
|
}
|
|
|
|
/**
|
|
* 销毁数据对象
|
|
*/
|
|
public destroy(): void{
|
|
if (this._isDestroyed) return;
|
|
this.clear();
|
|
this._isDestroyed = true;
|
|
this._isInitialized = null;
|
|
this._dataId = null;
|
|
}
|
|
|
|
/**
|
|
* 获取数据ID
|
|
*/
|
|
public getDataId(): string {
|
|
return this._dataId;
|
|
}
|
|
|
|
/**
|
|
* 设置数据ID
|
|
*/
|
|
public setDataId(dataId: string): void {
|
|
this._dataId = dataId;
|
|
}
|
|
|
|
/**
|
|
* 是否已初始化
|
|
*/
|
|
public isInitialized(): boolean {
|
|
return this._isInitialized;
|
|
}
|
|
|
|
/**
|
|
* 是否已销毁
|
|
*/
|
|
public isDestroyed(): boolean {
|
|
return this._isDestroyed;
|
|
}
|
|
}
|