Files
umed/web/components/DoctorCard.vue
T
2026-07-09 14:35:32 +08:00

238 lines
3.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
const props = defineProps<{
image: string
name: string
department?: string
/** 专家简介;有则展示,无则仅显示姓名与医院 */
expertInfo?: string
/** 未按医院筛选时展示所属医院 */
hospitalName?: string
/** 以顶部为锚点裁切,避免头部被遮挡 */
imageFocusTop?: boolean
imageFit?: 'cover' | 'contain'
/** 单独微调 object-position(cover 模式) */
imagePosition?: string
/** 略缩小照片,为头顶留出空间(cover 模式) */
imageScale?: number
/** 照片区域背景色(contain 时与证件照底色衔接) */
mediaBackground?: string
}>()
const mediaStyle = computed(() =>
props.mediaBackground ? { background: props.mediaBackground } : undefined
)
const photoStyle = computed(() => {
if (props.imageFit === 'contain') return undefined
const style: Record<string, string> = {}
if (props.imagePosition) style.objectPosition = props.imagePosition
if (props.imageScale != null && props.imageScale < 1) {
style.transform = `scale(${props.imageScale})`
style.transformOrigin = 'center top'
}
return Object.keys(style).length ? style : undefined
})
</script>
<template>
<article class="dcard">
<div
class="dcard__media"
:class="{ 'dcard__media--contain': imageFit === 'contain' }"
:style="mediaStyle"
>
<img
:src="image"
:alt="name"
class="dcard__photo"
:class="{
'dcard__photo--focus-top': imageFocusTop && imageFit !== 'contain',
'dcard__photo--contain': imageFit === 'contain'
}"
:style="photoStyle"
loading="lazy"
/>
</div>
<div class="dcard__body">
<h3 class="dcard__name">{{ name }}</h3>
<p v-if="expertInfo" class="dcard__info">{{ expertInfo }}</p>
<p v-else-if="department" class="dcard__dept">{{ department }}</p>
<p v-if="hospitalName" class="dcard__hospital">{{ hospitalName }}</p>
</div>
</article>
</template>
<style scoped>
.dcard {
border-radius: var(--radius);
overflow: hidden;
box-shadow: var(--shadow);
background: #fff;
display: flex;
flex-direction: column;
}
.dcard__media {
aspect-ratio: 243 / 280;
overflow: hidden;
background: #e8eef4;
}
.dcard__media--contain {
display: flex;
align-items: center;
justify-content: center;
}
.dcard__photo {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center center;
}
.dcard__photo--focus-top {
object-position: center top;
}
.dcard__photo--contain {
width: 100%;
height: 100%;
object-fit: contain;
object-position: center center;
}
.dcard__body {
padding: 14px 16px 18px;
border-top: 1px solid #eef2f6;
}
.dcard__name {
font-size: 17px;
font-weight: 800;
color: #0f2740;
line-height: 1.3;
}
.dcard__dept {
margin-top: 8px;
font-size: 13px;
line-height: 1.5;
color: var(--muted);
}
.dcard__info {
margin-top: 8px;
font-size: 13px;
line-height: 1.55;
color: var(--muted);
white-space: pre-line;
}
.dcard__hospital {
margin-top: 8px;
font-size: 12px;
line-height: 1.45;
color: #6b7f94;
}
</style>