<template>
    <view></view>
</template>

<script setup lang="ts">
import { ROLEINDEX } from '@/enums/cacheEnums'
import { useRoleData } from '@/hooks/useRoleData'
import { useTabBarStore } from '@/stores/tabbar'
import { useUserStore } from '@/stores/user'
import cache from '@/utils/cache'
import { onLoad } from '@dcloudio/uni-app'

const userStore = useUserStore()
const { roles } = useRoleData()
const tabBarStore = useTabBarStore()

const setNextRoute = () => {
    const ind = cache.get(ROLEINDEX) || 0
    const { userInfo } = userStore
    const obj = roles.find(role => {
        return role.ids.includes(userInfo.roles[ind].id)
    })
    tabBarStore.setTabBarList(obj?.tabBarList)
    uni.reLaunch({
        url: obj?.tabBarList[0].path || ''
    })
}

onLoad(() => {
    if (userStore.isLogin) {
        // 已经登录 => 首页
        setNextRoute()
    }
})
</script>
<style scoped></style>
