index.js 11 KB

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