Jelajahi Sumber

Merge branch 'cherry-pick-28060bec' into 'develop'

Merge branch 'fix/CMS_Portal_View_dict' into 'develop'

See merge request o2oa/o2oa!1571
蔡祥熠 5 tahun lalu
induk
melakukan
32dec84861

+ 286 - 14
o2web/source/o2_core/o2/xScript/CMSEnvironment.js

@@ -1546,7 +1546,164 @@ MWF.xScript.CMSJSONData = function(data, callback, key, parent){
 //        this.destory = this["delete"];
 //    }
 //};
-var dictLoaded = {};
+
+if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
+
+MWF.xScript.addDictToCache = function ( options, path, json ) {
+    if( !path )path = "root";
+    if( path.indexOf("root") !== 0 )path = "root." + path ;
+
+    var type = options.appType || "process";
+    var enableAnonymous = options.enableAnonymous || false;
+
+    var appFlagList = [];
+    if( options.application )appFlagList.push( options.application );
+    if( options.appId )appFlagList.push( options.appId );
+    if( options.appName )appFlagList.push( options.appName );
+    if( options.appAlias )appFlagList.push( options.appAlias );
+
+    var dictFlagList = [];
+    if( options.id )dictFlagList.push( options.id );
+    if( options.name )dictFlagList.push( options.name );
+    if( options.alias )dictFlagList.push( options.alias );
+
+    var cache = {};
+    cache[path] = json;
+
+    for( var i=0; i<appFlagList.length; i++ ){
+        for( var j=0; j<dictFlagList.length; j++ ){
+            var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
+            if( !MWF.xScript.dictLoaded[k] ){
+                MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
+                // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
+            }else if( i===0 && j===0 ){
+                MWF.xScript.setDictToCache( k, path ,json );
+                var arr = path.split(/\./g);
+                var p;
+                var cache = MWF.xScript.dictLoaded[k];
+                for( var l=0 ; l<arr.length; l++ ){
+                    p = l === 0 ? arr[0] : ( p + "." + arr[l] );
+                    if( cache[ p ] )break;
+                }
+                if( p ){
+                    var mathP = p+".";
+                    Object.keys( cache ).each( function( path, idx){
+                        if( path.indexOf( mathP ) === 0 )delete cache[path];
+                    })
+                }
+            }
+        }
+    }
+};
+
+MWF.xScript.getMatchedDict = function(key, path){
+    if( !path )path = "root";
+    if( path.indexOf("root") !== 0 )path = "root." + path ;
+
+    var arr = path.split(/\./g);
+    if( MWF.xScript.dictLoaded[key] ){
+        var dicts = MWF.xScript.dictLoaded[key];
+        var list = Array.clone(arr);
+        var p;
+        var dict;
+        for( var i=0 ; i<arr.length; i++ ){
+            p = i === 0 ? arr[0] : ( p + "." + arr[i] );
+            list.shift();
+            if( dicts[ p ] ){
+                dict = dicts[ p ];
+                break;
+            }
+        }
+        return {
+            dict : dict,
+            unmatchedPathList : list
+        }
+    }
+    return {
+        dict : null,
+        unmatchedPathList : list
+    }
+};
+
+MWF.xScript.insertDictToCache = function(key, path, json){
+    if( MWF.xScript.dictLoaded[key] ){
+        var matchedDict = MWF.xScript.getMatchedDict( key, path );
+        var dict = matchedDict.dict;
+        var list = matchedDict.unmatchedPathList;
+        if( !dict ){
+            MWF.xScript.dictLoaded[key][path] = json;
+        }else{
+            for( var j=0; j<list.length-1; j++ ){
+                if( !dict[ list[j] ] ){
+                    dict[ list[j] ] = {};
+                }
+                dict = dict[ list[j] ];
+            }
+            var lastPath = list[list.length-1];
+            if( !dict[lastPath] ){
+                dict[lastPath] = json;
+            }else if( typeOf( dict[lastPath] ) === "array" ){
+                dict[lastPath].push( json );
+            }
+        }
+    }else{
+        MWF.xScript.dictLoaded[key] = {};
+        MWF.xScript.dictLoaded[key][path] = json;
+    }
+};
+
+
+MWF.xScript.setDictToCache = function(key, path, json){
+    if( MWF.xScript.dictLoaded[key] ){
+        var matchedDict = MWF.xScript.getMatchedDict( key, path );
+        var dict = matchedDict.dict;
+        var list = matchedDict.unmatchedPathList;
+        if( !dict ){
+            MWF.xScript.dictLoaded[key][path] = json;
+        }else{
+            for( var j=0; j<list.length-1; j++ ){
+                if( !dict[ list[j] ] ){
+                    dict[ list[j] ] = {};
+                }
+                dict = dict[ list[j] ];
+            }
+            dict[list[list.length-1]] = json;
+        }
+    }else{
+        MWF.xScript.dictLoaded[key] = {};
+        MWF.xScript.dictLoaded[key][path] = json;
+    }
+};
+
+MWF.xScript.getDictFromCache = function( key, path ){
+    var matchedDict = MWF.xScript.getMatchedDict( key, path );
+    var dict = matchedDict.dict;
+    var list = matchedDict.unmatchedPathList;
+    if( dict ){
+        for( var j=0; j<list.length; j++ ){
+            dict = dict[ list[j] ];
+            if( !dict )return null;
+        }
+        return dict;
+    }
+    return null;
+};
+
+MWF.xScript.deleteDictToCache = function(key, path){
+    var matchedDict = MWF.xScript.getMatchedDict( key, path );
+    var dict = matchedDict.dict;
+    var list = matchedDict.unmatchedPathList;
+
+    if( dict){
+        for( var j=0; j<list.length-1; j++ ){
+            dict = dict[ list[j] ];
+            if( !dict )return;
+        }
+        delete dict[list[list.length-1]];
+    }
+};
+
+
 MWF.xScript.createCMSDict = function(application){
     //optionsOrName : {
     //  type : "", //默认为process, 可以为  process  cms
@@ -1565,9 +1722,16 @@ MWF.xScript.createCMSDict = function(application){
         var applicationId = options.application || application;
         var enableAnonymous = options.enableAnonymous || false;
 
-        var key = name+type+applicationId+enableAnonymous
-        if (!dictLoaded[key]) dictLoaded[key] = {};
-        this.dictData = dictLoaded[key];
+        var opt = {
+            "appType" : type,
+            "name" : name,
+            "appId" : applicationId,
+            "enableAnonymous" : enableAnonymous
+        };
+
+        var key = name+type+applicationId+enableAnonymous;
+        // if (!dictLoaded[key]) dictLoaded[key] = {};
+        // this.dictData = dictLoaded[key];
 
         //MWF.require("MWF.xScript.Actions.DictActions", null, false);
         if( type == "cms" ){
@@ -1586,29 +1750,31 @@ MWF.xScript.createCMSDict = function(application){
 
         this.get = function(path, success, failure, async, refresh){
             var value = null;
-            if (path){
-                if ( !refresh && this.dictData[path] ){
-                    if (success) success(this.dictData[path]);
-                    return this.dictData[path];
+            if (!refresh ){
+                var data = MWF.xScript.getDictFromCache( key, path );
+                if( data ){
+                    if (success) success( data );
+                    return data;
                 }
+            }
+
+            if (path){
 
                 var p = encodePath( path );
                 //var p = path.replace(/\./g, "/");
                 action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
                     value = json.data;
-                    this.dictData[path] = value;
+                    // this.dictData[path] = value;
+                    MWF.xScript.addDictToCache(opt, path, value);
                     if (success) success(json.data);
                 }.bind(this), function(xhr, text, error){
                     if (failure) failure(xhr, text, error);
                 }, !!async, false);
             }else{
-                if (this.dictData["root"]){
-                    if (success) success(this.dictData["root"]);
-                    return this.dictData["root"];
-                }
                 action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
                     value = json.data;
-                    this.dictData["root"] = value;
+                    // this.dictData["root"] = value;
+                    MWF.xScript.addDictToCache(opt, path, value);
                     if (success) success(json.data);
                 }.bind(this), function(xhr, text, error){
                     if (failure) failure(xhr, text, error);
@@ -1622,6 +1788,7 @@ MWF.xScript.createCMSDict = function(application){
             var p = encodePath( path );
             //var p = path.replace(/\./g, "/");
             action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
+                MWF.xScript.setDictToCache(key, path, value);
                 if (success) success(json.data);
             }, function(xhr, text, error){
                 if (failure) failure(xhr, text, error);
@@ -1631,6 +1798,7 @@ MWF.xScript.createCMSDict = function(application){
             var p = encodePath( path );
             //var p = path.replace(/\./g, "/");
             action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
+                MWF.xScript.insertDictToCache(key, path, value);
                 if (success) success(json.data);
             }, function(xhr, text, error){
                 if (failure) failure(xhr, text, error);
@@ -1640,6 +1808,7 @@ MWF.xScript.createCMSDict = function(application){
             var p = encodePath( path );
             //var p = path.replace(/\./g, "/");
             action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
+                MWF.xScript.deleteDictToCache(key, path);
                 if (success) success(json.data);
             }, function(xhr, text, error){
                 if (failure) failure(xhr, text, error);
@@ -1649,6 +1818,109 @@ MWF.xScript.createCMSDict = function(application){
     }
 };
 
+// var dictLoaded = {};
+// MWF.xScript.createCMSDict = function(application){
+//     //optionsOrName : {
+//     //  type : "", //默认为process, 可以为  process  cms
+//     //  application : "", //流程/CMS的名称/别名/id, 默认为当前应用
+//     //  name : "", // 数据字典名称/别名/id
+//     //  enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
+//     //}
+//     //或者name: "" // 数据字典名称/别名/id
+//     return function(optionsOrName){
+//         var options = optionsOrName;
+//         if( typeOf( options ) == "string" ){
+//             options = { name : options };
+//         }
+//         var name = this.name = options.name;
+//         var type = ( options.type && options.application ) ?  options.type : "cms";
+//         var applicationId = options.application || application;
+//         var enableAnonymous = options.enableAnonymous || false;
+//
+//         var key = name+type+applicationId+enableAnonymous
+//         if (!dictLoaded[key]) dictLoaded[key] = {};
+//         this.dictData = dictLoaded[key];
+//
+//         //MWF.require("MWF.xScript.Actions.DictActions", null, false);
+//         if( type == "cms" ){
+//             var action = MWF.Actions.get("x_cms_assemble_control");
+//         }else{
+//             var action = MWF.Actions.get("x_processplatform_assemble_surface");
+//         }
+//
+//         var encodePath = function( path ){
+//             var arr = path.split(/\./g);
+//             var ar = arr.map(function(v){
+//                 return encodeURIComponent(v);
+//             });
+//             return ar.join("/");
+//         };
+//
+//         this.get = function(path, success, failure, async, refresh){
+//             var value = null;
+//             if (path){
+//                 if ( !refresh && this.dictData[path] ){
+//                     if (success) success(this.dictData[path]);
+//                     return this.dictData[path];
+//                 }
+//
+//                 var p = encodePath( path );
+//                 //var p = path.replace(/\./g, "/");
+//                 action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
+//                     value = json.data;
+//                     this.dictData[path] = value;
+//                     if (success) success(json.data);
+//                 }.bind(this), function(xhr, text, error){
+//                     if (failure) failure(xhr, text, error);
+//                 }, !!async, false);
+//             }else{
+//                 if (this.dictData["root"]){
+//                     if (success) success(this.dictData["root"]);
+//                     return this.dictData["root"];
+//                 }
+//                 action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
+//                     value = json.data;
+//                     this.dictData["root"] = value;
+//                     if (success) success(json.data);
+//                 }.bind(this), function(xhr, text, error){
+//                     if (failure) failure(xhr, text, error);
+//                 }, !!async);
+//             }
+//
+//             return value;
+//         };
+//
+//         this.set = function(path, value, success, failure){
+//             var p = encodePath( path );
+//             //var p = path.replace(/\./g, "/");
+//             action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
+//                 if (success) success(json.data);
+//             }, function(xhr, text, error){
+//                 if (failure) failure(xhr, text, error);
+//             }, false, false);
+//         };
+//         this.add = function(path, value, success, failure){
+//             var p = encodePath( path );
+//             //var p = path.replace(/\./g, "/");
+//             action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
+//                 if (success) success(json.data);
+//             }, function(xhr, text, error){
+//                 if (failure) failure(xhr, text, error);
+//             }, false, false);
+//         };
+//         this["delete"] = function(path, success, failure){
+//             var p = encodePath( path );
+//             //var p = path.replace(/\./g, "/");
+//             action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
+//                 if (success) success(json.data);
+//             }, function(xhr, text, error){
+//                 if (failure) failure(xhr, text, error);
+//             }, false, false);
+//         };
+//         this.destory = this["delete"];
+//     }
+// };
+
 // MWF.xScript.createCMSDict = function(application){
 //     //optionsOrName : {
 //     //  type : "", //默认为cms, 可以为  process  cms

+ 1 - 32
o2web/source/o2_core/o2/xScript/Environment.js

@@ -1643,37 +1643,12 @@ MWF.xScript.JSONData = function(data, callback, key, parent, _form){
 //    }
 //};
 // var dictLoaded = {};
-MWF.xScript.dictLoaded = {};
+if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
 
 MWF.xScript.addDictToCache = function ( options, path, json ) {
-
-    debugger;
-
-    // if( !key ){
-    //     var name = options.name || options.id || options.alias;
-    //     var type = options.appType || "process";
-    //     var application = options.appName || options.appId || options.application || options.appAlias;
-    //     var enableAnonymous = options.enableAnonymous || false;
-    //     key = name+type+application+enableAnonymous;
-    // }
-
     if( !path )path = "root";
     if( path.indexOf("root") !== 0 )path = "root." + path ;
 
-    // if( MWF.xScript.dictLoaded[key] ){
-    //     var dicts = MWF.xScript.dictLoaded[key];
-    //     var arr = path.split(/\./g);
-    //     var p;
-    //     for( var i=0 ; i<arr.length; i++ ){
-    //         p = i === 0 ? arr[0] : ( p + "." + arr[i] );
-    //         if( dicts[ p ] )return; //如果上级路径存在,则返回
-    //     }
-    // }
-
-    // if( MWF.xScript.dictLoaded[key] && MWF.xScript.dictLoaded[key][path]){
-    //     MWF.xScript.dictLoaded[key][path] = json;
-    //     return;
-    // }
     var type = options.appType || "process";
     var enableAnonymous = options.enableAnonymous || false;
 
@@ -1718,9 +1693,6 @@ MWF.xScript.addDictToCache = function ( options, path, json ) {
 };
 
 MWF.xScript.getMatchedDict = function(key, path){
-
-    debugger;
-
     if( !path )path = "root";
     if( path.indexOf("root") !== 0 )path = "root." + path ;
 
@@ -1800,7 +1772,6 @@ MWF.xScript.setDictToCache = function(key, path, json){
 };
 
 MWF.xScript.getDictFromCache = function( key, path ){
-    debugger;
     var matchedDict = MWF.xScript.getMatchedDict( key, path );
     var dict = matchedDict.dict;
     var list = matchedDict.unmatchedPathList;
@@ -1815,8 +1786,6 @@ MWF.xScript.getDictFromCache = function( key, path ){
 };
 
 MWF.xScript.deleteDictToCache = function(key, path){
-
-    debugger;
     var matchedDict = MWF.xScript.getMatchedDict( key, path );
     var dict = matchedDict.dict;
     var list = matchedDict.unmatchedPathList;

+ 286 - 14
o2web/source/o2_core/o2/xScript/PageEnvironment.js

@@ -1359,7 +1359,164 @@ MWF.xScript.JSONData = function(data, callback, key, parent, _form){
     var type = typeOf(data);
     if (type==="object" || type==="array") define.apply(this);
 };
-var dictLoaded = {};
+
+if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
+
+MWF.xScript.addDictToCache = function ( options, path, json ) {
+    if( !path )path = "root";
+    if( path.indexOf("root") !== 0 )path = "root." + path ;
+
+    var type = options.appType || "process";
+    var enableAnonymous = options.enableAnonymous || false;
+
+    var appFlagList = [];
+    if( options.application )appFlagList.push( options.application );
+    if( options.appId )appFlagList.push( options.appId );
+    if( options.appName )appFlagList.push( options.appName );
+    if( options.appAlias )appFlagList.push( options.appAlias );
+
+    var dictFlagList = [];
+    if( options.id )dictFlagList.push( options.id );
+    if( options.name )dictFlagList.push( options.name );
+    if( options.alias )dictFlagList.push( options.alias );
+
+    var cache = {};
+    cache[path] = json;
+
+    for( var i=0; i<appFlagList.length; i++ ){
+        for( var j=0; j<dictFlagList.length; j++ ){
+            var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
+            if( !MWF.xScript.dictLoaded[k] ){
+                MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
+                // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
+            }else if( i===0 && j===0 ){
+                MWF.xScript.setDictToCache( k, path ,json );
+                var arr = path.split(/\./g);
+                var p;
+                var cache = MWF.xScript.dictLoaded[k];
+                for( var l=0 ; l<arr.length; l++ ){
+                    p = l === 0 ? arr[0] : ( p + "." + arr[l] );
+                    if( cache[ p ] )break;
+                }
+                if( p ){
+                    var mathP = p+".";
+                    Object.keys( cache ).each( function( path, idx){
+                        if( path.indexOf( mathP ) === 0 )delete cache[path];
+                    })
+                }
+            }
+        }
+    }
+};
+
+MWF.xScript.getMatchedDict = function(key, path){
+    if( !path )path = "root";
+    if( path.indexOf("root") !== 0 )path = "root." + path ;
+
+    var arr = path.split(/\./g);
+    if( MWF.xScript.dictLoaded[key] ){
+        var dicts = MWF.xScript.dictLoaded[key];
+        var list = Array.clone(arr);
+        var p;
+        var dict;
+        for( var i=0 ; i<arr.length; i++ ){
+            p = i === 0 ? arr[0] : ( p + "." + arr[i] );
+            list.shift();
+            if( dicts[ p ] ){
+                dict = dicts[ p ];
+                break;
+            }
+        }
+        return {
+            dict : dict,
+            unmatchedPathList : list
+        }
+    }
+    return {
+        dict : null,
+        unmatchedPathList : list
+    }
+};
+
+MWF.xScript.insertDictToCache = function(key, path, json){
+    if( MWF.xScript.dictLoaded[key] ){
+        var matchedDict = MWF.xScript.getMatchedDict( key, path );
+        var dict = matchedDict.dict;
+        var list = matchedDict.unmatchedPathList;
+        if( !dict ){
+            MWF.xScript.dictLoaded[key][path] = json;
+        }else{
+            for( var j=0; j<list.length-1; j++ ){
+                if( !dict[ list[j] ] ){
+                    dict[ list[j] ] = {};
+                }
+                dict = dict[ list[j] ];
+            }
+            var lastPath = list[list.length-1];
+            if( !dict[lastPath] ){
+                dict[lastPath] = json;
+            }else if( typeOf( dict[lastPath] ) === "array" ){
+                dict[lastPath].push( json );
+            }
+        }
+    }else{
+        MWF.xScript.dictLoaded[key] = {};
+        MWF.xScript.dictLoaded[key][path] = json;
+    }
+};
+
+
+MWF.xScript.setDictToCache = function(key, path, json){
+    if( MWF.xScript.dictLoaded[key] ){
+        var matchedDict = MWF.xScript.getMatchedDict( key, path );
+        var dict = matchedDict.dict;
+        var list = matchedDict.unmatchedPathList;
+        if( !dict ){
+            MWF.xScript.dictLoaded[key][path] = json;
+        }else{
+            for( var j=0; j<list.length-1; j++ ){
+                if( !dict[ list[j] ] ){
+                    dict[ list[j] ] = {};
+                }
+                dict = dict[ list[j] ];
+            }
+            dict[list[list.length-1]] = json;
+        }
+    }else{
+        MWF.xScript.dictLoaded[key] = {};
+        MWF.xScript.dictLoaded[key][path] = json;
+    }
+};
+
+MWF.xScript.getDictFromCache = function( key, path ){
+    var matchedDict = MWF.xScript.getMatchedDict( key, path );
+    var dict = matchedDict.dict;
+    var list = matchedDict.unmatchedPathList;
+    if( dict ){
+        for( var j=0; j<list.length; j++ ){
+            dict = dict[ list[j] ];
+            if( !dict )return null;
+        }
+        return dict;
+    }
+    return null;
+};
+
+MWF.xScript.deleteDictToCache = function(key, path){
+    var matchedDict = MWF.xScript.getMatchedDict( key, path );
+    var dict = matchedDict.dict;
+    var list = matchedDict.unmatchedPathList;
+
+    if( dict){
+        for( var j=0; j<list.length-1; j++ ){
+            dict = dict[ list[j] ];
+            if( !dict )return;
+        }
+        delete dict[list[list.length-1]];
+    }
+};
+
+
 MWF.xScript.createDict = function(application){
     //optionsOrName : {
     //  type : "", //默认为process, 可以为  process  cms
@@ -1378,9 +1535,16 @@ MWF.xScript.createDict = function(application){
         var applicationId = options.application || application;
         var enableAnonymous = options.enableAnonymous || false;
 
-        var key = name+type+applicationId+enableAnonymous
-        if (!dictLoaded[key]) dictLoaded[key] = {};
-        this.dictData = dictLoaded[key];
+        var opt = {
+            "appType" : type,
+            "name" : name,
+            "appId" : applicationId,
+            "enableAnonymous" : enableAnonymous
+        };
+
+        var key = name+type+applicationId+enableAnonymous;
+        // if (!dictLoaded[key]) dictLoaded[key] = {};
+        // this.dictData = dictLoaded[key];
 
         //MWF.require("MWF.xScript.Actions.DictActions", null, false);
         if( type == "cms" ){
@@ -1399,29 +1563,31 @@ MWF.xScript.createDict = function(application){
 
         this.get = function(path, success, failure, async, refresh){
             var value = null;
-            if (path){
-                if ( !refresh && this.dictData[path]){
-                    if (success) success(this.dictData[path]);
-                    return this.dictData[path];
+            if (!refresh ){
+                var data = MWF.xScript.getDictFromCache( key, path );
+                if( data ){
+                    if (success) success( data );
+                    return data;
                 }
+            }
+
+            if (path){
 
                 var p = encodePath( path );
                 //var p = path.replace(/\./g, "/");
                 action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
                     value = json.data;
-                    this.dictData[path] = value;
+                    // this.dictData[path] = value;
+                    MWF.xScript.addDictToCache(opt, path, value);
                     if (success) success(json.data);
                 }.bind(this), function(xhr, text, error){
                     if (failure) failure(xhr, text, error);
                 }, !!async, false);
             }else{
-                if (this.dictData["root"]){
-                    if (success) success(this.dictData["root"]);
-                    return this.dictData["root"];
-                }
                 action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
                     value = json.data;
-                    this.dictData["root"] = value;
+                    // this.dictData["root"] = value;
+                    MWF.xScript.addDictToCache(opt, path, value);
                     if (success) success(json.data);
                 }.bind(this), function(xhr, text, error){
                     if (failure) failure(xhr, text, error);
@@ -1435,6 +1601,7 @@ MWF.xScript.createDict = function(application){
             var p = encodePath( path );
             //var p = path.replace(/\./g, "/");
             action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
+                MWF.xScript.setDictToCache(key, path, value);
                 if (success) success(json.data);
             }, function(xhr, text, error){
                 if (failure) failure(xhr, text, error);
@@ -1444,6 +1611,7 @@ MWF.xScript.createDict = function(application){
             var p = encodePath( path );
             //var p = path.replace(/\./g, "/");
             action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
+                MWF.xScript.insertDictToCache(key, path, value);
                 if (success) success(json.data);
             }, function(xhr, text, error){
                 if (failure) failure(xhr, text, error);
@@ -1453,6 +1621,7 @@ MWF.xScript.createDict = function(application){
             var p = encodePath( path );
             //var p = path.replace(/\./g, "/");
             action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
+                MWF.xScript.deleteDictToCache(key, path);
                 if (success) success(json.data);
             }, function(xhr, text, error){
                 if (failure) failure(xhr, text, error);
@@ -1461,3 +1630,106 @@ MWF.xScript.createDict = function(application){
         this.destory = this["delete"];
     }
 };
+
+// var dictLoaded = {};
+// MWF.xScript.createDict = function(application){
+//     //optionsOrName : {
+//     //  type : "", //默认为process, 可以为  process  cms
+//     //  application : "", //流程/CMS的名称/别名/id, 默认为当前应用
+//     //  name : "", // 数据字典名称/别名/id
+//     //  enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
+//     //}
+//     //或者name: "" // 数据字典名称/别名/id
+//     return function(optionsOrName){
+//         var options = optionsOrName;
+//         if( typeOf( options ) == "string" ){
+//             options = { name : options };
+//         }
+//         var name = this.name = options.name;
+//         var type = ( options.type && options.application ) ?  options.type : "process";
+//         var applicationId = options.application || application;
+//         var enableAnonymous = options.enableAnonymous || false;
+//
+//         var key = name+type+applicationId+enableAnonymous
+//         if (!dictLoaded[key]) dictLoaded[key] = {};
+//         this.dictData = dictLoaded[key];
+//
+//         //MWF.require("MWF.xScript.Actions.DictActions", null, false);
+//         if( type == "cms" ){
+//             var action = MWF.Actions.get("x_cms_assemble_control");
+//         }else{
+//             var action = MWF.Actions.get("x_processplatform_assemble_surface");
+//         }
+//
+//         var encodePath = function( path ){
+//             var arr = path.split(/\./g);
+//             var ar = arr.map(function(v){
+//                 return encodeURIComponent(v);
+//             });
+//             return ar.join("/");
+//         };
+//
+//         this.get = function(path, success, failure, async, refresh){
+//             var value = null;
+//             if (path){
+//                 if ( !refresh && this.dictData[path]){
+//                     if (success) success(this.dictData[path]);
+//                     return this.dictData[path];
+//                 }
+//
+//                 var p = encodePath( path );
+//                 //var p = path.replace(/\./g, "/");
+//                 action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
+//                     value = json.data;
+//                     this.dictData[path] = value;
+//                     if (success) success(json.data);
+//                 }.bind(this), function(xhr, text, error){
+//                     if (failure) failure(xhr, text, error);
+//                 }, !!async, false);
+//             }else{
+//                 if (this.dictData["root"]){
+//                     if (success) success(this.dictData["root"]);
+//                     return this.dictData["root"];
+//                 }
+//                 action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
+//                     value = json.data;
+//                     this.dictData["root"] = value;
+//                     if (success) success(json.data);
+//                 }.bind(this), function(xhr, text, error){
+//                     if (failure) failure(xhr, text, error);
+//                 }, !!async);
+//             }
+//
+//             return value;
+//         };
+//
+//         this.set = function(path, value, success, failure){
+//             var p = encodePath( path );
+//             //var p = path.replace(/\./g, "/");
+//             action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
+//                 if (success) success(json.data);
+//             }, function(xhr, text, error){
+//                 if (failure) failure(xhr, text, error);
+//             }, false, false);
+//         };
+//         this.add = function(path, value, success, failure){
+//             var p = encodePath( path );
+//             //var p = path.replace(/\./g, "/");
+//             action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
+//                 if (success) success(json.data);
+//             }, function(xhr, text, error){
+//                 if (failure) failure(xhr, text, error);
+//             }, false, false);
+//         };
+//         this["delete"] = function(path, success, failure){
+//             var p = encodePath( path );
+//             //var p = path.replace(/\./g, "/");
+//             action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
+//                 if (success) success(json.data);
+//             }, function(xhr, text, error){
+//                 if (failure) failure(xhr, text, error);
+//             }, false, false);
+//         };
+//         this.destory = this["delete"];
+//     }
+// };

+ 182 - 14
o2web/source/o2_core/o2/xScript/ViewEnvironment.js

@@ -1116,8 +1116,164 @@ MWF.xScript.ViewEnvironment = function (ev) {
 };
 
 
-var dictLoaded = {};
+if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
+
 if( !MWF.xScript.createDict ){
+    MWF.xScript.addDictToCache = function ( options, path, json ) {
+        if( !path )path = "root";
+        if( path.indexOf("root") !== 0 )path = "root." + path ;
+
+        var type = options.appType || "process";
+        var enableAnonymous = options.enableAnonymous || false;
+
+        var appFlagList = [];
+        if( options.application )appFlagList.push( options.application );
+        if( options.appId )appFlagList.push( options.appId );
+        if( options.appName )appFlagList.push( options.appName );
+        if( options.appAlias )appFlagList.push( options.appAlias );
+
+        var dictFlagList = [];
+        if( options.id )dictFlagList.push( options.id );
+        if( options.name )dictFlagList.push( options.name );
+        if( options.alias )dictFlagList.push( options.alias );
+
+        var cache = {};
+        cache[path] = json;
+
+        for( var i=0; i<appFlagList.length; i++ ){
+            for( var j=0; j<dictFlagList.length; j++ ){
+                var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
+                if( !MWF.xScript.dictLoaded[k] ){
+                    MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
+                    // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
+                }else if( i===0 && j===0 ){
+                    MWF.xScript.setDictToCache( k, path ,json );
+                    var arr = path.split(/\./g);
+                    var p;
+                    var cache = MWF.xScript.dictLoaded[k];
+                    for( var l=0 ; l<arr.length; l++ ){
+                        p = l === 0 ? arr[0] : ( p + "." + arr[l] );
+                        if( cache[ p ] )break;
+                    }
+                    if( p ){
+                        var mathP = p+".";
+                        Object.keys( cache ).each( function( path, idx){
+                            if( path.indexOf( mathP ) === 0 )delete cache[path];
+                        })
+                    }
+                }
+            }
+        }
+    };
+
+    MWF.xScript.getMatchedDict = function(key, path){
+        if( !path )path = "root";
+        if( path.indexOf("root") !== 0 )path = "root." + path ;
+
+        var arr = path.split(/\./g);
+        if( MWF.xScript.dictLoaded[key] ){
+            var dicts = MWF.xScript.dictLoaded[key];
+            var list = Array.clone(arr);
+            var p;
+            var dict;
+            for( var i=0 ; i<arr.length; i++ ){
+                p = i === 0 ? arr[0] : ( p + "." + arr[i] );
+                list.shift();
+                if( dicts[ p ] ){
+                    dict = dicts[ p ];
+                    break;
+                }
+            }
+            return {
+                dict : dict,
+                unmatchedPathList : list
+            }
+        }
+        return {
+            dict : null,
+            unmatchedPathList : list
+        }
+    };
+
+    MWF.xScript.insertDictToCache = function(key, path, json){
+        if( MWF.xScript.dictLoaded[key] ){
+            var matchedDict = MWF.xScript.getMatchedDict( key, path );
+            var dict = matchedDict.dict;
+            var list = matchedDict.unmatchedPathList;
+            if( !dict ){
+                MWF.xScript.dictLoaded[key][path] = json;
+            }else{
+                for( var j=0; j<list.length-1; j++ ){
+                    if( !dict[ list[j] ] ){
+                        dict[ list[j] ] = {};
+                    }
+                    dict = dict[ list[j] ];
+                }
+                var lastPath = list[list.length-1];
+                if( !dict[lastPath] ){
+                    dict[lastPath] = json;
+                }else if( typeOf( dict[lastPath] ) === "array" ){
+                    dict[lastPath].push( json );
+                }
+            }
+        }else{
+            MWF.xScript.dictLoaded[key] = {};
+            MWF.xScript.dictLoaded[key][path] = json;
+        }
+    };
+
+
+    MWF.xScript.setDictToCache = function(key, path, json){
+        if( MWF.xScript.dictLoaded[key] ){
+            var matchedDict = MWF.xScript.getMatchedDict( key, path );
+            var dict = matchedDict.dict;
+            var list = matchedDict.unmatchedPathList;
+            if( !dict ){
+                MWF.xScript.dictLoaded[key][path] = json;
+            }else{
+                for( var j=0; j<list.length-1; j++ ){
+                    if( !dict[ list[j] ] ){
+                        dict[ list[j] ] = {};
+                    }
+                    dict = dict[ list[j] ];
+                }
+                dict[list[list.length-1]] = json;
+            }
+        }else{
+            MWF.xScript.dictLoaded[key] = {};
+            MWF.xScript.dictLoaded[key][path] = json;
+        }
+    };
+
+    MWF.xScript.getDictFromCache = function( key, path ){
+        var matchedDict = MWF.xScript.getMatchedDict( key, path );
+        var dict = matchedDict.dict;
+        var list = matchedDict.unmatchedPathList;
+        if( dict ){
+            for( var j=0; j<list.length; j++ ){
+                dict = dict[ list[j] ];
+                if( !dict )return null;
+            }
+            return dict;
+        }
+        return null;
+    };
+
+    MWF.xScript.deleteDictToCache = function(key, path){
+        var matchedDict = MWF.xScript.getMatchedDict( key, path );
+        var dict = matchedDict.dict;
+        var list = matchedDict.unmatchedPathList;
+
+        if( dict){
+            for( var j=0; j<list.length-1; j++ ){
+                dict = dict[ list[j] ];
+                if( !dict )return;
+            }
+            delete dict[list[list.length-1]];
+        }
+    };
+
+
     MWF.xScript.createDict = function(application){
         //optionsOrName : {
         //  type : "", //默认为process, 可以为  process  cms
@@ -1136,9 +1292,16 @@ if( !MWF.xScript.createDict ){
             var applicationId = options.application || application;
             var enableAnonymous = options.enableAnonymous || false;
 
-            var key = name+type+applicationId+enableAnonymous
-            if (!dictLoaded[key]) dictLoaded[key] = {};
-            this.dictData = dictLoaded[key];
+            var opt = {
+                "appType" : type,
+                "name" : name,
+                "appId" : applicationId,
+                "enableAnonymous" : enableAnonymous
+            };
+
+            var key = name+type+applicationId+enableAnonymous;
+            // if (!dictLoaded[key]) dictLoaded[key] = {};
+            // this.dictData = dictLoaded[key];
 
             //MWF.require("MWF.xScript.Actions.DictActions", null, false);
             if( type == "cms" ){
@@ -1157,29 +1320,31 @@ if( !MWF.xScript.createDict ){
 
             this.get = function(path, success, failure, async, refresh){
                 var value = null;
-                if (path){
-                    if (!refresh && this.dictData[path]){
-                        if (success) success(this.dictData[path]);
-                        return this.dictData[path];
+                if (!refresh ){
+                    var data = MWF.xScript.getDictFromCache( key, path );
+                    if( data ){
+                        if (success) success( data );
+                        return data;
                     }
+                }
+
+                if (path){
 
                     var p = encodePath( path );
                     //var p = path.replace(/\./g, "/");
                     action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
                         value = json.data;
-                        this.dictData[path] = value;
+                        // this.dictData[path] = value;
+                        MWF.xScript.addDictToCache(opt, path, value);
                         if (success) success(json.data);
                     }.bind(this), function(xhr, text, error){
                         if (failure) failure(xhr, text, error);
                     }, !!async, false);
                 }else{
-                    if (this.dictData["root"]){
-                        if (success) success(this.dictData["root"]);
-                        return this.dictData["root"];
-                    }
                     action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
                         value = json.data;
-                        this.dictData["root"] = value;
+                        // this.dictData["root"] = value;
+                        MWF.xScript.addDictToCache(opt, path, value);
                         if (success) success(json.data);
                     }.bind(this), function(xhr, text, error){
                         if (failure) failure(xhr, text, error);
@@ -1193,6 +1358,7 @@ if( !MWF.xScript.createDict ){
                 var p = encodePath( path );
                 //var p = path.replace(/\./g, "/");
                 action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
+                    MWF.xScript.setDictToCache(key, path, value);
                     if (success) success(json.data);
                 }, function(xhr, text, error){
                     if (failure) failure(xhr, text, error);
@@ -1202,6 +1368,7 @@ if( !MWF.xScript.createDict ){
                 var p = encodePath( path );
                 //var p = path.replace(/\./g, "/");
                 action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
+                    MWF.xScript.insertDictToCache(key, path, value);
                     if (success) success(json.data);
                 }, function(xhr, text, error){
                     if (failure) failure(xhr, text, error);
@@ -1211,6 +1378,7 @@ if( !MWF.xScript.createDict ){
                 var p = encodePath( path );
                 //var p = path.replace(/\./g, "/");
                 action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
+                    MWF.xScript.deleteDictToCache(key, path);
                     if (success) success(json.data);
                 }, function(xhr, text, error){
                     if (failure) failure(xhr, text, error);