From e181f04c642204e79749af93fa921875ff6c21ba Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期二, 20 五月 2025 10:46:35 +0800
Subject: [PATCH] refactor(qms): 重构趋势图展示逻辑

---
 src/store/modules/app.ts |  125 ++++++++++++++++++++---------------------
 1 files changed, 62 insertions(+), 63 deletions(-)

diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts
index b53dbad..0205fab 100644
--- a/src/store/modules/app.ts
+++ b/src/store/modules/app.ts
@@ -1,73 +1,72 @@
-import Cookies from 'js-cookie';
-import zhCn from 'element-plus/es/locale/lang/zh-cn';
-import en from 'element-plus/es/locale/lang/en';
+import zhCN from 'element-plus/es/locale/lang/zh-cn';
+import enUS from 'element-plus/es/locale/lang/en';
 
 export const useAppStore = defineStore('app', () => {
-	const sidebarStatus = Cookies.get('sidebarStatus');
-	const sidebar = reactive({
-		opened: sidebarStatus ? !!+sidebarStatus : true,
-		withoutAnimation: false,
-		hide: false
-	});
-	const device = ref<string>('desktop');
-	const size = ref(Cookies.get('size') || 'default');
-	// 璇█
-	const language = ref(Cookies.get('language'));
-	const locale = computed(() => {
-		if (language?.value == 'en') {
-			return en;
-		} else {
-			return zhCn;
-		}
-	});
+  const sidebarStatus = useStorage('sidebarStatus', '1');
+  const sidebar = reactive({
+    opened: sidebarStatus.value ? !!+sidebarStatus.value : true,
+    withoutAnimation: false,
+    hide: false
+  });
+  const device = ref<string>('desktop');
+  const size = useStorage<'large' | 'default' | 'small'>('size', 'default');
 
-	const toggleSideBar = (withoutAnimation?: boolean) => {
-		if (sidebar.hide) {
-			return false;
-		}
+  // 璇█
+  const language = useStorage('language', 'zh_CN');
+  const languageObj: any = {
+    en_US: enUS,
+    zh_CN: zhCN
+  };
+  const locale = computed(() => {
+    return languageObj[language.value];
+  });
 
-		sidebar.opened = !sidebar.opened;
-		sidebar.withoutAnimation = withoutAnimation as boolean;
-		if (sidebar.opened) {
-			Cookies.set('sidebarStatus', '1');
-		} else {
-			Cookies.set('sidebarStatus', '0');
-		}
-	};
+  const toggleSideBar = (withoutAnimation: boolean) => {
+    if (sidebar.hide) {
+      return false;
+    }
 
-	const closeSideBar = ({ withoutAnimation }: any): void => {
-		Cookies.set('sidebarStatus', '0');
-		sidebar.opened = false;
-		sidebar.withoutAnimation = withoutAnimation;
-	};
-	const toggleDevice = (d: string): void => {
-		device.value = d;
-	};
-	const setSize = (s: string): void => {
-		size.value = s;
-		Cookies.set('size', s);
-	};
-	const toggleSideBarHide = (status: boolean): void => {
-		sidebar.hide = status;
-	};
+    sidebar.opened = !sidebar.opened;
+    sidebar.withoutAnimation = withoutAnimation;
+    if (sidebar.opened) {
+      sidebarStatus.value = '1';
+    } else {
+      sidebarStatus.value = '0';
+    }
+  };
 
-	const changeLanguage = (val: string): void => {
-		language.value = val;
-	};
+  const closeSideBar = ({ withoutAnimation }: any): void => {
+    sidebarStatus.value = '0';
+    sidebar.opened = false;
+    sidebar.withoutAnimation = withoutAnimation;
+  };
+  const toggleDevice = (d: string): void => {
+    device.value = d;
+  };
+  const setSize = (s: 'large' | 'default' | 'small'): void => {
+    size.value = s;
+  };
+  const toggleSideBarHide = (status: boolean): void => {
+    sidebar.hide = status;
+  };
 
-	return {
-		device,
-		sidebar,
-		language,
-		locale,
-		size,
-		changeLanguage,
-		toggleSideBar,
-		closeSideBar,
-		toggleDevice,
-		setSize,
-		toggleSideBarHide
-	};
+  const changeLanguage = (val: string): void => {
+    language.value = val;
+  };
+
+  return {
+    device,
+    sidebar,
+    language,
+    locale,
+    size,
+    changeLanguage,
+    toggleSideBar,
+    closeSideBar,
+    toggleDevice,
+    setSize,
+    toggleSideBarHide
+  };
 });
 
 export default useAppStore;

--
Gitblit v1.9.3