<script lang="ts" setup>
|
import { computed, onMounted, ref, unref, watch } from 'vue'
|
import { useAppStore } from '@/store/modules/app'
|
import { useUserStoreWithOut } from '@/store/modules/user'
|
import { usePermissionStoreWithOut } from '@/store/modules/permission'
|
import { useDesign } from '@/hooks/web/useDesign'
|
import {isRelogin} from "@/config/axios/service";
|
import router from "@/router";
|
import type {RouteRecordRaw} from "vue-router";
|
import {CACHE_KEY, useCache, useSessionCache} from "@/hooks/web/useCache";
|
import {getAccessToken} from "@/utils/auth";
|
import {getInfo} from "@/api/login";
|
const { wsCache } = useCache()
|
const { wsSessionCache } = useSessionCache()
|
|
defineOptions({ name: 'Logo' })
|
|
const { getPrefixCls } = useDesign()
|
|
const prefixCls = getPrefixCls('logo')
|
|
const appStore = useAppStore()
|
|
const show = ref(true)
|
|
const homePath = ref('/index')
|
|
const title = computed(() => appStore.getTitle)
|
|
const layout = computed(() => appStore.getLayout)
|
|
const collapse = computed(() => appStore.getCollapse)
|
|
homePath.value = '/index'
|
|
onMounted(() => {
|
if (unref(collapse)) show.value = false
|
})
|
|
watch(
|
() => collapse.value,
|
(collapse: boolean) => {
|
if (unref(layout) === 'topLeft' || unref(layout) === 'cutMenu') {
|
show.value = true
|
return
|
}
|
if (!collapse) {
|
setTimeout(() => {
|
show.value = !collapse
|
}, 400)
|
} else {
|
show.value = !collapse
|
}
|
}
|
)
|
|
watch(
|
() => layout.value,
|
(layout) => {
|
if (layout === 'top' || layout === 'cutMenu') {
|
show.value = true
|
} else {
|
if (unref(collapse)) {
|
show.value = false
|
} else {
|
show.value = true
|
}
|
}
|
}
|
)
|
|
/** 刷新所有菜单权限 */
|
const gotoHome = async () => {
|
const permissionStore = usePermissionStoreWithOut()
|
isRelogin.show = true
|
let userInfo = await getInfo()
|
wsCache.set(CACHE_KEY.USER, userInfo)
|
wsSessionCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
|
isRelogin.show = false
|
// 后端过滤菜单
|
await permissionStore.generateRoutes()
|
permissionStore.getAddRouters.forEach((route) => {
|
router.addRoute(route as unknown as RouteRecordRaw) // 动态添加可访问路由表
|
})
|
}
|
|
</script>
|
|
<template>
|
<div>
|
<router-link
|
:class="[
|
prefixCls,
|
layout !== 'classic' ? `${prefixCls}__Top` : '',
|
'flex !h-[var(--logo-height)] items-center cursor-pointer pl-8px relative decoration-none overflow-hidden'
|
]"
|
@click="gotoHome"
|
:to="homePath"
|
>
|
<img
|
class="h-[calc(var(--logo-height)-10px)] w-[calc(var(--logo-height)-10px)]"
|
src="@/assets/imgs/logo.png"
|
/>
|
<div
|
v-if="show"
|
:class="[
|
'ml-10px text-16px font-700',
|
{
|
'text-[var(--logo-title-text-color)]': layout === 'classic',
|
'text-[var(--top-header-text-color)]':
|
layout === 'topLeft' || layout === 'top' || layout === 'cutMenu'
|
}
|
]"
|
>
|
{{ title }}
|
</div>
|
</router-link>
|
</div>
|
</template>
|