index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. },
  7. onLoad: function (options) {
  8. wx.hideShareMenu();
  9. if (options) {
  10. if (options.UserID) {
  11. console.log("UserID:" + options.UserID);
  12. app.globalData.introducer = options.UserID;
  13. if (options.QuestionTypeID)
  14. questionTypeID = options.QuestionTypeID;
  15. }
  16. if (options.goto) {
  17. console.log("goto:" + options.goto);
  18. app.globalData.goto = options.goto;
  19. }
  20. if (options.SourceID) {
  21. console.log("SourceID:" + options.SourceID);
  22. app.globalData.SourceID = options.SourceID;
  23. }
  24. // 扫码介绍人
  25. if (options.scene) {
  26. var scene = decodeURIComponent(options.scene);
  27. console.log("scene:" + scene);
  28. var introducer = 0;
  29. if (scene.indexOf("UserID") >= 0)
  30. introducer = scene.substr(scene.indexOf("UserID") + 7);
  31. console.log("introducer:" + introducer);
  32. app.globalData.introducer = scene;
  33. }
  34. if (options.ProductID) {
  35. this.setData({
  36. ProductID: options.ProductID,
  37. ProductUserID: options.ProductUserID,
  38. });
  39. }
  40. if (options.GiftID) {
  41. this.setData({
  42. GiftID: options.GiftID,
  43. });
  44. }
  45. }
  46. this.setData({
  47. Containnerheight: common.getSystemHeight(),
  48. });
  49. this.updateProgram();
  50. this.getUserInfo();
  51. },
  52. //得到用户信息
  53. getUserInfo: function (cb) {
  54. var that = this
  55. //调用登录接口
  56. wx.login({
  57. success: function (res0) {
  58. app.globalData.userInfo = {};
  59. app.globalData.userInfo.Code = res0.code;
  60. //console.log("Code:" + res0.code);
  61. wx.getSetting({
  62. scope: "scope.userInfo",
  63. success(res) {
  64. if (!res.authSetting['scope.userInfo']) {
  65. app.globalData.userInfo.nickName = "陌生用户";
  66. app.globalData.userInfo.language = "";
  67. app.globalData.userInfo.gender = "0";
  68. app.globalData.userInfo.city = "";
  69. app.globalData.userInfo.province = "";
  70. app.globalData.userInfo.country = "";
  71. app.globalData.userInfo.avatarUrl = "../images/universalpic_face_default_blue_120x120.png";
  72. that.login(app.globalData.userInfo);
  73. }
  74. else {
  75. wx.getUserInfo({
  76. withCredentials: false,
  77. success: function (res) {
  78. app.globalData.userInfo = res.userInfo;
  79. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  80. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  81. app.globalData.userInfo.Code = res0.code;
  82. that.login(app.globalData.userInfo);
  83. },
  84. fail: function (res) {
  85. that.login(app.globalData.userInfo);
  86. }
  87. });
  88. }
  89. }
  90. });
  91. },
  92. fail: function () {
  93. }
  94. });
  95. },
  96. login: function (param) {
  97. var that = this;
  98. server.getLocalHost(function () {
  99. server.postData('MiaoguoLogin', {
  100. Code: param.Code,
  101. NickName: param.nickName,
  102. Language: param.language,
  103. Gender: param.gender,
  104. City: param.city,
  105. Province: param.province,
  106. Country: param.country,
  107. AvatarUrl: param.avatarUrl,
  108. Introducer: app.globalData.introducer,
  109. UserSource: app.globalData.userSource,
  110. SourceID: app.globalData.SourceID,
  111. LastUserSource: app.globalData.userSource,
  112. Brand: app.globalData.systemInfo.brand,
  113. Model: app.globalData.systemInfo.model,
  114. PixelRatio: app.globalData.systemInfo.pixelRatio,
  115. ScreenWidth: app.globalData.systemInfo.screenWidth,
  116. ScreenHeight: app.globalData.systemInfo.screenHeight,
  117. WindowWidth: app.globalData.systemInfo.windowWidth,
  118. WindowHeight: app.globalData.systemInfo.windowHeight,
  119. WXLanguage: app.globalData.systemInfo.language,
  120. WXVersion: app.globalData.systemInfo.version,
  121. System: app.globalData.systemInfo.system,
  122. Platform: app.globalData.systemInfo.platform,
  123. SDKVersion: app.globalData.systemInfo.SDKVersion,
  124. ProgramVersion: app.globalData.Version,
  125. }, function (data) {
  126. if (!data) {
  127. timeout3 = setTimeout(function () {
  128. that.getUserInfo();
  129. console.log("reboot:" + new Date().getTime());
  130. }, 2000);
  131. }
  132. else {
  133. app.globalData.userInfo = data;
  134. var isShow = data.IsShow;
  135. if (isShow == -1) {
  136. isShow = 0;
  137. }
  138. else {
  139. var systemInfo = wx.getSystemInfoSync();
  140. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  141. isShow = 1;
  142. }
  143. }
  144. app.globalData.IsShow = isShow;
  145. if (app.globalData.userInfo.IsMember == 1)
  146. app.globalData.IsLocked = 0;
  147. //测试
  148. //var url = '../../package4/main/giftcard?GiftID=89542&UserID=1';
  149. //var url = '../main/share';
  150. // var url = '../../package4/main/share';
  151. // wx.redirectTo({
  152. // url: url,
  153. // });
  154. var url = '../main/default';
  155. setTimeout(function () {
  156. wx.redirectTo({
  157. url: url,
  158. });
  159. }, 2000);
  160. that.getBaiduToken();
  161. }
  162. });
  163. });
  164. },
  165. getBaiduToken: function () {
  166. server.getLocalHost(function () {
  167. server.getData('GetBaiduToken', function (data) {
  168. if (data) {
  169. app.globalData.BaiduToken = data;
  170. }
  171. });
  172. });
  173. },
  174. updateProgram: function () {
  175. const updateManager = wx.getUpdateManager();
  176. updateManager.onCheckForUpdate(function (res) {
  177. // 请求完新版本信息的回调
  178. console.log(res.hasUpdate)
  179. });
  180. updateManager.onUpdateReady(function () {
  181. wx.showModal({
  182. title: '更新提示',
  183. content: '新版本已经准备好,是否重启应用?',
  184. success: function (res) {
  185. if (res.confirm) {
  186. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  187. updateManager.applyUpdate()
  188. }
  189. }
  190. });
  191. });
  192. },
  193. onShareAppMessage: function () {
  194. return {
  195. title: app.globalData.ShareTitle,
  196. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  197. imageUrl: app.globalData.ShareImage,
  198. }
  199. },
  200. })