提交 | 用户 | 时间
|
820397
|
1 |
<script lang="ts" setup> |
H |
2 |
import { computed, onMounted, ref, unref, watch } from 'vue' |
|
3 |
import { useAppStore } from '@/store/modules/app' |
94d91d
|
4 |
import { useUserStoreWithOut } from '@/store/modules/user' |
H |
5 |
import { usePermissionStoreWithOut } from '@/store/modules/permission' |
820397
|
6 |
import { useDesign } from '@/hooks/web/useDesign' |
94d91d
|
7 |
import {isRelogin} from "@/config/axios/service"; |
H |
8 |
import router from "@/router"; |
|
9 |
import type {RouteRecordRaw} from "vue-router"; |
271781
|
10 |
import {CACHE_KEY, useCache, useSessionCache} from "@/hooks/web/useCache"; |
H |
11 |
import {getAccessToken} from "@/utils/auth"; |
|
12 |
import {getInfo} from "@/api/login"; |
94d91d
|
13 |
const { wsCache } = useCache() |
271781
|
14 |
const { wsSessionCache } = useSessionCache() |
820397
|
15 |
|
H |
16 |
defineOptions({ name: 'Logo' }) |
|
17 |
|
|
18 |
const { getPrefixCls } = useDesign() |
|
19 |
|
|
20 |
const prefixCls = getPrefixCls('logo') |
|
21 |
|
|
22 |
const appStore = useAppStore() |
|
23 |
|
|
24 |
const show = ref(true) |
|
25 |
|
39248b
|
26 |
const homePath = ref('/index') |
H |
27 |
|
820397
|
28 |
const title = computed(() => appStore.getTitle) |
H |
29 |
|
|
30 |
const layout = computed(() => appStore.getLayout) |
|
31 |
|
|
32 |
const collapse = computed(() => appStore.getCollapse) |
39248b
|
33 |
|
aef77f
|
34 |
homePath.value = '/index' |
820397
|
35 |
|
H |
36 |
onMounted(() => { |
|
37 |
if (unref(collapse)) show.value = false |
|
38 |
}) |
|
39 |
|
|
40 |
watch( |
|
41 |
() => collapse.value, |
|
42 |
(collapse: boolean) => { |
|
43 |
if (unref(layout) === 'topLeft' || unref(layout) === 'cutMenu') { |
|
44 |
show.value = true |
|
45 |
return |
|
46 |
} |
|
47 |
if (!collapse) { |
|
48 |
setTimeout(() => { |
|
49 |
show.value = !collapse |
|
50 |
}, 400) |
|
51 |
} else { |
|
52 |
show.value = !collapse |
|
53 |
} |
|
54 |
} |
|
55 |
) |
|
56 |
|
|
57 |
watch( |
|
58 |
() => layout.value, |
|
59 |
(layout) => { |
|
60 |
if (layout === 'top' || layout === 'cutMenu') { |
|
61 |
show.value = true |
|
62 |
} else { |
|
63 |
if (unref(collapse)) { |
|
64 |
show.value = false |
|
65 |
} else { |
|
66 |
show.value = true |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
) |
94d91d
|
71 |
|
H |
72 |
/** 刷新所有菜单权限 */ |
|
73 |
const gotoHome = async () => { |
|
74 |
const permissionStore = usePermissionStoreWithOut() |
|
75 |
isRelogin.show = true |
271781
|
76 |
let userInfo = await getInfo() |
H |
77 |
wsCache.set(CACHE_KEY.USER, userInfo) |
|
78 |
wsSessionCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus) |
94d91d
|
79 |
isRelogin.show = false |
H |
80 |
// 后端过滤菜单 |
|
81 |
await permissionStore.generateRoutes() |
|
82 |
permissionStore.getAddRouters.forEach((route) => { |
|
83 |
router.addRoute(route as unknown as RouteRecordRaw) // 动态添加可访问路由表 |
|
84 |
}) |
|
85 |
} |
|
86 |
|
820397
|
87 |
</script> |
H |
88 |
|
|
89 |
<template> |
|
90 |
<div> |
|
91 |
<router-link |
|
92 |
:class="[ |
|
93 |
prefixCls, |
|
94 |
layout !== 'classic' ? `${prefixCls}__Top` : '', |
|
95 |
'flex !h-[var(--logo-height)] items-center cursor-pointer pl-8px relative decoration-none overflow-hidden' |
|
96 |
]" |
94d91d
|
97 |
@click="gotoHome" |
39248b
|
98 |
:to="homePath" |
820397
|
99 |
> |
H |
100 |
<img |
|
101 |
class="h-[calc(var(--logo-height)-10px)] w-[calc(var(--logo-height)-10px)]" |
|
102 |
src="@/assets/imgs/logo.png" |
|
103 |
/> |
|
104 |
<div |
|
105 |
v-if="show" |
|
106 |
:class="[ |
|
107 |
'ml-10px text-16px font-700', |
|
108 |
{ |
|
109 |
'text-[var(--logo-title-text-color)]': layout === 'classic', |
|
110 |
'text-[var(--top-header-text-color)]': |
|
111 |
layout === 'topLeft' || layout === 'top' || layout === 'cutMenu' |
|
112 |
} |
|
113 |
]" |
|
114 |
> |
|
115 |
{{ title }} |
|
116 |
</div> |
|
117 |
</router-link> |
|
118 |
</div> |
|
119 |
</template> |