feat(phase-3): 京东商品卡片组件——主图/店铺徽标/标题/价格/编码复制/采集日期/勾选(additive,防冒泡钉死)

This commit is contained in:
2026-11-21 04:00:14 +08:00
parent 3702c83c60
commit b88432d8a9
2 changed files with 318 additions and 0 deletions
@@ -0,0 +1,204 @@
<script setup lang="ts">
/** 京东商品卡片(v1.6 蓝图 Phase 3,additive——页面接线随 Phase 5):
* 主图(无图占位)/店铺徽标/标题/价格区间/商品编码+复制/采集日期/勾选框,
* 字段映射与现表格「商品信息」列逐字段同源(价格走 jdPriceRange、日期走 formatDateTime)。
*
* 纯展示组件:入参=item+选中态+可勾选档;出事件=切换勾选、打开详情、复制编码。
* 卡片整体点击=开详情;勾选与复制 @click.stop 防冒泡(与现表格行 @click.stop 同形)。
* healthScore 徽标随图渲染(现表格同款「信息分」),null 不渲染。 */
import { formatDateTime } from '@/utils/datetime'
import { jdPriceRange, type JdProductItem } from './jd-product-model.ts'
const props = defineProps<{
/** 列表行(解析层归一后的 JdProductItem)。 */
item: JdProductItem
/** 勾选态(页面持有,跨页累计记忆)。 */
selected?: boolean
/** 可勾选档:管理员级/本组可写分类账号才渲染勾选框(页面按 canWriteProducts∨canManageCategories 投影)。 */
selectable?: boolean
}>()
const emit = defineEmits<{
/** 勾选切换(checked 来自 checkbox 原生 change)。 */
(event: 'toggle-select', checked: boolean): void
/** 打开详情(卡片整体点击;详情弹窗/抽屉由页面渲染)。 */
(event: 'open'): void
/** 复制商品编码(剪贴板与回执文案在页面,与现表格 copyText 同一条链)。 */
(event: 'copy'): void
}>()
const priceText = (): string => jdPriceRange(props.item) || '-'
</script>
<template>
<article class="jd-card" :class="{ selected: props.selected }" @click="emit('open')">
<label v-if="props.selectable" class="jd-card-check" @click.stop>
<input
type="checkbox"
:checked="props.selected"
aria-label="勾选商品"
@change="emit('toggle-select', ($event.target as HTMLInputElement).checked)"
/>
</label>
<div class="jd-card-figure">
<img v-if="props.item.mainImageUrl" class="jd-card-thumb" :src="props.item.mainImageUrl" alt="" loading="lazy" />
<span v-else class="jd-card-thumb jd-card-thumb-empty">无图</span>
<span v-if="props.item.healthScore !== null" class="jd-card-health">信息分 {{ props.item.healthScore }}</span>
<span v-if="props.item.shopName" class="jd-card-shop">{{ props.item.shopName }}</span>
</div>
<div class="jd-card-body">
<div class="jd-card-title" :title="props.item.title">{{ props.item.title || '-' }}</div>
<div class="jd-card-price">{{ priceText() }}</div>
<div class="jd-card-meta">
<span class="jd-card-code" :title="props.item.productCode">商品编码:{{ props.item.productCode || '-' }}</span>
<button
v-if="props.item.productCode"
class="jd-card-copy"
type="button"
title="复制商品编码"
@click.stop="emit('copy')"
>⧉</button>
</div>
<div class="jd-card-date">采集:{{ formatDateTime(props.item.syncedAt || '') }}</div>
</div>
</article>
</template>
<style scoped>
.jd-card {
position: relative;
display: flex;
flex-direction: column;
background: #fff;
border: 1px solid #e4e7ed;
border-radius: 8px;
overflow: hidden;
cursor: pointer;
transition: box-shadow 0.15s, border-color 0.15s;
}
.jd-card:hover {
border-color: #c6e2ff;
box-shadow: 0 2px 12px rgba(64, 158, 255, 0.12);
}
.jd-card.selected {
border-color: #409eff;
box-shadow: 0 0 0 1px #409eff inset;
}
.jd-card-check {
position: absolute;
top: 8px;
left: 8px;
z-index: 2;
line-height: 1;
cursor: pointer;
}
.jd-card-check input {
width: 15px;
height: 15px;
cursor: pointer;
}
.jd-card-figure {
position: relative;
aspect-ratio: 1 / 1;
background: #f5f7fa;
}
.jd-card-thumb {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.jd-card-thumb-empty {
display: flex;
align-items: center;
justify-content: center;
color: #c0c4cc;
font-size: 13px;
}
.jd-card-health {
position: absolute;
top: 8px;
right: 8px;
background: rgba(255, 255, 255, 0.92);
color: #e6a23c;
font-size: 12px;
border-radius: 10px;
padding: 1px 8px;
}
.jd-card-shop {
position: absolute;
bottom: 0;
left: 0;
right: 0;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
background: rgba(48, 49, 51, 0.62);
color: #fff;
font-size: 12px;
padding: 3px 8px;
}
.jd-card-body {
display: flex;
flex-direction: column;
gap: 6px;
padding: 10px 12px 12px;
}
.jd-card-title {
font-size: 13px;
color: #303133;
line-height: 1.4;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
min-height: 2.8em;
}
.jd-card-price {
font-size: 16px;
font-weight: 600;
color: #f56c6c;
}
.jd-card-meta {
display: flex;
align-items: center;
gap: 4px;
font-size: 12px;
color: #606266;
}
.jd-card-code {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.jd-card-copy {
flex-shrink: 0;
border: none;
background: transparent;
cursor: pointer;
color: #409eff;
font-size: 13px;
padding: 0 2px;
}
.jd-card-date {
font-size: 12px;
color: #909399;
}
</style>