App.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <script setup lang="ts">
  2. import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
  3. import { LOGIN_PAGE } from '@/router/config'
  4. import { navigateToInterceptor } from '@/router/interceptor'
  5. onLaunch((options) => {
  6. console.log('App.vue onLaunch', options)
  7. })
  8. onShow((options) => {
  9. console.log('App.vue onShow', options)
  10. // 获取当前页面路径
  11. const pages = getCurrentPages()
  12. const currentPage = pages[pages.length - 1]
  13. if (!currentPage) {
  14. console.log('App.vue onShow: currentPage is undefined, skipping...')
  15. return
  16. }
  17. const currentPath = `/${currentPage.route}`
  18. // 如果当前已经是登录页,不触发拦截器
  19. if (currentPath === LOGIN_PAGE) {
  20. return
  21. }
  22. // 处理直接进入页面路由的情况:如h5直接输入路由、微信小程序分享后进入等
  23. // https://github.com/unibest-tech/unibest/issues/192
  24. if (options?.path) {
  25. navigateToInterceptor.invoke({ url: `/${options.path}`, query: options.query })
  26. }
  27. else {
  28. navigateToInterceptor.invoke({ url: '/' })
  29. }
  30. })
  31. onHide(() => {
  32. console.log('App Hide')
  33. })
  34. </script>
  35. <style lang="scss">
  36. @import 'uview-plus/index.scss';
  37. </style>