index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. const arrSentence = [
  5. "荀子曰:\n君子博学而日参省乎己,\n则知明而行无过矣",
  6. "为什么订正过的题目还会错?\n天天秒过,反复巩固,不再出错",
  7. "子曰:\n学而时习之,不亦说乎。",
  8. "秒过之前,错字连篇\n秒过之后,错字罕见",
  9. "子曰:\n学而不思则罔\n思而不学则殆",
  10. "记忆是思考的残留物\n唯有不断思考才能记住",
  11. "荀子曰:\n青,取之于蓝,而青于蓝\n冰,水为之,而寒于水",
  12. "舒适区练习不会带来改变\n只有刻意练习才能提高",
  13. "荀子曰:\n不积跬步,无以至千里\n不积小流,无以成江海",
  14. "死记硬背? No! \n测试可以知晓自己\n问题在哪里。",
  15. "荀子曰:\n骐骥一跃,不能十步\n驽马十驾,功在不舍",
  16. "同一时间反复练习?No! \n要间隔练习、穿插练习、换环境练习",
  17. "荀子曰:\n锲而舍之,朽木不折\n锲而不舍,金石可镂",
  18. "所谓的粗心\n只是对细节缺乏敏感\n秒过关注每个细节",
  19. "孟子曰:\n故天将降大任于是人也\n必先苦其心志,劳其筋骨\n饿其体肤……",
  20. ];
  21. var timeout1 = 0, timeout3=0;
  22. var timeoutRedirect=0;
  23. Page({
  24. data: {
  25. Sentence:1,
  26. },
  27. onPullDownRefresh: function () {
  28. wx.reLaunch({
  29. url: './index',
  30. })
  31. },
  32. onLoad: function (options) {
  33. console.log("Time1:" + new Date().getTime());
  34. if (options) {
  35. if (options.UserID) {
  36. console.log("UserID:" + options.UserID);
  37. app.globalData.introducer = options.UserID;
  38. }
  39. if (options.SourceID) {
  40. console.log("SourceID:" + options.SourceID);
  41. app.globalData.SourceID = options.SourceID;
  42. }
  43. // 扫码介绍人
  44. if (options.scene) {
  45. var scene = decodeURIComponent(options.scene);
  46. console.log("scene:" + scene);
  47. if (scene.indexOf("type=print")>=0){
  48. options.type="print";
  49. options.PUserID=scene.substr(scene.indexOf("U") + 2);
  50. options.PrintID=scene.substring(scene.indexOf("P") + 2,scene.indexOf("&U"));
  51. }
  52. else{
  53. var introducer = 0;
  54. if (scene.indexOf("UserID") >= 0)
  55. introducer = scene.substr(scene.indexOf("UserID") + 7);
  56. console.log("introducer:" + introducer);
  57. app.globalData.introducer = scene;
  58. }
  59. }
  60. if (options.type == "share") {
  61. if (options.ColorIndex)
  62. app.globalData.ColorIndex = options.ColorIndex;
  63. this.setData({
  64. gotoType: "share",
  65. gotoUrl: '../main/preview?type=share&id=' + options.MiaoguoCardID,
  66. });
  67. }
  68. else if (options.type == "bebound") {
  69. this.setData({
  70. gotoType: "bebound",
  71. gotoUrl: "../other/binding?type=bebound&ParentUserID=" + options.ParentUserID + "&NickName=" + options.NickName + "&AvatarUrl=" + options.AvatarUrl + "&BindTime=" + options.BindTime,
  72. });
  73. }
  74. else if (options.type == "lesson" || options.type == "video") {
  75. //console.log("Lesson:" + options.LessonID);
  76. app.globalData.LessonID = options.LessonID;
  77. if (options.LessonPage)
  78. app.globalData.LessonPage = options.LessonPage;
  79. else
  80. app.globalData.LessonPage = 1;
  81. var url="";
  82. if (options.type == "video"){
  83. url = '../other/video?LessonID=' + app.globalData.LessonID + '&LessonPage=' + app.globalData.LessonPage
  84. }
  85. else{
  86. if (app.globalData.LessonID === "all") {
  87. url = '../other/lessonlist';
  88. }
  89. else if (app.globalData.LessonID > 0) {
  90. url = '../other/lesson?LessonID=' + app.globalData.LessonID + '&LessonPage=' + app.globalData.LessonPage
  91. }
  92. }
  93. this.setData({
  94. gotoType: "other",
  95. gotoUrl: url,
  96. });
  97. }
  98. else if (options.type == "marketing") {
  99. this.setData({
  100. gotoType: "other",
  101. gotoUrl: '../marketing/index',
  102. });
  103. }
  104. else if (options.type == "homework") {
  105. this.setData({
  106. gotoType: "other",
  107. gotoUrl: "../other/homework",
  108. });
  109. }
  110. else if (options.type == "userbook") {
  111. this.setData({
  112. gotoType: "other",
  113. gotoUrl: "../other/userbook",
  114. });
  115. }
  116. else if (options.type == "activity") {
  117. this.setData({
  118. gotoType: "other",
  119. gotoUrl: "../other/activity?ActivityID=" + options.ActivityID + "&EarlyBirdTimeStart=" + options.EarlyBirdTimeStart + "&EarlyBirdTimeEnd=" + options.EarlyBirdTimeEnd + "&EndTime=" + options.EndTime,
  120. });
  121. }
  122. else if (options.type == "webview") {
  123. this.setData({
  124. gotoType: "other",
  125. gotoUrl: "../other/webview?PageID=" + options.PageID,
  126. });
  127. }
  128. else if (options.type == "help") {
  129. this.setData({
  130. gotoType: "other",
  131. gotoUrl: "../other/help?IsShare=1&id=" + options.ID+"&idchild="+options.IDChild,
  132. });
  133. }
  134. else if (options.type == "paycustom") {
  135. this.setData({
  136. gotoType: "other",
  137. gotoUrl: "../other/pay?PayType=6&PayUserID="+options.PayUserID+"&DayNumber="+options.DayNumber+"&Price="+options.Price+"&Remark="+options.Remark,
  138. });
  139. }
  140. else if (options.type == "print") {
  141. var pid=options.PrintID;
  142. if (!pid)
  143. pid=options.P;
  144. this.setData({
  145. gotoType: "other",
  146. gotoUrl: "../main/mainlist?PrintID="+pid,
  147. });
  148. }
  149. else if (options.type == "paycontinue") {
  150. this.setData({
  151. gotoType: "other",
  152. gotoUrl: "../other/pay?PayType=7&EndDate="+options.EndDate,
  153. });
  154. }
  155. }
  156. this.setData({
  157. IsRefresh: false,
  158. Containnerheight: main.getWindowHeight(),
  159. //Sentence: arrSentence[common.random(0, arrSentence.length - 1)],
  160. Sentence:common.random(1, 9),
  161. });
  162. this.updateProgram();
  163. this.getUserInfo();
  164. var that = this;
  165. timeout1 = setTimeout(function () {
  166. that.setData({
  167. IsRefresh: true,
  168. })
  169. }, 15000);
  170. },
  171. //得到用户信息
  172. getUserInfo: function (cb) {
  173. var that = this
  174. //调用登录接口
  175. wx.login({
  176. success: function (res0) {
  177. app.globalData.userInfo = {};
  178. app.globalData.userInfo.Code = res0.code;
  179. console.log("Time2:" + new Date().getTime());
  180. wx.getSetting({
  181. scope: "scope.userInfo",
  182. success(res) {
  183. if (!res.authSetting['scope.userInfo']) {
  184. app.globalData.userInfo.nickName = "陌生用户";
  185. app.globalData.userInfo.language = "";
  186. app.globalData.userInfo.gender = "0";
  187. app.globalData.userInfo.city = "";
  188. app.globalData.userInfo.province = "";
  189. app.globalData.userInfo.country = "";
  190. app.globalData.userInfo.avatarUrl = "../images/universalpic_face_default_blue_120x120.png";
  191. that.login(app.globalData.userInfo);
  192. }
  193. else {
  194. wx.getUserInfo({
  195. withCredentials: false,
  196. success: function (res) {
  197. console.log("Time3:" + new Date().getTime());
  198. app.globalData.userInfo = res.userInfo;
  199. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  200. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  201. app.globalData.userInfo.Code = res0.code;
  202. that.login(app.globalData.userInfo);
  203. },
  204. fail: function (res) {
  205. that.login(app.globalData.userInfo);
  206. }
  207. });
  208. }
  209. }
  210. });
  211. },
  212. fail: function () {
  213. }
  214. });
  215. },
  216. login: function (param) {
  217. var that = this;
  218. //var userSource = wx.getLaunchOptionsSync();
  219. //console.log("userSource1:" + userSource.scene);
  220. //console.log("userSource2:" + app.globalData.userSource);
  221. main.getLocalHost(function () {
  222. main.postData('MiaoguoLogin', {
  223. Code: param.Code,
  224. NickName: param.nickName,
  225. Language: param.language,
  226. Gender: param.gender,
  227. City: param.city,
  228. Province: param.province,
  229. Country: param.country,
  230. AvatarUrl: param.avatarUrl,
  231. Introducer: app.globalData.introducer,
  232. UserSource: app.globalData.userSource,
  233. SourceID: app.globalData.SourceID,
  234. LastUserSource: app.globalData.userSource,
  235. Brand: app.globalData.systemInfo.brand,
  236. Model: app.globalData.systemInfo.model,
  237. PixelRatio: app.globalData.systemInfo.pixelRatio,
  238. ScreenWidth: app.globalData.systemInfo.screenWidth,
  239. ScreenHeight: app.globalData.systemInfo.screenHeight,
  240. WindowWidth: app.globalData.systemInfo.windowWidth,
  241. WindowHeight: app.globalData.systemInfo.windowHeight,
  242. WXLanguage: app.globalData.systemInfo.language,
  243. WXVersion: app.globalData.systemInfo.version,
  244. System: app.globalData.systemInfo.system,
  245. Platform: app.globalData.systemInfo.platform,
  246. SDKVersion: app.globalData.systemInfo.SDKVersion,
  247. ProgramVersion: app.globalData.Version,
  248. }, function (data) {
  249. console.log("Time4:" + new Date().getTime());
  250. if (!data) {
  251. timeout3 = setTimeout(function () {
  252. that.getUserInfo();
  253. console.log("reboot:" + new Date().getTime());
  254. }, 2000);
  255. }
  256. else {
  257. app.globalData.userInfo = data;
  258. var isShow = data.IsShow;
  259. if (isShow == -1) {
  260. isShow = 0;
  261. }
  262. else {
  263. var systemInfo = wx.getSystemInfoSync();
  264. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  265. isShow = 1;
  266. }
  267. }
  268. app.globalData.userInfo.IsShow = isShow;
  269. if (app.globalData.userInfo.IsMember == 1)
  270. app.globalData.IsLocked = 0;
  271. wx.removeStorageSync("UserID");
  272. wx.removeStorageSync("UserName");
  273. // //测试****************
  274. // var url = '../main/mainlist';
  275. // wx.redirectTo({
  276. // url: url,
  277. // });
  278. // return;
  279. // //测试****************
  280. if (that.data.gotoType == "share") {
  281. wx.reLaunch({
  282. url: that.data.gotoUrl,
  283. });
  284. }
  285. else if (that.data.gotoType == "bebound") {
  286. wx.reLaunch({
  287. url: that.data.gotoUrl,
  288. });
  289. }
  290. else {
  291. if (that.data.gotoType == "other"){
  292. app.globalData.GotoUrl = that.data.gotoUrl;
  293. var url = '../main/default';
  294. wx.redirectTo({
  295. url: url,
  296. });
  297. }
  298. else{
  299. var url = '../main/default';
  300. timeoutRedirect=setTimeout(function () {
  301. console.log("Time5:" + new Date().getTime());
  302. clearTimeout(timeout1);
  303. app.globalData.FolderList=[];
  304. wx.redirectTo({
  305. url: url,
  306. });
  307. }, 2000);
  308. }
  309. main.getUserConfig();
  310. }
  311. that.getBaiduToken();
  312. }
  313. });
  314. });
  315. },
  316. getBaiduToken: function () {
  317. main.getBaiduToken();
  318. },
  319. updateProgram: function () {
  320. const updateManager = wx.getUpdateManager();
  321. updateManager.onCheckForUpdate(function (res) {
  322. // 请求完新版本信息的回调
  323. //console.log(res.hasUpdate)
  324. });
  325. updateManager.onUpdateReady(function () {
  326. clearTimeout(timeoutRedirect);
  327. wx.showModal({
  328. title: '更新提示',
  329. content: '新版本已经准备好,重启应用',
  330. showCancel:false,
  331. success: function (res) {
  332. wx.removeStorageSync("UserID");
  333. wx.removeStorageSync("UserName");
  334. wx.removeStorageSync("SearchWord3");
  335. wx.removeStorageSync("HanziUpdateTime");
  336. wx.removeStorageSync("HanziAll");
  337. wx.removeStorageSync("EnglishAll");
  338. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  339. updateManager.applyUpdate();
  340. }
  341. });
  342. });
  343. },
  344. onShareAppMessage: function () {
  345. return {
  346. title: app.globalData.ShareTitle,
  347. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  348. imageUrl: app.globalData.ShareImage,
  349. }
  350. },
  351. })