index.js 5.4 KB

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