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