Sfoglia il codice sorgente

fix: 修复切换租户的bug

louhangfei 11 mesi fa
parent
commit
a7086ec7fd
2 ha cambiato i file con 5 aggiunte e 11 eliminazioni
  1. 1 1
      src/components/Nav.vue
  2. 4 10
      src/layout/components/SwitchTenant.vue

+ 1 - 1
src/components/Nav.vue

@@ -13,7 +13,7 @@
         <span>{{ item.meta?.title }}</span>
       </div>
     </nav>
-    <SwitchTenant />
+    <SwitchTenant v-if="userStore.info.tenantId === SYS_TENANT_ID" />
     <div class="platform__right">
       <div class="platform__right__search">
         <el-input v-model="searchValue" placeholder="搜索您想了解的" class="input-with-icon" clearable>

+ 4 - 10
src/layout/components/SwitchTenant.vue

@@ -1,6 +1,6 @@
 <!-- 切换租户 -->
 <template>
-  <div class="switchTenantLable-wrapper" v-if="optionsShown">
+  <div class="switchTenantLable-wrapper">
     <el-tree-select
       :model-value="currentTenant"
       :data="options"
@@ -14,11 +14,10 @@
   </div>
 </template>
 <script lang="ts" setup>
-  import { ref, computed, onMounted } from 'vue';
+  import { ref, onMounted } from 'vue';
   import { ElMessageBox, ElMessage } from 'element-plus';
-  import { useUserStore } from '@/store/modules/user';
   import { queryListTenant } from '@/api/tenant';
-  import { SYS_TENANT_ID, useTargetTenantIdSetting } from '@/utils/useTargetTenantIdSetting';
+  import { useTargetTenantIdSetting } from '@/utils/useTargetTenantIdSetting';
   import { replaceParams } from '@/utils/helper/treeHelper';
   import router from '@/router';
   import { useRoute } from 'vue-router';
@@ -29,7 +28,6 @@
     children?: TenantOption[];
   }
 
-  const userStore = useUserStore();
   const { setValue, getValue } = useTargetTenantIdSetting();
 
   const currentTenant = ref();
@@ -37,10 +35,6 @@
 
   const route = useRoute();
 
-  const optionsShown = computed(() => {
-    return userStore.info.tenantId === SYS_TENANT_ID;
-  });
-
   onMounted(() => {
     const routeTenantId = route.query.targetTenantId as string;
     if (routeTenantId && routeTenantId !== 'undefined') {
@@ -54,7 +48,7 @@
       if (!res) return;
       options.value = replaceParams(res || [], 'tenantName', 'id');
       /** 如果当前租户没选中的话,默认选中第一个 */
-      if (!currentTenant.value && res.length > 1) {
+      if (currentTenant.value === undefined && res.length > 1) {
         currentTenant.value = res[0].id;
       }
     });