index.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. ImageAll: ["../images/01003.png", "../images/01004.png", "../images/01005.png"],
  8. indexImage: 0,
  9. },
  10. onReady: function (e) {
  11. },
  12. onLoad: function (options) {
  13. if (options) {
  14. if (options.UserID) {
  15. console.log("UserID:" + options.UserID);
  16. app.globalData.introducer = options.UserID;
  17. }
  18. if (options.goto) {
  19. console.log("goto:" + options.goto);
  20. app.globalData.goto = options.goto;
  21. }
  22. if (options.SourceID) {
  23. console.log("SourceID:" + options.SourceID);
  24. app.globalData.SourceID = options.SourceID;
  25. }
  26. // 扫码介绍人
  27. if (options.scene) {
  28. var scene = decodeURIComponent(options.scene);
  29. console.log("scene:" + scene);
  30. var introducer = 0;
  31. if (scene.indexOf("UserID") >= 0)
  32. introducer = scene.substr(scene.indexOf("UserID") + 7);
  33. console.log("introducer:" + introducer);
  34. app.globalData.introducer = scene;
  35. }
  36. if (options.ProductID) {
  37. this.setData({
  38. ProductID: options.ProductID,
  39. ProductUserID: options.ProductUserID,
  40. });
  41. }
  42. }
  43. this.setData({
  44. Height: common.getSystemHeight(),
  45. indexImage: common.random(0, 2),
  46. });
  47. this.getUserInfo();
  48. var systemInfo = wx.getSystemInfoSync();
  49. if (systemInfo.model) {
  50. if (systemInfo.model.indexOf("iPad") >= 0) {
  51. this.setData({
  52. ipad: "ipad",
  53. })
  54. }
  55. }
  56. this.updateProgram();
  57. },
  58. //得到用户信息
  59. getUserInfo: function (cb) {
  60. var that = this
  61. //调用登录接口
  62. wx.login({
  63. success: function (res0) {
  64. app.globalData.userInfo = {};
  65. app.globalData.userInfo.Code = res0.code;
  66. //console.log("Code:" + res0.code);
  67. wx.getSetting({
  68. scope: "scope.userInfo",
  69. success(res) {
  70. if (!res.authSetting['scope.userInfo']) {
  71. app.globalData.userInfo.nickName = "陌生用户";
  72. app.globalData.userInfo.language = "";
  73. app.globalData.userInfo.gender = "0";
  74. app.globalData.userInfo.city = "";
  75. app.globalData.userInfo.province = "";
  76. app.globalData.userInfo.country = "";
  77. app.globalData.userInfo.avatarUrl = "../images/FACE.png";
  78. that.login(app.globalData.userInfo);
  79. }
  80. else {
  81. wx.getUserInfo({
  82. withCredentials: false,
  83. success: function (res) {
  84. app.globalData.userInfo = res.userInfo;
  85. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  86. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  87. app.globalData.userInfo.Code = res0.code;
  88. that.login(app.globalData.userInfo);
  89. },
  90. fail: function (res) {
  91. that.login(app.globalData.userInfo);
  92. }
  93. });
  94. }
  95. }
  96. });
  97. },
  98. fail: function () {
  99. timeout2 = setTimeout(function () {
  100. that.getUserInfo();
  101. console.log("reboot:" + new Date().getTime());
  102. }, 2000);
  103. }
  104. });
  105. },
  106. login: function (param) {
  107. var that = this;
  108. server.getLocalHost(function () {
  109. server.postData('HanziLogin', {
  110. Code: param.Code,
  111. NickName: param.nickName,
  112. Language: param.language,
  113. Gender: param.gender,
  114. City: param.city,
  115. Province: param.province,
  116. Country: param.country,
  117. AvatarUrl: param.avatarUrl,
  118. Introducer: app.globalData.introducer,
  119. UserSource: app.globalData.userSource,
  120. SourceID: app.globalData.SourceID,
  121. LastUserSource: app.globalData.userSource,
  122. Brand: app.globalData.systemInfo.brand,
  123. Model: app.globalData.systemInfo.model,
  124. PixelRatio: app.globalData.systemInfo.pixelRatio,
  125. ScreenWidth: app.globalData.systemInfo.screenWidth,
  126. ScreenHeight: app.globalData.systemInfo.screenHeight,
  127. WindowWidth: app.globalData.systemInfo.windowWidth,
  128. WindowHeight: app.globalData.systemInfo.windowHeight,
  129. WXLanguage: app.globalData.systemInfo.language,
  130. WXVersion: app.globalData.systemInfo.version,
  131. System: app.globalData.systemInfo.system,
  132. Platform: app.globalData.systemInfo.platform,
  133. SDKVersion: app.globalData.systemInfo.SDKVersion,
  134. ProgramVersion: app.globalData.Version,
  135. }, function (data) {
  136. //console.log("UserInfo:" + data);
  137. if (!data) {
  138. timeout3 = setTimeout(function () {
  139. that.getUserInfo();
  140. console.log("reboot:" + new Date().getTime());
  141. }, 2000);
  142. }
  143. else {
  144. app.globalData.userInfo = data;
  145. if (that.data.ProductID) {
  146. var url = "../../package4/main/activateOK?ProductID=" + that.data.ProductID
  147. + "&ProductUserID=" + that.data.ProductUserID
  148. + "&CurrentUserID=" + app.globalData.userInfo.UserID
  149. + "&CurrentProductID=" + app.globalData.ProgramID;
  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. that.getPriceList();
  164. }
  165. }
  166. });
  167. });
  168. },
  169. getHanzi: function (callback) {
  170. var that = this;
  171. var time = wx.getStorageSync("HanziUpdateTime");
  172. server.getData('GetHanziAll?UpdateTime=' + time, function (data) {
  173. if (data) {
  174. if (data.List) {
  175. var arr = common.Decrypt(data.List);
  176. wx.setStorageSync("HanziAll", arr);
  177. wx.setStorageSync("HanziUpdateTime", data.UpdateTime);
  178. }
  179. app.globalData.BaiduToken = data.String;
  180. callback();
  181. }
  182. });
  183. },
  184. getPriceList: function () {
  185. var that = this;
  186. if (!wx.getStorageSync("ProductPrice")) {
  187. server.getData('ProductPayPriceList500', function (data) {
  188. if (data) {
  189. var arrProduct = JSON.parse(common.Decrypt(data));
  190. var programList = server.getProgramList();
  191. for (var j = 0; j < arrProduct.length; j++) {
  192. arrProduct[j].ProductList = [];
  193. var arr = arrProduct[j].ProductNum.split(",");
  194. for (var k = 0; k < arr.length; k++) {
  195. for (var i = 0; i < programList.length; i++) {
  196. if (programList[i].ID == arr[k]) {
  197. arrProduct[j].ProductList.push(programList[i]);
  198. }
  199. }
  200. }
  201. }
  202. wx.setStorageSync("ProductPrice", arrProduct);
  203. }
  204. });
  205. }
  206. },
  207. updateProgram: function () {
  208. const updateManager = wx.getUpdateManager();
  209. updateManager.onCheckForUpdate(function (res) {
  210. // 请求完新版本信息的回调
  211. console.log(res.hasUpdate)
  212. });
  213. updateManager.onUpdateReady(function () {
  214. wx.showModal({
  215. title: '更新提示',
  216. content: '新版本已经准备好,是否重启应用?',
  217. success: function (res) {
  218. if (res.confirm) {
  219. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  220. updateManager.applyUpdate()
  221. }
  222. }
  223. });
  224. });
  225. },
  226. onShareAppMessage: function () {
  227. return {
  228. title: app.globalData.ShareTitle,
  229. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  230. imageUrl: app.globalData.ShareImage,
  231. }
  232. },
  233. })