index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. var timeout2, timeout3;
  5. Page({
  6. data: {
  7. version: app.globalData.version,
  8. FileUrl: app.globalData.fileUrl,
  9. },
  10. onLoad: function(options) {
  11. if (options) {
  12. if (options.UserID) {
  13. console.log("UserID:" + options.UserID);
  14. app.globalData.introducer = options.UserID;
  15. }
  16. if (options.SourceID) {
  17. console.log("SourceID:" + options.SourceID);
  18. app.globalData.SourceID = options.SourceID;
  19. }
  20. // 扫码介绍人
  21. if (options.scene) {
  22. var scene = decodeURIComponent(options.scene);
  23. console.log("scene:" + scene);
  24. var introducer = 0;
  25. if (scene.indexOf("UserID") >= 0)
  26. introducer = scene.substr(scene.indexOf("UserID") + 7);
  27. console.log("introducer:" + introducer);
  28. app.globalData.introducer = scene;
  29. }
  30. }
  31. this.setData({
  32. Containnerheight: server.getWindowHeight(),
  33. });
  34. this.getUserInfo();
  35. },
  36. //得到用户信息
  37. getUserInfo: function(cb) {
  38. var that = this
  39. //调用登录接口
  40. wx.login({
  41. success: function(res0) {
  42. app.globalData.userInfo = {};
  43. app.globalData.userInfo.Code = res0.code;
  44. //console.log("Code:" + res0.code);
  45. wx.getSetting({
  46. scope: "scope.userInfo",
  47. success(res) {
  48. if (!res.authSetting['scope.userInfo']) {
  49. app.globalData.userInfo.nickName = "陌生用户";
  50. app.globalData.userInfo.language = "";
  51. app.globalData.userInfo.gender = "0";
  52. app.globalData.userInfo.city = "";
  53. app.globalData.userInfo.province = "";
  54. app.globalData.userInfo.country = "";
  55. app.globalData.userInfo.avatarUrl = "";
  56. that.login(app.globalData.userInfo);
  57. } else {
  58. wx.getUserInfo({
  59. withCredentials: false,
  60. success: function(res) {
  61. app.globalData.userInfo = res.userInfo;
  62. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  63. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  64. app.globalData.userInfo.Code = res0.code;
  65. that.login(app.globalData.userInfo);
  66. },
  67. fail: function(res) {
  68. that.login(app.globalData.userInfo);
  69. }
  70. });
  71. }
  72. }
  73. });
  74. },
  75. fail: function() {
  76. timeout2 = setTimeout(function() {
  77. that.getUserInfo();
  78. console.log("reboot:" + new Date().getTime());
  79. }, 2000);
  80. }
  81. });
  82. },
  83. login: function(param) {
  84. var that = this;
  85. server.getLocalHost(function() {
  86. server.postData('MathLogin', {
  87. Code: param.Code,
  88. NickName: param.nickName,
  89. Language: param.language,
  90. Gender: param.gender,
  91. City: param.city,
  92. Province: param.province,
  93. Country: param.country,
  94. AvatarUrl: param.avatarUrl,
  95. Introducer: app.globalData.introducer,
  96. UserSource: app.globalData.userSource,
  97. SourceID: app.globalData.SourceID,
  98. LastUserSource: app.globalData.userSource,
  99. Brand: app.globalData.systemInfo.brand,
  100. Model: app.globalData.systemInfo.model,
  101. PixelRatio: app.globalData.systemInfo.pixelRatio,
  102. ScreenWidth: app.globalData.systemInfo.screenWidth,
  103. ScreenHeight: app.globalData.systemInfo.screenHeight,
  104. WindowWidth: app.globalData.systemInfo.windowWidth,
  105. WindowHeight: app.globalData.systemInfo.windowHeight,
  106. WXLanguage: app.globalData.systemInfo.language,
  107. WXVersion: app.globalData.systemInfo.version,
  108. System: app.globalData.systemInfo.system,
  109. Platform: app.globalData.systemInfo.platform,
  110. SDKVersion: app.globalData.systemInfo.SDKVersion,
  111. ProgramVersion: app.globalData.Version,
  112. }, function(data) {
  113. //console.log("UserInfo:" + data);
  114. if (!data) {
  115. timeout3 = setTimeout(function() {
  116. that.getUserInfo();
  117. console.log("reboot:" + new Date().getTime());
  118. }, 2000);
  119. } else {
  120. app.globalData.userInfo = data;
  121. //app.globalData.userInfo.AvatarUrl = param.avatarUrl;
  122. that.getQuestionType(function() {
  123. setTimeout(function() {
  124. wx.redirectTo({
  125. url: '../main/default'
  126. })
  127. }, 2000);
  128. });
  129. }
  130. });
  131. });
  132. },
  133. getQuestionType: function(callback) {
  134. var that = this;
  135. server.getData('GetQuestionTypes?Mode=2', function(data) {
  136. if (data) {
  137. //var arr = common.Decrypt(data);
  138. var arr=data;
  139. wx.setStorageSync("QuestionTypeList", arr);
  140. callback();
  141. }
  142. });
  143. },
  144. onShareAppMessage: function () {
  145. return {
  146. title: app.globalData.ShareTitle,
  147. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  148. imageUrl: app.globalData.ShareImageUrl,
  149. }
  150. },
  151. })