App.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <script setup lang="ts">
  2. import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
  3. /**
  4. * 应用启动
  5. */
  6. onLaunch(() => {
  7. console.log("App Launch");
  8. checkLoginStatus();
  9. });
  10. /**
  11. * 应用显示
  12. */
  13. onShow(() => {
  14. console.log("App Show");
  15. });
  16. /**
  17. * 应用隐藏
  18. */
  19. onHide(() => {
  20. console.log("App Hide");
  21. // 当应用隐藏时,清理购物页面的轮询状态
  22. const pollingActive = uni.getStorageSync('shoppingPollingActive');
  23. if (pollingActive === 'true') {
  24. console.log('应用隐藏,清理购物页面轮询状态');
  25. uni.removeStorageSync('shoppingPollingActive');
  26. }
  27. });
  28. /**
  29. * 检查登录状态
  30. * 如果未登录且当前不在登录页,则跳转到登录页
  31. */
  32. const checkLoginStatus = () => {
  33. const token = uni.getStorageSync('accessToken');
  34. // 获取当前页面路径
  35. const pages = getCurrentPages();
  36. const currentPage = pages[pages.length - 1];
  37. const currentPath = currentPage ? currentPage.route : '';
  38. console.log('[App] 检查登录状态 - token:', token ? '已存在' : '不存在', ', 当前页面:', currentPath);
  39. // 如果没有token且不在登录页,跳转到登录页
  40. if (!token && currentPath !== 'pages/login/login') {
  41. console.log('[App] 未登录,跳转到登录页');
  42. uni.reLaunch({
  43. url: '/pages/login/login'
  44. });
  45. }
  46. };
  47. </script>
  48. <style>
  49. /* 全局动画样式 */
  50. @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  51. @keyframes slideUp { from { opacity: 0; transform: translateY(40rpx); } to { opacity: 1; transform: translateY(0); } }
  52. @keyframes slideDown { from { opacity: 0; transform: translateY(-40rpx); } to { opacity: 1; transform: translateY(0); } }
  53. @keyframes scaleIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
  54. @keyframes pulse { 0%, 100% { transform: scale(1); opacity: 0.3; } 50% { transform: scale(1.05); opacity: 0.5; } }
  55. @keyframes bounce { 0% { transform: scale(0); opacity: 0; } 50% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
  56. @keyframes skeleton { 0%, 100% { background-color: #F5F5F5; } 50% { background-color: #EEEEEE; } }
  57. </style>