Files
cz-web/src/views/home/cpns/HomeBusinessCards.vue
2026-10-13 15:42:08 +08:00

174 lines
3.6 KiB
Vue

<script setup lang="ts">
import type { BusinessType } from '@/types/api'
import type { BusinessLine } from '@/types/business/home'
import defaultCover from '@/assets/home/chahua.png'
interface Props {
lines: BusinessLine[]
}
defineProps<Props>()
const FALLBACK_ACTIVE: BusinessType[] = ['internet']
function isImageUrl(value: string): boolean {
return /^(https?:)?\/\//i.test(value) || value.startsWith('/') || value.startsWith('data:')
}
function coverSrc(line: BusinessLine): string {
const remote = (line.cover || line.icon).trim()
if (remote && isImageUrl(remote)) return remote
return defaultCover
}
</script>
<template>
<section class="home-business">
<h3 class="home-business__title">业务服务</h3>
<div class="home-business__grid">
<RouterLink
v-for="line in lines"
:key="line.id"
:to="`/business/${line.id}`"
class="home-business__card"
:class="{
'home-business__card--active': FALLBACK_ACTIVE.includes(line.id),
}"
>
<img
class="home-business__cover"
:src="coverSrc(line)"
:alt="line.name"
>
<span class="home-business__check" aria-hidden="true" />
<h4 class="home-business__name">
{{ line.name }}
</h4>
<p class="home-business__desc">
{{ line.desc }}
</p>
</RouterLink>
</div>
</section>
</template>
<style lang="less" scoped>
.home-business {
padding: @spacing-xl;
border: none;
border-radius: @radius-base;
background: @white;
&__title {
margin: 0 0 @spacing-lg;
font-size: @font-size-xl;
font-weight: 600;
color: @home-ink;
}
&__grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: @spacing-base;
}
&__card {
position: relative;
.flex(column, flex-start, flex-start);
min-width: 0;
min-height: 168px;
box-sizing: border-box;
padding: @spacing-lg;
overflow: hidden;
border: 1px solid @border-color;
border-radius: @radius-base;
background: @white;
transition:
transform 0.2s,
box-shadow 0.2s,
border-color 0.2s;
&:hover {
border-color: @primary-color;
box-shadow: @shadow-base;
transform: translateY(-2px);
}
}
&__cover {
display: block;
width: 72px;
height: 72px;
object-fit: contain;
flex-shrink: 0;
}
&__check {
position: absolute;
top: @spacing-base;
right: @spacing-base;
z-index: 1;
flex-shrink: 0;
width: 20px;
height: 20px;
border: 1px solid @home-ring;
border-radius: @radius-round;
background: @white;
&::after {
content: '';
position: absolute;
inset: 0;
width: 12px;
height: 12px;
margin: auto;
border-radius: @radius-round;
background: @white;
opacity: 0;
}
}
&__name {
margin: @spacing-base 0 0;
padding-right: @spacing-xl;
font-size: @font-size-lg;
font-weight: 500;
line-height: 1.4;
color: @home-ink;
}
&__desc {
margin: @spacing-xs 0 0;
padding-right: @spacing-xl;
font-size: @font-size-sm;
font-weight: 400;
line-height: 1.5;
color: @text-color-secondary;
.multi-ellipsis(2);
}
&__card--active {
border-color: @primary-color;
background: @filter-selected-bg;
.home-business__check {
border-color: @primary-color;
&::after {
opacity: 1;
background: @primary-color;
}
}
.home-business__name {
color: @primary-strong;
}
.home-business__desc {
color: @text-color-secondary;
}
}
}
</style>