mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:59:19 +08:00
feat(product): 优化商品卡片展示和表单交互体验
This commit is contained in:
@@ -9,6 +9,8 @@ export namespace ProductDTO {
|
||||
name: string;
|
||||
/** 商品编码 */
|
||||
productCode?: string;
|
||||
/** 类目ID */
|
||||
categoryId?: number;
|
||||
/** 主图图片ID */
|
||||
mainImageId?: number;
|
||||
/** 商品规格列表(可选) */
|
||||
@@ -21,6 +23,8 @@ export namespace ProductDTO {
|
||||
name: string;
|
||||
/** 商品编码 */
|
||||
productCode?: string;
|
||||
/** 类目ID */
|
||||
categoryId?: number;
|
||||
/** 主图图片ID */
|
||||
mainImageId?: number;
|
||||
/** 商品规格列表(如果提供,则更新这些规格) */
|
||||
|
||||
+278
-127
@@ -1,13 +1,14 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductVO } from '#/api/ecommerce/product/types';
|
||||
|
||||
import { computed } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Card, Image, Popconfirm, Popover, Tag } from 'ant-design-vue';
|
||||
import { Button, Card, Image, Popconfirm } from 'ant-design-vue';
|
||||
|
||||
defineProps<Props>();
|
||||
const props = defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
const router = useRouter();
|
||||
|
||||
@@ -15,7 +16,7 @@ const router = useRouter();
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
const ChartIcon = createIconifyIcon('lucide:bar-chart-2');
|
||||
const ImageOffIcon = createIconifyIcon('lucide:package');
|
||||
const ImageOffIcon = createIconifyIcon('lucide:image-off');
|
||||
|
||||
interface Props {
|
||||
product: ProductVO.Info;
|
||||
@@ -37,148 +38,140 @@ const handleDelete = (product: ProductVO.Info) => {
|
||||
const goToDetails = (product: ProductVO.Info) => {
|
||||
router.push(`/ecom/product/details/${product.id}`);
|
||||
};
|
||||
|
||||
const visibleSpecs = computed(() => (props.product.specs || []).slice(0, 4));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card
|
||||
hoverable
|
||||
:body-style="{ padding: 0 }"
|
||||
class="group h-full border border-gray-200 transition-all duration-300 ease-out hover:-translate-y-1 hover:border-blue-500 hover:shadow-lg dark:border-gray-700"
|
||||
class="group management-card h-full border border-gray-200 transition-all duration-300 ease-out hover:-translate-y-1 hover:border-blue-500 hover:shadow-lg dark:border-gray-700"
|
||||
>
|
||||
<!-- 图片区域(点击进入详情) -->
|
||||
<div
|
||||
class="relative aspect-square cursor-pointer overflow-hidden rounded-t-lg bg-gray-100 dark:bg-neutral-800"
|
||||
@click="goToDetails(product)"
|
||||
>
|
||||
<Image
|
||||
v-if="product.mainImage"
|
||||
:src="product.mainImage"
|
||||
:alt="product.name"
|
||||
class="h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
|
||||
:preview="true"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
class="flex h-full w-full items-center justify-center text-gray-400 dark:text-gray-500"
|
||||
>
|
||||
<div class="text-center flex flex-col items-center justify-center">
|
||||
<ImageOffIcon class="mb-2 text-4xl text-gray-400 flex" />
|
||||
<div class="text-sm">暂无图片</div>
|
||||
<div class="product-header">
|
||||
<div class="product-image-box">
|
||||
<Image
|
||||
v-if="product.mainImage"
|
||||
:src="product.mainImage"
|
||||
:alt="product.name"
|
||||
class="product-image"
|
||||
:preview="true"
|
||||
/>
|
||||
<div v-else class="no-image">
|
||||
<ImageOffIcon class="mb-1 text-base" />
|
||||
<span>暂无商品图</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="product-main-info">
|
||||
<div
|
||||
class="product-name line-clamp-2"
|
||||
:title="product.name"
|
||||
>
|
||||
{{ product.name }}
|
||||
</div>
|
||||
<div class="info-grid">
|
||||
<div class="info-item">
|
||||
<span class="info-label">类目:</span>
|
||||
<span class="info-value">{{ product.categoryName || '未设置' }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">商品编码:</span>
|
||||
<span class="info-value">{{ product.productCode || '未填写' }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">创建时间:</span>
|
||||
<span class="info-value">{{ product.createTime || '-' }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">更新时间:</span>
|
||||
<span class="info-value">{{ product.updateTime || '-' }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">规格数:</span>
|
||||
<span class="info-value">{{ product.specs?.length || 0 }} 个</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 信息区域 -->
|
||||
<div class="p-3">
|
||||
<!-- 商品名称(点击进入详情) -->
|
||||
<div
|
||||
class="mb-2 line-clamp-2 cursor-pointer text-sm font-medium text-gray-900 hover:text-blue-500 dark:text-gray-100"
|
||||
:title="product.name"
|
||||
<div class="specs-section">
|
||||
<div class="section-header">
|
||||
<span class="section-title">多规格及成本清单</span>
|
||||
</div>
|
||||
<div v-if="visibleSpecs.length > 0" class="spec-list">
|
||||
<div class="spec-row spec-head">
|
||||
<span>规格编码</span>
|
||||
<span>规格描述</span>
|
||||
<span>商品成本</span>
|
||||
<span>运费成本</span>
|
||||
<span>其他成本</span>
|
||||
</div>
|
||||
<div
|
||||
v-for="spec in visibleSpecs"
|
||||
:key="spec.id"
|
||||
class="spec-row"
|
||||
>
|
||||
<span class="code-text">{{ spec.specCode || '未填写' }}</span>
|
||||
<span class="spec-desc">{{ spec.name || '-' }}</span>
|
||||
<span class="cost-col">¥{{ (spec.productCost ?? 0).toFixed(2) }}</span>
|
||||
<span class="cost-col">¥{{ (spec.shippingCost ?? 0).toFixed(2) }}</span>
|
||||
<span class="cost-col">¥{{ (spec.otherCost ?? 0).toFixed(2) }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="(product.specs?.length || 0) > visibleSpecs.length"
|
||||
class="more-tip"
|
||||
>
|
||||
仅展示前 {{ visibleSpecs.length }} 条规格,点击“统计”查看全部
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-text">暂无规格数据</div>
|
||||
</div>
|
||||
|
||||
<div class="card-actions">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleEdit(product)"
|
||||
title="编辑"
|
||||
>
|
||||
<template #icon>
|
||||
<EditIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">编辑</span>
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个商品吗?"
|
||||
@confirm="handleDelete(product)"
|
||||
>
|
||||
<Button type="text" size="small" danger title="删除">
|
||||
<template #icon>
|
||||
<TrashIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">删除</span>
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
title="查看统计"
|
||||
@click="goToDetails(product)"
|
||||
>
|
||||
{{ product.name }}
|
||||
</div>
|
||||
|
||||
<!-- 商品编码 -->
|
||||
<div
|
||||
v-if="product.productCode"
|
||||
class="mb-1 text-xs text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
编码: {{ product.productCode }}
|
||||
</div>
|
||||
|
||||
<!-- 品类 -->
|
||||
<div
|
||||
v-if="product.categoryName"
|
||||
class="mb-2 text-xs text-blue-500 dark:text-blue-400"
|
||||
>
|
||||
{{ product.categoryName }}
|
||||
</div>
|
||||
|
||||
<!-- 规格数量标签(支持悬停显示详情) -->
|
||||
<div v-if="product.specs && product.specs.length > 0" class="mb-3">
|
||||
<Popover placement="right" trigger="hover">
|
||||
<template #content>
|
||||
<div class="max-w-xs space-y-2">
|
||||
<div
|
||||
class="mb-2 text-sm font-medium text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
规格详情
|
||||
</div>
|
||||
<div
|
||||
v-for="spec in product.specs"
|
||||
:key="spec.id"
|
||||
class="flex items-center justify-between rounded-md bg-gray-50 px-3 py-2 text-xs dark:bg-neutral-800"
|
||||
>
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="font-medium text-gray-700 dark:text-gray-300">
|
||||
{{ spec.name }}
|
||||
</span>
|
||||
<span
|
||||
v-if="spec.specCode"
|
||||
class="text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
编码: {{ spec.specCode }}
|
||||
</span>
|
||||
</div>
|
||||
<span class="ml-4 font-semibold text-red-500 dark:text-red-400">
|
||||
¥{{ spec.productCost.toFixed(2) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<Tag color="blue" class="cursor-pointer">
|
||||
{{ product.specs.length }} 个规格
|
||||
</Tag>
|
||||
</Popover>
|
||||
</div>
|
||||
|
||||
<!-- 创建时间 -->
|
||||
<div class="mb-3 text-xs text-gray-500 dark:text-gray-400">
|
||||
{{ product.createTime }}
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="flex w-full items-center gap-2">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleEdit(product)"
|
||||
title="编辑"
|
||||
>
|
||||
<template #icon>
|
||||
<EditIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">编辑</span>
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个商品吗?"
|
||||
@confirm="handleDelete(product)"
|
||||
>
|
||||
<Button type="text" size="small" danger title="删除">
|
||||
<template #icon>
|
||||
<TrashIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">删除</span>
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
title="查看统计"
|
||||
@click="goToDetails(product)"
|
||||
>
|
||||
<template #icon>
|
||||
<ChartIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">统计</span>
|
||||
</Button>
|
||||
</div>
|
||||
<template #icon>
|
||||
<ChartIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">统计</span>
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.management-card {
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.line-clamp-2 {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
@@ -186,4 +179,162 @@ const goToDetails = (product: ProductVO.Info) => {
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.product-header {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
padding: 16px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.product-image-box {
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
flex-shrink: 0;
|
||||
border: 1px solid #f0f0f0;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
background: #fafafa;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.product-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.no-image {
|
||||
font-size: 12px;
|
||||
color: #bfbfbf;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.product-main-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
margin: 0 0 12px 0;
|
||||
font-size: 18px;
|
||||
line-height: 1.4;
|
||||
font-weight: 600;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.info-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
min-width: 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
.info-label {
|
||||
color: #595959;
|
||||
margin-right: 6px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.specs-section {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.section-title::before {
|
||||
content: '';
|
||||
width: 3px;
|
||||
height: 14px;
|
||||
margin-right: 7px;
|
||||
border-radius: 2px;
|
||||
background: #2f54eb;
|
||||
}
|
||||
|
||||
.spec-list {
|
||||
border: 1px solid #f0f0f0;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.spec-row {
|
||||
display: grid;
|
||||
grid-template-columns: 120px 1fr 110px 110px 110px;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
padding: 8px 10px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.spec-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.spec-head {
|
||||
background: #fafafa;
|
||||
font-weight: 600;
|
||||
color: #8c8c8c;
|
||||
}
|
||||
|
||||
.code-text {
|
||||
font-family: 'SFMono-Regular', Consolas, Menlo, monospace;
|
||||
background: #f5f5f5;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 4px;
|
||||
padding: 2px 4px;
|
||||
display: inline-block;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.spec-desc {
|
||||
color: #595959;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.cost-col {
|
||||
font-weight: 600;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.more-tip {
|
||||
padding: 7px 10px;
|
||||
font-size: 11px;
|
||||
color: #8c8c8c;
|
||||
border-top: 1px dashed #e5e7eb;
|
||||
background: #fcfcfc;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 12px;
|
||||
color: #bfbfbf;
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
.card-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
</style>
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ const [SyncModal, syncModalApi] = useVbenModal({
|
||||
syncModalApi.close();
|
||||
},
|
||||
});
|
||||
const syncFormData = ref<[string, string] | null>(null);
|
||||
const syncFormData = ref<[string, string] | undefined>(undefined);
|
||||
|
||||
async function openSyncModal(costChangedSpecIds: number[]) {
|
||||
try {
|
||||
|
||||
+6
-7
@@ -284,16 +284,15 @@ onUnmounted(() => {
|
||||
v-else-if="productList.length > 0"
|
||||
:list="productList"
|
||||
row-key="id"
|
||||
:width="240"
|
||||
:width="560"
|
||||
:breakpoints="{
|
||||
2000: { rowPerView: 5 },
|
||||
1700: { rowPerView: 4 },
|
||||
1400: { rowPerView: 3 },
|
||||
1100: { rowPerView: 2 },
|
||||
768: { rowPerView: 2 },
|
||||
2350: { rowPerView: 3 },
|
||||
1750: { rowPerView: 2 },
|
||||
1250: { rowPerView: 2 },
|
||||
900: { rowPerView: 1 },
|
||||
500: { rowPerView: 1 },
|
||||
}"
|
||||
:gutter="16"
|
||||
:gutter="20"
|
||||
class="product-waterfall"
|
||||
>
|
||||
<template #default="{ item }">
|
||||
|
||||
Reference in New Issue
Block a user