初始版本提交

This commit is contained in:
yaoyn
2024-02-05 09:15:37 +08:00
parent b52d4414be
commit 445292105f
1848 changed files with 236859 additions and 75 deletions

37
src/hooks/web/useTitle.ts Normal file
View File

@ -0,0 +1,37 @@
import { watch, unref } from 'vue';
import { useI18n } from '/@/hooks/web/useI18n';
import { useTitle as usePageTitle } from '@vueuse/core';
import { useGlobSetting } from '/@/hooks/setting';
import { useRouter } from 'vue-router';
import { useLocaleStore } from '/@/store/modules/locale';
import { useAppStore } from '/@/store/modules/app';
import { REDIRECT_NAME } from '/@/router/constant';
/**
* Listening to page changes and dynamically changing site titles
*/
export function useTitle() {
const { title } = useGlobSetting();
const { t } = useI18n();
const { currentRoute } = useRouter();
const localeStore = useLocaleStore();
const appStore = useAppStore();
const pageTitle = usePageTitle();
watch(
[() => currentRoute.value.path, () => localeStore.getLocale],
() => {
const route = unref(currentRoute);
if (route.name === REDIRECT_NAME) {
return;
}
const tTitle = t(route?.meta?.title as string);
pageTitle.value = tTitle
? ` ${tTitle} - ${appStore.getLogoConfig.shortName || title} `
: `${appStore.getLogoConfig.shortName || title}`;
},
{ immediate: true },
);
}