Przeglądaj źródła

Merge branch 'all-v4-liufei' into 'all-v4'

fix: 租户切换下拉列表显示逻辑;切换租户统一回到首页

See merge request skyeye/skyeye_frontend/skyeye-admin!361
Fei Liu 1 rok temu
rodzic
commit
c1a2b16514
1 zmienionych plików z 12 dodań i 21 usunięć
  1. 12 21
      src/layout/components/Header/SwitchTenant.vue

+ 12 - 21
src/layout/components/Header/SwitchTenant.vue

@@ -1,6 +1,6 @@
 <!-- 切换租户 -->
 <!-- 切换租户 -->
 <template>
 <template>
-  <div class="switchTenantLable-wrapper" v-if="options.length > 0">
+  <div class="switchTenantLable-wrapper" v-if="optionsShown">
     <div class="switchTenantLable">选择租户</div>
     <div class="switchTenantLable">选择租户</div>
     <el-tree-select
     <el-tree-select
       :model-value="currentTenant"
       :model-value="currentTenant"
@@ -20,12 +20,11 @@
   import { queryListTenant } from '@/api/tenant';
   import { queryListTenant } from '@/api/tenant';
   import { useTargetTenantIdSetting } from '@/utils/useTargetTenantIdSetting';
   import { useTargetTenantIdSetting } from '@/utils/useTargetTenantIdSetting';
   import { replaceParams } from '@/utils/helper/treeHelper';
   import { replaceParams } from '@/utils/helper/treeHelper';
-  import { useRoute } from 'vue-router';
-  import router from '@/router';
 
 
   interface TenantOption {
   interface TenantOption {
     label: string;
     label: string;
     value: string;
     value: string;
+    children?: TenantOption[];
   }
   }
 
 
   const userStore = useUserStore();
   const userStore = useUserStore();
@@ -36,8 +35,14 @@
   });
   });
   const currentTenant = ref(localTId ? Number(localTId) : Number(tenantId.value));
   const currentTenant = ref(localTId ? Number(localTId) : Number(tenantId.value));
   const options = ref<TenantOption[]>([]);
   const options = ref<TenantOption[]>([]);
-  const PAGE_MESSAGE_ALARM_CONFIG = 'MessageAlarmConfig';
-  const PAGE_LAYOUT_CONFIG = ['LayoutSceneConfig', 'LayoutCameraConfig'];
+
+  const optionsShown = computed(() => {
+    // 列表空
+    if (!options.value.length) return false;
+    // 当前租户本身,且没有子租户
+    if (options.value.length === 1 && !options.value[0].children?.length) return false;
+    return true;
+  });
 
 
   onMounted(() => {
   onMounted(() => {
     queryListTenant().then((res) => {
     queryListTenant().then((res) => {
@@ -46,7 +51,6 @@
     });
     });
   });
   });
 
 
-  const route = useRoute();
   /* 选择租户添加二次确认弹窗 */
   /* 选择租户添加二次确认弹窗 */
   const handleChange = (targetTenantId: string) => {
   const handleChange = (targetTenantId: string) => {
     ElMessageBox.confirm('是否切换租户?', '提示', {
     ElMessageBox.confirm('是否切换租户?', '提示', {
@@ -57,21 +61,8 @@
       .then(() => {
       .then(() => {
         setValue(targetTenantId);
         setValue(targetTenantId);
         currentTenant.value = Number(targetTenantId);
         currentTenant.value = Number(targetTenantId);
-
-        /**
-         * 如果处于小地图编辑状态,切换租户时候,返回布局列表
-         */
-        if (PAGE_LAYOUT_CONFIG.includes(route.name as string)) {
-          sessionStorage.removeItem('selectCompanyId'); //切换租户的时候,下拉公司列表清空
-          router.back();
-        } else if (route.name === PAGE_MESSAGE_ALARM_CONFIG) {
-          /* 当页面为报警推送详情,切换租户,返回列表页面 */
-          router.push({
-            name: 'MessageAlarm',
-          });
-        } else {
-          window.location.reload();
-        }
+        // 统一返回首页
+        window.location.href = '/';
       })
       })
       .catch(() => {
       .catch(() => {
         ElMessage({
         ElMessage({