feat(phase-4): 详情内容共享块+居中弹窗壳——抽屉薄壳化复用同一份实现(取数 watch immediate 钉死重挂载取数)

This commit is contained in:
2026-11-21 04:08:14 +08:00
parent b88432d8a9
commit 6034a7a961
4 changed files with 960 additions and 609 deletions
@@ -0,0 +1,636 @@
<script setup lang="ts">
/** 京东商品详情内容块(v1.6 蓝图 Phase 4,从 JdProductDetailDrawer 原样抽出):
* 数据自取(fetchJdProductDetail,失败条内可重试)+ hero「左图右信息」(2026-11-16 客户口径
* 「详情页样式和京麦商品详情一样」)+ attrGroups 分块表格(解析失败回 attrJsonRaw 原文)+
* SKU 矩阵 + 图片三区(MAIN/ATTR/DETAIL,attr 图按 attrName 归并)+ 自绘放大预览。
*
* Drawer(侧滑薄壳)与 Modal(居中弹窗壳)共用本组件:壳只管 chrome(遮罩/标题/关闭/
* 动作按钮),内容与取数全在这里——两条壳的行为由同一份实现保证等价。模板与类名照搬
* 旧抽屉(.detail-hero/.hero-main/.hero-info 等被页面 mount 测试逐字钉住,不得改名)。 */
import { computed, ref, watch } from 'vue'
import { fetchJdProductDetail } from './jd-product-api.ts'
import type {
JdProductImage,
JdProductItem,
JdProductAttrGroup,
JdProductSku,
} from './jd-product-model.ts'
import { jdPriceRange, jdSkuDimensions, jdSkuSummary } from './jd-product-model.ts'
import { formatDateTime } from '@/utils/datetime'
import { requestErrorMessage } from '../../api/envelope.ts'
const props = defineProps<{
item: JdProductItem | null
visible: boolean
}>()
const loading = ref(false)
const loadFailure = ref('')
const attrGroups = ref<JdProductAttrGroup[]>([])
const images = ref<JdProductImage[]>([])
const skus = ref<JdProductSku[]>([])
const attrJsonRaw = ref('')
/** SKU 矩阵维度(京麦「颜色 / 尺码」两列)与表头汇总。 */
const skuDimensions = computed(() => jdSkuDimensions(skus.value))
const skuSummary = computed(() => jdSkuSummary(skus.value))
function skuAttrValue(sku: JdProductSku, dimension: string): string {
return sku.saleAttrs.find((attr) => attr.name === dimension)?.value || '-'
}
/** 图片三区:MAIN / ATTR / DETAIL;未知类型归 DETAIL 之外的「其他」,不丢。 */
const mainImages = computed(() => images.value.filter((image) => image.imageType === 'MAIN'))
/** 顶部画廊:左侧主图大图+缩略图切换(MAIN 档),右侧关键信息。 */
const galleryImages = computed(() => mainImages.value)
const activeImageUrl = ref('')
function switchGallery(image: JdProductImage): void {
activeImageUrl.value = image.url
}
const attrImageGroups = computed(() => {
const buckets = new Map<string, JdProductImage[]>()
for (const image of images.value) {
if (image.imageType !== 'ATTR') continue
const key = image.attrName || '属性图'
const bucket = buckets.get(key)
if (bucket) bucket.push(image)
else buckets.set(key, [image])
}
return [...buckets.entries()].map(([attrName, list]) => ({ attrName, list }))
})
const detailImages = computed(() => images.value.filter((image) => image.imageType === 'DETAIL'))
const otherImages = computed(() =>
images.value.filter((image) => image.imageType !== 'MAIN' && image.imageType !== 'ATTR' && image.imageType !== 'DETAIL'),
)
/** 放大预览:点缩略图弹自绘 modal-mask,原图可新标签打开。 */
const previewVisible = ref(false)
const previewUrl = ref('')
function openPreview(url: string): void {
previewUrl.value = url
previewVisible.value = true
}
async function loadDetail(): Promise<void> {
const item = props.item
if (!item) return
loading.value = true
loadFailure.value = ''
attrGroups.value = []
images.value = []
skus.value = []
attrJsonRaw.value = ''
try {
const detail = await fetchJdProductDetail(item.id)
attrGroups.value = detail.attrGroups
images.value = detail.images
skus.value = detail.skus
attrJsonRaw.value = detail.attrJsonRaw
activeImageUrl.value = detail.images.find((image) => image.imageType === 'MAIN')?.url || ''
if (!detail.attrGroups.length && detail.attrJsonRaw) {
// 结构化解析失败但原文在:兜底展示原文,不静默吞
loadFailure.value = ''
}
} catch (error) {
loadFailure.value = requestErrorMessage(error) || '商品详情加载失败'
} finally {
loading.value = false
}
}
/** 打开/换行即取数。immediate 必须带:两条壳都把本组件放在 `v-if="visible"` 的遮罩里,
* 关闭时整组件卸载——重挂载(visible 已是 true)没有"变更"可触发,非 immediate 的
* watch 永远不跑=弹窗永远停在加载中(2026-11-21 薄壳化实测真红)。 */
watch(
() => [props.visible, props.item?.id] as const,
([visible]) => {
previewVisible.value = false
previewUrl.value = ''
activeImageUrl.value = ''
if (visible && props.item) void loadDetail()
},
{ immediate: true },
)
function dash(value: string | number | null | undefined): string {
const text = value === null || value === undefined ? '' : String(value).trim()
return text || '-'
}
</script>
<template>
<!-- 根节点随 visible 显隐:壳(Drawer/Modal)关闭时预览浮层必须一起摘掉,
不能留在 fixed 蒙层里挡住整屏(旧抽屉的 v-if 边界原样搬移)。 -->
<div v-if="visible" class="detail-content">
<div v-if="loadFailure" class="drawer-failure">
<span>{{ loadFailure }}</span>
<button class="btn btn-secondary" type="button" @click="loadDetail">重试</button>
</div>
<p v-else-if="loading" class="drawer-tip">加载中...</p>
<template v-else>
<!-- 顶部「左图右信息」(2026-11-16 客户口径「详情页的样式要和京麦商品详情一样的布局样式」):
左侧主图大图+缩略图切换,右侧关键信息;属性/SKU/详情图等区块保持下方。 -->
<section class="detail-block">
<div class="detail-hero">
<div class="hero-gallery">
<img
v-if="activeImageUrl"
class="hero-main"
:src="activeImageUrl"
alt=""
title="点击放大预览"
@click="openPreview(activeImageUrl)"
/>
<div v-else class="hero-empty">无图</div>
<div v-if="galleryImages.length > 1" class="hero-thumbs">
<img
v-for="image in galleryImages"
:key="image.id"
:src="image.url"
alt=""
loading="lazy"
:class="{ active: image.url === activeImageUrl }"
title="切换主图"
@click="switchGallery(image)"
/>
</div>
</div>
<dl class="hero-info">
<div class="info-item info-item-wide hero-title">
<dt>标题</dt>
<dd :title="item?.title || ''">{{ dash(item?.title) }}</dd>
</div>
<div class="info-item"><dt>价格区间</dt><dd>{{ dash(jdPriceRange(item ?? { priceMin: '', priceMax: '' })) }}</dd></div>
<div class="info-item"><dt>总库存</dt><dd>{{ dash(item?.stockTotal) }}</dd></div>
<div class="info-item"><dt>状态</dt><dd>{{ dash(item?.saleStatus) }}</dd></div>
<div class="info-item"><dt>信息分</dt><dd>{{ dash(item?.healthScore) }}</dd></div>
<div class="info-item"><dt>SKU 数</dt><dd>{{ dash(item?.skuCount) }}</dd></div>
<div class="info-item"><dt>商品编码</dt><dd>{{ dash(item?.productCode) }}</dd></div>
<div class="info-item"><dt>货号</dt><dd>{{ dash(item?.itemNum) }}</dd></div>
<div class="info-item"><dt>SKU</dt><dd>{{ dash(item?.skuId) }}</dd></div>
<div class="info-item"><dt>品牌</dt><dd>{{ dash(item?.brand) }}</dd></div>
<div class="info-item"><dt>店铺</dt><dd :title="item?.shopName || ''">{{ dash(item?.shopName) }}</dd></div>
<div class="info-item"><dt>分类</dt><dd>{{ dash(item?.groupName || '未分类') }}</dd></div>
<div class="info-item info-item-wide"><dt>类目</dt><dd :title="item?.categoryPath || ''">{{ dash(item?.categoryPath) }}</dd></div>
<div class="info-item"><dt>上架时间</dt><dd>{{ item?.jdOnlineAt ? formatDateTime(item.jdOnlineAt) : '-' }}</dd></div>
<div class="info-item"><dt>同步时间</dt><dd>{{ formatDateTime(item?.syncedAt || '') }}</dd></div>
<div class="info-item"><dt>京东创建时间</dt><dd>{{ item?.jdCreatedAt ? formatDateTime(item.jdCreatedAt) : '-' }}</dd></div>
<div class="info-item"><dt>京东修改时间</dt><dd>{{ item?.jdUpdatedAt ? formatDateTime(item.jdUpdatedAt) : '-' }}</dd></div>
</dl>
</div>
</section>
<section v-if="attrGroups.length" class="detail-block">
<h4>属性与设置(按京麦 Tab 分组)</h4>
<div v-for="group in attrGroups" :key="group.groupName" class="attr-group">
<h5>{{ group.groupName }}</h5>
<table>
<tbody>
<tr v-for="(attr, index) in group.attrs" :key="`${attr.key}-${index}`">
<th>{{ attr.label || attr.key || '-' }}</th>
<td>{{ attr.value || '-' }}</td>
</tr>
</tbody>
</table>
</div>
</section>
<section v-else-if="attrJsonRaw" class="detail-block">
<h4>属性(原始 JSON)</h4>
<pre class="attr-raw">{{ attrJsonRaw }}</pre>
</section>
<section class="detail-block">
<h4>销售属性 / SKU 矩阵</h4>
<template v-if="skus.length">
<p class="sku-summary">{{ skuSummary }}</p>
<div class="sku-table-wrap">
<table class="sku-table">
<thead>
<tr>
<th>序号</th>
<th v-for="dimension in skuDimensions" :key="dimension">{{ dimension }}</th>
<th>京东价</th>
<th>库存</th>
<th>SKU ID</th>
<th>SKU 名称</th>
</tr>
</thead>
<tbody>
<tr v-for="(sku, index) in skus" :key="sku.skuId">
<td>{{ sku.skuSeq || index + 1 }}</td>
<td v-for="dimension in skuDimensions" :key="dimension">{{ skuAttrValue(sku, dimension) }}</td>
<td>{{ sku.price ? `¥${sku.price}` : '-' }}</td>
<td>{{ dash(sku.stock) }}</td>
<td class="sku-id">{{ sku.skuId }}</td>
<td :title="sku.skuName">{{ dash(sku.skuName) }}</td>
</tr>
</tbody>
</table>
</div>
</template>
<p v-else class="drawer-tip">暂无 SKU 矩阵(V198 之前采集的旧行需重新采集)</p>
</section>
<section class="detail-block">
<h4>主图</h4>
<div v-if="mainImages.length" class="image-grid">
<img
v-for="image in mainImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
<p v-else class="drawer-tip">暂无主图</p>
</section>
<section v-for="bucket in attrImageGroups" :key="bucket.attrName" class="detail-block">
<h4>属性图 · {{ bucket.attrName }}</h4>
<div class="image-grid">
<img
v-for="image in bucket.list"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
</section>
<section class="detail-block">
<h4>详情图</h4>
<div v-if="detailImages.length" class="image-grid">
<img
v-for="image in detailImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
<p v-else class="drawer-tip">暂无详情图</p>
</section>
<section v-if="otherImages.length" class="detail-block">
<h4>其他图</h4>
<div class="image-grid">
<img
v-for="image in otherImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
</section>
</template>
<div v-if="previewVisible" class="modal-mask" @click.self="previewVisible = false">
<div class="preview-modal">
<div class="preview-head">
<h3>图片预览</h3>
<button class="drawer-close" type="button" aria-label="关闭" @click="previewVisible = false">×</button>
</div>
<img class="preview-image" :src="previewUrl" alt="" />
<div class="preview-foot">
<a :href="previewUrl" target="_blank" rel="noopener">新标签打开原图</a>
<button class="btn btn-secondary" type="button" @click="previewVisible = false">关闭</button>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.detail-content {
display: flex;
flex-direction: column;
gap: 18px;
}
.drawer-tip {
margin: 0;
color: #8293a5;
font-size: 13.5px;
}
.drawer-failure {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 14px;
border: 1px solid #f0c9c2;
border-radius: 10px;
background: #fdf1ef;
color: #a04432;
font-size: 13.5px;
}
.detail-block h4 {
margin: 0 0 10px;
font-size: 13.5px;
font-weight: 650;
color: #4e6479;
}
/* 顶部「左图右信息」(京麦详情布局):左侧主图大图+缩略图切换,右侧关键信息网格。 */
.detail-hero {
display: flex;
align-items: flex-start;
gap: 16px;
}
.hero-gallery {
flex: 0 0 300px;
display: flex;
flex-direction: column;
gap: 8px;
min-width: 0;
}
.hero-main {
display: block;
width: 100%;
aspect-ratio: 1;
object-fit: cover;
border: 1px solid #d8e3ee;
border-radius: 10px;
background: #f2f7fb;
cursor: zoom-in;
}
.hero-empty {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
aspect-ratio: 1;
border: 1px dashed #c7d7e5;
border-radius: 10px;
background: #f8fbfd;
color: #8293a5;
font-size: 13px;
}
.hero-thumbs {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.hero-thumbs img {
width: 44px;
height: 44px;
object-fit: cover;
border: 1px solid #d8e3ee;
border-radius: 6px;
cursor: pointer;
opacity: 0.85;
}
.hero-thumbs img.active {
outline: 2px solid #2f5d8b;
opacity: 1;
}
.hero-info {
flex: 1;
min-width: 0;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px 16px;
margin: 0;
}
.hero-info dt {
color: #5b6f83;
font-size: 12px;
margin-bottom: 3px;
}
.hero-info dd {
margin: 0;
color: #24384d;
font-size: 13.5px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.hero-title dd {
font-size: 14.5px;
font-weight: 650;
color: #24384d;
white-space: normal;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
@media (max-width: 760px) {
.detail-hero {
flex-direction: column;
}
.hero-gallery {
flex-basis: auto;
width: 100%;
}
}
.info-item {
min-width: 0;
}
.info-item-wide {
grid-column: 1 / -1;
}
.info-item dt {
color: #5b6f83;
font-size: 12px;
margin-bottom: 3px;
}
.info-item dd {
margin: 0;
color: #24384d;
font-size: 13.5px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.attr-group {
margin-bottom: 12px;
}
.attr-group h5 {
margin: 0 0 6px;
color: #5b6f83;
font-size: 12.5px;
}
.attr-group table {
width: 100%;
border-collapse: collapse;
border: 1px solid #dbe5ee;
border-radius: 8px;
overflow: hidden;
}
.attr-group th,
.attr-group td {
padding: 7px 10px;
border-bottom: 1px solid #e7eef5;
font-size: 13px;
text-align: left;
vertical-align: top;
}
.attr-group th {
width: 180px;
background: #f2f7fb;
color: #4e6479;
font-weight: 600;
}
.attr-group tr:last-child th,
.attr-group tr:last-child td {
border-bottom: 0;
}
.attr-raw {
margin: 0;
padding: 10px 12px;
border: 1px solid #dbe5ee;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 12px;
white-space: pre-wrap;
word-break: break-all;
max-height: 240px;
overflow-y: auto;
}
.sku-summary {
margin: 0 0 8px;
color: #5b6f83;
font-size: 12.5px;
}
.sku-table-wrap {
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 8px;
}
.sku-table {
width: 100%;
border-collapse: collapse;
font-size: 12.5px;
white-space: nowrap;
}
.sku-table th,
.sku-table td {
padding: 7px 10px;
border-bottom: 1px solid #e7eef5;
text-align: left;
color: #24384d;
}
.sku-table th {
background: #f2f7fb;
color: #4e6479;
font-weight: 600;
}
.sku-table tbody tr:last-child td {
border-bottom: 0;
}
.sku-table .sku-id {
font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
font-size: 12px;
color: #4e6479;
}
.image-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
gap: 10px;
}
.image-grid img {
display: block;
width: 100%;
aspect-ratio: 1;
object-fit: cover;
border: 1px solid #d8e3ee;
border-radius: 8px;
background: #f2f7fb;
cursor: zoom-in;
}
.modal-mask {
position: fixed;
inset: 0;
z-index: 3000;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(6px);
}
.preview-modal {
display: flex;
flex-direction: column;
width: min(880px, 100%);
max-height: 88vh;
padding: 16px 20px;
border: 1px solid #c7d7e5;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
}
.preview-head {
display: flex;
align-items: center;
justify-content: space-between;
}
.preview-head h3 {
margin: 0;
font-size: 15px;
color: #24384d;
}
.preview-image {
display: block;
flex: 1;
min-height: 0;
max-height: 68vh;
margin: 12px 0;
object-fit: contain;
background: #f2f7fb;
border-radius: 8px;
}
.preview-foot {
display: flex;
align-items: center;
justify-content: space-between;
}
.preview-foot a {
color: #2f5d8b;
font-size: 13px;
}
.drawer-close {
width: 30px;
height: 30px;
border: 1px solid transparent;
border-radius: 9px;
background: none;
color: #5b6f83;
font-size: 20px;
line-height: 1;
cursor: pointer;
}
.drawer-close:hover {
border-color: #cbd9e6;
background: #eef4fa;
color: #24384d;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 38px;
padding: 7px 16px;
border-radius: 9px;
font-size: 13px;
cursor: pointer;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border: 1px solid #c7d7e5;
}
.btn-secondary:hover {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
</style>
@@ -1,21 +1,11 @@
<script setup lang="ts">
/** 京东商品详情抽屉(v1.4 Phase 5):点行打开,展示基本信息 + attrGroups 分块表格 +
* 图片网格(MAIN/ATTR/DETAIL 三区,attr 图按 attrName 归并)。
* 基本信息=商品全部字段(B104:列表只摆部分字段,类目/信息分/SKU 数/上架时间/京东创建/
* 修改时间/店铺/分组都在这里看)。
* 图片点击放大预览用自绘 modal-mask(先例:RecordsHistoryPage 的 thumb + modal-mask +
* 原图新标签;不用 element-plus)。数据由本组件按 id 自取(公共库无公司维度),失败条内提示可重试。 */
import { computed, ref, watch } from 'vue'
import { fetchJdProductDetail } from './jd-product-api.ts'
import type {
JdProductImage,
JdProductItem,
JdProductAttrGroup,
JdProductSku,
} from './jd-product-model.ts'
import { jdPriceRange, jdSkuDimensions, jdSkuSummary } from './jd-product-model.ts'
import { formatDateTime } from '@/utils/datetime'
import { requestErrorMessage } from '../../api/envelope.ts'
/** 京东商品详情抽屉(v1.4 Phase 5 起,v1.6 蓝图 Phase 4 薄壳化):点行打开,右侧滑出。
* 内容(hero 左图右信息/属性分组/SKU 矩阵/图片三区/放大预览)与取数全部搬进共享块
* JdProductDetailContent(v1.6 蓝图:居中详情弹窗与侧滑抽屉共用同一份实现)——本壳只管
* chrome(遮罩/标题/关闭),页面行为零变化(.drawer/.drawer-mask 等类名被页面 mount
* 测试逐字钉住,不得改名)。 */
import JdProductDetailContent from './JdProductDetailContent.vue'
import type { JdProductItem } from './jd-product-model.ts'
const props = defineProps<{
item: JdProductItem | null
@@ -24,298 +14,22 @@ const props = defineProps<{
const emit = defineEmits<{ (event: 'close'): void }>()
const loading = ref(false)
const loadFailure = ref('')
const attrGroups = ref<JdProductAttrGroup[]>([])
const images = ref<JdProductImage[]>([])
const skus = ref<JdProductSku[]>([])
const attrJsonRaw = ref('')
/** SKU 矩阵维度(京麦「颜色 / 尺码」两列)与表头汇总。 */
const skuDimensions = computed(() => jdSkuDimensions(skus.value))
const skuSummary = computed(() => jdSkuSummary(skus.value))
function skuAttrValue(sku: JdProductSku, dimension: string): string {
return sku.saleAttrs.find((attr) => attr.name === dimension)?.value || '-'
}
/** 图片三区:MAIN / ATTR / DETAIL;未知类型归 DETAIL 之外的「其他」,不丢。 */
const mainImages = computed(() => images.value.filter((image) => image.imageType === 'MAIN'))
/** 顶部画廊(2026-11-16 客户口径「详情页样式和京麦商品详情一样」=左图右信息):
* 左侧主图大图+缩略图切换(MAIN 档),右侧关键信息。 */
const galleryImages = computed(() => mainImages.value)
const activeImageUrl = ref('')
function switchGallery(image: JdProductImage): void {
activeImageUrl.value = image.url
}
const attrImageGroups = computed(() => {
const buckets = new Map<string, JdProductImage[]>()
for (const image of images.value) {
if (image.imageType !== 'ATTR') continue
const key = image.attrName || '属性图'
const bucket = buckets.get(key)
if (bucket) bucket.push(image)
else buckets.set(key, [image])
}
return [...buckets.entries()].map(([attrName, list]) => ({ attrName, list }))
})
const detailImages = computed(() => images.value.filter((image) => image.imageType === 'DETAIL'))
const otherImages = computed(() =>
images.value.filter((image) => image.imageType !== 'MAIN' && image.imageType !== 'ATTR' && image.imageType !== 'DETAIL'),
)
/** 放大预览:点缩略图弹自绘 modal-mask,原图可新标签打开。 */
const previewVisible = ref(false)
const previewUrl = ref('')
function openPreview(url: string): void {
previewUrl.value = url
previewVisible.value = true
}
function close(): void {
previewVisible.value = false
emit('close')
}
async function loadDetail(): Promise<void> {
const item = props.item
if (!item) return
loading.value = true
loadFailure.value = ''
attrGroups.value = []
images.value = []
skus.value = []
attrJsonRaw.value = ''
try {
const detail = await fetchJdProductDetail(item.id)
attrGroups.value = detail.attrGroups
images.value = detail.images
skus.value = detail.skus
attrJsonRaw.value = detail.attrJsonRaw
activeImageUrl.value = detail.images.find((image) => image.imageType === 'MAIN')?.url || ''
if (!detail.attrGroups.length && detail.attrJsonRaw) {
// 结构化解析失败但原文在:兜底展示原文,不静默吞
loadFailure.value = ''
}
} catch (error) {
loadFailure.value = requestErrorMessage(error) || '商品详情加载失败'
} finally {
loading.value = false
}
}
watch(
() => [props.visible, props.item?.id] as const,
([visible]) => {
previewVisible.value = false
previewUrl.value = ''
activeImageUrl.value = ''
if (visible && props.item) void loadDetail()
},
)
function dash(value: string | number | null | undefined): string {
const text = value === null || value === undefined ? '' : String(value).trim()
return text || '-'
}
const title = (): string =>
`商品详情${props.item?.productCode ? ` · ${props.item.productCode}` : ''}`
</script>
<template>
<div v-if="visible" class="drawer-mask" @click.self="close">
<div v-if="props.visible" class="drawer-mask" @click.self="emit('close')">
<aside class="drawer">
<header class="drawer-head">
<h3>商品详情{{ item?.productCode ? ` · ${item.productCode}` : '' }}</h3>
<button class="drawer-close" type="button" aria-label="关闭" @click="close">×</button>
<h3>{{ title() }}</h3>
<button class="drawer-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
</header>
<div class="drawer-body">
<div v-if="loadFailure" class="drawer-failure">
<span>{{ loadFailure }}</span>
<button class="btn btn-secondary" type="button" @click="loadDetail">重试</button>
</div>
<p v-else-if="loading" class="drawer-tip">加载中...</p>
<template v-else>
<!-- 顶部「左图右信息」(2026-11-16 客户口径「详情页的样式要和京麦商品详情一样的布局样式」):
左侧主图大图+缩略图切换,右侧关键信息;属性/SKU/详情图等区块保持下方。 -->
<section class="detail-block">
<div class="detail-hero">
<div class="hero-gallery">
<img
v-if="activeImageUrl"
class="hero-main"
:src="activeImageUrl"
alt=""
title="点击放大预览"
@click="openPreview(activeImageUrl)"
/>
<div v-else class="hero-empty">无图</div>
<div v-if="galleryImages.length > 1" class="hero-thumbs">
<img
v-for="image in galleryImages"
:key="image.id"
:src="image.url"
alt=""
loading="lazy"
:class="{ active: image.url === activeImageUrl }"
title="切换主图"
@click="switchGallery(image)"
/>
</div>
</div>
<dl class="hero-info">
<div class="info-item info-item-wide hero-title">
<dt>标题</dt>
<dd :title="item?.title || ''">{{ dash(item?.title) }}</dd>
</div>
<div class="info-item"><dt>价格区间</dt><dd>{{ dash(jdPriceRange(item ?? { priceMin: '', priceMax: '' })) }}</dd></div>
<div class="info-item"><dt>总库存</dt><dd>{{ dash(item?.stockTotal) }}</dd></div>
<div class="info-item"><dt>状态</dt><dd>{{ dash(item?.saleStatus) }}</dd></div>
<div class="info-item"><dt>信息分</dt><dd>{{ dash(item?.healthScore) }}</dd></div>
<div class="info-item"><dt>SKU 数</dt><dd>{{ dash(item?.skuCount) }}</dd></div>
<div class="info-item"><dt>商品编码</dt><dd>{{ dash(item?.productCode) }}</dd></div>
<div class="info-item"><dt>货号</dt><dd>{{ dash(item?.itemNum) }}</dd></div>
<div class="info-item"><dt>SKU</dt><dd>{{ dash(item?.skuId) }}</dd></div>
<div class="info-item"><dt>品牌</dt><dd>{{ dash(item?.brand) }}</dd></div>
<div class="info-item"><dt>店铺</dt><dd :title="item?.shopName || ''">{{ dash(item?.shopName) }}</dd></div>
<div class="info-item"><dt>分类</dt><dd>{{ dash(item?.groupName || '未分类') }}</dd></div>
<div class="info-item info-item-wide"><dt>类目</dt><dd :title="item?.categoryPath || ''">{{ dash(item?.categoryPath) }}</dd></div>
<div class="info-item"><dt>上架时间</dt><dd>{{ item?.jdOnlineAt ? formatDateTime(item.jdOnlineAt) : '-' }}</dd></div>
<div class="info-item"><dt>同步时间</dt><dd>{{ formatDateTime(item?.syncedAt || '') }}</dd></div>
<div class="info-item"><dt>京东创建时间</dt><dd>{{ item?.jdCreatedAt ? formatDateTime(item.jdCreatedAt) : '-' }}</dd></div>
<div class="info-item"><dt>京东修改时间</dt><dd>{{ item?.jdUpdatedAt ? formatDateTime(item.jdUpdatedAt) : '-' }}</dd></div>
</dl>
</div>
</section>
<section v-if="attrGroups.length" class="detail-block">
<h4>属性与设置(按京麦 Tab 分组)</h4>
<div v-for="group in attrGroups" :key="group.groupName" class="attr-group">
<h5>{{ group.groupName }}</h5>
<table>
<tbody>
<tr v-for="(attr, index) in group.attrs" :key="`${attr.key}-${index}`">
<th>{{ attr.label || attr.key || '-' }}</th>
<td>{{ attr.value || '-' }}</td>
</tr>
</tbody>
</table>
</div>
</section>
<section v-else-if="attrJsonRaw" class="detail-block">
<h4>属性(原始 JSON)</h4>
<pre class="attr-raw">{{ attrJsonRaw }}</pre>
</section>
<section class="detail-block">
<h4>销售属性 / SKU 矩阵</h4>
<template v-if="skus.length">
<p class="sku-summary">{{ skuSummary }}</p>
<div class="sku-table-wrap">
<table class="sku-table">
<thead>
<tr>
<th>序号</th>
<th v-for="dimension in skuDimensions" :key="dimension">{{ dimension }}</th>
<th>京东价</th>
<th>库存</th>
<th>SKU ID</th>
<th>SKU 名称</th>
</tr>
</thead>
<tbody>
<tr v-for="(sku, index) in skus" :key="sku.skuId">
<td>{{ sku.skuSeq || index + 1 }}</td>
<td v-for="dimension in skuDimensions" :key="dimension">{{ skuAttrValue(sku, dimension) }}</td>
<td>{{ sku.price ? `¥${sku.price}` : '-' }}</td>
<td>{{ dash(sku.stock) }}</td>
<td class="sku-id">{{ sku.skuId }}</td>
<td :title="sku.skuName">{{ dash(sku.skuName) }}</td>
</tr>
</tbody>
</table>
</div>
</template>
<p v-else class="drawer-tip">暂无 SKU 矩阵(V198 之前采集的旧行需重新采集)</p>
</section>
<section class="detail-block">
<h4>主图</h4>
<div v-if="mainImages.length" class="image-grid">
<img
v-for="image in mainImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
<p v-else class="drawer-tip">暂无主图</p>
</section>
<section v-for="bucket in attrImageGroups" :key="bucket.attrName" class="detail-block">
<h4>属性图 · {{ bucket.attrName }}</h4>
<div class="image-grid">
<img
v-for="image in bucket.list"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
</section>
<section class="detail-block">
<h4>详情图</h4>
<div v-if="detailImages.length" class="image-grid">
<img
v-for="image in detailImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
<p v-else class="drawer-tip">暂无详情图</p>
</section>
<section v-if="otherImages.length" class="detail-block">
<h4>其他图</h4>
<div class="image-grid">
<img
v-for="image in otherImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
</section>
</template>
<JdProductDetailContent :item="props.item" :visible="props.visible" />
</div>
</aside>
<div v-if="previewVisible" class="modal-mask" @click.self="previewVisible = false">
<div class="preview-modal">
<div class="preview-head">
<h3>图片预览</h3>
<button class="drawer-close" type="button" aria-label="关闭" @click="previewVisible = false">×</button>
</div>
<img class="preview-image" :src="previewUrl" alt="" />
<div class="preview-foot">
<a :href="previewUrl" target="_blank" rel="noopener">新标签打开原图</a>
<button class="btn btn-secondary" type="button" @click="previewVisible = false">关闭</button>
</div>
</div>
</div>
</div>
</template>
@@ -371,315 +85,5 @@ function dash(value: string | number | null | undefined): string {
min-height: 0;
overflow-y: auto;
padding: 16px 20px 28px;
display: flex;
flex-direction: column;
gap: 18px;
}
.drawer-tip {
margin: 0;
color: #8293a5;
font-size: 13.5px;
}
.drawer-failure {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 14px;
border: 1px solid #f0c9c2;
border-radius: 10px;
background: #fdf1ef;
color: #a04432;
font-size: 13.5px;
}
.detail-block h4 {
margin: 0 0 10px;
font-size: 13.5px;
font-weight: 650;
color: #4e6479;
}
/* 顶部「左图右信息」(京麦详情布局):左侧主图大图+缩略图切换,右侧关键信息网格。 */
.detail-hero {
display: flex;
align-items: flex-start;
gap: 16px;
}
.hero-gallery {
flex: 0 0 300px;
display: flex;
flex-direction: column;
gap: 8px;
min-width: 0;
}
.hero-main {
display: block;
width: 100%;
aspect-ratio: 1;
object-fit: cover;
border: 1px solid #d8e3ee;
border-radius: 10px;
background: #f2f7fb;
cursor: zoom-in;
}
.hero-empty {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
aspect-ratio: 1;
border: 1px dashed #c7d7e5;
border-radius: 10px;
background: #f8fbfd;
color: #8293a5;
font-size: 13px;
}
.hero-thumbs {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.hero-thumbs img {
width: 44px;
height: 44px;
object-fit: cover;
border: 1px solid #d8e3ee;
border-radius: 6px;
cursor: pointer;
opacity: 0.85;
}
.hero-thumbs img.active {
outline: 2px solid #2f5d8b;
opacity: 1;
}
.hero-info {
flex: 1;
min-width: 0;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px 16px;
margin: 0;
}
.hero-info dt {
color: #5b6f83;
font-size: 12px;
margin-bottom: 3px;
}
.hero-info dd {
margin: 0;
color: #24384d;
font-size: 13.5px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.hero-title dd {
font-size: 14.5px;
font-weight: 650;
color: #24384d;
white-space: normal;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
@media (max-width: 760px) {
.detail-hero {
flex-direction: column;
}
.hero-gallery {
flex-basis: auto;
width: 100%;
}
}
.info-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px 16px;
margin: 0;
}
.info-item {
min-width: 0;
}
.info-item-wide {
grid-column: 1 / -1;
}
.info-item dt {
color: #5b6f83;
font-size: 12px;
margin-bottom: 3px;
}
.info-item dd {
margin: 0;
color: #24384d;
font-size: 13.5px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.attr-group {
margin-bottom: 12px;
}
.attr-group h5 {
margin: 0 0 6px;
color: #5b6f83;
font-size: 12.5px;
}
.attr-group table {
width: 100%;
border-collapse: collapse;
border: 1px solid #dbe5ee;
border-radius: 8px;
overflow: hidden;
}
.attr-group th,
.attr-group td {
padding: 7px 10px;
border-bottom: 1px solid #e7eef5;
font-size: 13px;
text-align: left;
vertical-align: top;
}
.attr-group th {
width: 180px;
background: #f2f7fb;
color: #4e6479;
font-weight: 600;
}
.attr-group tr:last-child th,
.attr-group tr:last-child td {
border-bottom: 0;
}
.attr-raw {
margin: 0;
padding: 10px 12px;
border: 1px solid #dbe5ee;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 12px;
white-space: pre-wrap;
word-break: break-all;
max-height: 240px;
overflow-y: auto;
}
.sku-summary {
margin: 0 0 8px;
color: #5b6f83;
font-size: 12.5px;
}
.sku-table-wrap {
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 8px;
}
.sku-table {
width: 100%;
border-collapse: collapse;
font-size: 12.5px;
white-space: nowrap;
}
.sku-table th,
.sku-table td {
padding: 7px 10px;
border-bottom: 1px solid #e7eef5;
text-align: left;
color: #24384d;
}
.sku-table th {
background: #f2f7fb;
color: #4e6479;
font-weight: 600;
}
.sku-table tbody tr:last-child td {
border-bottom: 0;
}
.sku-table .sku-id {
font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
font-size: 12px;
color: #4e6479;
}
.image-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
gap: 10px;
}
.image-grid img {
display: block;
width: 100%;
aspect-ratio: 1;
object-fit: cover;
border: 1px solid #d8e3ee;
border-radius: 8px;
background: #f2f7fb;
cursor: zoom-in;
}
.modal-mask {
position: fixed;
inset: 0;
z-index: 3000;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(6px);
}
.preview-modal {
display: flex;
flex-direction: column;
width: min(880px, 100%);
max-height: 88vh;
padding: 16px 20px;
border: 1px solid #c7d7e5;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
}
.preview-head {
display: flex;
align-items: center;
justify-content: space-between;
}
.preview-head h3 {
margin: 0;
font-size: 15px;
color: #24384d;
}
.preview-image {
display: block;
flex: 1;
min-height: 0;
max-height: 68vh;
margin: 12px 0;
object-fit: contain;
background: #f2f7fb;
border-radius: 8px;
}
.preview-foot {
display: flex;
align-items: center;
justify-content: space-between;
}
.preview-foot a {
color: #2f5d8b;
font-size: 13px;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 38px;
padding: 7px 16px;
border-radius: 9px;
font-size: 13px;
cursor: pointer;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border: 1px solid #c7d7e5;
}
.btn-secondary:hover {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
</style>
@@ -0,0 +1,150 @@
<script setup lang="ts">
/** 京东商品详情居中弹窗(v1.6 蓝图 Phase 4,additive——页面接线随 Phase 5):
* 居中大弹窗壳(设计稿款式):顶部标题+「编辑/删除」动作(按写权限档渲染)+关闭,
* 内容区=JdProductDetailContent 共享块(hero 左图右信息/属性分组/SKU 矩阵/图片三区/
* 放大预览,数据自取)。壳不发请求、不碰业务链——编辑/删除 emit 给页面接既有链
* (EditDrawer 与 removeOne),与现表格行操作同源。 */
import JdProductDetailContent from './JdProductDetailContent.vue'
import type { JdProductItem } from './jd-product-model.ts'
const props = defineProps<{
/** 详情行(来自列表行集;内容块按 item.id 自取详情)。 */
item: JdProductItem | null
visible: boolean
/** 写权限档(isAdminRole 投影):可写档顶部渲染「编辑/删除」,普通账号只读无动作。 */
canWrite?: boolean
}>()
const emit = defineEmits<{
/** 关闭弹窗(mask 自身点击/右上 ×)。 */
(event: 'close'): void
/** 编辑(页面开 JdProductEditDrawer 既有链)。 */
(event: 'edit'): void
/** 删除(页面走 removeOne 既有链:确认弹窗→先桶后库)。 */
(event: 'remove'): void
}>()
const title = (): string =>
`商品详情${props.item?.productCode ? ` · ${props.item.productCode}` : ''}`
</script>
<template>
<div v-if="props.visible" class="jd-modal-mask" @click.self="emit('close')">
<div class="jd-modal" role="dialog" aria-label="商品详情">
<header class="jd-modal-head">
<h3>{{ title() }}</h3>
<div v-if="props.canWrite" class="jd-modal-actions">
<button class="jd-modal-btn" type="button" @click="emit('edit')">编辑</button>
<button class="jd-modal-btn jd-modal-btn-danger" type="button" @click="emit('remove')">删除</button>
</div>
<button class="jd-modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
</header>
<div class="jd-modal-body">
<JdProductDetailContent :item="props.item" :visible="props.visible" />
</div>
</div>
</div>
</template>
<style scoped>
.jd-modal-mask {
position: fixed;
inset: 0;
z-index: 2600;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(4px);
}
.jd-modal {
display: flex;
flex-direction: column;
width: min(1080px, 100%);
max-height: 90vh;
background: #ffffff;
border-radius: 14px;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
overflow: hidden;
}
.jd-modal-head {
display: flex;
align-items: center;
gap: 12px;
padding: 14px 20px;
border-bottom: 1px solid #dbe5ee;
}
.jd-modal-head h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.jd-modal-actions {
display: flex;
gap: 8px;
flex-shrink: 0;
}
.jd-modal-btn {
min-height: 32px;
padding: 4px 14px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #2f5d8b;
font-size: 13px;
cursor: pointer;
}
.jd-modal-btn:hover {
border-color: #95b1cb;
background: #edf5fb;
}
.jd-modal-btn-danger {
color: #a04432;
border-color: #f0c9c2;
}
.jd-modal-btn-danger:hover {
background: #fdf1ef;
border-color: #e0a79c;
}
.jd-modal-close {
flex-shrink: 0;
width: 30px;
height: 30px;
border: 1px solid transparent;
border-radius: 9px;
background: none;
color: #5b6f83;
font-size: 20px;
line-height: 1;
cursor: pointer;
}
.jd-modal-close:hover {
border-color: #cbd9e6;
background: #eef4fa;
color: #24384d;
}
.jd-modal-body {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 16px 20px 28px;
}
</style>
@@ -0,0 +1,161 @@
/**
* 京东商品详情居中弹窗(JdProductDetailModal,v1.6 蓝图 Phase 4)的挂载契约。
*
* 弹窗壳只管 chrome(遮罩/标题/「编辑/删除」动作分档/关闭),内容与取数在共享块
* JdProductDetailContent(与侧滑抽屉同一份实现,抽屉薄壳化行为由页面 mount 测试兜住)。
* 挂载时序与真实页面一致:先 visible=false 挂载,再置 true(Content 的 watch 靠变更触发取数)。
*
* 跑法:`npx vitest run tests/mount/jd-product-detail-modal.mount.test.ts`
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import JdProductDetailModal from '@/pages/jd/JdProductDetailModal.vue'
import type { JdProductItem } from '@/pages/jd/jd-product-model.ts'
const jdApi = vi.hoisted(() => ({
fetchJdProductDetail: vi.fn(),
}))
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
function item(): JdProductItem {
return {
id: 1,
shopId: 3,
shopName: '旗舰自营店',
productCode: 'JD-10086',
skuId: 'SKU-1',
itemNum: 'ITEM-1',
skuCount: 1,
healthScore: 81,
title: '304不锈钢保温杯大容量便携',
brand: '锅宝',
categoryPath: '家居 > 厨具 > 保温杯',
priceMin: '12.90',
priceMax: '15.90',
stockTotal: 500,
saleStatus: '上架中',
listTab: 'search',
jdCreatedAt: '2026-11-07 18:49:47',
jdOnlineAt: '2026-11-12 15:03:37',
jdUpdatedAt: '2026-11-13 14:06:07',
mainImageUrl: 'https://img.example/main-1.jpg',
attrCount: 6,
imageCount: 2,
groupId: 7,
groupName: '甲组',
syncedAt: '2026-11-12 09:00:00',
} as JdProductItem
}
/** fetchJdProductDetail 的返回(已由 parseJdProductDetail 归一的形状,与页面 mount 测试同构)。 */
function detailPayload() {
return {
item: item(),
attrGroups: [
{ groupName: '规格', attrs: [{ key: 'capacity', label: '容量', value: '500ml' }] },
],
images: [
{ id: 1, imageType: 'MAIN', attrName: '', sortNo: 1, url: 'https://img.example/main.jpg', byteSize: null, width: 800, height: 800 },
{ id: 2, imageType: 'DETAIL', attrName: '', sortNo: 2, url: 'https://img.example/detail.jpg', byteSize: null, width: null, height: null },
],
skus: [
{ skuId: 'S1', skuName: '上衣 S', skuSeq: '1', price: '162', stock: 200, saleAttrs: [{ name: '颜色', value: '上衣' }, { name: '尺码', value: 'S' }], sortNo: 0 },
],
attrJsonRaw: '',
}
}
beforeEach(() => {
vi.clearAllMocks()
})
/** 与真实页面同构的挂载:先 visible=false 挂载,再置 true 触发 Content 取数。 */
async function mountOpened(canWrite = true): Promise<VueWrapper<Element>> {
jdApi.fetchJdProductDetail.mockResolvedValue(detailPayload())
const wrapper = mount(JdProductDetailModal, {
props: { item: item(), visible: false, canWrite },
})
await wrapper.setProps({ visible: true })
await flushPromises()
await flushPromises()
return wrapper
}
describe('居中弹窗 chrome(设计稿款式:居中大弹窗+顶部动作)', () => {
it('打开即取数(按 item.id)并渲染共享块内容:hero 左图右信息/属性分组/SKU 矩阵/图片三区', async () => {
const wrapper = await mountOpened()
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1)
expect(wrapper.get('.jd-modal-mask').exists()).toBe(true)
expect(wrapper.get('.jd-modal-head h3').text()).toBe('商品详情 · JD-10086')
// 共享块(与侧滑抽屉同一份实现)——类名与页面 mount 测试钉住的抽屉断言同字。
expect(wrapper.get('.detail-hero').exists()).toBe(true)
expect(wrapper.get('.hero-main').exists()).toBe(true)
expect(wrapper.get('.hero-info').text()).toContain('价格区间')
expect(wrapper.get('.hero-info').text()).toContain('12.9 ~ 15.9')
expect(wrapper.get('.jd-modal').text()).toContain('规格')
expect(wrapper.get('.jd-modal').text()).toContain('容量')
expect(wrapper.get('.jd-modal').text()).toContain('销售属性 / SKU 矩阵')
expect(wrapper.get('.jd-modal').text()).toContain('1 个 SKU · ¥162 · 库存 200')
expect(wrapper.get('.jd-modal').text()).toContain('主图')
expect(wrapper.get('.jd-modal').text()).toContain('详情图')
wrapper.unmount()
})
it('关闭:点遮罩自身与右上 × 都 emit close;关闭后 mask 摘掉', async () => {
const wrapper = await mountOpened()
await wrapper.get('.jd-modal-mask').trigger('click')
expect(wrapper.emitted('close')).toHaveLength(1, 'mask @click.self(点内容区不算)')
await wrapper.get('.jd-modal-close').trigger('click')
expect(wrapper.emitted('close')).toHaveLength(2)
await wrapper.setProps({ visible: false })
await flushPromises()
expect(wrapper.find('.jd-modal-mask').exists()).toBe(false)
wrapper.unmount()
})
})
describe('顶部动作按写权限档分档(emit 给页面接既有链)', () => {
it('可写档渲染「编辑/删除」:点击分别 emit edit/remove 且不冒泡成 close', async () => {
const wrapper = await mountOpened(true)
const actions = wrapper.get('.jd-modal-actions')
const buttons = actions.findAll('button')
expect(buttons.map((b) => b.text())).toEqual(['编辑', '删除'])
await buttons[0]!.trigger('click')
expect(wrapper.emitted('edit')).toHaveLength(1)
expect(wrapper.emitted('close')).toBeFalsy()
await buttons[1]!.trigger('click')
expect(wrapper.emitted('remove')).toHaveLength(1)
expect(wrapper.emitted('close')).toBeFalsy()
wrapper.unmount()
})
it('只读档(canWrite=false):无动作区(普通账号只读,与现表格操作列分档同口径)', async () => {
const wrapper = await mountOpened(false)
expect(wrapper.find('.jd-modal-actions').exists()).toBe(false)
expect(wrapper.findAll('button').map((b) => b.text())).not.toContain('编辑')
expect(wrapper.findAll('button').map((b) => b.text())).not.toContain('删除')
wrapper.unmount()
})
})
describe('加载失败与重试(取数在共享块,两条壳同一份兜底)', () => {
it('失败红条可见且重试真能重跑', async () => {
jdApi.fetchJdProductDetail.mockRejectedValueOnce(new Error('上游 502'))
jdApi.fetchJdProductDetail.mockResolvedValue(detailPayload())
const wrapper = mount(JdProductDetailModal, { props: { item: item(), visible: false, canWrite: true } })
await wrapper.setProps({ visible: true })
await flushPromises()
await flushPromises()
const bar = wrapper.get('.drawer-failure')
expect(bar.text()).toContain('上游 502', 'requestErrorMessage 透传后端/网络原因(与旧抽屉同一出口)')
expect(bar.find('button').text()).toBe('重试')
await bar.find('button').trigger('click')
await flushPromises()
await flushPromises()
expect(wrapper.find('.drawer-failure').exists()).toBe(false, '重试成功后红条消失')
expect(wrapper.get('.detail-hero').exists()).toBe(true)
wrapper.unmount()
})
})