DynamicTenant.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <script setup lang="ts">
  2. import apis from "@a"
  3. import router from "@r"
  4. import appStore from "@s"
  5. const tenantEnabled = ref(true)
  6. const tenantId = ref("")
  7. const tenantOptions = ref<any>([])
  8. const show = computed(() => {
  9. return appStore.authStore.canChangeTenant()
  10. })
  11. const initTenant = async () => {
  12. apis.loginApi.getTenantList().then((res: any) => {
  13. tenantEnabled.value = res.data.tenantEnabled === undefined ? true : res.data.tenantEnabled
  14. if (tenantEnabled.value) {
  15. tenantOptions.value = res.data.voList
  16. }
  17. })
  18. }
  19. function onDynamicTenant() {
  20. if (tenantId.value != null && tenantId.value !== "") {
  21. apis.system.tenantApi.dynamicTenant(tenantId.value).then((res: any) => {
  22. appStore.authStore.setDynamic(true)
  23. appStore.tagViewStore.delAllViews()
  24. router.push({ path: "/" })
  25. })
  26. }
  27. }
  28. function onDynamicClear() {
  29. apis.system.tenantApi.dynamicClear().then((res: any) => {
  30. appStore.authStore.setDynamic(false)
  31. appStore.tagViewStore.delAllViews()
  32. router.push({ path: "/" })
  33. })
  34. }
  35. function init() {
  36. initTenant()
  37. }
  38. onMounted(init)
  39. </script>
  40. <template>
  41. <div class="app-navbar-item ms-1 ms-md-3" v-if="show">
  42. <el-select
  43. v-model="tenantId"
  44. clearable
  45. filterable
  46. reserve-keyword
  47. placeholder="请选择租户"
  48. @change="onDynamicTenant"
  49. @clear="onDynamicClear">
  50. <el-option
  51. v-for="item in tenantOptions"
  52. :key="item.tenantId"
  53. :label="item.companyName"
  54. :value="item.tenantId"></el-option>
  55. <template #prefix>
  56. <svg-icon icon-class="company" class="el-input__icon input-icon" />
  57. </template>
  58. </el-select>
  59. </div>
  60. </template>