You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
graphResource2/test/makeClass.js

131 lines
2.9 KiB

// | ------------------------------------------------------------
// | @版本: version 0.1
// | @创建人: 【Nie-x7129】
// | @E-mail: x71291@outlook.com
// | @所在项目: graphResource2
// | @文件描述: makeClass.js -
// | @创建时间: 2023-12-03 16:41
// | @更新时间: 2023-12-03 16:41
// | @修改记录:
// | -*-*-*- (时间--修改人--修改说明) -*-*-*-
// | =
// | ------------------------------------------------------------
const obj = {
id: 1,
name: '何希',
age: 25
}
const f1 = {
id: 2,
name: '何希的妈妈',
age: 45
}
const f2 = {
id: 3,
name: '何希的爸爸',
age: 45
}
class resourceClass{
baseInfo;
expandInfo;
fatherObject = {}
constructor(baseInfo, expandInfo = {}) {
this.baseInfo = baseInfo;
this.expandInfo = expandInfo
}
addFather(obj){
this.fatherObject[obj.id] = obj
}
delFather(obj){
delete this.fatherObject[obj.id]
}
get baseInfo(){
return this.baseInfo
}
get expandInfo(){
return this.expandInfo
}
get fatherId(){
return Object.keys(this.fatherObject)
}
get fatherObj(){
return this.fatherObj
}
get fatherList(){
return Object.keys(this.fatherObj).map(i => this.fatherObject[i])
}
}
function makeClass(obj1, obj2 = {}){
return new resourceClass(obj1, obj2)
}
const R1 = makeClass(obj);
const R2 = makeClass(obj);
obj.age++
console.log(R1.baseInfo)
console.log(R1)
console.log(R2.baseInfo)
const resourceCache = {
// 基础数据库信息
baseData:{
// 基础资源类信息
resourceClassList: [],
resourceClassObject:{},
// 拓展资源类信息
resourceClassExpandFieldList: [],
resourceClassExpandFieldObject: {},
// 实体字段信息
resourceEntityStructList: [],
resourceEntityStructObject: {},
// 资源实体信息
resourceEntityList: [],
resourceEntityObject: {},
// 资源类关系信息
resourceClassRelationList: [],
resourceClassRelationObject: {}
},
// 合成资源信息,计算数据
computedData:{
// 资源类完整数据 - 继承于baseData-resourceClassObject
resourceClassObject: {
resourceClassId: {
// 基础资源类信息,查找字典值
baseClassData: {
},
// 拓展资源类信息,查找字典值
expandClassData:{
},
// 资源实体结构转化为对象格式
entityStructData:{
},
// 资源类的父节点,及其关联下的子节点
relationClass:{
fatherId:['childId']
}
}
}
},
// 资源关联信息
relationData:{}
}
// 第一步加载数据库数据