From 964fc7d8b4535f2be89818dcd027ceafee7f9400 Mon Sep 17 00:00:00 2001 From: zhangrenyuan <18990852002@163.com> Date: Tue, 25 Nov 2025 19:02:56 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E4=BD=BF=E7=94=A8vue-i18n?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=EF=BC=8C=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E4=B8=AD=E8=8B=B1=E6=B3=B0=E7=9A=84=E5=AD=97=E6=AE=B5=E5=88=87?= =?UTF-8?q?=E6=8D=A2=EF=BC=8C=E5=85=A8=E5=B1=80=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 82 ++++++++++++++++++++- package.json | 1 + src/App.vue | 29 ++++++-- src/components/dialogs/LanguageSwitch.vue | 118 ++++++++++++++++++++++++++++++ src/components/locales/index.js | 28 +++++++ src/components/locales/lang/en.js | 10 +++ src/components/locales/lang/th.js | 10 +++ src/components/locales/lang/zh-CN.js | 10 +++ src/main.ts | 3 + src/views/audit/gold/audit.vue | 3 +- src/views/home.vue | 19 ++++- 11 files changed, 301 insertions(+), 12 deletions(-) create mode 100644 src/components/dialogs/LanguageSwitch.vue create mode 100644 src/components/locales/index.js create mode 100644 src/components/locales/lang/en.js create mode 100644 src/components/locales/lang/th.js create mode 100644 src/components/locales/lang/zh-CN.js diff --git a/package-lock.json b/package-lock.json index 6da4030..03592ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "pinia": "^3.0.2", "pinyin-match": "^1.2.8", "vue": "^3.5.12", + "vue-i18n": "^9.14.5", "vue-icons-plus": "^0.1.7", "vue-json-excel": "^0.3.0", "vue-router": "^4.5.0", @@ -115,6 +116,7 @@ "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.26.10.tgz", "integrity": "sha512-vMqyb7XCDMPvJFFOaT9kxtiRh42GwlZEg1/uIgtZshS5a/8OaduUfCi7kynKgc3Tw/6Uo2D+db9qBttghhmxwQ==", "dev": true, + "peer": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.26.2", @@ -2018,6 +2020,7 @@ "version": "6.7.2", "resolved": "https://registry.npmmirror.com/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-6.7.2.tgz", "integrity": "sha512-yxtOBWDrdi5DD5o1pmVdq3WMCvnobT0LU6R8RyyVXPvFRd2o79/0NCuQoCjNTeZz9EzA9xS3JxNWfv54RIHFEA==", + "peer": true, "dependencies": { "@fortawesome/fontawesome-common-types": "6.7.2" }, @@ -2045,6 +2048,50 @@ "vue": ">= 3.0.0 < 4" } }, + "node_modules/@intlify/core-base": { + "version": "9.14.5", + "resolved": "https://registry.npmjs.org/@intlify/core-base/-/core-base-9.14.5.tgz", + "integrity": "sha512-5ah5FqZG4pOoHjkvs8mjtv+gPKYU0zCISaYNjBNNqYiaITxW8ZtVih3GS/oTOqN8d9/mDLyrjD46GBApNxmlsA==", + "license": "MIT", + "dependencies": { + "@intlify/message-compiler": "9.14.5", + "@intlify/shared": "9.14.5" + }, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/kazupon" + } + }, + "node_modules/@intlify/message-compiler": { + "version": "9.14.5", + "resolved": "https://registry.npmjs.org/@intlify/message-compiler/-/message-compiler-9.14.5.tgz", + "integrity": "sha512-IHzgEu61/YIpQV5Pc3aRWScDcnFKWvQA9kigcINcCBXN8mbW+vk9SK+lDxA6STzKQsVJxUPg9ACC52pKKo3SVQ==", + "license": "MIT", + "dependencies": { + "@intlify/shared": "9.14.5", + "source-map-js": "^1.0.2" + }, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/kazupon" + } + }, + "node_modules/@intlify/shared": { + "version": "9.14.5", + "resolved": "https://registry.npmjs.org/@intlify/shared/-/shared-9.14.5.tgz", + "integrity": "sha512-9gB+E53BYuAEMhbCAxVgG38EZrk59sxBtv3jSizNL2hEWlgjBjAw1AwpLHtNaeda12pe6W20OGEa0TwuMSRbyQ==", + "license": "MIT", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/kazupon" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.8", "resolved": "https://mirrors.huaweicloud.com/repository/npm/@jridgewell/gen-mapping/-/gen-mapping-0.3.8.tgz", @@ -2746,6 +2793,7 @@ "resolved": "https://mirrors.huaweicloud.com/repository/npm/@types/lodash-es/-/lodash-es-4.17.12.tgz", "integrity": "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==", "license": "MIT", + "peer": true, "dependencies": { "@types/lodash": "*" } @@ -2756,6 +2804,7 @@ "integrity": "sha512-F8Q+SeGimwOo86fiovQh8qiXfFEh2/ocYv7tU5pJ3EXMSSxk1Joj5wefpFK2fHTf/N6HKGSxIDBT9f3gCxXPkQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "undici-types": "~6.20.0" } @@ -3292,6 +3341,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001688", "electron-to-chromium": "^1.5.73", @@ -4196,13 +4246,15 @@ "version": "4.17.21", "resolved": "https://mirrors.huaweicloud.com/repository/npm/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/lodash-es": { "version": "4.17.21", "resolved": "https://mirrors.huaweicloud.com/repository/npm/lodash-es/-/lodash-es-4.17.21.tgz", "integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==", - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/lodash-unified": { "version": "1.0.3", @@ -4672,6 +4724,7 @@ "integrity": "sha512-wc2cBWqJgkU3Iz5oztRkQbfVkbxoz5EhnCGOrnJvnLnQ7O0WhQUYyv18qQI79O8L7DdHrrlJNeCHd4VGpnaXKQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/estree": "1.0.6" }, @@ -4749,6 +4802,7 @@ "resolved": "https://registry.npmmirror.com/sass/-/sass-1.86.3.tgz", "integrity": "sha512-iGtg8kus4GrsGLRDLRBRHY9dNVA78ZaS7xr01cWnS7PEMQyFtTqBiyCrfpTYTZXRWM94akzckYjh8oADfFNTzw==", "dev": true, + "peer": true, "dependencies": { "chokidar": "^4.0.0", "immutable": "^5.0.2", @@ -4895,6 +4949,7 @@ "integrity": "sha512-GWANVlPM/ZfYzuPHjq0nxT+EbOEDDN3Jwhwdg1D8TU8oSkktp8w64Uq4auuGLxFSoNTRDncTq2hQHX1Ld9KHkA==", "dev": true, "license": "BSD-2-Clause", + "peer": true, "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.8.2", @@ -4948,6 +5003,7 @@ "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", "devOptional": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -5040,6 +5096,7 @@ "integrity": "sha512-RjjMipCKVoR4hVfPY6GQTgveinjNuyLw+qruksLDvA5ktI1150VmcMBKmQaEWJhg/j6Uaf6dNCNA0AfdzUb/hQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.24.2", "postcss": "^8.5.1", @@ -5131,6 +5188,7 @@ "resolved": "https://mirrors.huaweicloud.com/repository/npm/vue/-/vue-3.5.13.tgz", "integrity": "sha512-wmeiSMxkZCSc+PM2w2VRsOYAZC8GdipNFRTsLSfodVqI9mbejKeXEGr8SckuLnrQPGe3oJN5c3K0vpoU9q/wCQ==", "license": "MIT", + "peer": true, "dependencies": { "@vue/compiler-dom": "3.5.13", "@vue/compiler-sfc": "3.5.13", @@ -5147,6 +5205,26 @@ } } }, + "node_modules/vue-i18n": { + "version": "9.14.5", + "resolved": "https://registry.npmjs.org/vue-i18n/-/vue-i18n-9.14.5.tgz", + "integrity": "sha512-0jQ9Em3ymWngyiIkj0+c/k7WgaPO+TNzjKSNq9BvBQaKJECqn9cd9fL4tkDhB5G1QBskGl9YxxbDAhgbFtpe2g==", + "license": "MIT", + "dependencies": { + "@intlify/core-base": "9.14.5", + "@intlify/shared": "9.14.5", + "@vue/devtools-api": "^6.5.0" + }, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/kazupon" + }, + "peerDependencies": { + "vue": "^3.0.0" + } + }, "node_modules/vue-icons-plus": { "version": "0.1.7", "resolved": "https://mirrors.huaweicloud.com/repository/npm/vue-icons-plus/-/vue-icons-plus-0.1.7.tgz", diff --git a/package.json b/package.json index d667c43..b017c12 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "pinia": "^3.0.2", "pinyin-match": "^1.2.8", "vue": "^3.5.12", + "vue-i18n": "^9.14.5", "vue-icons-plus": "^0.1.7", "vue-json-excel": "^0.3.0", "vue-router": "^4.5.0", diff --git a/src/App.vue b/src/App.vue index ccbcd97..9f17303 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,9 +1,26 @@ - - - + \ No newline at end of file diff --git a/src/components/dialogs/LanguageSwitch.vue b/src/components/dialogs/LanguageSwitch.vue new file mode 100644 index 0000000..d18b840 --- /dev/null +++ b/src/components/dialogs/LanguageSwitch.vue @@ -0,0 +1,118 @@ + + + + + + \ No newline at end of file diff --git a/src/components/locales/index.js b/src/components/locales/index.js new file mode 100644 index 0000000..0422819 --- /dev/null +++ b/src/components/locales/index.js @@ -0,0 +1,28 @@ +import { createI18n } from 'vue-i18n' + +// 引入你的本地语言包 +import zhCN from './lang/zh-CN' +import en from './lang/en' +import th from './lang/th' // 泰文 + +// 组合语言包 +const messages = { + 'zh-CN': zhCN, + 'en': en, + 'th': th +} + +// 获取浏览器默认语言或缓存语言 +const getLocale = () => { + // 优先读取缓存,没有则读取浏览器语言,默认 zh-CN + return localStorage.getItem('language') || 'zh-CN' +} + +const i18n = createI18n({ + legacy: false, // Vue 3 组合式 API 必须设置为 false + globalInjection: true, // 全局注入 $t 函数 + locale: getLocale(), // 初始化语言 + messages // 语言包数据 +}) + +export default i18n \ No newline at end of file diff --git a/src/components/locales/lang/en.js b/src/components/locales/lang/en.js new file mode 100644 index 0000000..88b11ce --- /dev/null +++ b/src/components/locales/lang/en.js @@ -0,0 +1,10 @@ +export default { + common: { + confirm: 'Confirm', + cancel: 'Cancel' + }, + audit: { + rechargeAudit: 'Recharge Audit', + status: 'Status' + } +} \ No newline at end of file diff --git a/src/components/locales/lang/th.js b/src/components/locales/lang/th.js new file mode 100644 index 0000000..e535453 --- /dev/null +++ b/src/components/locales/lang/th.js @@ -0,0 +1,10 @@ +export default { + common: { + confirm: 'ยืนยัน', + cancel: 'ยกเลิก' + }, + audit: { + rechargeAudit: 'การตรวจสอบการเติมเงิน', + status: 'สถานะ' + } +} \ No newline at end of file diff --git a/src/components/locales/lang/zh-CN.js b/src/components/locales/lang/zh-CN.js new file mode 100644 index 0000000..b23152c --- /dev/null +++ b/src/components/locales/lang/zh-CN.js @@ -0,0 +1,10 @@ +export default { + common: { + confirm: '确定', + cancel: '取消' + }, + audit: { + rechargeAudit: '充值审核', // 你的需求字段 + status: '状态' + } +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 830388d..9079501 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,6 +18,8 @@ import request from "@/util/request"; import "./global.css"; import '@/assets/css/btn.css'; import {useMessageStore} from "@/store"; +import i18n from './components/locales' + const app = createApp(App) @@ -40,6 +42,7 @@ app.use(ElementPlus, { .use(VxeUI) .use(VxeUITable) .use(pinia) + .use(i18n) .mount('#app') // 在 app 挂载之后再使用 store diff --git a/src/views/audit/gold/audit.vue b/src/views/audit/gold/audit.vue index 4c02a4b..3689595 100644 --- a/src/views/audit/gold/audit.vue +++ b/src/views/audit/gold/audit.vue @@ -8,7 +8,7 @@ @click="navigateTo('rechargeAudit')" v-if="hasRecharge" > - 充值审核 + {{ $t('audit.rechargeAudit') }} { } } +// ------------------ 语言切换 ------------------ +const languageSwitchRef = ref() + +const openLanguageSwitch = () => { + languageSwitchRef.value?.open() +} + +const handleLanguageChanged = (lang) => { + ElMessage.success(`语言已切换到${lang}`) +} + // ------------------ 刷新数据 ------------------ const refreshData = async () => { try { @@ -75,7 +87,6 @@ const adminStore = useAdminStore() const {adminData, menuTree, flag} = storeToRefs(adminStore) const menuList = ref(filterMenu(menuTree.value)) - function findBestMatch(menuList, path) { let bestMatch = '' @@ -369,7 +380,7 @@ onMounted(() => getMessage())