<template>
  <router-view />
</template>

<script lang="ts" setup>
import { useNavigation } from '@/hooks/navigation'
import { dialog } from '@/utils/vant'
import { useLogin } from '@/business/login'
import eventBus from '@/services/bus'

const { userLogout } = useLogin()
const { backHomePage } = useNavigation()

const quit = (showLogin = false) => {
  backHomePage({ tabName: 'home', showLogin })
}

// 接收用户登出通知
eventBus.$on('LogoutNotify', (msg) => {
  userLogout(() => {
    if (msg) {
      dialog({
        message: msg as string,
      }).then(() => {
        quit(true)
      })
    } else {
      quit()
    }
  })
})
</script>