index.js 11 KB

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