index.js 6.5 KB

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