//活動頁面登錄組件 var PageLogin = function PageLogin(basePath,activePath, browseType, successFun, failFun) { //登錄狀態(tài) this.isLogin = false; //接口參數(shù) this.bType = browseType ? browseType : "WAP"; this.basePath = basePath; this.activePath = activePath; //初始化函數(shù) this.initPage(successFun, failFun); }; $.extend(PageLogin.prototype, { /** *頁面登錄初始化 * @param successFun 登錄成功方法 * @param failFun 登錄失敗方法 */ initPage: function (successFun, failFun) { //bType是wap和web的類型 var self = this, isApp = self.isApp, bType = self.bType; if (self.getIsApp()) { //alert("userId" + userId); var userId = $("#j_userid").val(); if (userId == -4 || userId == "" || userId == undefined) {//未登錄 failFun(); } else { successFun(); self.isLogin = true; } } else { //先去請求一個jsonp接口 $.ajax({ type: "get", url: self.basePath + "/jsonp", dataType: "jsonp", data: { m: parseInt(Math.random() * 1000000) }, success: function (data) { login2(data); } }); } //第二次登陸接口判斷 function login2(userid) { var _userid = userid; if (userid == undefined) { _userid = ""; } $.ajax({ type: "get", url: self.activePath + "/checkredis/_" + self.bType + "/" + _userid, data: { m: parseInt(Math.random() * 1000000) }, success: function (data) { if (data == "success") { successFun(); self.isLogin = true; } else { failFun(); } } }); } }, /** * 頁面是否app頁內(nèi)打開 * @returns {boolean} */ getIsApp: function () { var isApp = false; var ua = window.navigator.userAgent.toLowerCase(); if (ua.indexOf("@tzg-ios") > -1 || ua.indexOf("@tzg-android") > -1) { isApp = true; } return isApp; }, /** * 頁面是否登錄 * @returns {boolean} */ getIsLogin: function () { return this.isLogin; } }); return PageLogin; }); |
|
來自: 涅槃沉殤 > 《軟件開發(fā)》