//活动页面登录组件 var PageLogin = function PageLogin(basePath,activePath, browseType, successFun, failFun) { //登录状态 this.isLogin = false; //接口参数 this.bType = browseType ? browseType : "WAP"; this.basePath = basePath; this.activePath = activePath; //初始化函数 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页内打开 * @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; }); |
|