Просмотр исходного кода

Merge branch 'fix/soo' into 'wrdp'

修复单点sso.html文中的res.isRunning方法

See merge request o2oa/o2oa!2443
胡起 5 лет назад
Родитель
Сommit
fc16dbeb9f
3 измененных файлов с 91 добавлено и 129 удалено
  1. 80 0
      o2web/source/x_desktop/js/sso.js
  2. 6 66
      o2web/source/x_desktop/smapsso.html
  3. 5 63
      o2web/source/x_desktop/sso.html

+ 80 - 0
o2web/source/x_desktop/js/sso.js

@@ -0,0 +1,80 @@
+window.layout = window.layout || {};
+function getServiceAddress(config, callback){
+    window.layout.config = config;
+    if (config.configMapping && (config.configMapping[window.location.host] || config.configMapping[window.location.hostname])) {
+        var mapping = config.configMapping[window.location.host] || config.configMapping[window.location.hostname];
+        if (mapping.servers){
+            window.layout.serviceAddressList = mapping.servers;
+            if (mapping.center) center = (o2.typeOf(mapping.center)==="array") ? mapping.center[0] : mapping.center;
+            window.layout.centerServer = center;
+            if (callback) callback();
+        }else{
+            if (mapping.center) layout.config.center = (o2.typeOf(mapping.center)==="array") ? mapping.center : [mapping.center];
+            getServiceAddressConfigArray(layout.config, callback);
+        }
+    }else{
+        if (typeOf(config.center)=="object"){
+            getServiceAddressConfigObject(callback);
+        }else if (typeOf(config.center)=="array"){
+            // var center = chooseCenter(config);
+            // if (center){
+            //     getServiceAddressConfigObject(callback, center);
+            // }else{
+            getServiceAddressConfigArray(config, callback);
+            // }
+        }
+    }
+
+
+}
+function chooseCenter(config){
+    var host = window.location.host;
+    var center = null;
+    for (var i=0; i<config.center.length; i++){
+        var ct = config.center[i];
+        if (ct.webHost==host){
+            center = ct;
+            break;
+        }
+    }
+    return center;
+}
+function getServiceAddressConfigArray(config, callback) {
+    var requests = [];
+    config.center.each(function(center){
+        requests.push(
+            getServiceAddressConfigObject(function(){
+                requests.each(function(res){
+                    if (res.res && res.res.isRunning && res.res.isRunning()){res.res.cancel();}
+                });
+                if (callback) callback();
+            }.bind(this), center)
+        );
+    }.bind(this));
+}
+function getServiceAddressConfigObject(callback, center){
+    var centerConfig = center;
+    var host = centerConfig.host || window.location.hostname;
+    var port = centerConfig.port;
+    var uri = "";
+    var locate = window.location;
+    var protocol = locate.protocol;
+    if (!port || port=="80"){
+        uri = protocol+"//"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
+    }else{
+        uri = protocol+"//"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
+    }
+    var currenthost = window.location.hostname;
+    uri = uri.replace(/{source}/g, currenthost);
+    //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
+    return MWF.restful("get", uri, null, function(json){
+        window.layout.serviceAddressList = json.data;
+        window.layout.centerServer = center;
+
+        // var serviceAddressList = json.data;
+        // var addressObj = serviceAddressList["x_organization_assemble_authentication"];
+        // var address = protocol+"//"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+"/z_sso_control/jaxrs/sso/smplogin";
+
+        if (callback) callback();
+    }.bind(this));
+}

+ 6 - 66
o2web/source/x_desktop/smapsso.html

@@ -5,75 +5,15 @@
     <meta charset="UTF-8">
     <title>登录中...</title>
     <script src="../o2_core/o2.min.js"></script>
-    <script src="../o2_lib/Decimal.js"></script>
+    <script src="js/sso.min.js"></script>
     <script>
-        function getServiceAddress(config, callback){
-            if (typeOf(config.center)=="object"){
-                getServiceAddressConfigObject(callback);
-            }else if (typeOf(config.center)=="array"){
-                var center = chooseCenter(config);
-                if (center){
-                    getServiceAddressConfigObject(callback, center);
-                }else{
-                    getServiceAddressConfigArray(config, callback);
-                }
-                //this.getServiceAddressConfigArray(callback);
-            }
-        }
-        function chooseCenter(config){
-            var host = window.location.host;
-            var center = null;
-            for (var i=0; i<config.center.length; i++){
-                var ct = config.center[i];
-                if (ct.webHost==host){
-                    center = ct;
-                    break;
-                }
-            }
-            return center;
-        }
-        function getServiceAddressConfigArray(config, callback) {
-            var requests = [];
-            config.center.each(function(center){
-                requests.push(
-                        getServiceAddressConfigObject(function(address){
-                            requests.each(function(res){
-                                if (res.isRunning && res.isRunning()){res.cancel();}
-                            });
-                            if (callback) callback(address);
-                        }.bind(this), center)
-                );
-            }.bind(this));
-        }
-        function getServiceAddressConfigObject(callback, center){
-            var centerConfig = center;
-            var host = centerConfig.host || window.location.hostname;
-            var port = centerConfig.port;
-            var uri = "";
-            var locate = window.location;
-            var protocol = locate.protocol;
-            if (!port || port=="80"){
-                uri = protocol+"//"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
-            }else{
-                uri = protocol+"//"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
-            }
-            var currenthost = window.location.hostname;
-            uri = uri.replace(/{source}/g, currenthost);
-            //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
-            return MWF.restful("get", uri, null, function(json){
-                var serviceAddressList = json.data;
-                var addressObj = serviceAddressList["x_organization_assemble_authentication"];
-                var address = protocol+"//"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+"/z_sso_control/jaxrs/sso/smplogin";
-
-                if (callback) callback(address);
-            }.bind(this));
-        }
-
         o2.addReady(function(){
             o2.JSON.get("res/config/config.json", function(config){
-                window.layout = {};
-                window.layout.config = config;
-                getServiceAddress(config, function(address){
+                getServiceAddress(config, function(){
+                    var locate = window.location;
+                    var protocol = locate.protocol;
+                    var addressObj = layout.serviceAddressList["x_organization_assemble_authentication"];
+                    var address = protocol+"//"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+"/z_sso_control/jaxrs/sso/smplogin";
 
                     var uri = new URI(window.location.toString());
                     var xtoken = uri.getData("SMAP_SESSION_DATA");

+ 5 - 63
o2web/source/x_desktop/sso.html

@@ -7,73 +7,16 @@
     <script src="../o2_core/o2.min.js"></script>
     <script src="../o2_lib/Decimal.js"></script>
     <script>
-        function getServiceAddress(config, callback){
-            if (typeOf(config.center)=="object"){
-                getServiceAddressConfigObject(callback);
-            }else if (typeOf(config.center)=="array"){
-                var center = chooseCenter(config);
-                if (center){
-                    getServiceAddressConfigObject(callback, center);
-                }else{
-                    getServiceAddressConfigArray(config, callback);
-                }
-                //this.getServiceAddressConfigArray(callback);
-            }
-        }
-        function chooseCenter(config){
-            var host = window.location.host;
-            var center = null;
-            for (var i=0; i<config.center.length; i++){
-                var ct = config.center[i];
-                if (ct.webHost==host){
-                    center = ct;
-                    break;
-                }
-            }
-            return center;
-        }
-        function getServiceAddressConfigArray(config, callback) {
-            var requests = [];
-            config.center.each(function(center){
-                requests.push(
-                        getServiceAddressConfigObject(function(address){
-                            requests.each(function(res){
-                                if (res.isRunning()){res.cancel();}
-                            });
-                            if (callback) callback(address);
-                        }.bind(this), center)
-                );
-            }.bind(this));
-        }
-        function getServiceAddressConfigObject(callback, center){
-            var centerConfig = center;
-            var host = centerConfig.host || window.location.hostname;
-            var port = centerConfig.port;
-            var uri = "";
-            var locate = window.location;
-            var protocol = locate.protocol;
-            if (!port || port=="80"){
-                uri = protocol+"//"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
-            }else{
-                uri = protocol+"//"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
-            }
-            var currenthost = window.location.hostname;
-            uri = uri.replace(/{source}/g, currenthost);
-            //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
-            return MWF.restful("get", uri, null, function(json){
-                var serviceAddressList = json.data;
-                var addressObj = serviceAddressList["x_organization_assemble_authentication"];
-                var address = protocol+"//"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+addressObj.context;
-
-                if (callback) callback(address);
-            }.bind(this));
-        }
-
         o2.addReady(function(){
             o2.JSON.get("res/config/config.json", function(config){
                 if (!window.layout) window.layout = {};
                 window.layout.config = config;
                 getServiceAddress(config, function(address){
+                    var locate = window.location;
+                    var protocol = locate.protocol;
+                    var addressObj = layout.serviceAddressList["x_organization_assemble_authentication"];
+                    var address = protocol+"//"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+addressObj.context;
+
                     var uri = new URI(window.location.toString());
                     var xtoken = uri.getData("xtoken");
                     var client = uri.getData("client");
@@ -115,7 +58,6 @@
             });
 
         });
-
     </script>
 </head>
 <body bgcolor="#faebd7" bgcolor="#ffc0cb">