App.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <script>
  2. import { isLoggedIn } from '@/api/services/auth.js';
  3. export default {
  4. onLaunch: function() {
  5. console.log('App Launch');
  6. this.checkLoginStatus();
  7. },
  8. onShow: function() {
  9. console.log('App Show');
  10. },
  11. onHide: function() {
  12. console.log('App Hide');
  13. },
  14. methods: {
  15. checkLoginStatus() {
  16. // 登录状态检查,对敏感页面进行拦截
  17. const pages = ['pages/dashboard/index', 'pages/user/index', 'pages/activity/index', 'pages/device/index'];
  18. uni.addInterceptor('navigateTo', {
  19. invoke(e) {
  20. const url = e.url;
  21. // 检查是否属于需要登录的页面
  22. const needLogin = pages.some(page => url.indexOf(page) > -1);
  23. if (needLogin && !isLoggedIn()) {
  24. uni.navigateTo({
  25. url: '/pages/login/index'
  26. });
  27. return false;
  28. }
  29. return true;
  30. }
  31. });
  32. uni.addInterceptor('switchTab', {
  33. invoke(e) {
  34. const url = e.url;
  35. // 检查是否属于需要登录的页面
  36. const needLogin = pages.some(page => url.indexOf(page) > -1);
  37. if (needLogin && !isLoggedIn()) {
  38. uni.navigateTo({
  39. url: '/pages/login/index'
  40. });
  41. return false;
  42. }
  43. return true;
  44. }
  45. });
  46. }
  47. }
  48. }
  49. </script>
  50. <template>
  51. <view class="content">
  52. <slot />
  53. </view>
  54. </template>
  55. <style>
  56. /* 全局基础样式 */
  57. page {
  58. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  59. font-size: 28rpx;
  60. line-height: 1.5;
  61. color: #333;
  62. background-color: #f5f5f5;
  63. }
  64. /* 去除按钮默认边框 */
  65. button::after {
  66. border: none;
  67. }
  68. /* 隐藏滚动条 */
  69. ::-webkit-scrollbar {
  70. width: 0;
  71. height: 0;
  72. color: transparent;
  73. }
  74. </style>