index.js 6.9 KB

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