index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. var UserAssociatedID=0;
  7. Page({
  8. data: {
  9. Sentence:1,
  10. },
  11. onPullDownRefresh: function () {
  12. wx.reLaunch({
  13. url: './index',
  14. })
  15. },
  16. onLoad: function (options) {
  17. console.log("Time1:" + new Date().getTime());
  18. if (options) {
  19. if (options.UserID) {
  20. console.log("UserID:" + options.UserID);
  21. app.globalData.introducer = options.UserID;
  22. }
  23. if (options.UserAssociatedID)
  24. UserAssociatedID=options.UserAssociatedID;
  25. if (options.SourceID) {
  26. console.log("SourceID:" + options.SourceID);
  27. app.globalData.SourceID = options.SourceID;
  28. }
  29. // 扫码介绍人
  30. if (options.scene) {
  31. var scene = decodeURIComponent(options.scene);
  32. console.log("scene:" + scene);
  33. if (scene.indexOf("type=print")>=0){
  34. options.type="print";
  35. options.PUserID=scene.substr(scene.indexOf("U") + 2);
  36. options.PrintID=scene.substring(scene.indexOf("P") + 2,scene.indexOf("&U"));
  37. }
  38. else{
  39. var introducer = 0;
  40. if (scene.indexOf("UserID") >= 0)
  41. introducer = scene.substr(scene.indexOf("UserID") + 7);
  42. console.log("introducer:" + introducer);
  43. app.globalData.introducer = scene;
  44. }
  45. }
  46. if (options.type == "share") {
  47. if (options.ColorIndex)
  48. app.globalData.ColorIndex = options.ColorIndex;
  49. this.setData({
  50. gotoType: "share",
  51. gotoUrl: '../main/preview?type=share&id=' + options.MiaoguoCardID,
  52. });
  53. }
  54. else if (options.type == "bebound") {
  55. this.setData({
  56. gotoType: "bebound",
  57. gotoUrl: "../other/binding?type=bebound&ParentUserID=" + options.ParentUserID + "&NickName=" + options.NickName + "&AvatarUrl=" + options.AvatarUrl + "&BindTime=" + options.BindTime,
  58. });
  59. }
  60. else if (options.type == "lesson" || options.type == "video") {
  61. app.globalData.LessonID = options.LessonID;
  62. if (options.LessonPage)
  63. app.globalData.LessonPage = options.LessonPage;
  64. else
  65. app.globalData.LessonPage = 1;
  66. var url="";
  67. if (options.type == "video"){
  68. url = '../other/video?LessonID=' + app.globalData.LessonID + '&LessonPage=' + app.globalData.LessonPage
  69. }
  70. else{
  71. if (app.globalData.LessonID === "all") {
  72. if (!options.ListType)
  73. url = '../other/lessonlistselect';
  74. else
  75. url = '../other/lessonlist?listtype='+options.ListType;
  76. }
  77. else if (app.globalData.LessonID > 0) {
  78. url = '../other/lesson?LessonID=' + app.globalData.LessonID + '&LessonPage=' + app.globalData.LessonPage
  79. }
  80. }
  81. this.setData({
  82. gotoType: "other",
  83. gotoUrl: url,
  84. });
  85. }
  86. else if (options.type == "marketing") {
  87. this.setData({
  88. gotoType: "other",
  89. gotoUrl: '../../pages_agent/marketing/index',
  90. });
  91. }
  92. else if (options.type == "homework") {
  93. this.setData({
  94. gotoType: "other",
  95. gotoUrl: "../other/homework",
  96. });
  97. }
  98. else if (options.type == "userbook") {
  99. this.setData({
  100. gotoType: "other",
  101. gotoUrl: "../other/userbook",
  102. });
  103. }
  104. else if (options.type == "activity") {
  105. this.setData({
  106. gotoType: "other",
  107. gotoUrl: "../other/activity?ActivityID=" + options.ActivityID + "&EarlyBirdTimeStart=" + options.EarlyBirdTimeStart + "&EarlyBirdTimeEnd=" + options.EarlyBirdTimeEnd + "&EndTime=" + options.EndTime,
  108. });
  109. }
  110. else if (options.type == "webview") {
  111. this.setData({
  112. gotoType: "other",
  113. gotoUrl: "../other/webview?PageID=" + options.PageID,
  114. });
  115. }
  116. else if (options.type == "shareIndex") {
  117. this.setData({
  118. gotoType: "other",
  119. gotoUrl: "../share/shareindex",
  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. UserAssociatedID:UserAssociatedID,
  195. NickName: param.nickName,
  196. Language: param.language,
  197. Gender: param.gender,
  198. City: param.city,
  199. Province: param.province,
  200. Country: param.country,
  201. AvatarUrl: param.avatarUrl,
  202. Introducer: app.globalData.introducer,
  203. UserSource: app.globalData.userSource,
  204. SourceID: app.globalData.SourceID,
  205. LastUserSource: app.globalData.userSource,
  206. Brand: app.globalData.systemInfo.brand,
  207. Model: app.globalData.systemInfo.model,
  208. PixelRatio: app.globalData.systemInfo.pixelRatio,
  209. ScreenWidth: app.globalData.systemInfo.screenWidth,
  210. ScreenHeight: app.globalData.systemInfo.screenHeight,
  211. WindowWidth: app.globalData.systemInfo.windowWidth,
  212. WindowHeight: app.globalData.systemInfo.windowHeight,
  213. WXLanguage: app.globalData.systemInfo.language,
  214. WXVersion: app.globalData.systemInfo.version,
  215. System: app.globalData.systemInfo.system,
  216. Platform: app.globalData.systemInfo.platform,
  217. SDKVersion: app.globalData.systemInfo.SDKVersion,
  218. ProgramVersion: app.globalData.Version,
  219. }, function (data) {
  220. console.log("Time4:" + new Date().getTime());
  221. if (!data) {
  222. timeout3 = setTimeout(function () {
  223. that.getUserInfo();
  224. console.log("reboot:" + new Date().getTime());
  225. }, 2000);
  226. }
  227. else {
  228. app.globalData.userInfo = data;
  229. var isShow = data.IsShow;
  230. if (isShow == -1) {
  231. isShow = 0;
  232. }
  233. else {
  234. var systemInfo = wx.getSystemInfoSync();
  235. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  236. isShow = 1;
  237. }
  238. }
  239. app.globalData.userInfo.IsShow = isShow;
  240. if (app.globalData.userInfo.IsMember == 1)
  241. app.globalData.IsLocked = 0;
  242. wx.removeStorageSync("UserID");
  243. wx.removeStorageSync("UserName");
  244. // //测试****************
  245. // var url = '../share/shareindex';
  246. // wx.redirectTo({
  247. // url: url,
  248. // });
  249. // return;
  250. // //测试****************
  251. if (that.data.gotoType == "share") {
  252. wx.reLaunch({
  253. url: that.data.gotoUrl,
  254. });
  255. }
  256. else if (that.data.gotoType == "bebound") {
  257. wx.reLaunch({
  258. url: that.data.gotoUrl,
  259. });
  260. }
  261. else {
  262. if (that.data.gotoType == "other"){
  263. app.globalData.GotoUrl = that.data.gotoUrl;
  264. var url = '../main/default';
  265. wx.redirectTo({
  266. url: url,
  267. });
  268. }
  269. else{
  270. var url = '../main/default';
  271. timeoutRedirect=setTimeout(function () {
  272. console.log("Time5:" + new Date().getTime());
  273. clearTimeout(timeout1);
  274. clearTimeout(timeout3);
  275. app.globalData.FolderList=[];
  276. wx.redirectTo({
  277. url: url,
  278. });
  279. }, 2000);
  280. }
  281. main.getUserConfig();
  282. }
  283. main.getServerSoundErrorArr();
  284. main.getBaiduToken();
  285. }
  286. });
  287. });
  288. },
  289. updateProgram: function () {
  290. const updateManager = wx.getUpdateManager();
  291. updateManager.onCheckForUpdate(function (res) {
  292. // 请求完新版本信息的回调
  293. });
  294. updateManager.onUpdateReady(function () {
  295. clearTimeout(timeoutRedirect);
  296. wx.showModal({
  297. title: '更新提示',
  298. content: '新版本已经准备好,重启应用',
  299. showCancel:false,
  300. success: function (res) {
  301. wx.removeStorageSync("UserID");
  302. wx.removeStorageSync("UserName");
  303. wx.removeStorageSync("SearchWord3");
  304. wx.removeStorageSync("HanziUpdateTime");
  305. wx.removeStorageSync("HanziAll");
  306. wx.removeStorageSync("EnglishAll");
  307. updateManager.applyUpdate();
  308. }
  309. });
  310. });
  311. },
  312. onShareAppMessage: function () {
  313. return {
  314. title: app.globalData.ShareTitle,
  315. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  316. imageUrl: app.globalData.ShareImage,
  317. }
  318. },
  319. })