Sfoglia il codice sorgente

feat: 增加选择租户功能

louhangfei 1 anno fa
parent
commit
d058010ff8

+ 2 - 2
.env

@@ -10,10 +10,10 @@ VITE_GLOB_PROD_MOCK = false
 
 
 
-VITE_GLOB_LOGIN_APP = '/skyeye-login/#/'
+VITE_GLOB_LOGIN_APP = '/skyeye-login-zongbu2/#/'
 
 VITE_GLOB_SKYEYE_WORLD = /skyeye-world/
 
 VITE_GLOB_APP_PC = /skyeyev3pc/
 
-VITE_GLOB_TENANT_CODE=shangfei
+# VITE_GLOB_TENANT_CODE=zongbu

+ 1 - 1
.env.development

@@ -20,7 +20,7 @@ VITE_DROP_CONSOLE = true
 # VITE_PROXY=[["/skyeye-admin-api","http://192.168.13.68/skyeye-admin-api"],[],["/eye_api_bak","http://192.168.13.68/eye_api"],["/push_stream_host","http://192.168.13.68/push_stream_host"],["/skyeye-login","http://192.168.13.68/skyeye-login"],["/ws_api_bak","ws://192.168.13.68/ws_api_bak"]]
 # 中建材 staff
 #VITE_PROXY=[["/skyeye-admin-api","http://192.168.13.68:70/skyeye-admin-api"],["/eye_api_bak","http://192.168.13.68:70/eye_api"],["/push_stream_host","http://192.168.13.68:70/push_stream_host"],["/skyeye-login","http://192.168.13.68:70/skyeye-login"],["/ws_api_bak","ws://192.168.13.68:70/ws_api_bak"]]
-VITE_PROXY=[["/skyeye-admin-api","http://192.168.13.68/skyeye-admin-api"],[],["/eye_api_bak","http://192.168.13.68/eye_api"],["/push_stream_host","http://192.168.13.68/push_stream_host"],["/skyeye-login","http://192.168.13.68/skyeye-login"],["/ws_api_bak","ws://192.168.13.68/ws_api_bak"],["/skyeye-file-upload","http://192.168.13.68/skyeye-file-upload"],["/nvr_download","http://192.168.13.68/nvr_download"]]
+VITE_PROXY=[["/eye_api_bak","http://192.168.13.102:8800"],["/push_stream_host","http://192.168.13.68/push_stream_host"],["/skyeye-login-zongbu2","http://192.168.13.102/skyeye-login-zongbu2"],["/ws_api_bak","ws://192.168.13.102/ws_api_bak"],["/skyeye-file-upload","http://192.168.13.68/skyeye-file-upload"],["/nvr_download","http://192.168.13.68/nvr_download"]]
 
 
 # VITE_PROXY=[["/skyeye-admin-api","http://192.168.13.68/skyeye-admin-api"],[],["/eye_api_bak","http://192.168.13.68/eye_api"],["/push_stream_host","http://192.168.13.68/push_stream_host"],["/skyeye-login","http://192.168.13.68/skyeye-login"],["/ws_api_bak","ws://192.168.13.68/ws_api_bak"],["/skyeye-file-upload","http://192.168.13.68/skyeye-file-upload"]]

+ 11 - 0
src/api/tenant/index.ts

@@ -54,3 +54,14 @@ export function tenantInfo(params) {
     params,
   });
 }
+
+/** 获取有总部权限时的所有租户 */
+export function getListUseZongbu() {
+  return http.request(
+    {
+      url: '/tenant/listUseZongbu',
+      method: 'get',
+    },
+    { isShowErrorMessage: false },
+  );
+}

+ 59 - 0
src/layout/components/Header/SwitchTenant.vue

@@ -0,0 +1,59 @@
+<!-- 切换租户 -->
+<template>
+  <div class="switchTenantLable" v-if="options.length > 0">
+    <div class="switchTenantLable">选择租户</div>
+    <ElSelect
+      v-model="currentTenant"
+      :placeholder="tenantName"
+      style="width: 100px"
+      @update:modelValue="handleChange"
+    >
+      <ElOption v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
+    </ElSelect>
+  </div>
+</template>
+<script lang="ts" setup>
+  import { ElSelect } from 'element-plus';
+  import { ref, computed, onMounted } from 'vue';
+  import { useUserStore } from '@/store/modules/user';
+  import { getListUseZongbu } from '@/api/tenant';
+
+  interface TenantOption {
+    label: string;
+    value: string;
+  }
+
+  const localTId = window.localStorage.getItem('targetTenantId');
+
+  const currentTenant = ref(localTId ? Number(localTId) : '');
+
+  const options = ref<TenantOption[]>([]);
+
+  const userStore = useUserStore();
+
+  const tenantName = computed(() => {
+    return userStore.info.tenantName;
+  });
+
+  onMounted(() => {
+    getListUseZongbu().then((res) => {
+      if (!res) return;
+      options.value = res.map((x) => ({ ...x, label: x.tenantName, value: x.tenantId }));
+    });
+  });
+
+  const handleChange = (targetTenantId: string) => {
+    window.localStorage.setItem('targetTenantId', targetTenantId);
+    currentTenant.value = targetTenantId;
+    window.location.reload();
+  };
+</script>
+<style scoped>
+  .switchTenantLable {
+    margin-right: 15px;
+    display: inline-block;
+  }
+  .switchTenantWrapper {
+    margin-right: 20px;
+  }
+</style>

+ 2 - 0
src/layout/components/Header/index.vue

@@ -112,6 +112,7 @@
           </el-icon>
         </el-tooltip>
       </div> -->
+      <SwitchTenant />
       <!-- 个人中心 -->
       <div class="layout-header-trigger layout-header-trigger-min">
         <el-dropdown trigger="hover" @command="avatarSelect">
@@ -228,6 +229,7 @@
   import { Render, getRender } from '@/components/Render';
   import { getLogoutUrl, getRedirectUrl } from '@/utils/getRedirectUrl';
   import { useGlobSetting } from '@/hooks/setting';
+  import SwitchTenant from './SwitchTenant.vue';
 
   defineEmits(['update:collapsed']);
 

+ 2 - 4
src/store/modules/user.ts

@@ -128,11 +128,9 @@ export const useUserStore = defineStore({
     },
 
     checkPermission(permission: string) {
-      return this.permissions.find(x => x.value === permission)
-    }
+      return this.permissions.find((x) => x.value === permission);
+    },
   },
-
-
 });
 
 // Need to be used outside the setup

+ 5 - 0
src/utils/http/axios/index.ts

@@ -205,6 +205,7 @@ const transform: AxiosTransform = {
     const userStore = useUserStoreWidthOut();
     const token = userStore.getToken;
     const tenantId = userStore.getTenantId;
+    const targetTenantId = localStorage.getItem('targetTenantId');
     if (token && (config as Recordable)?.requestOptions?.withToken !== false) {
       // jwt token
       (config as Recordable).headers.satoken = options.authenticationScheme
@@ -215,6 +216,10 @@ const transform: AxiosTransform = {
     if (tenantId) {
       (config as Recordable).headers.tenantId = tenantId;
     }
+    if (targetTenantId) {
+      (config as Recordable).headers.targetTenantId = targetTenantId;
+    }
+
     return config;
   },