index.js 11 KB

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