wip: 新增电商模块

This commit is contained in:
ah--desktop
2025-09-11 00:15:25 +08:00
parent a305dcdc3f
commit a79058f1f6
74 changed files with 3841 additions and 241 deletions
@@ -20,7 +20,20 @@
### 3. 店铺管理 (Shop Management)
- 店铺信息管理功能(开发中)
- **店铺信息管理**: 支持店铺的增删改查操作
- **平台管理**: 支持淘宝、京东、拼多多、天猫等主流电商平台
- **Logo管理**: 支持店铺Logo的URL设置和预览
- **搜索过滤**: 支持按店铺名称和平台进行搜索过滤
- **分页展示**: 支持分页展示店铺列表
### 4. 商品管理 (Product Management)
- **商品信息管理**: 支持商品的增删改查操作
- **商品编码管理**: 支持商品编码和SKU管理
- **价格管理**: 支持成本价设置和价格范围搜索
- **图片管理**: 支持商品主图URL设置和预览
- **高级搜索**: 支持按商品名称、编码、SKU和价格范围进行搜索过滤
- **分页展示**: 支持分页展示商品列表
## 使用流程
@@ -127,6 +140,8 @@ src/views/ecommerce/
│ └── index.vue # 数据分析页面
├── shop-management/
│ └── index.vue # 店铺管理页面
├── product-management/
│ └── index.vue # 商品管理页面
└── README.md # 说明文档
```
@@ -15,7 +15,7 @@
<!-- 字段映射表格 -->
<div class="border rounded-lg">
<VbenTable
<Table
:columns="mappingColumns"
:data-source="mappingData"
:pagination="false"
@@ -26,7 +26,7 @@
<!-- 数据预览 -->
<div v-if="previewData.length > 0">
<h4 class="text-md font-medium mb-3">映射后数据预览</h4>
<VbenTable
<Table
:columns="previewColumns"
:data-source="previewData.slice(0, 5)"
:pagination="false"
@@ -51,8 +51,8 @@
</template>
<script setup lang="ts">
import { ref, computed, watch } from 'vue'
import { message } from 'ant-design-vue'
import { ref, computed, watch, h } from 'vue'
import { message, Table } from 'ant-design-vue'
import { transformDataWithMapping, generateExportData, downloadJSON } from '#/utils/csv-utils'
// Props
@@ -114,7 +114,7 @@ const mappingColumns = [
key: 'standardField',
width: 200,
customRender: ({ record }: any) => {
return h('VbenSelect', {
return h('Select', {
value: record.standardField,
placeholder: '选择标准字段',
allowClear: true,
@@ -131,7 +131,7 @@ const mappingColumns = [
key: 'customName',
width: 200,
customRender: ({ record }: any) => {
return h('VbenInput', {
return h('Input', {
value: record.customName,
placeholder: '可选:自定义字段名',
onChange: (e: any) => {
@@ -198,8 +198,6 @@ const handleExport = () => {
emit('confirm', exportData)
}
// 导入h函数
import { h } from 'vue'
</script>
<style scoped>
@@ -0,0 +1,375 @@
<script lang="ts" setup>
import { h, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, Form, Input, InputNumber, Modal, Table, message } from 'ant-design-vue';
import {
createProductApi,
deleteProductApi,
getProductPageApi,
updateProductApi,
type ProductVO,
type ProductDTO
} from '#/api/ecommerce';
import type { PageQueryDTO } from '#/types/common';
defineOptions({ name: 'ProductManagement' });
// 响应式数据
const loading = ref(false);
const productList = ref<ProductVO.ProductInfoVO[]>([]);
const total = ref(0);
const current = ref(1);
const pageSize = ref(10);
const modalVisible = ref(false);
const modalTitle = ref('');
const isEdit = ref(false);
const currentProductId = ref<number | null>(null);
const formRef = ref();
// 搜索表单
const searchForm = ref({
name: '',
specCode: '',
skuCode: '',
minCostPrice: undefined as number | undefined,
maxCostPrice: undefined as number | undefined,
});
// 表单数据
const formData = ref<ProductDTO.CreateProductDTO>({
name: '',
specCode: '',
skuCode: '',
mainImage: '',
costPrice: 0,
});
// 表格列配置
const columns = [
{
title: '商品名称',
dataIndex: 'name',
key: 'name',
width: 200,
},
{
title: '商品编码',
dataIndex: 'specCode',
key: 'specCode',
width: 150,
},
{
title: '商品SKU',
dataIndex: 'skuCode',
key: 'skuCode',
width: 180,
},
{
title: '主图',
dataIndex: 'mainImage',
key: 'mainImage',
width: 100,
customRender: ({ record }: { record: ProductVO.ProductInfoVO }) => {
if (record.mainImage) {
return h('img', {
src: record.mainImage,
alt: record.name,
style: { width: '40px', height: '40px', objectFit: 'cover', borderRadius: '4px' },
});
}
return h('span', { style: { color: '#999' } }, '暂无图片');
},
},
{
title: '成本价',
dataIndex: 'costPrice',
key: 'costPrice',
width: 120,
customRender: ({ record }: { record: ProductVO.ProductInfoVO }) => {
return h('span', { style: { color: '#f50' } }, `¥${record.costPrice.toFixed(2)}`);
},
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
width: 180,
},
{
title: '更新时间',
dataIndex: 'updateTime',
key: 'updateTime',
width: 180,
},
{
title: '操作',
key: 'action',
width: 200,
fixed: 'right' as const,
customRender: ({ record }: { record: ProductVO.ProductInfoVO }) => {
return h('div', { style: 'display: flex; gap: 8px;' }, [
h(Button, {
size: 'small',
onClick: () => handleEdit(record),
}, { default: () => '编辑' }),
h(Button, {
size: 'small',
danger: true,
onClick: () => handleDelete(record),
}, { default: () => '删除' }),
]);
},
},
];
// 获取商品列表
async function fetchProductList() {
try {
loading.value = true;
const params: PageQueryDTO<ProductDTO.ProductFiltersDTO> = {
page: current.value,
pageSize: pageSize.value,
filters: {
name: searchForm.value.name || undefined,
specCode: searchForm.value.specCode || undefined,
skuCode: searchForm.value.skuCode || undefined,
minCostPrice: searchForm.value.minCostPrice,
maxCostPrice: searchForm.value.maxCostPrice,
},
};
const data = await getProductPageApi(params);
productList.value = data.records;
total.value = data.total;
} catch (error) {
console.error('获取商品列表失败:', error);
message.error('获取商品列表失败');
} finally {
loading.value = false;
}
}
// 处理搜索
function handleSearch() {
current.value = 1;
fetchProductList();
}
// 处理重置
function handleReset() {
searchForm.value = {
name: '',
specCode: '',
skuCode: '',
minCostPrice: undefined,
maxCostPrice: undefined,
};
current.value = 1;
fetchProductList();
}
// 处理分页变化
function handleTableChange(pagination: any) {
current.value = pagination.current;
pageSize.value = pagination.pageSize;
fetchProductList();
}
// 处理添加商品
function handleAdd() {
modalTitle.value = '添加商品';
isEdit.value = false;
currentProductId.value = null;
formData.value = {
name: '',
specCode: '',
skuCode: '',
mainImage: '',
costPrice: 0,
};
modalVisible.value = true;
}
// 处理编辑商品
function handleEdit(record: ProductVO.ProductInfoVO) {
modalTitle.value = '编辑商品';
isEdit.value = true;
currentProductId.value = record.id;
formData.value = {
name: record.name,
specCode: record.specCode || '',
skuCode: record.skuCode || '',
mainImage: record.mainImage || '',
costPrice: record.costPrice,
};
modalVisible.value = true;
}
// 处理删除商品
async function handleDelete(record: ProductVO.ProductInfoVO) {
try {
await deleteProductApi(record.id);
message.success('删除成功');
await fetchProductList();
} catch (error) {
console.error('删除商品失败:', error);
message.error('删除商品失败');
}
}
// 处理表单提交
async function handleSubmit() {
try {
await formRef.value?.validate();
if (isEdit.value && currentProductId.value) {
await updateProductApi(currentProductId.value, formData.value);
message.success('更新成功');
} else {
await createProductApi(formData.value);
message.success('创建成功');
}
modalVisible.value = false;
await fetchProductList();
} catch (error) {
console.error('保存商品失败:', error);
message.error('保存商品失败');
}
}
// 初始化
fetchProductList();
</script>
<template>
<Page title="商品管理">
<template #description>
<div class="text-foreground/80 mt-2">
管理商品信息,包括商品基本信息、编码、SKU和价格设置
</div>
</template>
<template #extra>
<Button type="primary" @click="handleAdd">
添加商品
</Button>
</template>
<!-- 搜索表单 -->
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">商品名称</label>
<Input
v-model:value="searchForm.name"
placeholder="请输入商品名称"
style="width: 200px;"
@press-enter="handleSearch"
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">商品编码</label>
<Input
v-model:value="searchForm.specCode"
placeholder="请输入商品编码"
style="width: 150px;"
@press-enter="handleSearch"
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">商品SKU</label>
<Input
v-model:value="searchForm.skuCode"
placeholder="请输入商品SKU"
style="width: 150px;"
@press-enter="handleSearch"
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">成本价范围</label>
<div style="display: flex; gap: 8px; align-items: center;">
<InputNumber
v-model:value="searchForm.minCostPrice"
placeholder="最小值"
style="width: 100px;"
:min="0"
:precision="2"
/>
<span>-</span>
<InputNumber
v-model:value="searchForm.maxCostPrice"
placeholder="最大值"
style="width: 100px;"
:min="0"
:precision="2"
/>
</div>
</div>
<div style="display: flex; gap: 8px; align-items: end;">
<Button type="primary" @click="handleSearch">搜索</Button>
<Button @click="handleReset">重置</Button>
</div>
</div>
</div>
<!-- 数据表格 -->
<Table
:columns="columns"
:data-source="productList"
:loading="loading"
:pagination="{
current: current,
pageSize: pageSize,
total: total,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
}"
row-key="id"
@change="handleTableChange"
/>
<!-- 添加/编辑模态框 -->
<Modal
v-model:open="modalVisible"
:title="modalTitle"
width="600px"
@ok="handleSubmit"
>
<Form
ref="formRef"
:model="formData"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 18 }"
>
<Form.Item label="商品名称" name="name" :rules="[{ required: true, message: '请输入商品名称' }]">
<Input v-model:value="formData.name" placeholder="请输入商品名称" />
</Form.Item>
<Form.Item label="商品编码" name="specCode">
<Input v-model:value="formData.specCode" placeholder="请输入商品编码" />
</Form.Item>
<Form.Item label="商品SKU" name="skuCode">
<Input v-model:value="formData.skuCode" placeholder="请输入商品SKU" />
</Form.Item>
<Form.Item label="主图URL" name="mainImage">
<Input v-model:value="formData.mainImage" placeholder="请输入主图URL" />
</Form.Item>
<Form.Item label="成本价" name="costPrice" :rules="[{ required: true, message: '请输入成本价' }]">
<InputNumber
v-model:value="formData.costPrice"
placeholder="请输入成本价"
style="width: 100%;"
:min="0"
:precision="2"
/>
</Form.Item>
</Form>
</Modal>
</Page>
</template>
@@ -1,15 +1,316 @@
<template>
<div class="p-6">
<VbenCard title="店铺管理">
<div class="text-center py-12">
<VbenIcon icon="lucide:store" class="w-16 h-16 mx-auto text-gray-400 mb-4" />
<h3 class="text-lg font-medium text-gray-700 mb-2">店铺管理功能</h3>
<p class="text-gray-500">此功能正在开发中,敬请期待...</p>
</div>
</VbenCard>
</div>
</template>
<script lang="ts" setup>
import { h, ref } from 'vue';
<script setup lang="ts">
// 店铺管理页面占位
import { Page } from '@vben/common-ui';
import { Button, Form, Input, Modal, Select, Table, message } from 'ant-design-vue';
import {
createShopApi,
deleteShopApi,
getShopPageApi,
updateShopApi,
type ShopVO ,
type ShopDTO
} from '#/api/ecommerce';
import type { PageQueryDTO } from '#/types/common';
defineOptions({ name: 'ShopManagement' });
// 响应式数据
const loading = ref(false);
const shopList = ref<ShopVO.ShopInfoVO[]>([]);
const total = ref(0);
const current = ref(1);
const pageSize = ref(10);
const modalVisible = ref(false);
const modalTitle = ref('');
const isEdit = ref(false);
const currentShopId = ref<number | null>(null);
const formRef = ref();
// 搜索表单
const searchForm = ref({
name: '',
platform: undefined as string | undefined,
});
// 表单数据
const formData = ref<ShopDTO.CreateShopDTO>({
name: '',
logo: '',
platform: '',
});
// 平台选项
const platformOptions = [
{ label: '淘宝', value: '淘宝' },
{ label: '京东', value: '京东' },
{ label: '拼多多', value: '拼多多' },
{ label: '天猫', value: '天猫' },
];
// 表格列配置
const columns = [
{
title: '店铺名称',
dataIndex: 'name',
key: 'name',
width: 200,
},
{
title: '平台',
dataIndex: 'platform',
key: 'platform',
width: 120,
},
{
title: 'Logo',
dataIndex: 'logo',
key: 'logo',
width: 200,
customRender: ({ record }: { record: ShopVO.ShopInfoVO }) => {
if (record.logo) {
return h('img', {
src: record.logo,
alt: record.name,
style: { width: '40px', height: '40px', objectFit: 'cover', borderRadius: '4px' },
});
}
return h('span', { style: { color: '#999' } }, '暂无Logo');
},
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
width: 180,
},
{
title: '更新时间',
dataIndex: 'updateTime',
key: 'updateTime',
width: 180,
},
{
title: '操作',
key: 'action',
width: 200,
fixed: 'right' as const,
customRender: ({ record }: { record: ShopVO.ShopInfoVO }) => {
return h('div', { style: 'display: flex; gap: 8px;' }, [
h(Button, {
size: 'small',
onClick: () => handleEdit(record),
}, { default: () => '编辑' }),
h(Button, {
size: 'small',
danger: true,
onClick: () => handleDelete(record),
}, { default: () => '删除' }),
]);
},
},
];
// 获取店铺列表
async function fetchShopList() {
try {
loading.value = true;
const params: PageQueryDTO<ShopDTO.ShopFiltersDTO> = {
page: current.value,
pageSize: pageSize.value,
filters: {
name: searchForm.value.name || undefined,
platform: searchForm.value.platform,
},
};
const data = await getShopPageApi(params);
shopList.value = data.records;
total.value = data.total;
} catch (error) {
console.error('获取店铺列表失败:', error);
message.error('获取店铺列表失败');
} finally {
loading.value = false;
}
}
// 处理搜索
function handleSearch() {
current.value = 1;
fetchShopList();
}
// 处理重置
function handleReset() {
searchForm.value = {
name: '',
platform: undefined,
};
current.value = 1;
fetchShopList();
}
// 处理分页变化
function handleTableChange(pagination: any) {
current.value = pagination.current;
pageSize.value = pagination.pageSize;
fetchShopList();
}
// 处理添加店铺
function handleAdd() {
modalTitle.value = '添加店铺';
isEdit.value = false;
currentShopId.value = null;
formData.value = {
name: '',
logo: '',
platform: '',
};
modalVisible.value = true;
}
// 处理编辑店铺
function handleEdit(record: ShopVO.ShopInfoVO) {
modalTitle.value = '编辑店铺';
isEdit.value = true;
currentShopId.value = record.id;
formData.value = {
name: record.name,
logo: record.logo || '',
platform: record.platform || '',
};
modalVisible.value = true;
}
// 处理删除店铺
async function handleDelete(record: ShopVO.ShopInfoVO) {
try {
await deleteShopApi(record.id);
message.success('删除成功');
await fetchShopList();
} catch (error) {
console.error('删除店铺失败:', error);
message.error('删除店铺失败');
}
}
// 处理表单提交
async function handleSubmit() {
try {
await formRef.value?.validate();
if (isEdit.value && currentShopId.value) {
await updateShopApi(currentShopId.value, formData.value);
message.success('更新成功');
} else {
await createShopApi(formData.value);
message.success('创建成功');
}
modalVisible.value = false;
await fetchShopList();
} catch (error) {
console.error('保存店铺失败:', error);
message.error('保存店铺失败');
}
}
// 初始化
fetchShopList();
</script>
<template>
<Page title="店铺管理">
<template #description>
<div class="text-foreground/80 mt-2">
管理电商店铺信息,包括店铺基本信息、平台信息和Logo设置
</div>
</template>
<template #extra>
<Button type="primary" @click="handleAdd">
添加店铺
</Button>
</template>
<!-- 搜索表单 -->
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">店铺名称</label>
<Input
v-model:value="searchForm.name"
placeholder="请输入店铺名称"
style="width: 200px;"
@press-enter="handleSearch"
/>
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">平台</label>
<Select
v-model:value="searchForm.platform"
placeholder="请选择平台"
style="width: 120px;"
:options="platformOptions"
allow-clear
/>
</div>
<div style="display: flex; gap: 8px; align-items: end;">
<Button type="primary" @click="handleSearch">搜索</Button>
<Button @click="handleReset">重置</Button>
</div>
</div>
</div>
<!-- 数据表格 -->
<Table
:columns="columns"
:data-source="shopList"
:loading="loading"
:pagination="{
current: current,
pageSize: pageSize,
total: total,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
}"
row-key="id"
@change="handleTableChange"
/>
<!-- 添加/编辑模态框 -->
<Modal
v-model:open="modalVisible"
:title="modalTitle"
width="600px"
@ok="handleSubmit"
>
<Form
ref="formRef"
:model="formData"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 18 }"
>
<Form.Item label="店铺名称" name="name" :rules="[{ required: true, message: '请输入店铺名称' }]">
<Input v-model:value="formData.name" placeholder="请输入店铺名称" />
</Form.Item>
<Form.Item label="平台" name="platform">
<Select
v-model:value="formData.platform"
placeholder="请选择平台"
:options="platformOptions"
allow-clear
/>
</Form.Item>
<Form.Item label="Logo URL" name="logo">
<Input v-model:value="formData.logo" placeholder="请输入Logo URL" />
</Form.Item>
</Form>
</Modal>
</Page>
</template>