App.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <script>
  2. import storage from "@/utils/storage.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 && !storage.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 && !storage.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 lang="scss">
  56. /* 全局基础样式 */
  57. @import "uview-ui/index.scss";
  58. page {
  59. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  60. font-size: 28rpx;
  61. line-height: 1.5;
  62. color: #333;
  63. background-color: #f5f5f5;
  64. }
  65. /* 去除按钮默认边框 */
  66. button::after {
  67. border: none;
  68. }
  69. /* 隐藏滚动条 */
  70. ::-webkit-scrollbar {
  71. width: 0;
  72. height: 0;
  73. color: transparent;
  74. }
  75. </style>