feat: move

This commit is contained in:
ah--desktop
2025-12-17 01:12:10 +08:00
parent ca15b80d86
commit cb35521713
14 changed files with 1347 additions and 551 deletions
@@ -0,0 +1,170 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import { computed, onMounted, ref, watch } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import { Card, Statistic } from 'ant-design-vue';
interface Props {
/** 标题 */
title: string;
/** 统计数据 */
data: ShopVO.DailyStatistics;
/** 格式化函数 */
formatter?: (value: number) => string;
/** 图表类型 */
chartType?: 'bar' | 'line';
/** 图表颜色 */
color?: string;
}
defineOptions({ name: 'ChartCard' });
const props = withDefaults(defineProps<Props>(), {
chartType: 'line',
color: '#5ab1ef',
formatter: (value: number) => value.toLocaleString('zh-CN'),
});
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
// 图表配置类型(使用 Record 类型,避免直接导入 echarts 类型)
type ChartOptions = Record<string, any>;
// 格式化日期:从 "2025-11-17" 提取日期部分 "17"
function formatDateToDay(dateStr: string): string {
const date = new Date(dateStr);
return date.getDate().toString();
}
// 图表配置
const chartOptions = computed<ChartOptions>(() => {
const { dailyDataList } = props.data;
// 横坐标只显示日期(日)
const dateLabels = dailyDataList.map((item) => formatDateToDay(item.date));
// 保存完整日期用于 tooltip
const fullDates = dailyDataList.map((item) => item.date);
const values = dailyDataList.map((item) => item.value);
const isLine = props.chartType === 'line';
return {
grid: {
bottom: 20,
containLabel: true,
left: '3%',
right: '3%',
top: '10%',
},
tooltip: {
axisPointer: {
lineStyle: {
color: props.color,
width: 1,
},
},
trigger: 'axis',
formatter: (params: any) => {
const param = Array.isArray(params) ? params[0] : params;
const index = param.dataIndex;
const fullDate = fullDates[index];
const value = param.value;
const formattedValue = props.formatter(value);
return `${fullDate}<br/>${props.title}: ${formattedValue}`;
},
},
xAxis: {
axisTick: {
show: false,
},
boundaryGap: !isLine,
data: dateLabels,
type: 'category',
},
yAxis: {
axisTick: {
show: false,
},
splitLine: {
lineStyle: {
type: 'dashed',
},
show: true,
},
type: 'value',
},
series: [
{
areaStyle: isLine
? {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: props.color,
},
{
offset: 1,
color: `${props.color}00`, // 透明
},
],
},
}
: undefined,
data: values,
itemStyle: {
color: props.color,
},
smooth: isLine,
type: props.chartType,
...(props.chartType === 'bar' && { barMaxWidth: 60 }),
},
],
};
});
// 渲染图表
function renderChart() {
if (chartRef.value && props.data.dailyDataList.length > 0) {
renderEcharts(chartOptions.value);
}
}
// 监听数据变化
watch(
() => props.data,
() => {
renderChart();
},
{ deep: true },
);
onMounted(() => {
renderChart();
});
</script>
<template>
<Card :title="title" class="h-full">
<div class="mb-4">
<Statistic
:title="`${title}总计`"
:value="data.total"
:formatter="({ value }) => formatter(value as number)"
/>
</div>
<div class="h-64 min-h-0">
<EchartsUI ref="chartRef" />
</div>
</Card>
</template>
@@ -0,0 +1,210 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { ShopDTO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { computed, ref, watch } from 'vue';
import { Page } from '@vben/common-ui';
import { Image, message, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getShopProductPageApi } from '#/api/ecommerce/shop';
interface Props {
shopId: number;
}
defineOptions({ name: 'ProductsTab' });
const props = defineProps<Props>();
// 响应式数据
const loading = ref(false);
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
title: '序号',
},
{
title: '主图',
width: 60,
slots: { default: 'mainImage' },
},
{
field: 'name',
title: '商品名称',
minWidth: 200,
showOverflow: 'tooltip' as const,
},
{
field: 'productCode',
title: '商品编码',
minWidth: 150,
showOverflow: 'tooltip' as const,
},
{
title: '规格数量',
minWidth: 100,
slots: { default: 'specs' },
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
},
{
field: 'updateTime',
title: '更新时间',
minWidth: 180,
},
],
height: 'auto',
border: true,
stripe: true,
highlightHoverRow: true,
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
// 配置远程加载
proxyConfig: {
ajax: {
query: async ({ page }) => {
if (!props.shopId) {
return {
items: [],
total: 0,
};
}
try {
loading.value = true;
const params: PageQueryDTO<ShopDTO.ProductPageFilters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: props.shopId,
},
};
const data = await getShopProductPageApi(params);
return {
items: data.records,
total: data.total,
};
} catch (error) {
console.error('获取商品列表失败:', error);
message.error('获取商品列表失败');
return {
items: [],
total: 0,
};
} finally {
loading.value = false;
}
},
},
},
};
// 搜索表单配置
const formOptions = computed(() => ({
schema: [
{
component: 'Input',
componentProps: {
placeholder: '请输入商品名称',
},
fieldName: 'name',
label: '商品名称',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入商品编码',
},
fieldName: 'productCode',
label: '商品编码',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '商品列表',
});
// 监听 shopId 变化,刷新表格
watch(
() => props.shopId,
() => {
if (props.shopId && gridApi) {
gridApi.reload();
}
},
);
</script>
<template>
<Page auto-content-height content-class="flex flex-col">
<Grid :loading="loading">
<!-- 主图列 -->
<template #mainImage="{ row }: { row: any }">
<Image
v-if="row.mainImage"
:src="row.mainImage"
:alt="row.name"
width="60"
height="60"
style="object-fit: cover; border-radius: 4px"
:preview="true"
/>
<span v-else class="text-xs text-gray-400">暂无图片</span>
</template>
<!-- 规格数量列 -->
<template #specs="{ row }: { row: any }">
<Tag :color="(row.specs?.length || 0) > 0 ? 'blue' : 'default'">
{{ row.specs?.length || 0 }} 个规格
</Tag>
</template>
</Grid>
</Page>
</template>
@@ -3,23 +3,27 @@ import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
import { onMounted, ref, watch } from 'vue';
import { Card, Col, DatePicker, message, Row, Space, Statistic } from 'ant-design-vue';
import {
Card,
Col,
DatePicker,
message,
Row,
Space,
Statistic,
} from 'ant-design-vue';
import dayjs from 'dayjs';
import { getShopDetailApi } from '#/api/ecommerce/shop';
import { getShopOverviewApi } from '#/api/ecommerce/shop';
defineOptions({ name: 'ShopStatistics' });
const props = defineProps<Props>();
interface Props {
shopId: number;
}
const props = defineProps<Props>();
const emit = defineEmits<{
productListUpdate: [products: ShopVO.ProductDetail[]];
}>();
// 响应式数据
const loading = ref(false);
const customStats = ref<null | ShopVO.Statistics>(null);
@@ -41,23 +45,34 @@ function formatPercent(value: number): string {
return `${(value * 100).toFixed(2)}%`;
}
// 获取店铺详情(包含统计信息和商品列表)
async function fetchShopDetail() {
// 从 Overview 中提取统计信息
function extractStatistics(overview: ShopVO.Overview): ShopVO.Statistics {
return {
salesAmount: overview.salesAmount.total,
orderCount: overview.orderCount.total,
averageOrderValue: overview.averageOrderValue.total,
costAmount: overview.costAmount.total,
refundAmount: overview.refundAmount.total,
promotionFee: overview.promotionFee.total,
feeRatio: overview.feeRatio.total,
};
}
// 获取店铺总览数据
async function fetchShopOverview() {
if (!props.shopId || !dateRange.value) return;
try {
loading.value = true;
const params: ShopDTO.DetailQuery = {
const params: ShopDTO.StatisticsQuery = {
shopId: props.shopId,
startDate: dateRange.value[0].format('YYYY-MM-DD'),
endDate: dateRange.value[1].format('YYYY-MM-DD'),
};
const data = await getShopDetailApi(params);
customStats.value = data.statistics;
// 通知父组件更新商品列表
emit('productListUpdate', data.products || []);
const data = await getShopOverviewApi(params);
customStats.value = extractStatistics(data);
} catch (error) {
console.error('获取店铺详情失败:', error);
message.error('获取店铺详情失败');
console.error('获取店铺总览失败:', error);
message.error('获取店铺总览失败');
} finally {
loading.value = false;
}
@@ -65,7 +80,7 @@ async function fetchShopDetail() {
// 处理日期范围变化
function handleDateRangeChange() {
fetchShopDetail();
fetchShopOverview();
}
// 监听 shopId 变化
@@ -73,7 +88,7 @@ watch(
() => props.shopId,
(newShopId) => {
if (newShopId) {
fetchShopDetail();
fetchShopOverview();
}
},
);
@@ -81,7 +96,7 @@ watch(
// 初始化数据
onMounted(() => {
if (props.shopId) {
fetchShopDetail();
fetchShopOverview();
}
});
</script>
@@ -147,4 +162,3 @@ onMounted(() => {
</Row>
</Card>
</template>
@@ -1,16 +1,13 @@
<script lang="ts" setup>
import type { ColumnsType } from 'ant-design-vue/es/table';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import { computed, onMounted, ref } from 'vue';
import { computed, ref } from 'vue';
import { useRoute } from 'vue-router';
import { Page } from '@vben/common-ui';
import { Card, Image, message, Table } from 'ant-design-vue';
import { Tabs } from 'ant-design-vue';
import ShopStatistics from './components/ShopStatistics.vue';
import OverviewTab from './tabs/OverviewTab.vue';
import ProductsTab from './tabs/ProductsTab.vue';
defineOptions({ name: 'ShopDetails' });
@@ -22,162 +19,23 @@ const shopId = computed(() => {
return id ? Number(id) : 0;
});
// 响应式数据
const loading = ref(false);
const productList = ref<ShopVO.ProductDetail[]>([]);
// 格式化金额
function formatCurrency(value: number): string {
return `¥${value.toLocaleString('zh-CN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}`;
}
// 处理商品列表更新(由 ShopStatistics 组件触发)
function handleProductListUpdate(products: ShopVO.ProductDetail[]) {
productList.value = products || [];
}
// 表格列配置
const columns: ColumnsType<ShopVO.ProductDetail> = [
{
title: '序号',
width: 80,
align: 'center',
customRender: ({ index }) => index + 1,
},
{
title: '商品主图',
width: 100,
align: 'center',
dataIndex: 'mainImage',
key: 'mainImage',
},
{
title: '商品名称',
dataIndex: 'productName',
key: 'productName',
ellipsis: true,
minWidth: 200,
},
{
title: '商品编码',
dataIndex: 'productCode',
key: 'productCode',
ellipsis: true,
minWidth: 150,
},
{
title: '销售额',
dataIndex: 'salesAmount',
key: 'salesAmount',
width: 150,
align: 'right',
customRender: ({ text }) => formatCurrency(text || 0),
},
{
title: '订单数',
dataIndex: 'orderCount',
key: 'orderCount',
width: 120,
align: 'right',
},
{
title: '客单价',
dataIndex: 'averageOrderValue',
key: 'averageOrderValue',
width: 150,
align: 'right',
customRender: ({ text }) => formatCurrency(text || 0),
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
width: 180,
},
];
// 初始化数据
onMounted(async () => {
if (shopId.value) {
// 等待 ShopStatistics 组件加载完成后,会自动触发 dateRangeChange 事件
// 这里不需要手动调用 fetchShopDetail
} else {
message.error('店铺ID不存在');
}
});
// 当前激活的 tab
const activeKey = ref('overview');
</script>
<template>
<Page auto-content-height content-class="flex flex-col">
<!-- 店铺统计信息 -->
<ShopStatistics
:shop-id="shopId"
@product-list-update="handleProductListUpdate"
/>
<!-- 商品列表表格 -->
<Card
title="商品详细信息"
:loading="loading"
<Tabs
v-model:active-key="activeKey"
class="flex min-h-0 flex-1 flex-col"
:body-style="{
display: 'flex',
flexDirection: 'column',
overflow: 'hidden',
flex: 1,
}"
:tab-bar-style="{ marginBottom: '16px' }"
>
<!-- 表格 -->
<div class="min-h-0 flex-1 overflow-auto">
<Table
:columns="columns"
:data-source="productList"
:loading="loading"
:pagination="false"
:scroll="{ x: 'max-content' }"
size="small"
bordered
row-key="productId"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'mainImage'">
<div
v-if="record.mainImage"
style="
display: flex;
justify-content: center;
align-items: center;
"
>
<Image
:src="record.mainImage"
:alt="record.productName"
:preview="false"
style="
width: 50px;
height: 50px;
object-fit: cover;
border-radius: 4px;
"
/>
</div>
<div
v-else
style="
display: flex;
justify-content: center;
align-items: center;
"
>
<span style="color: #999">暂无图片</span>
</div>
</template>
</template>
</Table>
</div>
</Card>
<Tabs.TabPane key="overview" tab="总览">
<OverviewTab :shop-id="shopId" />
</Tabs.TabPane>
<Tabs.TabPane key="products" tab="商品">
<ProductsTab :shop-id="shopId" />
</Tabs.TabPane>
</Tabs>
</Page>
</template>
@@ -0,0 +1,178 @@
<script lang="ts" setup>
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
import { onMounted, ref, watch } from 'vue';
import { Card, Col, DatePicker, message, Row, Space } from 'ant-design-vue';
import dayjs from 'dayjs';
import { getShopOverviewApi } from '#/api/ecommerce/shop';
import ChartCard from '../components/ChartCard.vue';
defineOptions({ name: 'OverviewTab' });
const props = defineProps<Props>();
interface Props {
shopId: number;
}
// 响应式数据
const loading = ref(false);
const overviewData = ref<null | ShopVO.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 fetchShopOverview() {
if (!props.shopId || !dateRange.value) return;
try {
loading.value = true;
const params: ShopDTO.StatisticsQuery = {
shopId: props.shopId,
startDate: dateRange.value[0].format('YYYY-MM-DD'),
endDate: dateRange.value[1].format('YYYY-MM-DD'),
};
const data = await getShopOverviewApi(params);
overviewData.value = data;
} catch (error) {
console.error('获取店铺总览失败:', error);
message.error('获取店铺总览失败');
} finally {
loading.value = false;
}
}
// 处理日期范围变化
function handleDateRangeChange() {
fetchShopOverview();
}
// 监听 shopId 变化
watch(
() => props.shopId,
(newShopId) => {
if (newShopId) {
fetchShopOverview();
}
},
);
// 初始化数据
onMounted(() => {
if (props.shopId) {
fetchShopOverview();
}
});
</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>
<!-- 图表展示 -->
<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"
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>
@@ -0,0 +1,210 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { ShopDTO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { computed, ref, watch } from 'vue';
import { Page } from '@vben/common-ui';
import { Image, message, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getShopProductPageApi } from '#/api/ecommerce/shop';
interface Props {
shopId: number;
}
defineOptions({ name: 'ProductsTab' });
const props = defineProps<Props>();
// 响应式数据
const loading = ref(false);
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
title: '序号',
},
{
title: '主图',
width: 60,
slots: { default: 'mainImage' },
},
{
field: 'name',
title: '商品名称',
minWidth: 200,
showOverflow: 'tooltip' as const,
},
{
field: 'productCode',
title: '商品编码',
minWidth: 150,
showOverflow: 'tooltip' as const,
},
{
title: '规格数量',
minWidth: 100,
slots: { default: 'specs' },
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
},
{
field: 'updateTime',
title: '更新时间',
minWidth: 180,
},
],
height: 'auto',
border: true,
stripe: true,
highlightHoverRow: true,
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
// 配置远程加载
proxyConfig: {
ajax: {
query: async ({ page }) => {
if (!props.shopId) {
return {
items: [],
total: 0,
};
}
try {
loading.value = true;
const params: PageQueryDTO<ShopDTO.ProductPageFilters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: props.shopId,
},
};
const data = await getShopProductPageApi(params);
return {
items: data.records,
total: data.total,
};
} catch (error) {
console.error('获取商品列表失败:', error);
message.error('获取商品列表失败');
return {
items: [],
total: 0,
};
} finally {
loading.value = false;
}
},
},
},
};
// 搜索表单配置
const formOptions = computed(() => ({
schema: [
{
component: 'Input',
componentProps: {
placeholder: '请输入商品名称',
},
fieldName: 'name',
label: '商品名称',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入商品编码',
},
fieldName: 'productCode',
label: '商品编码',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '商品列表',
});
// 监听 shopId 变化,刷新表格
watch(
() => props.shopId,
() => {
if (props.shopId && gridApi) {
gridApi.reload();
}
},
);
</script>
<template>
<Page auto-content-height content-class="flex flex-col">
<Grid :loading="loading">
<!-- 主图列 -->
<template #mainImage="{ row }: { row: any }">
<Image
v-if="row.mainImage"
:src="row.mainImage"
:alt="row.name"
width="60"
height="60"
style="object-fit: cover; border-radius: 4px"
:preview="true"
/>
<span v-else class="text-xs text-gray-400">暂无图片</span>
</template>
<!-- 规格数量列 -->
<template #specs="{ row }: { row: any }">
<Tag :color="(row.specs?.length || 0) > 0 ? 'blue' : 'default'">
{{ row.specs?.length || 0 }} 个规格
</Tag>
</template>
</Grid>
</Page>
</template>