index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. }
  79. this.setData({
  80. IsRefresh: false,
  81. Containnerheight: main.getWindowHeight(),
  82. Sentence:common.random(1, 9),
  83. });
  84. this.updateProgram();
  85. this.getUserInfo();
  86. var that = this;
  87. timeout1 = setTimeout(function () {
  88. that.setData({
  89. IsRefresh: true,
  90. })
  91. }, 15000);
  92. },
  93. //得到用户信息
  94. getUserInfo: function (cb) {
  95. var that = this
  96. //调用登录接口
  97. wx.login({
  98. success: function (res0) {
  99. app.globalData.userInfo = {};
  100. app.globalData.userInfo.Code = res0.code;
  101. console.log("Time2:" + new Date().getTime());
  102. app.globalData.userInfo.nickName = "陌生用户";
  103. app.globalData.userInfo.language = "";
  104. app.globalData.userInfo.gender = "0";
  105. app.globalData.userInfo.city = "";
  106. app.globalData.userInfo.province = "";
  107. app.globalData.userInfo.country = "";
  108. app.globalData.userInfo.avatarUrl = "../images/universalpic_face_default_blue_120x120.png";
  109. that.login(app.globalData.userInfo);
  110. },
  111. fail: function () {}
  112. });
  113. },
  114. login: function (param) {
  115. var that = this;
  116. main.getLocalHost(function () {
  117. main.postData('MPSLogin', {
  118. Code: param.Code,
  119. NickName: param.nickName,
  120. Language: param.language,
  121. Gender: param.gender,
  122. City: param.city,
  123. Province: param.province,
  124. Country: param.country,
  125. AvatarUrl: param.avatarUrl,
  126. Introducer: app.globalData.introducer,
  127. UserSource: app.globalData.userSource,
  128. SourceID: app.globalData.SourceID,
  129. LastUserSource: app.globalData.userSource,
  130. Brand: app.globalData.systemInfo.brand,
  131. Model: app.globalData.systemInfo.model,
  132. PixelRatio: app.globalData.systemInfo.pixelRatio,
  133. ScreenWidth: app.globalData.systemInfo.screenWidth,
  134. ScreenHeight: app.globalData.systemInfo.screenHeight,
  135. WindowWidth: app.globalData.systemInfo.windowWidth,
  136. WindowHeight: app.globalData.systemInfo.windowHeight,
  137. WXLanguage: app.globalData.systemInfo.language,
  138. WXVersion: app.globalData.systemInfo.version,
  139. System: app.globalData.systemInfo.system,
  140. Platform: app.globalData.systemInfo.platform,
  141. SDKVersion: app.globalData.systemInfo.SDKVersion,
  142. ProgramVersion: app.globalData.Version,
  143. }, function (data) {
  144. console.log("Time4:" + new Date().getTime());
  145. if (!data) {
  146. timeout3 = setTimeout(function () {
  147. that.getUserInfo();
  148. console.log("reboot:" + new Date().getTime());
  149. }, 2000);
  150. }
  151. else {
  152. app.globalData.userInfo = data;
  153. var isShow = data.IsShow;
  154. if (isShow == -1) {
  155. isShow = 0;
  156. }
  157. else {
  158. var systemInfo = wx.getSystemInfoSync();
  159. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  160. isShow = 1;
  161. }
  162. }
  163. app.globalData.userInfo.IsShow = isShow;
  164. if (app.globalData.userInfo.IsMember == 1)
  165. app.globalData.IsLocked = 0;
  166. wx.removeStorageSync("UserID");
  167. wx.removeStorageSync("UserName");
  168. wx.removeStorageSync("CollectList");
  169. if (that.data.gotoType == "other"){
  170. app.globalData.GotoUrl = that.data.gotoUrl;
  171. var url = '../main/default';
  172. wx.redirectTo({
  173. url: url,
  174. });
  175. }
  176. else{
  177. var url = '../main/default';
  178. timeoutRedirect=setTimeout(function () {
  179. console.log("Time5:" + new Date().getTime());
  180. clearTimeout(timeout1);
  181. wx.redirectTo({
  182. url: url,
  183. });
  184. }, 200);
  185. }
  186. that.getBaiduToken();
  187. }
  188. });
  189. });
  190. },
  191. getBaiduToken: function () {
  192. main.getBaiduToken();
  193. },
  194. updateProgram: function () {
  195. const updateManager = wx.getUpdateManager();
  196. updateManager.onCheckForUpdate(function (res) {
  197. // 请求完新版本信息的回调
  198. });
  199. updateManager.onUpdateReady(function () {
  200. clearTimeout(timeoutRedirect);
  201. wx.showModal({
  202. title: '更新提示',
  203. content: '新版本已经准备好,重启应用',
  204. showCancel:false,
  205. success: function (res) {
  206. wx.removeStorageSync("UserID");
  207. wx.removeStorageSync("UserName");
  208. updateManager.applyUpdate();
  209. }
  210. });
  211. });
  212. },
  213. onShareAppMessage: function () {
  214. return {
  215. title: app.globalData.ShareTitle,
  216. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  217. imageUrl: app.globalData.ShareImage,
  218. }
  219. },
  220. })