Procházet zdrojové kódy

feat: 当前选择公司添加进缓存

gatsby před 1 měsícem
rodič
revize
5f4394d856

+ 1 - 1
frontend/src/layouts/components/NavBar/components/EnterpriseSwitcher.vue

@@ -118,7 +118,7 @@ function handleSwitch(enterpriseId: string) {
   align-items: center;
   justify-content: space-between;
   width: 100%;
-  min-width: 150px;
+  min-width: 200px;
 
   &__name {
     flex: 1;

+ 9 - 1
frontend/src/store/modules/enterprise.store.ts

@@ -46,6 +46,11 @@ export const useEnterpriseStore = defineStore("enterprise", {
       if (state.currentEnterprise) {
         return state.currentEnterprise;
       }
+      // 从sessionStorage获取当前选中的企业
+      const currentEnterpriseJson = sessionStorage.getItem(CURRENT_ENTERPRISE_KEY);
+      if (currentEnterpriseJson) {
+        return JSON.parse(currentEnterpriseJson);
+      }
       // 如果没有选中的企业,返回列表中的第一个企业
       if (state.enterpriseList && state.enterpriseList.length > 0) {
         return state.enterpriseList[0];
@@ -99,8 +104,11 @@ export const useEnterpriseStore = defineStore("enterprise", {
       // if (this.currentEnterprise) {
       //   sessionStorage.setItem(CURRENT_ENTERPRISE_KEY, JSON.stringify(this.currentEnterprise));
       // }
-       this.currentEnterprise =
+      this.currentEnterprise =
             this.enterpriseList.find((e: EnterpriseItem) => e.enterprise_id === enterpriseId) || null;
+      if (this.currentEnterprise) {
+        sessionStorage.setItem(CURRENT_ENTERPRISE_KEY, JSON.stringify(this.currentEnterprise));
+      }
     },
 
     clearEnterprise() {