index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. FileUrl: "../../",
  8. ImageAll: ["../../images/01003.png", "../../images/01004.png", "../../images/01005.png"],
  9. indexImage: 0,
  10. },
  11. onReady: function (e) {
  12. },
  13. onLoad: function (options) {
  14. if (options) {
  15. if (options.UserID) {
  16. console.log("UserID:" + options.UserID);
  17. app.globalData.introducer = options.UserID;
  18. }
  19. if (options.SourceID) {
  20. console.log("SourceID:" + options.SourceID);
  21. app.globalData.SourceID = options.SourceID;
  22. }
  23. // 扫码介绍人
  24. if (options.scene) {
  25. var scene = decodeURIComponent(options.scene);
  26. console.log("scene:" + scene);
  27. var introducer = 0;
  28. if (scene.indexOf("UserID") >= 0)
  29. introducer = scene.substr(scene.indexOf("UserID") + 7);
  30. console.log("introducer:" + introducer);
  31. app.globalData.introducer = scene;
  32. }
  33. if (options.ProductID) {
  34. this.setData({
  35. ProductID: options.ProductID,
  36. ProductUserID: options.ProductUserID,
  37. BuyType: options.BuyType,
  38. ProductBuyInfoID: options.ProductBuyInfoID,
  39. });
  40. }
  41. }
  42. this.setData({
  43. Height: common.getSystemHeight(),
  44. indexImage: common.random(0, 2),
  45. });
  46. this.getUserInfo();
  47. var systemInfo = wx.getSystemInfoSync();
  48. if (systemInfo.model) {
  49. if (systemInfo.model.indexOf("iPad") >= 0) {
  50. this.setData({
  51. ipad: "ipad",
  52. })
  53. }
  54. }
  55. },
  56. //得到用户信息
  57. getUserInfo: function (cb) {
  58. var that = this
  59. //调用登录接口
  60. wx.login({
  61. success: function (res0) {
  62. app.globalData.userInfo = {};
  63. app.globalData.userInfo.Code = res0.code;
  64. //console.log("Code:" + res0.code);
  65. wx.getSetting({
  66. scope: "scope.userInfo",
  67. success(res) {
  68. if (!res.authSetting['scope.userInfo']) {
  69. app.globalData.userInfo.nickName = "陌生用户";
  70. app.globalData.userInfo.language = "";
  71. app.globalData.userInfo.gender = "0";
  72. app.globalData.userInfo.city = "";
  73. app.globalData.userInfo.province = "";
  74. app.globalData.userInfo.country = "";
  75. app.globalData.userInfo.avatarUrl = "../../images/FACE.png";
  76. that.login(app.globalData.userInfo);
  77. }
  78. else {
  79. wx.getUserInfo({
  80. withCredentials: false,
  81. success: function (res) {
  82. app.globalData.userInfo = res.userInfo;
  83. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  84. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  85. app.globalData.userInfo.Code = res0.code;
  86. that.login(app.globalData.userInfo);
  87. },
  88. fail: function (res) {
  89. that.login(app.globalData.userInfo);
  90. }
  91. });
  92. }
  93. }
  94. });
  95. },
  96. fail: function () {
  97. timeout2 = setTimeout(function () {
  98. that.getUserInfo();
  99. console.log("reboot:" + new Date().getTime());
  100. }, 2000);
  101. }
  102. });
  103. },
  104. login: function (param) {
  105. var that = this;
  106. server.getLocalHost(function () {
  107. server.postData('HanziLogin', {
  108. Code: param.Code,
  109. NickName: param.nickName,
  110. Language: param.language,
  111. Gender: param.gender,
  112. City: param.city,
  113. Province: param.province,
  114. Country: param.country,
  115. AvatarUrl: param.avatarUrl,
  116. Introducer: app.globalData.introducer,
  117. UserSource: app.globalData.userSource,
  118. SourceID: app.globalData.SourceID,
  119. LastUserSource: app.globalData.userSource,
  120. Brand: app.globalData.systemInfo.brand,
  121. Model: app.globalData.systemInfo.model,
  122. PixelRatio: app.globalData.systemInfo.pixelRatio,
  123. ScreenWidth: app.globalData.systemInfo.screenWidth,
  124. ScreenHeight: app.globalData.systemInfo.screenHeight,
  125. WindowWidth: app.globalData.systemInfo.windowWidth,
  126. WindowHeight: app.globalData.systemInfo.windowHeight,
  127. WXLanguage: app.globalData.systemInfo.language,
  128. WXVersion: app.globalData.systemInfo.version,
  129. System: app.globalData.systemInfo.system,
  130. Platform: app.globalData.systemInfo.platform,
  131. SDKVersion: app.globalData.systemInfo.SDKVersion,
  132. ProgramVersion: app.globalData.Version,
  133. }, function (data) {
  134. //console.log("UserInfo:" + data);
  135. if (!data) {
  136. timeout3 = setTimeout(function () {
  137. that.getUserInfo();
  138. console.log("reboot:" + new Date().getTime());
  139. }, 2000);
  140. }
  141. else {
  142. app.globalData.userInfo = data;
  143. if (that.data.ProductID) {
  144. var url = "../index/activate?ProductID=" + that.data.ProductID
  145. + "&ProductUserID=" + that.data.ProductUserID
  146. + "&CurrentUserID=" + app.globalData.userInfo.UserID
  147. + "&CurrentProductID=" + app.globalData.ProgramID
  148. + "&ProductBuyInfoID=" + that.data.ProductBuyInfoID
  149. + "&BuyType=" + that.data.BuyType;
  150. wx.redirectTo({
  151. url: url
  152. });
  153. }
  154. else {
  155. //app.globalData.userInfo.AvatarUrl = param.avatarUrl;
  156. that.getHanzi(function(){
  157. setTimeout(function () {
  158. wx.redirectTo({
  159. url: '../main/index'
  160. })
  161. }, 2000);
  162. });
  163. }
  164. }
  165. });
  166. });
  167. },
  168. getHanzi: function (callback) {
  169. var that = this;
  170. var time = wx.getStorageSync("HanziUpdateTime");
  171. server.getData('GetHanziAll?UpdateTime=' + time, function (data) {
  172. if (data) {
  173. if (data.List) {
  174. var arr = common.Decrypt(data.List);
  175. wx.setStorageSync("HanziAll", arr);
  176. wx.setStorageSync("HanziUpdateTime", data.UpdateTime);
  177. }
  178. app.globalData.BaiduToken = data.String;
  179. callback();
  180. }
  181. });
  182. },
  183. onShareAppMessage: function () {
  184. return {
  185. title: app.globalData.ShareTitle,
  186. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  187. imageUrl: '../../images/07001.png',
  188. }
  189. },
  190. })