index.js 12 KB

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