zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
    @name Edo.managers.SystemManager
    @class 
    @single
    @description 组件系统管理器   
    @example 
*/ 
Edo.managers.SystemManager = {
    all: {},    
    /**
        @name Edo.managers.SystemManager#register
        @function
        @static
        @param {Object} cmp 组件对象(所有从Edo.core.Component派生的类对象)        
        @description 将组件加入组件对象池
    */
    register: function(c){        
        if(!c.id) throw new Error("必须保证组件具备id");            
        var o = Edo.managers.SystemManager.all[c.id];
        if(o) throw new Error("已存在id为:"+o.id+"的组件");
        
        Edo.managers.SystemManager.all[c.id] = c;       
        if(c.id == 'window') 
        if(window[c.id]) throw new Error("不能设置此ID:"+o.id);
        window[c.id] = c;
    },
    /**
        @name Edo.managers.SystemManager#unregister
        @function
        @static
        @param {Object} cmp 组件对象(所有从Edo.core.Component派生的类对象)        
        @description 将组件从组件对象池注销
    */
    unregister: function(c){
        delete Edo.managers.SystemManager.all[c.id];
        //if(c == WINDOW[c.id]) WINDOW[c.id] = null;//非常耗性能!
        //WINDOW[c.id] = null;
    },
    /**
        @name Edo.managers.SystemManager#destroy
        @function
        @static        
        @description 销毁所有组件(页面关闭情况等特殊场合使用) 
    */
    destroy: function(c){        
        if(c){
            if(typeof c === 'string') c = Edo.managers.SystemManager.all[c];
            if(c) c.destroy();
        }else{           
            var un = Edo.managers.SystemManager.unregister;
            var all = Edo.managers.SystemManager.all;
            //1)找出所有的topContainer顶级容器
            var tops = [];
            for(var id in all){
                var o = all[id];
                if(!o.parent) tops.push(o);
            }
            var sss = new Date();            
            for(var i=0,l=tops.length; i<l; i++){    
                var o = tops[i];
                if(all[o.id]){
                    o.destroy(true);
                }
            }
            //Binding.clearBind();                        
        }
    },
    /**
        @name Edo.managers.SystemManager#get
        @function
        @static       
        @param {String} id 组件id
        @description 根据id获得组件对象.同Edo.get(id)
    */    
    get: function(id){
        return Edo.managers.SystemManager.all[id];
    },
    /**
        @name Edo.managers.SystemManager#getByName
        @function
        @static       
        @param {String} name 组件name
        @param {Object} parent 父容器.为空表示从全局获取
        @description 从一个父容器下获取所有name命名的组件集合.同Edo.getByName(name, parent)
    */       
    getByName: function(name, parent){
        return Edo.managers.SystemManager.getByProperty('name', name, parent);
    },    
    /**
        @name Edo.managers.SystemManager#getByProperty
        @function
        @static
        @param {String} property 属性名
        @param {Object} value 属性值
        @param {Object} parent 父容器.为空表示从全局获取
        @description 根据某一属性匹配, 获得所有匹配的组件
    */
    getByProperty: function(name, value, parent){  //
        var cs = [];
        var m = Edo.managers.SystemManager;
        var all = m.all;
        for(var id in all){
            var o = all[id];
            if(o[name] == value){
                if(!parent || (parent && m.isAncestor(parent, o))){
                    cs.push(o);
                }
            }
        }
        return cs;
    },
    /**
        @name Edo.managers.SystemManager#getType
        @function
        @static       
        @param {String} type 类别名, 如box,app,text等
        @description 根据类别名获取类对象.同Edo.getType.一般用来创建类的实例,如new Edo.getType('box')
    */         
    getType: function(type){
        return Edo.types[type.toLowerCase()];
    },
    /**
        @name Edo.managers.SystemManager#build
        @function
        @static       
        @param {Object} config 组件配置对象
        @description 根据一个组件配置对象,创建组件实例.同Edo.create, Edo.build
    */          
    build: function(config){
        if(!config) return;
        if(typeof config === 'string') {
            if(Edo.types[config]){
                config = {type: config};
            }
            else{
                //config = styleHandler(config);//
                var swf =  Edo.getParser();
                var o = swf.parserXML(config);
                if(!o.success) throw new Error(o.errorMsg); 
                var config = o.json;
                if(!config.renderTo) config.renderTo = document.body;
            }
        }        
        if(!config.constructor.superclass) {
            var cls = Edo.types[config.type.toLowerCase()];
            if(!cls) throw new Error('组件类未定义');
            var obj = new cls();
            if(obj.set) {
                obj.set(Edo.apply({}, config)); //复制配置对象, 防止配置对象被删除属性, 从而是配置对象的拷贝失效,出问题
            }
            return obj;
        }
        return config;
    },
    //判断p是否是c的父元素    
    isAncestor: function(p, c){
        if(p === c) return true;
        var ret = false;
        while (c = c.parent) {
            ret = c == p;
            if(ret) break;
        }
        return ret;
    }
};
Edo.regCmp = Edo.managers.SystemManager.register;
Edo.unregCmp = Edo.managers.SystemManager.unregister;
Edo.get = Edo.getCmp = Edo.managers.SystemManager.get;
Edo.build = Edo.create = Edo.managers.SystemManager.build;
Edo.getType = Edo.managers.SystemManager.getType;
Edo.getByName = Edo.managers.SystemManager.getByName;
Edo.getByProperty = Edo.managers.SystemManager.getByProperty;
Edo.isAncestor = Edo.managers.SystemManager.isAncestor;