From b01723592cc0e6a9702dea57fb176a465c5ee45c Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期四, 23 十月 2025 13:18:34 +0800
Subject: [PATCH] 仓储设备图色块修改,element组件国际化语言添加

---
 UI-Project/src/lang/index.js |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/UI-Project/src/lang/index.js b/UI-Project/src/lang/index.js
index b2d76c4..e533cb9 100644
--- a/UI-Project/src/lang/index.js
+++ b/UI-Project/src/lang/index.js
@@ -3,11 +3,14 @@
 import zh from "./zh"
 import py from "./py"
 import en from "./en"
+import { useLocale } from 'element-plus'; 
+import enLocale from 'element-plus/es/locale/lang/en';
+import zhLocale from 'element-plus/es/locale/lang/zh-cn';
 
 let messages = {
-    zh:zh,
+    zh: {...zh, ...zhLocale},
     py:py,
-    en: en
+    en: {...en, ...enLocale}
 }
 
 const i18n = createI18n({
@@ -17,4 +20,29 @@
     messages
 })
 
+const syncElementLocale = () => {
+  // 鍦ㄦ柟娉曞唴璋冪敤 useLocale锛堢‘淇濆湪 Vue 涓婁笅鏂囧唴锛�
+  const { locale } = useLocale(); 
+  const currentLang = i18n.global.locale.value;
+  // 鏍规嵁褰撳墠璇█鍒囨崲 Element 缁勪欢鐨勮瑷�鍖�
+    if (currentLang === 'zh') {
+    locale.value = { ...zhLocale }; // 涓枃鍐呯疆鏂囨湰
+  } else {
+    locale.value = { ...enLocale }; // 鑻辨枃鍐呯疆鏂囨湰
+  }
+  
+  // 棰濆瑙﹀彂涓�娆� i18n 鍒锋柊锛堣В鍐崇紦瀛橀棶棰橈級
+  i18n.global.locale.value = currentLang;
+};
+
+// 鍒濆鍖栧悓姝�
+syncElementLocale();
+
+// 璇█鍒囨崲鏂规硶
+export const switchLang = (lang) => {
+  localStorage.setItem('lang', lang);
+  i18n.global.locale.value = lang;
+  syncElementLocale(); // 鍒囨崲鍚庡悓姝�
+};
+export { syncElementLocale };
 export default i18n
\ No newline at end of file

--
Gitblit v1.8.0