Home.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // pages/Home/Home.js
  2. Page({
  3. data: {
  4. selected: 0
  5. },
  6. // 页面显示时的逻辑
  7. onShow: function() {
  8. // 检查缓存中的登录用户
  9. const currentUser = wx.getStorageSync('currentUser');
  10. // 如果用户已登录,跳转到 /pages/threshold/threshold 页面
  11. if (currentUser) {
  12. wx.switchTab({
  13. url: '/pages/threshold/threshold'
  14. });
  15. return; // 停止后续代码执行
  16. }
  17. // 如果没有登录,则正常显示页面内容
  18. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  19. this.getTabBar().setData({
  20. selected: 0 // 当前页面在tabBar中的索引
  21. });
  22. }
  23. // 隐藏返回首页按钮
  24. if (wx.hideHomeButton) {
  25. wx.hideHomeButton();
  26. }
  27. },
  28. // 其他跳转方法
  29. SoilPro() {
  30. wx.navigateTo({
  31. url: '/shoping/SoilPro/SoilPro'
  32. });
  33. },
  34. Overview: function() {
  35. wx.navigateTo({
  36. url: '/shoping/Overview/Overview'
  37. });
  38. },
  39. ResearchFindings() {
  40. wx.navigateTo({
  41. url: '/shoping/ResearchFindings/ResearchFindings'
  42. });
  43. },
  44. Unit_Team_Profile() {
  45. wx.navigateTo({
  46. url: '/shoping/Unit Team Profile/Unit Team Profile'
  47. });
  48. },
  49. mapView() {
  50. wx.navigateTo({
  51. url: '/shoping/mapView/mapView'
  52. });
  53. }
  54. });