index.js 12 KB

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