refactor: 重构电商模块目录结构

This commit is contained in:
ah--desktop
2025-12-07 23:02:48 +08:00
parent d3d9fd47d8
commit 407c650973
43 changed files with 669 additions and 9 deletions
@@ -0,0 +1,377 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type {
PromotionFeeDTO,
PromotionFeeVO,
} from '#/api/shop/promotion-fee/types';
import type { PageQueryDTO } from '#/types/common';
import { computed, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deletePromotionFeeApi,
getPromotionFeePageApi,
} from '#/api/shop/promotion-fee';
import PromotionFeeFormModal from './components/PromotionFeeFormModal.vue';
defineOptions({ name: 'PromotionFeeManagement' });
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
// 响应式数据
const loading = ref(false);
const formModalVisible = ref(false);
const currentPromotionFeeData = ref<null | PromotionFeeVO.Info>(null);
// 搜索表单
const searchForm = ref({
shopId: undefined as number | undefined,
feeTypeId: undefined as number | undefined,
platform: '',
feeDateStart: undefined as string | undefined,
feeDateEnd: undefined as string | undefined,
});
// 平台选项
const platformOptions = [
{ label: '淘宝', value: '淘宝' },
{ label: '京东', value: '京东' },
{ label: '拼多多', value: '拼多多' },
{ label: '天猫', value: '天猫' },
{ label: '抖音', value: '抖音' },
{ label: '快手', value: '快手' },
{ label: '其他', value: '其他' },
];
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
title: '序号',
},
{
field: 'feeName',
title: '推广费名称',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
field: 'shopName',
title: '店铺名称',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
field: 'feeTypeName',
title: '推广费类型',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
title: '平台',
minWidth: 'auto',
slots: { default: 'platform' },
},
{
field: 'campaignName',
title: '推广活动',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
title: '推广费金额',
minWidth: 'auto',
slots: { default: 'feeAmount' },
},
{
field: 'feeDate',
title: '发生日期',
minWidth: 'auto',
},
{
title: '操作',
minWidth: 'auto',
fixed: 'right' as const,
slots: { default: 'action' },
},
],
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 }) => {
try {
loading.value = true;
const params: PageQueryDTO<PromotionFeeDTO.Filters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: searchForm.value.shopId || undefined,
feeTypeId: searchForm.value.feeTypeId || undefined,
platform: searchForm.value.platform || undefined,
feeDateStart: searchForm.value.feeDateStart || undefined,
feeDateEnd: searchForm.value.feeDateEnd || undefined,
},
};
const data = await getPromotionFeePageApi(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: 'Select',
componentProps: {
placeholder: '请选择店铺',
// TODO: 这里需要从店铺API获取店铺列表
options: [],
allowClear: true,
},
fieldName: 'shopId',
label: '店铺',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择推广费类型',
// TODO: 这里需要从推广费类型API获取类型列表
options: [],
allowClear: true,
},
fieldName: 'feeTypeId',
label: '推广费类型',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择平台',
options: platformOptions,
allowClear: true,
},
fieldName: 'platform',
label: '平台',
},
{
component: 'DatePicker',
componentProps: {
placeholder: '开始日期',
style: { width: '100%' },
},
fieldName: 'feeDateStart',
label: '发生日期',
},
{
component: 'DatePicker',
componentProps: {
placeholder: '结束日期',
style: { width: '100%' },
},
fieldName: 'feeDateEnd',
label: '至',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// 刷新表格数据
function refreshTable() {
if (gridApi) {
gridApi.reload();
}
}
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '推广费管理',
});
// 处理新增
const handleAdd = () => {
currentPromotionFeeData.value = null;
formModalVisible.value = true;
};
// 处理编辑
const handleEdit = (record: PromotionFeeVO.Info) => {
currentPromotionFeeData.value = record;
formModalVisible.value = true;
};
// 处理删除
const handleDelete = async (id: number) => {
try {
await deletePromotionFeeApi(id);
message.success('删除成功');
refreshTable();
} catch {
message.error('删除失败');
}
};
// 处理表单成功
const handleFormSuccess = () => {
refreshTable();
};
// 格式化金额
const formatAmount = (amount: number) => {
return `¥${amount.toFixed(2)}`;
};
// 获取平台标签颜色
const getPlatformColor = (platform: string | undefined) => {
switch (platform) {
case '京东': {
return 'red';
}
case '天猫': {
return 'purple';
}
case '快手': {
return 'cyan';
}
case '抖音': {
return 'blue';
}
case '拼多多': {
return 'green';
}
case '淘宝': {
return 'orange';
}
default: {
return 'default';
}
}
};
</script>
<template>
<Page title="推广费管理" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理店铺推广费用记录,支持按店铺、类型、平台等维度查询和统计
</div>
</template>
<template #extra>
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon class="mr-2 h-4 w-4" />
新增推广费记录
</Button>
</Space>
</template>
<!-- 数据表格 -->
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
<span class="text-gray-500">
支持按店铺、类型、平台等维度查询推广费记录
</span>
</Space>
</template>
<!-- 平台列 -->
<template #platform="{ row }: { row: any }">
<Tag v-if="row.platform" :color="getPlatformColor(row.platform)">
{{ row.platform }}
</Tag>
<span v-else class="text-gray-400">-</span>
</template>
<!-- 推广费金额列 -->
<template #feeAmount="{ row }: { row: any }">
<span class="font-medium text-red-600">
{{ formatAmount(row.feeAmount) }}
</span>
</template>
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Button size="small" danger @click="handleDelete(row.id)">
删除
</Button>
</Space>
</template>
</Grid>
<!-- 表单弹窗 -->
<PromotionFeeFormModal
v-model:open="formModalVisible"
:promotion-fee-data="currentPromotionFeeData"
@success="handleFormSuccess"
@cancel="formModalVisible = false"
/>
</Page>
</template>