index.js 5.5 KB

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