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

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

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

// 接收用户登出通知
eventBus.$on('LogoutNotify', (msg) => {
  // ---待优化---
  // 登出后应该回退到首页，如果回退后非首页，会导致路由拦截而跳转到登录页面，此时因为 tabIndex = 0 的问题，登录页被 replace 成首页，导致路由还能继续后退
  // 临时解决方案是先退回首页后再进行登出操作
  backHome()
  setTimeout(() => {
    userLogout()
    if (msg) {
      dialog({
        message: msg as string,
        confirmButtonText: '确定'
      })
    }
  }, 0)
})

// 接收风控通知
eventBus.$on('RiskToWebNtf', (msg, type) => {
  const res = msg as { title: string, content: string }
  if (type === 1) {
    notify(res.content, 'warning')
  } else {
    dialog({
      title: res.title,
      message: res.content,
      confirmButtonText: '确定'
    })
  }
})
</script>