feat:提交
This commit is contained in:
28
tests/dev1/dataHandle/models/config.ts
Normal file
28
tests/dev1/dataHandle/models/config.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 配置基类,下划线开头的变量不会被序列化
|
||||
*/
|
||||
export class ConfigBase {
|
||||
name: string = '';
|
||||
version:string = '1.0.0';
|
||||
[key: string]: any;
|
||||
|
||||
/**
|
||||
* 加载反序列化数据
|
||||
* @param data
|
||||
*/
|
||||
load(data:Record<string,unknown>){
|
||||
for (const key of Object.getOwnPropertyNames(this).filter(i=>i[0]!=='_')) {
|
||||
if(data[key]!=undefined){
|
||||
this[key] = data[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化json方法
|
||||
* @returns
|
||||
*/
|
||||
toJson(){
|
||||
return JSON.stringify(this,(k,v)=>k[0]=='_'?undefined:v);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user