index.js 11 KB

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