gaoluyang
2026-06-29 27cd042df9aca0383a49f3514bc21958dd890912
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<script lang="ts" setup>
import { computed } from 'vue';
 
import { IconifyIcon } from '../../../../../icons/src';
import { $t } from '../../../../../locales/src';
 
import {
  Button,
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from '../../../../../@core/ui-kit/shadcn-ui/src';
 
interface Tenant {
  id?: number;
  name: string;
  packageId: number;
  contactName: string;
  contactMobile: string;
  accountCount: number;
  expireTime: Date;
  websites: string[];
  status: number;
}
 
defineOptions({
  name: 'TenantDropdown',
});
 
const props = defineProps<{
  tenantList?: Tenant[];
  visitTenantId?: null | number;
}>();
 
const emit = defineEmits(['success']);
 
// 租户列表
const tenants = computed(() => props.tenantList ?? []);
 
async function handleChange(id: number | undefined) {
  if (!id) {
    return;
  }
  const tenant = tenants.value.find((item) => item.id === id);
 
  emit('success', tenant);
}
</script>
<template>
  <DropdownMenu>
    <DropdownMenuTrigger>
      <Button
        variant="outline"
        class="hover:bg-accent ml-1 mr-2 h-8 w-32 cursor-pointer rounded-full p-1.5"
      >
        <IconifyIcon icon="lucide:align-justify" class="mr-4" />
        {{
          tenants.find((item) => item.id === visitTenantId)?.name ||
          $t('page.tenant.placeholder')
        }}
      </Button>
    </DropdownMenuTrigger>
    <DropdownMenuContent class="w-40 p-0 pb-1">
      <DropdownMenuGroup>
        <DropdownMenuItem
          v-for="tenant in tenants"
          :key="tenant.id"
          :disabled="tenant.id === visitTenantId"
          class="mx-1 flex cursor-pointer items-center rounded-sm py-1 leading-8"
          @click="handleChange(tenant.id)"
        >
          <template v-if="tenant.id === visitTenantId">
            <IconifyIcon icon="lucide:check" class="mr-2" />
            {{ tenant.name }}
          </template>
          <template v-else>
            {{ tenant.name }}
          </template>
        </DropdownMenuItem>
      </DropdownMenuGroup>
    </DropdownMenuContent>
  </DropdownMenu>
</template>