feat: 系统标题支持i18n

This commit is contained in:
2025-02-12 15:03:55 +08:00
parent 07e9187a12
commit b1b00a3a02
8 changed files with 19 additions and 21 deletions

View File

@@ -1,3 +1,4 @@
title: System Title
buttons:AccountSettings: Account buttons:AccountSettings: Account
buttons:LoginOut: LoginOut buttons:LoginOut: LoginOut
buttons:Login: Login buttons:Login: Login

View File

@@ -1,3 +1,4 @@
title: 系统标题
buttons:AccountSettings: 账户设置 buttons:AccountSettings: 账户设置
buttons:LoginOut: 退出系统 buttons:LoginOut: 退出系统
buttons:Login: 登录 buttons:Login: 登录

View File

@@ -1,6 +1,6 @@
{ {
"Version": "5.9.0", "Version": "5.9.0",
"Title": "PureAdmin", "Period":"2024-present",
"FixedHeader": true, "FixedHeader": true,
"HiddenSideBar": false, "HiddenSideBar": false,
"MultiTagsCache": false, "MultiTagsCache": false,

View File

@@ -1,20 +1,17 @@
<script setup lang="ts"> <script setup lang="ts">
import { useI18n } from "vue-i18n";
import { getConfig } from "@/config"; import { getConfig } from "@/config";
const { t } = useI18n();
const TITLE = getConfig("Title"); const Period = getConfig("Period");
</script> </script>
<template> <template>
<footer <footer
class="layout-footer text-[rgba(0,0,0,0.6)] dark:text-[rgba(220,220,242,0.8)]" class="layout-footer text-[rgba(0,0,0,0.6)] dark:text-[rgba(220,220,242,0.8)]"
> >
Copyright © 2020-present Copyright © {{ Period }}
<a <a class="hover:text-primary" href="#" target="_blank">
class="hover:text-primary" &nbsp;{{ t("title") }}
href="https://github.com/pure-admin"
target="_blank"
>
&nbsp;{{ TITLE }}
</a> </a>
</footer> </footer>
</template> </template>

View File

@@ -82,18 +82,18 @@ export function useNav() {
return pureApp.getDevice; return pureApp.getDevice;
}); });
const { $storage, $config } = useGlobal<GlobalPropertiesApi>(); const { $storage } = useGlobal<GlobalPropertiesApi>();
const layout = computed(() => { const layout = computed(() => {
return $storage?.layout?.layout; return $storage?.layout?.layout;
}); });
const title = computed(() => { const title = computed(() => {
return $config.Title; return transformI18n("title");
}); });
/** 动态title */ /** 动态title */
function changeTitle(meta: routeMetaType) { function changeTitle(meta: routeMetaType) {
const Title = getConfig().Title; const Title = transformI18n("title");
if (Title) document.title = `${transformI18n(meta.title)} | ${Title}`; if (Title) document.title = `${transformI18n(meta.title)} | ${Title}`;
else document.title = transformI18n(meta.title); else document.title = transformI18n(meta.title);
} }

View File

@@ -1,5 +1,4 @@
import "@/utils/sso"; import "@/utils/sso";
import { getConfig } from "@/config";
import NProgress from "@/utils/progress"; import NProgress from "@/utils/progress";
import { transformI18n } from "@/plugins/i18n"; import { transformI18n } from "@/plugins/i18n";
import { buildHierarchyTree } from "@/utils/tree"; import { buildHierarchyTree } from "@/utils/tree";
@@ -119,7 +118,7 @@ router.beforeEach((to: ToRouteType, _from, next) => {
if (!externalLink) { if (!externalLink) {
to.matched.some(item => { to.matched.some(item => {
if (!item.meta.title) return ""; if (!item.meta.title) return "";
const Title = getConfig().Title; const Title = transformI18n("title");
if (Title) { if (Title) {
document.title = `${transformI18n(item.meta.title)} | ${Title}`; document.title = `${transformI18n(item.meta.title)} | ${Title}`;
} else document.title = transformI18n(item.meta.title); } else document.title = transformI18n(item.meta.title);

View File

@@ -1,16 +1,16 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { type setType, store, getConfig } from "../utils"; import { type setType, store, getConfig } from "../utils";
import { transformI18n } from "@/plugins/i18n";
export const useSettingStore = defineStore({ export const useSettingStore = defineStore({
id: "setting", id: "setting",
state: (): setType => ({ state: (): setType => ({
title: getConfig().Title, title: transformI18n("title"),
fixedHeader: getConfig().FixedHeader, fixedHeader: getConfig().FixedHeader,
hiddenSideBar: getConfig().HiddenSideBar hiddenSideBar: getConfig().HiddenSideBar
}), }),
getters: { getters: {
getTitle(state) { getTitle() {
return state.title; return transformI18n("title");
}, },
getFixedHeader(state) { getFixedHeader(state) {
return state.fixedHeader; return state.fixedHeader;

4
types/global.d.ts vendored
View File

@@ -83,7 +83,7 @@ declare global {
*/ */
interface PlatformConfigs { interface PlatformConfigs {
Version?: string; Version?: string;
Title?: string; Period?: string;
FixedHeader?: boolean; FixedHeader?: boolean;
HiddenSideBar?: boolean; HiddenSideBar?: boolean;
MultiTagsCache?: boolean; MultiTagsCache?: boolean;
@@ -116,7 +116,7 @@ declare global {
*/ */
interface StorageConfigs { interface StorageConfigs {
version?: string; version?: string;
title?: string; period?: string;
fixedHeader?: boolean; fixedHeader?: boolean;
hiddenSideBar?: boolean; hiddenSideBar?: boolean;
multiTagsCache?: boolean; multiTagsCache?: boolean;