35 lines
922 B
Vue
35 lines
922 B
Vue
|
|
<template>
|
||
|
|
<div class="change-home" v-if="isAdmin">
|
||
|
|
<el-button type="primary" @click="changeHome">
|
||
|
|
<span v-if="home">前往用户页</span>
|
||
|
|
<span v-else>前往管理页</span>
|
||
|
|
</el-button>
|
||
|
|
</div>
|
||
|
|
</template>
|
||
|
|
<script setup lang="ts">
|
||
|
|
import { ref, onMounted } from 'vue';
|
||
|
|
import { useRouter } from 'vue-router';
|
||
|
|
|
||
|
|
const isAdmin = ref<boolean>(false);
|
||
|
|
const home = ref<boolean>(false);
|
||
|
|
const router = useRouter();
|
||
|
|
const routes = router.getRoutes();
|
||
|
|
|
||
|
|
function hasAdmin(){
|
||
|
|
return routes.some((route: any) => route.path.startsWith('/admin'));
|
||
|
|
}
|
||
|
|
|
||
|
|
function changeHome(){
|
||
|
|
if(home.value){
|
||
|
|
router.push('/home');
|
||
|
|
}else{
|
||
|
|
router.push('/admin/overview');
|
||
|
|
}
|
||
|
|
home.value = !home.value;
|
||
|
|
}
|
||
|
|
onMounted(() => {
|
||
|
|
isAdmin.value = hasAdmin();
|
||
|
|
home.value = router.currentRoute.value.path.startsWith('/admin');
|
||
|
|
});
|
||
|
|
</script>
|
||
|
|
<style scoped lang="scss"></style>
|