index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. url = '../other/lessonlist?listtype='+options.ListType;
  70. }
  71. else if (app.globalData.LessonID > 0) {
  72. url = '../other/lesson?LessonID=' + app.globalData.LessonID + '&LessonPage=' + app.globalData.LessonPage
  73. }
  74. }
  75. this.setData({
  76. gotoType: "other",
  77. gotoUrl: url,
  78. });
  79. }
  80. else if (options.type == "marketing") {
  81. this.setData({
  82. gotoType: "other",
  83. gotoUrl: '../marketing/index',
  84. });
  85. }
  86. else if (options.type == "homework") {
  87. this.setData({
  88. gotoType: "other",
  89. gotoUrl: "../other/homework",
  90. });
  91. }
  92. else if (options.type == "userbook") {
  93. this.setData({
  94. gotoType: "other",
  95. gotoUrl: "../other/userbook",
  96. });
  97. }
  98. else if (options.type == "activity") {
  99. this.setData({
  100. gotoType: "other",
  101. gotoUrl: "../other/activity?ActivityID=" + options.ActivityID + "&EarlyBirdTimeStart=" + options.EarlyBirdTimeStart + "&EarlyBirdTimeEnd=" + options.EarlyBirdTimeEnd + "&EndTime=" + options.EndTime,
  102. });
  103. }
  104. else if (options.type == "webview") {
  105. this.setData({
  106. gotoType: "other",
  107. gotoUrl: "../other/webview?PageID=" + options.PageID,
  108. });
  109. }
  110. else if (options.type == "help") {
  111. this.setData({
  112. gotoType: "other",
  113. gotoUrl: "../other/help?IsShare=1&id=" + options.ID+"&idchild="+options.IDChild,
  114. });
  115. }
  116. else if (options.type == "paycustom") {
  117. this.setData({
  118. gotoType: "other",
  119. gotoUrl: "../other/pay?PayType=6&PayUserID="+options.PayUserID+"&DayNumber="+options.DayNumber+"&Price="+options.Price+"&Remark="+options.Remark,
  120. });
  121. }
  122. else if (options.type == "print") {
  123. var pid=options.PrintID;
  124. if (!pid)
  125. pid=options.P;
  126. var puid=options.PUserID;
  127. this.setData({
  128. gotoType: "other",
  129. gotoUrl: "../main/mainlist?PrintID="+pid+"&PrintUserID="+puid,
  130. });
  131. }
  132. else if (options.type == "paycontinue") {
  133. this.setData({
  134. gotoType: "other",
  135. gotoUrl: "../other/pay?PayType=7&EndDate="+options.EndDate,
  136. });
  137. }
  138. }
  139. this.setData({
  140. IsRefresh: false,
  141. Containnerheight: main.getWindowHeight(),
  142. Sentence:common.random(1, 9),
  143. });
  144. this.updateProgram();
  145. this.getUserInfo();
  146. var that = this;
  147. timeout1 = setTimeout(function () {
  148. that.setData({
  149. IsRefresh: true,
  150. })
  151. }, 15000);
  152. },
  153. //得到用户信息
  154. getUserInfo: function (cb) {
  155. var that = this
  156. //调用登录接口
  157. wx.login({
  158. success: function (res0) {
  159. app.globalData.userInfo = {};
  160. app.globalData.userInfo.Code = res0.code;
  161. console.log("Time2:" + new Date().getTime());
  162. app.globalData.userInfo.nickName = "陌生用户";
  163. app.globalData.userInfo.language = "";
  164. app.globalData.userInfo.gender = "0";
  165. app.globalData.userInfo.city = "";
  166. app.globalData.userInfo.province = "";
  167. app.globalData.userInfo.country = "";
  168. app.globalData.userInfo.avatarUrl = "../images/universalpic_face_default_blue_120x120.png";
  169. that.login(app.globalData.userInfo);
  170. },
  171. fail: function () {}
  172. });
  173. },
  174. login: function (param) {
  175. var that = this;
  176. main.getLocalHost(function () {
  177. main.postData('MiaoguoLogin', {
  178. Code: param.Code,
  179. NickName: param.nickName,
  180. Language: param.language,
  181. Gender: param.gender,
  182. City: param.city,
  183. Province: param.province,
  184. Country: param.country,
  185. AvatarUrl: param.avatarUrl,
  186. Introducer: app.globalData.introducer,
  187. UserSource: app.globalData.userSource,
  188. SourceID: app.globalData.SourceID,
  189. LastUserSource: app.globalData.userSource,
  190. Brand: app.globalData.systemInfo.brand,
  191. Model: app.globalData.systemInfo.model,
  192. PixelRatio: app.globalData.systemInfo.pixelRatio,
  193. ScreenWidth: app.globalData.systemInfo.screenWidth,
  194. ScreenHeight: app.globalData.systemInfo.screenHeight,
  195. WindowWidth: app.globalData.systemInfo.windowWidth,
  196. WindowHeight: app.globalData.systemInfo.windowHeight,
  197. WXLanguage: app.globalData.systemInfo.language,
  198. WXVersion: app.globalData.systemInfo.version,
  199. System: app.globalData.systemInfo.system,
  200. Platform: app.globalData.systemInfo.platform,
  201. SDKVersion: app.globalData.systemInfo.SDKVersion,
  202. ProgramVersion: app.globalData.Version,
  203. }, function (data) {
  204. console.log("Time4:" + new Date().getTime());
  205. if (!data) {
  206. timeout3 = setTimeout(function () {
  207. that.getUserInfo();
  208. console.log("reboot:" + new Date().getTime());
  209. }, 2000);
  210. }
  211. else {
  212. app.globalData.userInfo = data;
  213. var isShow = data.IsShow;
  214. if (isShow == -1) {
  215. isShow = 0;
  216. }
  217. else {
  218. var systemInfo = wx.getSystemInfoSync();
  219. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  220. isShow = 1;
  221. }
  222. }
  223. app.globalData.userInfo.IsShow = isShow;
  224. if (app.globalData.userInfo.IsMember == 1)
  225. app.globalData.IsLocked = 0;
  226. wx.removeStorageSync("UserID");
  227. wx.removeStorageSync("UserName");
  228. // //测试****************
  229. // var url = '../other/newuser';
  230. // wx.redirectTo({
  231. // url: url,
  232. // });
  233. // return;
  234. // //测试****************
  235. if (that.data.gotoType == "share") {
  236. wx.reLaunch({
  237. url: that.data.gotoUrl,
  238. });
  239. }
  240. else if (that.data.gotoType == "bebound") {
  241. wx.reLaunch({
  242. url: that.data.gotoUrl,
  243. });
  244. }
  245. else {
  246. if (that.data.gotoType == "other"){
  247. app.globalData.GotoUrl = that.data.gotoUrl;
  248. var url = '../main/default';
  249. wx.redirectTo({
  250. url: url,
  251. });
  252. }
  253. else{
  254. var url = '../main/default';
  255. timeoutRedirect=setTimeout(function () {
  256. console.log("Time5:" + new Date().getTime());
  257. clearTimeout(timeout1);
  258. app.globalData.FolderList=[];
  259. wx.redirectTo({
  260. url: url,
  261. });
  262. }, 2000);
  263. }
  264. main.getUserConfig();
  265. }
  266. that.getBaiduToken();
  267. }
  268. });
  269. });
  270. },
  271. getBaiduToken: function () {
  272. main.getBaiduToken();
  273. },
  274. updateProgram: function () {
  275. const updateManager = wx.getUpdateManager();
  276. updateManager.onCheckForUpdate(function (res) {
  277. // 请求完新版本信息的回调
  278. });
  279. updateManager.onUpdateReady(function () {
  280. clearTimeout(timeoutRedirect);
  281. wx.showModal({
  282. title: '更新提示',
  283. content: '新版本已经准备好,重启应用',
  284. showCancel:false,
  285. success: function (res) {
  286. wx.removeStorageSync("UserID");
  287. wx.removeStorageSync("UserName");
  288. wx.removeStorageSync("SearchWord3");
  289. wx.removeStorageSync("HanziUpdateTime");
  290. wx.removeStorageSync("HanziAll");
  291. wx.removeStorageSync("EnglishAll");
  292. updateManager.applyUpdate();
  293. }
  294. });
  295. });
  296. },
  297. onShareAppMessage: function () {
  298. return {
  299. title: app.globalData.ShareTitle,
  300. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  301. imageUrl: app.globalData.ShareImage,
  302. }
  303. },
  304. })