SwitchTenant.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <!-- 切换租户 -->
  2. <template>
  3. <div class="switchTenantLable-wrapper" v-if="options.length > 0">
  4. <div class="switchTenantLable">选择租户</div>
  5. <el-tree-select
  6. v-model="currentTenant"
  7. :data="options"
  8. check-strictly
  9. show-all-levels
  10. default-expand-all
  11. placeholder="请选择租户"
  12. @change="handleChange"
  13. />
  14. </div>
  15. </template>
  16. <script lang="ts" setup>
  17. import { ref, computed, onMounted } from 'vue';
  18. import { useUserStore } from '@/store/modules/user';
  19. import { queryListTenant } from '@/api/tenant';
  20. import { useTargetTenantIdSetting } from '@/utils/useTargetTenantIdSetting';
  21. import { replaceParams } from '@/utils/helper/treeHelper';
  22. import { useRoute } from 'vue-router';
  23. import useMiniMap from '@/views/map-config/mini-map/use-mini-map.ts'
  24. import router from '@/router';
  25. const miniMap = useMiniMap();
  26. const {isInConfigEditor} = miniMap;
  27. interface TenantOption {
  28. label: string;
  29. value: string;
  30. }
  31. const userStore = useUserStore();
  32. const { setValue, getValue } = useTargetTenantIdSetting();
  33. const localTId = getValue();
  34. const tenantId = computed(() => {
  35. return userStore.info.tenantId;
  36. });
  37. const currentTenant = ref(localTId ? Number(localTId) : Number(tenantId.value));
  38. const options = ref<TenantOption[]>([]);
  39. onMounted(() => {
  40. queryListTenant().then((res) => {
  41. if (!res) return;
  42. options.value = replaceParams(res || [], 'tenantName', 'id')
  43. });
  44. });
  45. const route = useRoute();
  46. const handleChange = (targetTenantId: string) => {
  47. setValue(targetTenantId);
  48. currentTenant.value = Number(targetTenantId);
  49. window.location.reload();
  50. /**
  51. * 如果处于小地图编辑状态,切换租户时候,返回布局列表
  52. */
  53. if (isInConfigEditor(route.name)) {
  54. router.back();
  55. }
  56. sessionStorage.removeItem('selectCompanyId'); //切换租户的时候,下拉公司列表清空
  57. };
  58. </script>
  59. <style scoped>
  60. .switchTenantLable {
  61. margin-right: 15px;
  62. display: inline-block;
  63. width: 100px;
  64. }
  65. .switchTenantWrapper {
  66. margin-right: 20px;
  67. }
  68. .switchTenantLable-wrapper {
  69. display: flex;
  70. align-items: center;
  71. justify-content: center;
  72. width: 200px;
  73. }
  74. </style>