index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. // var interval=null;
  17. // var index=0;
  18. // interval = setInterval(function () {
  19. // index++;
  20. // console.log(index);
  21. // if (index>10) {
  22. // clearInterval(interval);
  23. // }
  24. // },200);
  25. console.log("Time1:" + new Date().getTime());
  26. if (options) {
  27. if (options.UserID) {
  28. console.log("UserID:" + options.UserID);
  29. app.globalData.introducer = options.UserID;
  30. }
  31. if (options.SourceID) {
  32. console.log("SourceID:" + options.SourceID);
  33. app.globalData.SourceID = options.SourceID;
  34. }
  35. // 扫码介绍人
  36. if (options.scene) {
  37. var scene = decodeURIComponent(options.scene);
  38. console.log("scene:" + scene);
  39. if (scene.indexOf("type=print")>=0){
  40. options.type="print";
  41. options.PUserID=scene.substr(scene.indexOf("U") + 2);
  42. options.PrintID=scene.substring(scene.indexOf("P") + 2,scene.indexOf("&U"));
  43. }
  44. else{
  45. var introducer = 0;
  46. if (scene.indexOf("UserID") >= 0)
  47. introducer = scene.substr(scene.indexOf("UserID") + 7);
  48. console.log("introducer:" + introducer);
  49. app.globalData.introducer = scene;
  50. }
  51. }
  52. if (options.type == "share") {
  53. if (options.ColorIndex)
  54. app.globalData.ColorIndex = options.ColorIndex;
  55. this.setData({
  56. gotoType: "share",
  57. gotoUrl: '../main/preview?type=share&id=' + options.MiaoguoCardID,
  58. });
  59. }
  60. else if (options.type == "bebound") {
  61. this.setData({
  62. gotoType: "bebound",
  63. gotoUrl: "../other/binding?type=bebound&ParentUserID=" + options.ParentUserID + "&NickName=" + options.NickName + "&AvatarUrl=" + options.AvatarUrl + "&BindTime=" + options.BindTime,
  64. });
  65. }
  66. else if (options.type == "lesson" || options.type == "video") {
  67. app.globalData.LessonID = options.LessonID;
  68. if (options.LessonPage)
  69. app.globalData.LessonPage = options.LessonPage;
  70. else
  71. app.globalData.LessonPage = 1;
  72. var url="";
  73. if (options.type == "video"){
  74. url = '../other/video?LessonID=' + app.globalData.LessonID + '&LessonPage=' + app.globalData.LessonPage
  75. }
  76. else{
  77. if (app.globalData.LessonID === "all") {
  78. if (!options.ListType)
  79. url = '../other/lessonlistselect';
  80. else
  81. url = '../other/lessonlist?listtype='+options.ListType;
  82. }
  83. else if (app.globalData.LessonID > 0) {
  84. url = '../other/lesson?LessonID=' + app.globalData.LessonID + '&LessonPage=' + app.globalData.LessonPage
  85. }
  86. }
  87. this.setData({
  88. gotoType: "other",
  89. gotoUrl: url,
  90. });
  91. }
  92. else if (options.type == "marketing") {
  93. this.setData({
  94. gotoType: "other",
  95. gotoUrl: '../marketing/index',
  96. });
  97. }
  98. else if (options.type == "homework") {
  99. this.setData({
  100. gotoType: "other",
  101. gotoUrl: "../other/homework",
  102. });
  103. }
  104. else if (options.type == "userbook") {
  105. this.setData({
  106. gotoType: "other",
  107. gotoUrl: "../other/userbook",
  108. });
  109. }
  110. else if (options.type == "activity") {
  111. this.setData({
  112. gotoType: "other",
  113. gotoUrl: "../other/activity?ActivityID=" + options.ActivityID + "&EarlyBirdTimeStart=" + options.EarlyBirdTimeStart + "&EarlyBirdTimeEnd=" + options.EarlyBirdTimeEnd + "&EndTime=" + options.EndTime,
  114. });
  115. }
  116. else if (options.type == "webview") {
  117. this.setData({
  118. gotoType: "other",
  119. gotoUrl: "../other/webview?PageID=" + options.PageID,
  120. });
  121. }
  122. else if (options.type == "help") {
  123. this.setData({
  124. gotoType: "other",
  125. gotoUrl: "../other/help?IsShare=1&id=" + options.ID+"&idchild="+options.IDChild,
  126. });
  127. }
  128. else if (options.type == "paycustom") {
  129. this.setData({
  130. gotoType: "other",
  131. gotoUrl: "../other/pay?PayType=6&PayUserID="+options.PayUserID+"&DayNumber="+options.DayNumber+"&Price="+options.Price+"&Remark="+options.Remark,
  132. });
  133. }
  134. else if (options.type == "print") {
  135. var pid=options.PrintID;
  136. if (!pid)
  137. pid=options.P;
  138. var puid=options.PUserID;
  139. this.setData({
  140. gotoType: "other",
  141. gotoUrl: "../main/mainlist?PrintID="+pid+"&PrintUserID="+puid,
  142. });
  143. }
  144. else if (options.type == "paycontinue") {
  145. this.setData({
  146. gotoType: "other",
  147. gotoUrl: "../other/pay?PayType=7&EndDate="+options.EndDate,
  148. });
  149. }
  150. }
  151. this.setData({
  152. IsRefresh: false,
  153. Containnerheight: main.getWindowHeight(),
  154. Sentence:common.random(1, 9),
  155. });
  156. this.updateProgram();
  157. this.getUserInfo();
  158. var that = this;
  159. timeout1 = setTimeout(function () {
  160. that.setData({
  161. IsRefresh: true,
  162. })
  163. }, 15000);
  164. },
  165. //得到用户信息
  166. getUserInfo: function (cb) {
  167. var that = this
  168. //调用登录接口
  169. wx.login({
  170. success: function (res0) {
  171. app.globalData.userInfo = {};
  172. app.globalData.userInfo.Code = res0.code;
  173. console.log("Time2:" + new Date().getTime());
  174. app.globalData.userInfo.nickName = "陌生用户";
  175. app.globalData.userInfo.language = "";
  176. app.globalData.userInfo.gender = "0";
  177. app.globalData.userInfo.city = "";
  178. app.globalData.userInfo.province = "";
  179. app.globalData.userInfo.country = "";
  180. app.globalData.userInfo.avatarUrl = "../images/universalpic_face_default_blue_120x120.png";
  181. that.login(app.globalData.userInfo);
  182. },
  183. fail: function () {}
  184. });
  185. },
  186. login: function (param) {
  187. var that = this;
  188. main.getLocalHost(function () {
  189. main.postData('MiaoguoLogin', {
  190. Code: param.Code,
  191. NickName: param.nickName,
  192. Language: param.language,
  193. Gender: param.gender,
  194. City: param.city,
  195. Province: param.province,
  196. Country: param.country,
  197. AvatarUrl: param.avatarUrl,
  198. Introducer: app.globalData.introducer,
  199. UserSource: app.globalData.userSource,
  200. SourceID: app.globalData.SourceID,
  201. LastUserSource: app.globalData.userSource,
  202. Brand: app.globalData.systemInfo.brand,
  203. Model: app.globalData.systemInfo.model,
  204. PixelRatio: app.globalData.systemInfo.pixelRatio,
  205. ScreenWidth: app.globalData.systemInfo.screenWidth,
  206. ScreenHeight: app.globalData.systemInfo.screenHeight,
  207. WindowWidth: app.globalData.systemInfo.windowWidth,
  208. WindowHeight: app.globalData.systemInfo.windowHeight,
  209. WXLanguage: app.globalData.systemInfo.language,
  210. WXVersion: app.globalData.systemInfo.version,
  211. System: app.globalData.systemInfo.system,
  212. Platform: app.globalData.systemInfo.platform,
  213. SDKVersion: app.globalData.systemInfo.SDKVersion,
  214. ProgramVersion: app.globalData.Version,
  215. }, function (data) {
  216. console.log("Time4:" + new Date().getTime());
  217. if (!data) {
  218. timeout3 = setTimeout(function () {
  219. that.getUserInfo();
  220. console.log("reboot:" + new Date().getTime());
  221. }, 2000);
  222. }
  223. else {
  224. app.globalData.userInfo = data;
  225. var isShow = data.IsShow;
  226. if (isShow == -1) {
  227. isShow = 0;
  228. }
  229. else {
  230. var systemInfo = wx.getSystemInfoSync();
  231. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  232. isShow = 1;
  233. }
  234. }
  235. app.globalData.userInfo.IsShow = isShow;
  236. if (app.globalData.userInfo.IsMember == 1)
  237. app.globalData.IsLocked = 0;
  238. wx.removeStorageSync("UserID");
  239. wx.removeStorageSync("UserName");
  240. // //测试****************
  241. // var url = '../other/newuser';
  242. // wx.redirectTo({
  243. // url: url,
  244. // });
  245. // return;
  246. // //测试****************
  247. if (that.data.gotoType == "share") {
  248. wx.reLaunch({
  249. url: that.data.gotoUrl,
  250. });
  251. }
  252. else if (that.data.gotoType == "bebound") {
  253. wx.reLaunch({
  254. url: that.data.gotoUrl,
  255. });
  256. }
  257. else {
  258. if (that.data.gotoType == "other"){
  259. app.globalData.GotoUrl = that.data.gotoUrl;
  260. var url = '../main/default';
  261. wx.redirectTo({
  262. url: url,
  263. });
  264. }
  265. else{
  266. var url = '../main/default';
  267. timeoutRedirect=setTimeout(function () {
  268. console.log("Time5:" + new Date().getTime());
  269. clearTimeout(timeout1);
  270. clearTimeout(timeout3);
  271. app.globalData.FolderList=[];
  272. wx.redirectTo({
  273. url: url,
  274. });
  275. }, 2000);
  276. }
  277. main.getUserConfig();
  278. }
  279. that.getBaiduToken();
  280. }
  281. });
  282. });
  283. },
  284. getBaiduToken: function () {
  285. main.getBaiduToken();
  286. },
  287. updateProgram: function () {
  288. const updateManager = wx.getUpdateManager();
  289. updateManager.onCheckForUpdate(function (res) {
  290. // 请求完新版本信息的回调
  291. });
  292. updateManager.onUpdateReady(function () {
  293. clearTimeout(timeoutRedirect);
  294. wx.showModal({
  295. title: '更新提示',
  296. content: '新版本已经准备好,重启应用',
  297. showCancel:false,
  298. success: function (res) {
  299. wx.removeStorageSync("UserID");
  300. wx.removeStorageSync("UserName");
  301. wx.removeStorageSync("SearchWord3");
  302. wx.removeStorageSync("HanziUpdateTime");
  303. wx.removeStorageSync("HanziAll");
  304. wx.removeStorageSync("EnglishAll");
  305. updateManager.applyUpdate();
  306. }
  307. });
  308. });
  309. },
  310. onShareAppMessage: function () {
  311. return {
  312. title: app.globalData.ShareTitle,
  313. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  314. imageUrl: app.globalData.ShareImage,
  315. }
  316. },
  317. })