mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:09:20 +08:00
feat: 商品详情页功能完成
后端: - ProductOverviewController POST /ec/product/overview - ProductOverviewQueryDTO / ProductOverviewVO (productId + 7个统计字段) - ProductOverviewServiceImpl 前端: - ProductCard 添加统计入口,goToDetails 改用 path 导航 - /api/ecommerce/product-overview/ 接口定义 - views/ecommerce/product/details/ 商品详情页 + OverviewTab (7个ChartCard) 数据库: - sys_menu id=43 parent_id 从 8 改为 6
This commit is contained in:
+25
-3
@@ -1,15 +1,20 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductVO } from '#/api/ecommerce/product/types';
|
||||
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Card, Image, Popconfirm, Popover, Tag } from 'ant-design-vue';
|
||||
|
||||
defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
const router = useRouter();
|
||||
|
||||
// 创建图标组件
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
const ChartIcon = createIconifyIcon('lucide:bar-chart-2');
|
||||
|
||||
interface Props {
|
||||
product: ProductVO.Info;
|
||||
@@ -27,6 +32,10 @@ const handleEdit = (product: ProductVO.Info) => {
|
||||
const handleDelete = (product: ProductVO.Info) => {
|
||||
emit('delete', product);
|
||||
};
|
||||
|
||||
const goToDetails = (product: ProductVO.Info) => {
|
||||
router.push(`/ecom/product/details/${product.id}`);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -35,9 +44,10 @@ const handleDelete = (product: ProductVO.Info) => {
|
||||
: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"
|
||||
>
|
||||
<!-- 图片区域 -->
|
||||
<!-- 图片区域(点击进入详情) -->
|
||||
<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"
|
||||
@@ -59,10 +69,11 @@ const handleDelete = (product: ProductVO.Info) => {
|
||||
|
||||
<!-- 信息区域 -->
|
||||
<div class="p-3">
|
||||
<!-- 商品名称 -->
|
||||
<!-- 商品名称(点击进入详情) -->
|
||||
<div
|
||||
class="mb-2 line-clamp-2 text-sm font-medium text-gray-900 dark:text-gray-100"
|
||||
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"
|
||||
@click="goToDetails(product)"
|
||||
>
|
||||
{{ product.name }}
|
||||
</div>
|
||||
@@ -142,6 +153,17 @@ const handleDelete = (product: ProductVO.Info) => {
|
||||
<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>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { Tabs } from 'ant-design-vue';
|
||||
|
||||
import OverviewTab from './tabs/OverviewTab.vue';
|
||||
|
||||
defineOptions({ name: 'ProductDetails' });
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
// 商品ID(从路由参数获取)
|
||||
const productId = computed(() => {
|
||||
const id = route.params.id;
|
||||
return id ? Number(id) : 0;
|
||||
});
|
||||
|
||||
// 当前激活的 tab
|
||||
const activeKey = ref('overview');
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height content-class="flex flex-col">
|
||||
<Tabs
|
||||
v-model:active-key="activeKey"
|
||||
class="flex min-h-0 flex-1 flex-col"
|
||||
:tab-bar-style="{ marginBottom: '16px' }"
|
||||
>
|
||||
<Tabs.TabPane key="overview" tab="总览">
|
||||
<OverviewTab :product-id="productId" />
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
</Page>
|
||||
</template>
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductOverviewVO } from '#/api/ecommerce/product-overview/types';
|
||||
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { Card, Col, DatePicker, message, Row, Space, Typography } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getProductOverviewApi } from '#/api/ecommerce/product-overview';
|
||||
|
||||
import ChartCard from '../../../shop/details/components/ChartCard.vue';
|
||||
|
||||
defineOptions({ name: 'ProductOverviewTab' });
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
interface Props {
|
||||
productId: number;
|
||||
}
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const overviewData = ref<null | ProductOverviewVO.Overview>(null);
|
||||
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
||||
dayjs().subtract(30, 'day'),
|
||||
dayjs(),
|
||||
]);
|
||||
|
||||
// 格式化金额
|
||||
function formatCurrency(value: number): string {
|
||||
return `¥${value.toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
})}`;
|
||||
}
|
||||
|
||||
// 格式化百分比
|
||||
function formatPercent(value: number): string {
|
||||
return `${(value * 100).toFixed(2)}%`;
|
||||
}
|
||||
|
||||
// 获取商品总览数据
|
||||
async function fetchProductOverview() {
|
||||
if (!props.productId || !dateRange.value) return;
|
||||
try {
|
||||
loading.value = true;
|
||||
const data = await getProductOverviewApi({
|
||||
productId: props.productId,
|
||||
startDate: dateRange.value[0].format('YYYY-MM-DD'),
|
||||
endDate: dateRange.value[1].format('YYYY-MM-DD'),
|
||||
});
|
||||
overviewData.value = data;
|
||||
} catch (error) {
|
||||
console.error('获取商品总览失败:', error);
|
||||
message.error('获取商品总览失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理日期范围变化
|
||||
function handleDateRangeChange() {
|
||||
fetchProductOverview();
|
||||
}
|
||||
|
||||
// 监听 productId 变化
|
||||
watch(
|
||||
() => props.productId,
|
||||
(newProductId) => {
|
||||
if (newProductId) {
|
||||
fetchProductOverview();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 初始化数据
|
||||
onMounted(() => {
|
||||
if (props.productId) {
|
||||
fetchProductOverview();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex h-full flex-col">
|
||||
<!-- 日期选择器 -->
|
||||
<Card :loading="loading" class="mb-4 flex-shrink-0">
|
||||
<Space>
|
||||
<span>选择日期范围:</span>
|
||||
<DatePicker.RangePicker
|
||||
v-model:value="dateRange"
|
||||
format="YYYY-MM-DD"
|
||||
@change="handleDateRangeChange"
|
||||
/>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
<!-- 商品名称标题 -->
|
||||
<Card v-if="overviewData" :loading="loading" class="mb-4 flex-shrink-0">
|
||||
<Typography.Title :level="4" style="margin: 0">
|
||||
{{ overviewData.productName }}
|
||||
</Typography.Title>
|
||||
</Card>
|
||||
|
||||
<!-- 图表展示 -->
|
||||
<div v-if="overviewData" class="min-h-0 flex-1 overflow-auto">
|
||||
<Row :gutter="[16, 16]">
|
||||
<!-- 销售额 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.salesAmount"
|
||||
:formatter="formatCurrency"
|
||||
title="销售额"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 订单数 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.orderCount"
|
||||
:formatter="(v) => v.toLocaleString()"
|
||||
chart-type="bar"
|
||||
color="#019680"
|
||||
title="订单数"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 客单价 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.averageOrderValue"
|
||||
:formatter="formatCurrency"
|
||||
color="#ff9800"
|
||||
title="客单价"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 成本 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.costAmount"
|
||||
:formatter="formatCurrency"
|
||||
color="#f56c6c"
|
||||
title="成本"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 退款金额 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.refundAmount"
|
||||
:formatter="formatCurrency"
|
||||
color="#e6a23c"
|
||||
title="退款金额"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 推广费 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.promotionFee"
|
||||
:formatter="formatCurrency"
|
||||
color="#909399"
|
||||
title="推广费"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 费比 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.feeRatio"
|
||||
:formatter="formatPercent"
|
||||
color="#67c23a"
|
||||
title="费比"
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<div v-else class="flex flex-1 items-center justify-center">
|
||||
<span class="text-gray-400">暂无数据</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user