import common from '../../utils/util'; import server from '../../utils/main'; const app = getApp(); var timeout2, timeout3; Page({ data: { version: app.globalData.version, }, onLoad: function (options) { if (options) { if (options.UserID) { console.log("UserID:" + options.UserID); app.globalData.introducer = options.UserID; } if (options.SourceID) { console.log("SourceID:" + options.SourceID); app.globalData.SourceID = options.SourceID; } // 扫码介绍人 if (options.scene) { var scene = decodeURIComponent(options.scene); console.log("scene:" + scene); var introducer = 0; if (scene.indexOf("UserID") >= 0) introducer = scene.substr(scene.indexOf("UserID") + 7); console.log("introducer:" + introducer); app.globalData.introducer = scene; } } this.setData({ Containnerheight: server.getWindowHeight(), }); this.getUserInfo(); }, //得到用户信息 getUserInfo: function (cb) { var that = this //调用登录接口 wx.login({ success: function (res0) { app.globalData.userInfo = {}; app.globalData.userInfo.Code = res0.code; //console.log("Code:" + res0.code); wx.getSetting({ scope: "scope.userInfo", success(res) { if (!res.authSetting['scope.userInfo']) { app.globalData.userInfo.nickName = "陌生用户"; app.globalData.userInfo.language = ""; app.globalData.userInfo.gender = "0"; app.globalData.userInfo.city = ""; app.globalData.userInfo.province = ""; app.globalData.userInfo.country = ""; app.globalData.userInfo.avatarUrl = ""; that.login(app.globalData.userInfo); } else { wx.getUserInfo({ withCredentials: false, success: function (res) { app.globalData.userInfo = res.userInfo; app.globalData.userInfo.NickName = app.globalData.userInfo.nickName; app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl; app.globalData.userInfo.Code = res0.code; that.login(app.globalData.userInfo); }, fail: function (res) { that.login(app.globalData.userInfo); } }); } } }); }, fail: function () { timeout2 = setTimeout(function () { that.getUserInfo(); console.log("reboot:" + new Date().getTime()); }, 2000); } }); }, login: function (param) { var that = this; server.getLocalHost(function () { server.postData('MathLogin', { Code: param.Code, NickName: param.nickName, Language: param.language, Gender: param.gender, City: param.city, Province: param.province, Country: param.country, AvatarUrl: param.avatarUrl, Introducer: app.globalData.introducer, UserSource: app.globalData.userSource, SourceID: app.globalData.SourceID, LastUserSource: app.globalData.userSource, Brand: app.globalData.systemInfo.brand, Model: app.globalData.systemInfo.model, PixelRatio: app.globalData.systemInfo.pixelRatio, ScreenWidth: app.globalData.systemInfo.screenWidth, ScreenHeight: app.globalData.systemInfo.screenHeight, WindowWidth: app.globalData.systemInfo.windowWidth, WindowHeight: app.globalData.systemInfo.windowHeight, WXLanguage: app.globalData.systemInfo.language, WXVersion: app.globalData.systemInfo.version, System: app.globalData.systemInfo.system, Platform: app.globalData.systemInfo.platform, SDKVersion: app.globalData.systemInfo.SDKVersion, ProgramVersion: app.globalData.version, }, function (data) { //console.log("UserInfo:" + data); if (!data) { timeout3 = setTimeout(function () { that.getUserInfo(); console.log("reboot:" + new Date().getTime()); }, 2000); } else { app.globalData.userInfo = data; //app.globalData.userInfo.AvatarUrl = param.avatarUrl; that.getQuestionType(function () { setTimeout(function () { common.getStorageValue(that, "IsStart", false, function () { if (that.data.IsStart) { wx.redirectTo({ url: '../main/default' }) } else { wx.redirectTo({ url: '../index/guide' }) } }); }, 2000); }); } }); }); }, getQuestionType: function (callback) { var that = this; server.getData('GetQuestionTypes?Mode=2', function (data) { if (data) { //var arr = common.Decrypt(data); var arr = data; wx.setStorageSync("QuestionTypeList", arr); callback(); } }); server.getData('GetBaiduToken', function (data) { if (data) { app.globalData.BaiduToken = data; } }); }, onShareAppMessage: function () { return { title: app.globalData.ShareTitle, path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID, imageUrl: app.globalData.ShareImageUrl, } }, })