Files
ecom-dmb/ecom-dmb-frontend/apps/web-antd/src/views/company/components/CompanyLogoAvatar.vue
T

63 lines
1.3 KiB
Vue

<script setup lang="ts">
import { computed } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import { Avatar } from 'ant-design-vue';
defineOptions({ name: 'CompanyLogoAvatar' });
const props = withDefaults(
defineProps<{
logo?: string;
name?: string;
size?: number;
}>(),
{
logo: undefined,
name: undefined,
size: 36,
},
);
const BuildingIcon = createIconifyIcon('lucide:building-2');
/** 无 logo 时用名称首字;仍无则显示公司图标 */
const fallbackText = computed(() => {
const text = props.name?.trim();
return text ? text.charAt(0).toUpperCase() : '';
});
</script>
<template>
<Avatar
:size="size"
:src="logo"
:alt="name"
shape="square"
class="company-logo-avatar shrink-0 !rounded-md !bg-slate-200 !text-slate-700 dark:!bg-slate-600 dark:!text-slate-100"
>
<span
v-if="fallbackText"
class="company-logo-avatar__text text-xs font-semibold"
>
{{ fallbackText }}
</span>
<BuildingIcon v-else class="h-4 w-4 text-muted-foreground" />
</Avatar>
</template>
<style scoped>
.company-logo-avatar {
display: inline-flex !important;
align-items: center !important;
justify-content: center !important;
}
.company-logo-avatar__text {
display: block;
line-height: 1;
color: inherit;
}
</style>