zhouwx
2024-12-04 80c8993820fc3f958397bebe9dbd72be6a449c55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<template>
    <div class="layout-view-bg-white flex layout-view-link" :style="{ height: `calc(100vh - ${setLinkHeight}` }">
        <a :href="currentRouteMeta.isLink" target="_blank" rel="opener" class="flex-margin"> {{ $t(currentRouteMeta.title) }}:{{ currentRouteMeta.isLink }} </a>
    </div>
</template>
 
<script lang="ts">
import { defineComponent, toRefs, reactive, computed, watch } from 'vue';
import { useRoute, RouteMeta } from 'vue-router';
import { storeToRefs } from 'pinia';
import { useThemeConfig } from '/@/stores/themeConfig';
 
// 定义接口来定义对象的类型
interface LinkViewState {
    currentRouteMeta: {
        isLink: string;
        title: string;
    };
}
interface LinkViewRouteMeta extends RouteMeta {
    isLink: string;
    title: string;
}
 
export default defineComponent({
    name: 'layoutLinkView',
    setup() {
        const storesThemeConfig = useThemeConfig();
        const { themeConfig } = storeToRefs(storesThemeConfig);
        const route = useRoute();
        const state = reactive<LinkViewState>({
            currentRouteMeta: {
                isLink: '',
                title: ''
            }
        });
        // 设置 link 的高度
        const setLinkHeight = computed(() => {
            let { isTagsview } = themeConfig.value;
            if (isTagsview) return `115px`;
            else return `80px`;
        });
        // 监听路由的变化,设置内容
        watch(
            () => route.path,
            () => {
                state.currentRouteMeta = <LinkViewRouteMeta>route.meta;
            },
            {
                immediate: true
            }
        );
        return {
            setLinkHeight,
            ...toRefs(state)
        };
    }
});
</script>