index.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var timeout1 = 0, timeout3=0;
  5. var timeoutRedirect=0;
  6. Page({
  7. data: {
  8. Sentence:1,
  9. },
  10. onPullDownRefresh: function () {
  11. wx.reLaunch({
  12. url: './index',
  13. })
  14. },
  15. onLoad: function (options) {
  16. console.log("Time1:" + new Date().getTime());
  17. if (options) {
  18. if (options.UserID) {
  19. console.log("UserID:" + options.UserID);
  20. app.globalData.introducer = options.UserID;
  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. if (scene.indexOf("type=article")>=0){
  31. app.globalData.SourceID=scene.substr(scene.indexOf("ID=") + 3);
  32. this.setData({
  33. gotoType: "other",
  34. gotoUrl: '../main/docs?ID=' + app.globalData.SourceID,
  35. });
  36. }
  37. else if (scene.indexOf("type=web")>=0){
  38. app.globalData.SourceID=scene.substr(scene.indexOf("ID=") + 3);
  39. }
  40. else{
  41. var introducer = 0;
  42. if (scene.indexOf("UserID") >= 0)
  43. introducer = scene.substr(scene.indexOf("UserID") + 7);
  44. console.log("introducer:" + introducer);
  45. app.globalData.introducer = scene;
  46. }
  47. }
  48. if (options.type == "school") {
  49. this.setData({
  50. gotoType: "other",
  51. gotoUrl: '../main/school?ID=' + options.ID,
  52. });
  53. }
  54. else if (options.type == "district") {
  55. this.setData({
  56. gotoType: "other",
  57. gotoUrl: '../main/district?ID=' + options.ID+'&Name='+options.Name,
  58. });
  59. }
  60. else if (options.type == "recruitment") {
  61. this.setData({
  62. gotoType: "other",
  63. gotoUrl: '../main/recruitment?PanelType=' + options.PanelType+'&DistrictID='+options.DistrictID,
  64. });
  65. }
  66. else if (options.type == "scoreline") {
  67. this.setData({
  68. gotoType: "other",
  69. gotoUrl: '../main/scoreline?PageType='+options.type+'&ScoreTypeID='+options.ScoreTypeID+'&DistrictID=' + options.ID+"&YearIndex="+options.YearIndex,
  70. });
  71. }
  72. else if (options.type == "docs") {
  73. this.setData({
  74. gotoType: "other",
  75. gotoUrl: '../main/docs?ID=' + options.ID,
  76. });
  77. }
  78. else if (options.type == "wish") {
  79. this.setData({
  80. gotoType: "other",
  81. gotoUrl: '../main/wishinfo?Share=1&ID=' + options.ID,
  82. });
  83. }
  84. }
  85. this.setData({
  86. IsRefresh: false,
  87. Containnerheight: main.getWindowHeight(),
  88. Sentence:common.random(1, 9),
  89. });
  90. this.updateProgram();
  91. this.getUserInfo();
  92. var that = this;
  93. timeout1 = setTimeout(function () {
  94. that.setData({
  95. IsRefresh: true,
  96. })
  97. }, 15000);
  98. },
  99. //得到用户信息
  100. getUserInfo: function (cb) {
  101. var that = this
  102. //调用登录接口
  103. wx.login({
  104. success: function (res0) {
  105. app.globalData.userInfo = {};
  106. app.globalData.userInfo.Code = res0.code;
  107. console.log("Time2:" + new Date().getTime());
  108. app.globalData.userInfo.nickName = "陌生用户";
  109. app.globalData.userInfo.language = "";
  110. app.globalData.userInfo.gender = "0";
  111. app.globalData.userInfo.city = "";
  112. app.globalData.userInfo.province = "";
  113. app.globalData.userInfo.country = "";
  114. app.globalData.userInfo.avatarUrl = "../images/icon_sys_14.png";
  115. that.login(app.globalData.userInfo);
  116. },
  117. fail: function () {}
  118. });
  119. },
  120. login: function (param) {
  121. var that = this;
  122. main.getLocalHost(function () {
  123. main.postData('MPSLogin', {
  124. Code: param.Code,
  125. NickName: param.nickName,
  126. Language: param.language,
  127. Gender: param.gender,
  128. City: param.city,
  129. Province: param.province,
  130. Country: param.country,
  131. AvatarUrl: param.avatarUrl,
  132. Introducer: app.globalData.introducer,
  133. UserSource: app.globalData.userSource,
  134. SourceID: app.globalData.SourceID,
  135. LastUserSource: app.globalData.userSource,
  136. Brand: app.globalData.systemInfo.brand,
  137. Model: app.globalData.systemInfo.model,
  138. PixelRatio: app.globalData.systemInfo.pixelRatio,
  139. ScreenWidth: app.globalData.systemInfo.screenWidth,
  140. ScreenHeight: app.globalData.systemInfo.screenHeight,
  141. WindowWidth: app.globalData.systemInfo.windowWidth,
  142. WindowHeight: app.globalData.systemInfo.windowHeight,
  143. WXLanguage: app.globalData.systemInfo.language,
  144. WXVersion: app.globalData.systemInfo.version,
  145. System: app.globalData.systemInfo.system,
  146. Platform: app.globalData.systemInfo.platform,
  147. SDKVersion: app.globalData.systemInfo.SDKVersion,
  148. ProgramVersion: app.globalData.Version,
  149. }, function (data) {
  150. console.log("Time4:" + new Date().getTime());
  151. if (!data) {
  152. timeout3 = setTimeout(function () {
  153. that.getUserInfo();
  154. console.log("reboot:" + new Date().getTime());
  155. }, 2000);
  156. }
  157. else {
  158. app.globalData.userInfo = data;
  159. var isShow = data.IsShow;
  160. if (isShow == -1) {
  161. isShow = 0;
  162. }
  163. else {
  164. var systemInfo = wx.getSystemInfoSync();
  165. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  166. isShow = 1;
  167. }
  168. }
  169. app.globalData.userInfo.IsShow = isShow;
  170. if (app.globalData.userInfo.IsMember == 1)
  171. app.globalData.IsLocked = 0;
  172. wx.removeStorageSync("UserID");
  173. wx.removeStorageSync("UserName");
  174. wx.removeStorageSync("CollectList");
  175. if (that.data.gotoType == "other"){
  176. app.globalData.GotoUrl = that.data.gotoUrl;
  177. var url = '../main/default';
  178. wx.redirectTo({
  179. url: url,
  180. });
  181. }
  182. else{
  183. var url = '../main/default';
  184. timeoutRedirect=setTimeout(function () {
  185. console.log("Time5:" + new Date().getTime());
  186. clearTimeout(timeout1);
  187. wx.redirectTo({
  188. url: url,
  189. });
  190. }, 200);
  191. }
  192. that.getBaiduToken();
  193. }
  194. });
  195. });
  196. },
  197. getBaiduToken: function () {
  198. main.getBaiduToken();
  199. },
  200. updateProgram: function () {
  201. const updateManager = wx.getUpdateManager();
  202. updateManager.onCheckForUpdate(function (res) {
  203. // 请求完新版本信息的回调
  204. });
  205. updateManager.onUpdateReady(function () {
  206. clearTimeout(timeoutRedirect);
  207. wx.showModal({
  208. title: '更新提示',
  209. content: '新版本已经准备好,重启应用',
  210. showCancel:false,
  211. success: function (res) {
  212. wx.removeStorageSync("UserID");
  213. wx.removeStorageSync("UserName");
  214. updateManager.applyUpdate();
  215. }
  216. });
  217. });
  218. },
  219. onShareAppMessage: function () {
  220. return {
  221. title: app.globalData.ShareTitle,
  222. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  223. imageUrl: app.globalData.ShareImage,
  224. }
  225. },
  226. })