index.js 10 KB

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