Files
mayfly-go/frontend/src/App.vue

119 lines
2.9 KiB
Vue
Raw Normal View History

<template>
2024-11-20 22:43:53 +08:00
<el-config-provider :size="getGlobalComponentSize" :locale="getGlobalI18n">
2025-04-23 20:36:32 +08:00
<div class="h-full">
2024-11-20 22:43:53 +08:00
<el-watermark
:zIndex="100000"
2024-11-20 22:43:53 +08:00
:width="210"
v-if="themeConfig.isWatermark"
:font="{ color: 'rgba(180, 180, 180, 0.3)' }"
:content="themeConfig.watermarkText"
class="!h-full"
2024-11-20 22:43:53 +08:00
>
<router-view />
2024-11-20 22:43:53 +08:00
</el-watermark>
<router-view v-if="!themeConfig.isWatermark" />
2024-11-20 22:43:53 +08:00
<Setings />
2024-11-20 22:43:53 +08:00
</div>
</el-config-provider>
</template>
2023-03-15 11:41:03 +08:00
<script setup lang="ts" name="app">
import { onMounted, nextTick, watch, computed } from 'vue';
import { useRoute } from 'vue-router';
2023-03-15 11:41:03 +08:00
import { storeToRefs } from 'pinia';
import { useThemeConfig } from '@/store/themeConfig';
2023-09-26 17:38:52 +08:00
import Setings from '@/layout/navBars/breadcrumb/setings.vue';
import { useIntervalFn } from '@vueuse/core';
2024-11-20 22:43:53 +08:00
import { useI18n } from 'vue-i18n';
import EnumValue from './common/Enum';
import { I18nEnum } from './common/commonEnum';
import { saveThemeConfig } from './common/utils/storage';
2023-03-15 11:41:03 +08:00
const route = useRoute();
const themeConfigStores = useThemeConfig();
const { themeConfig } = storeToRefs(themeConfigStores);
2024-11-20 22:43:53 +08:00
// 定义变量内容
const { locale, t } = useI18n();
2023-03-15 11:41:03 +08:00
// 页面加载时
onMounted(() => {
nextTick(() => {
// 初始化系统主题
themeConfigStores.initThemeConfig();
2023-03-15 11:41:03 +08:00
});
});
2023-10-14 00:38:51 +08:00
// 监听 themeConfig isWartermark配置文件的变化
watch(
2023-10-14 16:00:16 +08:00
() => themeConfig.value.isWatermark,
2023-10-14 00:38:51 +08:00
(val) => {
if (val) {
setTimeout(() => {
setWatermarkContent();
refreshWatermarkTime();
resume();
2023-10-14 16:00:16 +08:00
}, 500);
} else {
pause();
2023-10-14 00:38:51 +08:00
}
}
);
2024-11-20 22:43:53 +08:00
watch(
() => themeConfig.value.globalI18n,
(val) => {
locale.value = val;
}
);
watch(
themeConfig,
(val) => {
saveThemeConfig(val);
},
{ deep: true }
);
// 获取全局组件大小
const getGlobalComponentSize = computed(() => {
return themeConfig.value.globalComponentSize;
});
// 获取全局 i18n
const getGlobalI18n = computed(() => {
return EnumValue.getEnumByValue(I18nEnum, locale.value)?.extra.el;
});
// 刷新水印时间
const { pause, resume } = useIntervalFn(() => {
if (!themeConfig.value.isWatermark) {
pause();
}
refreshWatermarkTime();
}, 60000);
2023-10-14 00:38:51 +08:00
const setWatermarkContent = () => {
2023-10-14 16:00:16 +08:00
themeConfigStores.setWatermarkUser();
2023-10-14 00:38:51 +08:00
};
/**
* 刷新水印时间
*/
const refreshWatermarkTime = () => {
themeConfigStores.setWatermarkNowTime();
2023-10-14 00:38:51 +08:00
};
2023-03-15 11:41:03 +08:00
// 监听路由的变化,设置网站标题
watch(
() => route.path,
() => {
nextTick(() => {
2024-11-20 22:43:53 +08:00
document.title = `${t((route.meta.title as string) || '')} - ${themeConfig.value.globalTitle}` || themeConfig.value.globalTitle;
2023-03-15 11:41:03 +08:00
});
}
);
</script>