import common from '../../utils/util'; import server from '../../utils/main'; const app = getApp(); Page({ data: { }, onLoad: function (options) { wx.hideShareMenu(); if (options) { if (options.UserID) { console.log("UserID:" + options.UserID); app.globalData.introducer = options.UserID; if (options.QuestionTypeID) questionTypeID = options.QuestionTypeID; } if (options.goto) { console.log("goto:" + options.goto); app.globalData.goto = options.goto; } 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; } if (options.ProductID) { this.setData({ ProductID: options.ProductID, ProductUserID: options.ProductUserID, }); } if (options.GiftID) { this.setData({ GiftID: options.GiftID, }); } if (options.Share==1) { this.setData({ MiaoguoCardID: options.MiaoguoCardID, }); } } this.setData({ Containnerheight: common.getSystemHeight(), }); this.updateProgram(); 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 = "../images/universalpic_face_default_blue_120x120.png"; 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 () { } }); }, login: function (param) { var that = this; server.getLocalHost(function () { server.postData('MiaoguoLogin', { 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) { if (!data) { timeout3 = setTimeout(function () { that.getUserInfo(); console.log("reboot:" + new Date().getTime()); }, 2000); } else { app.globalData.userInfo = data; var isShow = data.IsShow; if (isShow == -1) { isShow = 0; } else { var systemInfo = wx.getSystemInfoSync(); if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) { isShow = 1; } } app.globalData.IsShow = isShow; if (app.globalData.userInfo.IsMember == 1) app.globalData.IsLocked = 0; wx.removeStorageSync("UserID"); wx.removeStorageSync("UserName"); //测试 //var url = '../../package4/main/giftcard?GiftID=89542&UserID=1'; //var url = '../main/share'; // var url = '../../package4/main/share'; // wx.redirectTo({ // url: url, // }); var url = '../main/default'; if (that.data.MiaoguoCardID){ url += "?Share=1&MiaoguoCardID=" + that.data.MiaoguoCardID; } setTimeout(function () { wx.redirectTo({ url: url, }); }, 2000); that.getBaiduToken(); } }); }); }, getBaiduToken: function () { server.getLocalHost(function () { server.getData('GetBaiduToken', function (data) { if (data) { app.globalData.BaiduToken = data; //console.log(app.globalData.BaiduToken); } }); }); }, updateProgram: function () { const updateManager = wx.getUpdateManager(); updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调 //console.log(res.hasUpdate) }); updateManager.onUpdateReady(function () { wx.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success: function (res) { if (res.confirm) { // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 updateManager.applyUpdate() } } }); }); }, onShareAppMessage: function () { return { title: app.globalData.ShareTitle, path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID, imageUrl: app.globalData.ShareImage, } }, })