index.js 8.5 KB

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