index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. Page({
  22. data: {
  23. },
  24. onPullDownRefresh: function () {
  25. wx.reLaunch({
  26. url: './index',
  27. })
  28. },
  29. onLoad: function (options) {
  30. if (options) {
  31. if (options.UserID) {
  32. console.log("UserID:" + options.UserID);
  33. app.globalData.introducer = options.UserID;
  34. if (options.QuestionTypeID)
  35. questionTypeID = options.QuestionTypeID;
  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.Share == 1) {
  52. this.setData({
  53. MiaoguoCardID: options.MiaoguoCardID,
  54. });
  55. }
  56. if (options.LessonID) {
  57. console.log("Lesson:" + options.LessonID);
  58. app.globalData.LessonID = options.LessonID;
  59. if (options.LessonPage)
  60. app.globalData.LessonPage = options.LessonPage;
  61. else
  62. app.globalData.LessonPage = 1;
  63. }
  64. }
  65. this.setData({
  66. Containnerheight: main.getWindowHeight(),
  67. Sentence: arrSentence[common.random(0, arrSentence.length - 1)],
  68. });
  69. this.updateProgram();
  70. this.getUserInfo();
  71. },
  72. //得到用户信息
  73. getUserInfo: function (cb) {
  74. var that = this
  75. //调用登录接口
  76. wx.login({
  77. success: function (res0) {
  78. app.globalData.userInfo = {};
  79. app.globalData.userInfo.Code = res0.code;
  80. //console.log("Code:" + res0.code);
  81. wx.getSetting({
  82. scope: "scope.userInfo",
  83. success(res) {
  84. if (!res.authSetting['scope.userInfo']) {
  85. app.globalData.userInfo.nickName = "陌生用户";
  86. app.globalData.userInfo.language = "";
  87. app.globalData.userInfo.gender = "0";
  88. app.globalData.userInfo.city = "";
  89. app.globalData.userInfo.province = "";
  90. app.globalData.userInfo.country = "";
  91. app.globalData.userInfo.avatarUrl = "../images/universalpic_face_default_blue_120x120.png";
  92. that.login(app.globalData.userInfo);
  93. }
  94. else {
  95. wx.getUserInfo({
  96. withCredentials: false,
  97. success: function (res) {
  98. app.globalData.userInfo = res.userInfo;
  99. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  100. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  101. app.globalData.userInfo.Code = res0.code;
  102. that.login(app.globalData.userInfo);
  103. },
  104. fail: function (res) {
  105. that.login(app.globalData.userInfo);
  106. }
  107. });
  108. }
  109. }
  110. });
  111. },
  112. fail: function () {
  113. }
  114. });
  115. },
  116. login: function (param) {
  117. var that = this;
  118. main.getLocalHost(function () {
  119. main.postData('MiaoguoLogin', {
  120. Code: param.Code,
  121. NickName: param.nickName,
  122. Language: param.language,
  123. Gender: param.gender,
  124. City: param.city,
  125. Province: param.province,
  126. Country: param.country,
  127. AvatarUrl: param.avatarUrl,
  128. Introducer: app.globalData.introducer,
  129. UserSource: app.globalData.userSource,
  130. SourceID: app.globalData.SourceID,
  131. LastUserSource: app.globalData.userSource,
  132. Brand: app.globalData.systemInfo.brand,
  133. Model: app.globalData.systemInfo.model,
  134. PixelRatio: app.globalData.systemInfo.pixelRatio,
  135. ScreenWidth: app.globalData.systemInfo.screenWidth,
  136. ScreenHeight: app.globalData.systemInfo.screenHeight,
  137. WindowWidth: app.globalData.systemInfo.windowWidth,
  138. WindowHeight: app.globalData.systemInfo.windowHeight,
  139. WXLanguage: app.globalData.systemInfo.language,
  140. WXVersion: app.globalData.systemInfo.version,
  141. System: app.globalData.systemInfo.system,
  142. Platform: app.globalData.systemInfo.platform,
  143. SDKVersion: app.globalData.systemInfo.SDKVersion,
  144. ProgramVersion: app.globalData.Version,
  145. }, function (data) {
  146. if (!data) {
  147. timeout3 = setTimeout(function () {
  148. that.getUserInfo();
  149. console.log("reboot:" + new Date().getTime());
  150. }, 2000);
  151. }
  152. else {
  153. app.globalData.userInfo = data;
  154. var isShow = data.IsShow;
  155. if (isShow == -1) {
  156. isShow = 0;
  157. }
  158. else {
  159. var systemInfo = wx.getSystemInfoSync();
  160. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  161. isShow = 1;
  162. }
  163. }
  164. app.globalData.IsShow = isShow;
  165. if (app.globalData.userInfo.IsMember == 1)
  166. app.globalData.IsLocked = 0;
  167. wx.removeStorageSync("UserID");
  168. wx.removeStorageSync("UserName");
  169. //测试
  170. //var url = '../../package4/main/giftcard?GiftID=89542&UserID=1';
  171. //var url = '../main/share';
  172. // var url = '../../package4/main/share';
  173. // wx.redirectTo({
  174. // url: url,
  175. // });
  176. if (that.data.MiaoguoCardID) {
  177. wx.reLaunch({
  178. url: '../main/preview?type=share&id=' + that.data.MiaoguoCardID,
  179. });
  180. }
  181. else {
  182. var url = '../main/default?IsStart=1';
  183. setTimeout(function () {
  184. wx.redirectTo({
  185. url: url,
  186. });
  187. }, 2000);
  188. main.UpdateMiaoguoCardTodayAll(false,function () {
  189. that.getTaskTodayList();
  190. });
  191. }
  192. that.getBaiduToken();
  193. }
  194. });
  195. });
  196. },
  197. getBaiduToken: function () {
  198. main.getData('GetBaiduToken', function (data) {
  199. if (data) {
  200. app.globalData.BaiduToken = data;
  201. //console.log(app.globalData.BaiduToken);
  202. }
  203. });
  204. },
  205. //得到当天任务
  206. getTaskTodayList: function () {
  207. var that = this;
  208. main.postData('UploadUserConfig?Type=getData&UserID=' + app.globalData.userInfo.UserID, {}, function (data) {
  209. var url = 'GetMiaoguoCardToday?UserID=' + app.globalData.userInfo.UserID;
  210. url += "&New=" + data.CardMaxNumberNew;
  211. url += "&History=" + data.CardMaxNumberHistory;
  212. url += "&SortTypeIndex=" + data.SortTypeIndex;
  213. main.getData(url, function (data) {
  214. if (data) {
  215. var TodayTaskNumber = data.ListNew.length + data.ListReview.length + data.ListHistory.length;
  216. that.setData({
  217. List: data,
  218. DayNumber: data.DayNumber,
  219. TodayTaskNumber: TodayTaskNumber,
  220. IsStart: data.IsStart,
  221. });
  222. app.globalData.TaskToday = data;
  223. app.globalData.CardList = [];
  224. }
  225. });
  226. wx.setStorageSync("CardMaxNumberNew", data.CardMaxNumberNew);
  227. wx.setStorageSync("CardMaxNumberHistory", data.CardMaxNumberHistory);
  228. wx.setStorageSync("SortTypeIndex", data.SortTypeIndex);
  229. wx.setStorageSync("MemoryLevel", data.MemoryLevel);
  230. wx.setStorageSync("ClickType", data.ClickType);
  231. wx.setStorageSync("SecondConfigArray", data.SecondConfigArray.split(","));
  232. wx.setStorageSync("ColorIndexArr", data.ColorIndexArr.split(","));
  233. });
  234. },
  235. updateProgram: function () {
  236. const updateManager = wx.getUpdateManager();
  237. updateManager.onCheckForUpdate(function (res) {
  238. // 请求完新版本信息的回调
  239. //console.log(res.hasUpdate)
  240. });
  241. updateManager.onUpdateReady(function () {
  242. wx.showModal({
  243. title: '更新提示',
  244. content: '新版本已经准备好,是否重启应用?',
  245. success: function (res) {
  246. if (res.confirm) {
  247. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  248. updateManager.applyUpdate()
  249. }
  250. }
  251. });
  252. });
  253. },
  254. onShareAppMessage: function () {
  255. return {
  256. title: app.globalData.ShareTitle,
  257. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  258. imageUrl: app.globalData.ShareImage,
  259. }
  260. },
  261. })