index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var timeout1 = 0, timeout3=0;
  5. var timeoutRedirect=0;
  6. Page({
  7. data: {
  8. Sentence:1,
  9. },
  10. onPullDownRefresh: function () {
  11. wx.reLaunch({
  12. url: './index',
  13. })
  14. },
  15. onLoad: function (options) {
  16. console.log("Time1:" + new Date().getTime());
  17. if (options) {
  18. if (options.UserID) {
  19. console.log("UserID:" + options.UserID);
  20. app.globalData.introducer = options.UserID;
  21. }
  22. if (options.SourceID) {
  23. console.log("SourceID:" + options.SourceID);
  24. app.globalData.SourceID = options.SourceID;
  25. }
  26. // 扫码介绍人
  27. if (options.scene) {
  28. var scene = decodeURIComponent(options.scene);
  29. console.log("scene:" + scene);
  30. if (scene.indexOf("type=print")>=0){
  31. options.type="print";
  32. options.PUserID=scene.substr(scene.indexOf("U") + 2);
  33. options.PrintID=scene.substring(scene.indexOf("P") + 2,scene.indexOf("&U"));
  34. }
  35. else{
  36. var introducer = 0;
  37. if (scene.indexOf("UserID") >= 0)
  38. introducer = scene.substr(scene.indexOf("UserID") + 7);
  39. console.log("introducer:" + introducer);
  40. app.globalData.introducer = scene;
  41. }
  42. }
  43. if (options.type == "share") {
  44. if (options.ColorIndex)
  45. app.globalData.ColorIndex = options.ColorIndex;
  46. this.setData({
  47. gotoType: "share",
  48. gotoUrl: '../main/preview?type=share&id=' + options.MiaoguoCardID,
  49. });
  50. }
  51. else if (options.type == "bebound") {
  52. this.setData({
  53. gotoType: "bebound",
  54. gotoUrl: "../other/binding?type=bebound&ParentUserID=" + options.ParentUserID + "&NickName=" + options.NickName + "&AvatarUrl=" + options.AvatarUrl + "&BindTime=" + options.BindTime,
  55. });
  56. }
  57. else if (options.type == "lesson" || options.type == "video") {
  58. app.globalData.LessonID = options.LessonID;
  59. if (options.LessonPage)
  60. app.globalData.LessonPage = options.LessonPage;
  61. else
  62. app.globalData.LessonPage = 1;
  63. var url="";
  64. if (options.type == "video"){
  65. url = '../other/video?LessonID=' + app.globalData.LessonID + '&LessonPage=' + app.globalData.LessonPage
  66. }
  67. else{
  68. if (app.globalData.LessonID === "all") {
  69. if (!options.ListType)
  70. url = '../other/lessonlistselect';
  71. else
  72. url = '../other/lessonlist?listtype='+options.ListType;
  73. }
  74. else if (app.globalData.LessonID > 0) {
  75. url = '../other/lesson?LessonID=' + app.globalData.LessonID + '&LessonPage=' + app.globalData.LessonPage
  76. }
  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/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 == "activity") {
  102. this.setData({
  103. gotoType: "other",
  104. gotoUrl: "../other/activity?ActivityID=" + options.ActivityID + "&EarlyBirdTimeStart=" + options.EarlyBirdTimeStart + "&EarlyBirdTimeEnd=" + options.EarlyBirdTimeEnd + "&EndTime=" + options.EndTime,
  105. });
  106. }
  107. else if (options.type == "webview") {
  108. this.setData({
  109. gotoType: "other",
  110. gotoUrl: "../other/webview?PageID=" + options.PageID,
  111. });
  112. }
  113. else if (options.type == "help") {
  114. this.setData({
  115. gotoType: "other",
  116. gotoUrl: "../other/help?IsShare=1&id=" + options.ID+"&idchild="+options.IDChild,
  117. });
  118. }
  119. else if (options.type == "paycustom") {
  120. this.setData({
  121. gotoType: "other",
  122. gotoUrl: "../other/pay?PayType=6&PayUserID="+options.PayUserID+"&DayNumber="+options.DayNumber+"&Price="+options.Price+"&Remark="+options.Remark,
  123. });
  124. }
  125. else if (options.type == "print") {
  126. var pid=options.PrintID;
  127. if (!pid)
  128. pid=options.P;
  129. var puid=options.PUserID;
  130. this.setData({
  131. gotoType: "other",
  132. gotoUrl: "../main/mainlist?PrintID="+pid+"&PrintUserID="+puid,
  133. });
  134. }
  135. else if (options.type == "paycontinue") {
  136. this.setData({
  137. gotoType: "other",
  138. gotoUrl: "../other/pay?PayType=7&EndDate="+options.EndDate,
  139. });
  140. }
  141. }
  142. this.setData({
  143. IsRefresh: false,
  144. Containnerheight: main.getWindowHeight(),
  145. Sentence:common.random(1, 9),
  146. });
  147. this.updateProgram();
  148. this.getUserInfo();
  149. var that = this;
  150. timeout1 = setTimeout(function () {
  151. that.setData({
  152. IsRefresh: true,
  153. })
  154. }, 15000);
  155. },
  156. //得到用户信息
  157. getUserInfo: function (cb) {
  158. var that = this
  159. //调用登录接口
  160. wx.login({
  161. success: function (res0) {
  162. app.globalData.userInfo = {};
  163. app.globalData.userInfo.Code = res0.code;
  164. console.log("Time2:" + new Date().getTime());
  165. app.globalData.userInfo.nickName = "陌生用户";
  166. app.globalData.userInfo.language = "";
  167. app.globalData.userInfo.gender = "0";
  168. app.globalData.userInfo.city = "";
  169. app.globalData.userInfo.province = "";
  170. app.globalData.userInfo.country = "";
  171. app.globalData.userInfo.avatarUrl = "../images/universalpic_face_default_blue_120x120.png";
  172. that.login(app.globalData.userInfo);
  173. },
  174. fail: function () {}
  175. });
  176. },
  177. login: function (param) {
  178. var that = this;
  179. main.getLocalHost(function () {
  180. main.postData('MiaoguoLogin', {
  181. Code: param.Code,
  182. NickName: param.nickName,
  183. Language: param.language,
  184. Gender: param.gender,
  185. City: param.city,
  186. Province: param.province,
  187. Country: param.country,
  188. AvatarUrl: param.avatarUrl,
  189. Introducer: app.globalData.introducer,
  190. UserSource: app.globalData.userSource,
  191. SourceID: app.globalData.SourceID,
  192. LastUserSource: app.globalData.userSource,
  193. Brand: app.globalData.systemInfo.brand,
  194. Model: app.globalData.systemInfo.model,
  195. PixelRatio: app.globalData.systemInfo.pixelRatio,
  196. ScreenWidth: app.globalData.systemInfo.screenWidth,
  197. ScreenHeight: app.globalData.systemInfo.screenHeight,
  198. WindowWidth: app.globalData.systemInfo.windowWidth,
  199. WindowHeight: app.globalData.systemInfo.windowHeight,
  200. WXLanguage: app.globalData.systemInfo.language,
  201. WXVersion: app.globalData.systemInfo.version,
  202. System: app.globalData.systemInfo.system,
  203. Platform: app.globalData.systemInfo.platform,
  204. SDKVersion: app.globalData.systemInfo.SDKVersion,
  205. ProgramVersion: app.globalData.Version,
  206. }, function (data) {
  207. console.log("Time4:" + new Date().getTime());
  208. if (!data) {
  209. timeout3 = setTimeout(function () {
  210. that.getUserInfo();
  211. console.log("reboot:" + new Date().getTime());
  212. }, 2000);
  213. }
  214. else {
  215. app.globalData.userInfo = data;
  216. var isShow = data.IsShow;
  217. if (isShow == -1) {
  218. isShow = 0;
  219. }
  220. else {
  221. var systemInfo = wx.getSystemInfoSync();
  222. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  223. isShow = 1;
  224. }
  225. }
  226. app.globalData.userInfo.IsShow = isShow;
  227. if (app.globalData.userInfo.IsMember == 1)
  228. app.globalData.IsLocked = 0;
  229. wx.removeStorageSync("UserID");
  230. wx.removeStorageSync("UserName");
  231. // //测试****************
  232. // var url = '../other/newuser';
  233. // wx.redirectTo({
  234. // url: url,
  235. // });
  236. // return;
  237. // //测试****************
  238. if (that.data.gotoType == "share") {
  239. wx.reLaunch({
  240. url: that.data.gotoUrl,
  241. });
  242. }
  243. else if (that.data.gotoType == "bebound") {
  244. wx.reLaunch({
  245. url: that.data.gotoUrl,
  246. });
  247. }
  248. else {
  249. if (that.data.gotoType == "other"){
  250. app.globalData.GotoUrl = that.data.gotoUrl;
  251. var url = '../main/default';
  252. wx.redirectTo({
  253. url: url,
  254. });
  255. }
  256. else{
  257. var url = '../main/default';
  258. timeoutRedirect=setTimeout(function () {
  259. console.log("Time5:" + new Date().getTime());
  260. clearTimeout(timeout1);
  261. clearTimeout(timeout3);
  262. app.globalData.FolderList=[];
  263. wx.redirectTo({
  264. url: url,
  265. });
  266. }, 2000);
  267. }
  268. main.getUserConfig();
  269. }
  270. that.getBaiduToken();
  271. }
  272. });
  273. });
  274. },
  275. getBaiduToken: function () {
  276. main.getBaiduToken();
  277. },
  278. updateProgram: function () {
  279. const updateManager = wx.getUpdateManager();
  280. updateManager.onCheckForUpdate(function (res) {
  281. // 请求完新版本信息的回调
  282. });
  283. updateManager.onUpdateReady(function () {
  284. clearTimeout(timeoutRedirect);
  285. wx.showModal({
  286. title: '更新提示',
  287. content: '新版本已经准备好,重启应用',
  288. showCancel:false,
  289. success: function (res) {
  290. wx.removeStorageSync("UserID");
  291. wx.removeStorageSync("UserName");
  292. wx.removeStorageSync("SearchWord3");
  293. wx.removeStorageSync("HanziUpdateTime");
  294. wx.removeStorageSync("HanziAll");
  295. wx.removeStorageSync("EnglishAll");
  296. updateManager.applyUpdate();
  297. }
  298. });
  299. });
  300. },
  301. onShareAppMessage: function () {
  302. return {
  303. title: app.globalData.ShareTitle,
  304. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  305. imageUrl: app.globalData.ShareImage,
  306. }
  307. },
  308. })