index.js 11 KB

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