<template>
    <div class="change-home">
        <div class="change-home-item" @click="changeHome">
            <span v-if="home">前往用户页</span>
            <span v-else>前往管理页</span>
        </div>
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';

const home = ref<boolean>(false);
const router = useRouter();
const route = useRoute();

// 组件加载时根据当前路由判断是否在管理页
onMounted(() => {
    // 如果当前路径以 /admin 开头，说明在管理页，应该显示"前往用户页"
    home.value = route.path.startsWith('/admin');
});

function changeHome(){
    if(home.value){
        router.push('/home');
    }else{
        router.push('/admin/overview');
    }
    home.value = !home.value;
}

</script>
<style scoped lang="scss">
</style>