Преглед изворни кода

fix: 修复切换租户可能导致的NAN问题

louhangfei пре 11 месеци
родитељ
комит
3585bbed2b
3 измењених фајлова са 10 додато и 6 уклоњено
  1. 1 0
      src/components/Nav.vue
  2. 8 5
      src/layout/components/SwitchTenant.vue
  3. 1 1
      src/utils/http/axios/index.ts

+ 1 - 0
src/components/Nav.vue

@@ -44,6 +44,7 @@
   import { useGlobSetting } from '@/hooks/setting';
   import { useUserStore } from '@/store/modules/user';
   import SwitchTenant from '@/layout/components/SwitchTenant.vue';
+  import { SYS_TENANT_ID } from '@/utils/useTargetTenantIdSetting';
 
   const userStore = useUserStore();
   const activeNav = ref(NAV_LIST[0].name);

+ 8 - 5
src/layout/components/SwitchTenant.vue

@@ -31,11 +31,8 @@
 
   const userStore = useUserStore();
   const { setValue, getValue } = useTargetTenantIdSetting();
-  const localTId = getValue();
-  const tenantId = computed(() => {
-    return userStore.info.tenantId;
-  });
-  const currentTenant = ref(localTId ? Number(localTId) : Number(tenantId.value));
+
+  const currentTenant = ref();
   const options = ref<TenantOption[]>([]);
 
   const route = useRoute();
@@ -50,10 +47,16 @@
       const nextTenantId = Number(routeTenantId);
       currentTenant.value = nextTenantId;
       setValue(routeTenantId);
+    } else {
+      currentTenant.value = getValue();
     }
     queryListTenant().then((res) => {
       if (!res) return;
       options.value = replaceParams(res || [], 'tenantName', 'id');
+      /** 如果当前租户没选中的话,默认选中第一个 */
+      if (!currentTenant.value) {
+        currentTenant.value = res[0].id;
+      }
     });
   });
 

+ 1 - 1
src/utils/http/axios/index.ts

@@ -192,7 +192,7 @@ const transform: AxiosTransform = {
     const userStore = useUserStoreWidthOut();
     const { getValue } = useTargetTenantIdSetting();
     const token = userStore.getToken;
-    const tenantId = userStore.getTenantId;
+    const tenantId = userStore.info.tenantId;
     const targetTenantId = getValue();
 
     if (token && (config as Recordable)?.requestOptions?.withToken !== false) {