<script setup lang="ts">
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
import { LOGIN_PAGE } from '@/router/config'
import { navigateToInterceptor } from '@/router/interceptor'

onLaunch((options) => {
    console.log('App.vue onLaunch', options)
})
onShow((options) => {
    console.log('App.vue onShow', options)
    // 获取当前页面路径
    const pages = getCurrentPages()
    const currentPage = pages[pages.length - 1]

    if (!currentPage) {
        console.log('App.vue onShow: currentPage is undefined, skipping...')
        return
    }

    const currentPath = `/${currentPage.route}`

    // 如果当前已经是登录页，不触发拦截器
    if (currentPath === LOGIN_PAGE) {
        return
    }

    // 处理直接进入页面路由的情况：如h5直接输入路由、微信小程序分享后进入等
    // https://github.com/unibest-tech/unibest/issues/192
    if (options?.path) {
        navigateToInterceptor.invoke({ url: `/${options.path}`, query: options.query })
    }
    else {
        navigateToInterceptor.invoke({ url: '/' })
    }
})
onHide(() => {
    console.log('App Hide')
})
</script>

<style lang="scss">
@import 'uview-plus/index.scss';
</style>
