马宇豪
2024-04-10 4cc743acbbe2ff41ccff1a72334bfa106e910b00
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
<!--        <transition name="fade" mode="out-in">-->
<!--            <keep-alive :exclude="excludeList">-->
<!--                <router-view v-if="!$route.json.meta.iskeepAlive" :key="$route.json.path"></router-view>-->
<!--            </keep-alive>-->
<!--        </transition>-->
    <!--    <router-view v-if="!$route.json.meta.iskeepAlive" v-slot="{ Component }">-->
    <!--        <transition name="fade" mode="in-out">-->
    <!--            <keep-alive :exclude="excludeList" :include="includeList">-->
    <!--                <components :is="Component" :key="$route.json.id"></components>-->
    <!--            </keep-alive>-->
    <!--        </transition>-->
    <!--    </router-view>-->
    <el-config-provider :size="getGlobalComponentSize" :locale="i18nLocale">
        <router-view v-show="themeConfig.lockScreenTime > 1" />
        <LockScreen v-if="themeConfig.isLockScreen" />
        <Setings ref="setingsRef" v-show="themeConfig.lockScreenTime > 1" />
        <CloseFull v-if="!themeConfig.isLockScreen" />
    </el-config-provider>
</template>
 
<script lang="ts">
import { computed, ref, getCurrentInstance, onBeforeMount, onMounted, onUnmounted, nextTick, defineComponent, watch, reactive, toRefs } from 'vue';
import { useRoute } from 'vue-router';
import { storeToRefs } from 'pinia';
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
import { useThemeConfig } from '/@/stores/themeConfig';
import other from '/@/utils/other';
import { Local, Session } from '/@/utils/storage';
import setIntroduction from '/@/utils/setIconfont';
import LockScreen from '/@/layout/lockScreen/index.vue';
import Setings from '/@/layout/navBars/breadcrumb/setings.vue';
import CloseFull from '/@/layout/navBars/breadcrumb/closeFull.vue';
import { initBackEndControlRoutes } from './router/backEnd';
 
export default {
    name: 'app',
    components: { LockScreen, Setings, CloseFull },
    setup() {
        const { proxy } = <any>getCurrentInstance();
        const setingsRef = ref();
        const route = useRoute();
        const stores = useTagsViewRoutes();
        const storesThemeConfig = useThemeConfig();
        const { themeConfig } = storeToRefs(storesThemeConfig);
        const state = reactive({
            i18nLocale: null,
            excludeList: ['a-e'],
            includeList: []
        });
 
        // 获取全局组件大小
        const getGlobalComponentSize = computed(() => {
            return other.globalComponentSize();
        });
        // 布局配置弹窗打开
        const openSetingsDrawer = () => {
            setingsRef.value.openDrawer();
        };
        // 设置初始化,防止刷新时恢复默认
        onBeforeMount(() => {
            // 设置批量第三方 icon 图标
            setIntroduction.cssCdn();
            // 设置批量第三方 js
            setIntroduction.jsCdn();
        });
        // 页面加载时
        onMounted(() => {
            nextTick(() => {
                // 监听布局配置弹窗点击打开
                proxy.mittBus.on('openSetingsDrawer', () => {
                    openSetingsDrawer();
                });
                // 设置 i18n,App.vue 中的 el-config-provider
                proxy.mittBus.on('getI18nConfig', (locale: string) => {
                    (state.i18nLocale as string | null) = locale;
                });
                // 获取缓存中的布局配置;
                if (Local.get('themeConfig')) {
                    storesThemeConfig.setThemeConfig(themeConfig.value);
                    // storesThemeConfig.setThemeConfig(Local.get('themeConfig'));
                    document.documentElement.style.cssText = Local.get('themeConfigStyle');
                }
                // 获取缓存中的全屏配置
                if (Session.get('isTagsViewCurrenFull')) {
                    stores.setCurrenFullscreen(Session.get('isTagsViewCurrenFull'));
                }
            });
            // if(!Session.get('token')) return
            // initBackEndControlRoutes()
        });
 
        // 页面销毁时,关闭监听布局配置/i18n监听
        onUnmounted(() => {
            proxy.mittBus.off('openSetingsDrawer', () => {});
            proxy.mittBus.off('getI18nConfig', () => {});
        });
        // 监听路由的变化,设置网站标题
        watch(
            () => route.path,
            () => {
                other.useTitle();
            },
            {
                deep: true
            }
        );
        return {
            themeConfig,
            setingsRef,
            getGlobalComponentSize,
            ...toRefs(state)
        };
    }
};
</script>