index.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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学而不思则罔,\n思而不学则殆。",
  8. "荀子曰:\n青,取之于蓝,而青于蓝。\n冰,水为之,而寒于水。",
  9. "荀子曰:\n不积跬步,无以至千里;\n不积小流,无以成江海。",
  10. "荀子曰:\n骐骥一跃,不能十步;\n驽马十驾,功在不舍。",
  11. "荀子曰:\n锲而舍之,朽木不折;\n锲而不舍,金石可镂。",
  12. "孟子曰:\n故天将降大任于是人也,\n必先苦其心志,劳其筋骨,\n饿其体肤……",
  13. ];
  14. Page({
  15. data: {
  16. },
  17. onLoad: function (options) {
  18. wx.hideShareMenu();
  19. if (options) {
  20. if (options.UserID) {
  21. console.log("UserID:" + options.UserID);
  22. app.globalData.introducer = options.UserID;
  23. if (options.QuestionTypeID)
  24. questionTypeID = options.QuestionTypeID;
  25. }
  26. if (options.goto) {
  27. console.log("goto:" + options.goto);
  28. app.globalData.goto = options.goto;
  29. }
  30. if (options.SourceID) {
  31. console.log("SourceID:" + options.SourceID);
  32. app.globalData.SourceID = options.SourceID;
  33. }
  34. // 扫码介绍人
  35. if (options.scene) {
  36. var scene = decodeURIComponent(options.scene);
  37. console.log("scene:" + scene);
  38. var introducer = 0;
  39. if (scene.indexOf("UserID") >= 0)
  40. introducer = scene.substr(scene.indexOf("UserID") + 7);
  41. console.log("introducer:" + introducer);
  42. app.globalData.introducer = scene;
  43. }
  44. if (options.ProductID) {
  45. this.setData({
  46. ProductID: options.ProductID,
  47. ProductUserID: options.ProductUserID,
  48. });
  49. }
  50. if (options.GiftID) {
  51. this.setData({
  52. GiftID: options.GiftID,
  53. });
  54. }
  55. if (options.Share == 1) {
  56. this.setData({
  57. MiaoguoCardID: options.MiaoguoCardID,
  58. });
  59. }
  60. }
  61. this.setData({
  62. Containnerheight: main.getWindowHeight(),
  63. Sentence: arrSentence[common.random(0, arrSentence.length - 1)],
  64. });
  65. this.updateProgram();
  66. this.getUserInfo();
  67. },
  68. //得到用户信息
  69. getUserInfo: function (cb) {
  70. var that = this
  71. //调用登录接口
  72. wx.login({
  73. success: function (res0) {
  74. app.globalData.userInfo = {};
  75. app.globalData.userInfo.Code = res0.code;
  76. //console.log("Code:" + res0.code);
  77. wx.getSetting({
  78. scope: "scope.userInfo",
  79. success(res) {
  80. if (!res.authSetting['scope.userInfo']) {
  81. app.globalData.userInfo.nickName = "陌生用户";
  82. app.globalData.userInfo.language = "";
  83. app.globalData.userInfo.gender = "0";
  84. app.globalData.userInfo.city = "";
  85. app.globalData.userInfo.province = "";
  86. app.globalData.userInfo.country = "";
  87. app.globalData.userInfo.avatarUrl = "../images/universalpic_face_default_blue_120x120.png";
  88. that.login(app.globalData.userInfo);
  89. }
  90. else {
  91. wx.getUserInfo({
  92. withCredentials: false,
  93. success: function (res) {
  94. app.globalData.userInfo = res.userInfo;
  95. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  96. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  97. app.globalData.userInfo.Code = res0.code;
  98. that.login(app.globalData.userInfo);
  99. },
  100. fail: function (res) {
  101. that.login(app.globalData.userInfo);
  102. }
  103. });
  104. }
  105. }
  106. });
  107. },
  108. fail: function () {
  109. }
  110. });
  111. },
  112. login: function (param) {
  113. var that = this;
  114. main.getLocalHost(function () {
  115. main.postData('MiaoguoLogin', {
  116. Code: param.Code,
  117. NickName: param.nickName,
  118. Language: param.language,
  119. Gender: param.gender,
  120. City: param.city,
  121. Province: param.province,
  122. Country: param.country,
  123. AvatarUrl: param.avatarUrl,
  124. Introducer: app.globalData.introducer,
  125. UserSource: app.globalData.userSource,
  126. SourceID: app.globalData.SourceID,
  127. LastUserSource: app.globalData.userSource,
  128. Brand: app.globalData.systemInfo.brand,
  129. Model: app.globalData.systemInfo.model,
  130. PixelRatio: app.globalData.systemInfo.pixelRatio,
  131. ScreenWidth: app.globalData.systemInfo.screenWidth,
  132. ScreenHeight: app.globalData.systemInfo.screenHeight,
  133. WindowWidth: app.globalData.systemInfo.windowWidth,
  134. WindowHeight: app.globalData.systemInfo.windowHeight,
  135. WXLanguage: app.globalData.systemInfo.language,
  136. WXVersion: app.globalData.systemInfo.version,
  137. System: app.globalData.systemInfo.system,
  138. Platform: app.globalData.systemInfo.platform,
  139. SDKVersion: app.globalData.systemInfo.SDKVersion,
  140. ProgramVersion: app.globalData.Version,
  141. }, function (data) {
  142. if (!data) {
  143. timeout3 = setTimeout(function () {
  144. that.getUserInfo();
  145. console.log("reboot:" + new Date().getTime());
  146. }, 2000);
  147. }
  148. else {
  149. app.globalData.userInfo = data;
  150. var isShow = data.IsShow;
  151. if (isShow == -1) {
  152. isShow = 0;
  153. }
  154. else {
  155. var systemInfo = wx.getSystemInfoSync();
  156. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  157. isShow = 1;
  158. }
  159. }
  160. app.globalData.IsShow = isShow;
  161. if (app.globalData.userInfo.IsMember == 1)
  162. app.globalData.IsLocked = 0;
  163. wx.removeStorageSync("UserID");
  164. wx.removeStorageSync("UserName");
  165. //测试
  166. //var url = '../../package4/main/giftcard?GiftID=89542&UserID=1';
  167. //var url = '../main/share';
  168. // var url = '../../package4/main/share';
  169. // wx.redirectTo({
  170. // url: url,
  171. // });
  172. if (that.data.MiaoguoCardID) {
  173. wx.reLaunch({
  174. url: '../main/preview?type=share&id=' + that.data.MiaoguoCardID,
  175. });
  176. }
  177. else {
  178. var url = '../main/default?IsStart=1';
  179. setTimeout(function () {
  180. wx.redirectTo({
  181. url: url,
  182. });
  183. }, 2000);
  184. that.getTaskTodayList();
  185. }
  186. that.getBaiduToken();
  187. }
  188. });
  189. });
  190. },
  191. getBaiduToken: function () {
  192. main.getData('GetBaiduToken', function (data) {
  193. if (data) {
  194. app.globalData.BaiduToken = data;
  195. //console.log(app.globalData.BaiduToken);
  196. }
  197. });
  198. },
  199. //得到当天任务
  200. getTaskTodayList: function () {
  201. var that = this;
  202. common.getStorageValue(that, "CardMaxNumberNew", 10, function () {
  203. common.getStorageValue(that, "CardMaxNumberHistory", 30, function () {
  204. common.getStorageValue(that, "SortTypeIndex", 0, function () {
  205. var url = 'GetMiaoguoCardToday?UserID=' + app.globalData.userInfo.UserID;
  206. url += "&New=" + that.data.CardMaxNumberNew;
  207. url += "&History=" + that.data.CardMaxNumberHistory;
  208. url += "&SortTypeIndex=" + that.data.SortTypeIndex;
  209. main.getData(url, function (data) {
  210. if (data) {
  211. var TodayTaskNumber = data.ListNew.length + data.ListReview.length + data.ListHistory.length;
  212. that.setData({
  213. List: data,
  214. DayNumber: data.DayNumber,
  215. TodayTaskNumber: TodayTaskNumber,
  216. IsStart: data.IsStart,
  217. });
  218. app.globalData.TaskToday = data;
  219. app.globalData.CardList = [];
  220. }
  221. });
  222. });
  223. });
  224. });
  225. },
  226. updateProgram: function () {
  227. const updateManager = wx.getUpdateManager();
  228. updateManager.onCheckForUpdate(function (res) {
  229. // 请求完新版本信息的回调
  230. //console.log(res.hasUpdate)
  231. });
  232. updateManager.onUpdateReady(function () {
  233. wx.showModal({
  234. title: '更新提示',
  235. content: '新版本已经准备好,是否重启应用?',
  236. success: function (res) {
  237. if (res.confirm) {
  238. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  239. updateManager.applyUpdate()
  240. }
  241. }
  242. });
  243. });
  244. },
  245. onShareAppMessage: function () {
  246. return {
  247. title: app.globalData.ShareTitle,
  248. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  249. imageUrl: app.globalData.ShareImage,
  250. }
  251. },
  252. })