index.js 9.2 KB

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