| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { Autowired } from "../../Bean/Bean"
- import { GlobalSaveData } from "../annotation/DataAnnotation"
- export class SaveUtil {
- protected map: Map<string, any> = new Map
- @Autowired(GlobalSaveData)
- protected globalSaveData: GlobalSaveData
- init(data: any) {
- data = data || {}
- let map = this.globalSaveData.getClassMap()
-
- this.getCompentKey().forEach((key) => {
- let component = this.globalSaveData.unserialize(map.get(key), data[key])
- this.map.set(key, component)
- })
-
- }
- protected getCompentByName(name: string) {
- return this.map.get(name)
- }
- protected getCompentByClass<T>(constructor: new (...args: any[]) => T) {
- let name = this.globalSaveData.getNameByConstructor(constructor)
- return this.map.get(name)
- }
- protected getCompentKey(): string[] {
- return Array.from(this.globalSaveData.getClassMap().keys())
- }
- serialize() {
- let res = {}
- this.getCompentKey().forEach((key) => {
- let component = this.globalSaveData.serialize(this.map.get(key))
- res[key] = component
- })
- return res
- }
- }
- enum saveCompoent {
- }
|