ソースを参照

调整udbproxy-new

DW-PC\DW 5 年 前
コミット
e31ade3111
1 ファイル変更62 行追加6 行削除
  1. 62 6
      公共资源/src/js/dwudbproxy-new.js

+ 62 - 6
公共资源/src/js/dwudbproxy-new.js

@@ -9,6 +9,32 @@
 
     var plainFunction = function () { }
 
+    //多玩客户端不支持window.open,在这里做统一兼容处理
+    var dwClientIncompatible = {
+        isClient: function() {
+            return !!(window.external && window.external.OpenThirdLogin)
+        },
+        open: function(url,target) {
+            if(dwClientIncompatible.isClient()){
+                window.external.OpenThirdLogin(url)
+            } else {    
+              return window.open(url,target)
+            }
+        },
+        focus: function(context) {
+            if(!dwClientIncompatible.isClient()){
+                context && context.focus()
+            }
+        },
+        close: function(context) {
+            if(dwClientIncompatible.isClient()){
+                window.external.CloseThirdLogin()
+            } else {
+                context && context.close()
+            }
+        }
+    }
+
     var Config = {
         multilogin: {
             domainMap: [
@@ -34,6 +60,8 @@
         loginSuccCallbacks: $.Callbacks('memory'),//登录成功后的回调队列
         bindCallbacks: $.Callbacks('memory'),
         bindSuccCallbacks: $.Callbacks('memory'),//绑定成功后的回调队列
+        logoutCallbacks: $.Callbacks('memory'),
+        logoutSuccCallbacks: $.Callbacks('memory'),//注销成功后的回调队列
         intervalHandle: 0,
 
         getCookie: Cookie.get,
@@ -176,12 +204,14 @@
                     fn = function () {
                         that.bindCallbacks.fire()
                         that.bindSuccCallbacks.fire()
+                        that.bindCallbacks = $.Callbacks('memory')
                     }
                 } else {
 
                     fn = function () {
-                        that.loginCallbacks.fire();
-                        that.loginSuccCallbacks.fire(Util.getUserInfo());
+                        that.loginCallbacks.fire()
+                        that.loginSuccCallbacks.fire(Util.getUserInfo())
+                        that.loginCallbacks = $.Callbacks('memory')
                     }
                 }
 
@@ -429,7 +459,17 @@
 
         logout: function (successURL) {
             var that = this;
-            successURL = Util.decorateURL(successURL);
+
+            Util.logoutCallbacks.empty()
+
+            if ('function' == typeof successURL) {
+                Util.logoutCallbacks.add(successURL)
+            } else {
+                Util.logoutCallbacks.add(function(){
+                    window.location.href = successURL;
+                })
+            }
+            
             $.getJSON(that.getDelCookieURL + '&jsonpcallback=?', function (data) {
                 if ("1" != data.success) {
                     alert(data.errMsg);
@@ -439,7 +479,12 @@
                     UDBSdk.deleteCrossmainCookieWithCallBack(
                         data.delCookieURL,
                         function () {
-                            window.location.href = successURL;
+                            if(dwClientIncompatible.isClient()){
+                                window.external.Logout()
+                            }
+                            Util.logoutCallbacks.fire()
+                            Util.logoutSuccCallbacks.fire()
+                            Util.logoutCallbacks = $.Callbacks('memory')
                         });
                 });
             });
@@ -548,6 +593,9 @@
                 var url = this.baseURL + "?do=" + authorize + '&appid=' + this.appid + "&loginType=" + loginType + "&callbackUrl=" + encodeURIComponent(successURL);
             }
 
+            // this.minWindow = dwClientIncompatible.open(url, "_loginWin");
+            // dwClientIncompatible.focus(this.minWindow);
+
             this.minWindow = window.open(url, "_loginWin");
             this.minWindow.focus();
         },
@@ -561,14 +609,17 @@
 
             var url = this.baseURL + "?do=" + bindUrl + '&appid=' + this.appid + "&loginType=" + bindType + "&callbackUrl=" + encodeURIComponent(successURL);
 
+            // this.minWindow = dwClientIncompatible.open(url, "_loginWin");
+            // dwClientIncompatible.focus(this.minWindow);
+            
             this.minWindow = window.open(url, "_loginWin");
             this.minWindow.focus();
         },
 
         reloadPage: function (successURL) {
             var that = this;
-            if (that.minWindow) {
-                that.minWindow.close();
+            if (this.minWindow) {
+                this.minWindow.close()
             }
             this.writeOtherDomainCookie(function () {
                 if (!successURL) {
@@ -887,6 +938,7 @@
             if (this.loginPopupObj) this.loginPopupObj.hide()
             if (this.loginMaskObj) this.loginMaskObj.hide()
             if (this.setNickName) this.setNickName.hide()
+            if (this.yyLoginTip) this.yyLoginTip.hide()
         }
     };
 
@@ -970,6 +1022,10 @@
             Util.bindSuccCallbacks.add(callback)
         },
 
+        addLogout:function(callback){
+            Util.logoutSuccCallbacks.add(callback)
+        },
+
         /**绑定相关的操作 */
         bind: function (type, callback) {
             return __ThirdLogin.bind(type, callback);