App.vue 928 B

1234567891011121314151617181920212223242526272829303132
  1. <template>
  2. <router-view />
  3. </template>
  4. <script lang="ts" setup>
  5. import { useNavigation } from '@mobile/router/navigation'
  6. import { dialog } from '@/utils/vant'
  7. import { useLogin } from '@/business/login'
  8. import eventBus from '@/services/bus'
  9. const { userLogout } = useLogin()
  10. const { backHome } = useNavigation()
  11. // 接收用户登出通知
  12. eventBus.$on('LogoutNotify', (msg) => {
  13. userLogout(() => {
  14. if (msg) {
  15. dialog({
  16. message: msg as string,
  17. confirmButtonText: '确定'
  18. }).then(() => {
  19. // ---待处理---
  20. // 登出后应该回退到首页,如果回退后非首页,会导致路由拦截而跳转到登录页面,此时因为 tabIndex = 0 的问题,登录页被 replace 成首页,导致路由还能继续后退
  21. // 临时解决方案是先退回首页后再进行登出操作
  22. backHome()
  23. })
  24. } else {
  25. backHome()
  26. }
  27. })
  28. })
  29. </script>