index.js 11 KB

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