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
@@ -1,5 +1,6 @@
<script lang="ts" setup>
import { h, ref } from 'vue';
import { h, ref, onUnmounted } from 'vue';
import dayjs from 'dayjs';
import { Page } from '@vben/common-ui';
import { Button, DatePicker, Form, Input, Modal, Select, Table, message } from 'ant-design-vue';
@@ -9,14 +10,16 @@ import {
deleteCompanyApi,
getCompanyPageApi,
updateCompanyApi,
type CompanyApi as CompanyApiType
} from '#/api/core/organization';
type CompanyVO,
type CompanyDTO
} from '#/api/org';
import type { PageQueryDTO } from '#/types/common';
defineOptions({ name: 'CompanyManagement' });
// 响应式数据
const loading = ref(false);
const companyList = ref<CompanyApiType.CompanyInfo[]>([]);
const companyList = ref<CompanyVO.CompanyInfoVO[]>([]);
const total = ref(0);
const current = ref(1);
const pageSize = ref(10);
@@ -33,7 +36,7 @@ const searchForm = ref({
});
// 表单数据
const formData = ref<CompanyApiType.CreateCompanyParams>({
const formData = ref({
name: '',
address: '',
contactPerson: '',
@@ -41,7 +44,7 @@ const formData = ref<CompanyApiType.CreateCompanyParams>({
email: '',
logo: '',
status: 1,
expireTime: '',
expireTime: null as any,
});
// 状态选项
@@ -82,12 +85,28 @@ const columns = [
key: 'email',
width: 200,
},
{
title: 'Logo',
dataIndex: 'logo',
key: 'logo',
width: 100,
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
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: 'status',
key: 'status',
width: 100,
customRender: ({ record }: { record: CompanyApiType.CompanyInfo }) => {
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
return h('span', {
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
}, record.status === 1 ? '正常' : '禁用');
@@ -98,6 +117,15 @@ const columns = [
dataIndex: 'expireTime',
key: 'expireTime',
width: 180,
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
if (!record.expireTime) {
return h('span', { style: { color: '#999' } }, '未设置');
}
const isExpired = record.expired;
return h('span', {
style: { color: isExpired ? '#ff4d4f' : '#52c41a' },
}, record.expireTime);
},
},
{
title: '创建时间',
@@ -110,44 +138,22 @@ const columns = [
key: 'action',
width: 200,
fixed: 'right' as const,
customRender: ({ record }: { record: CompanyApiType.CompanyInfo }) => {
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
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 fetchCompanyList() {
try {
loading.value = true;
const params = {
page: current.value,
size: pageSize.value,
filter: {
name: searchForm.value.name || undefined,
status: searchForm.value.status,
},
};
const data = await getCompanyPageApi(params);
companyList.value = data.records;
total.value = data.total;
} catch (error) {
console.error('获取公司列表失败:', error);
message.error('获取公司列表失败');
} finally {
loading.value = false;
}
}
// 处理搜索
function handleSearch() {
@@ -185,13 +191,13 @@ function handleAdd() {
email: '',
logo: '',
status: 1,
expireTime: '',
expireTime: null,
};
modalVisible.value = true;
}
// 处理编辑公司
function handleEdit(record: CompanyApiType.CompanyInfo) {
function handleEdit(record: CompanyVO.CompanyInfoVO) {
modalTitle.value = '编辑公司';
isEdit.value = true;
currentCompanyId.value = record.id;
@@ -203,18 +209,65 @@ function handleEdit(record: CompanyApiType.CompanyInfo) {
email: record.email || '',
logo: record.logo || '',
status: record.status,
expireTime: record.expireTime || '',
expireTime: record.expireTime ? dayjs(record.expireTime) : null,
};
modalVisible.value = true;
}
// 组件卸载标志
let isUnmounted = false;
// 组件卸载时设置标志
onUnmounted(() => {
isUnmounted = true;
});
// 获取公司列表
async function fetchCompanyList() {
if (isUnmounted) return;
try {
loading.value = true;
const params: PageQueryDTO<CompanyDTO.CompanyFiltersDTO> = {
page: current.value,
pageSize: pageSize.value,
filters: {
name: searchForm.value.name || undefined,
status: searchForm.value.status,
},
};
const data = await getCompanyPageApi(params);
if (isUnmounted) return;
companyList.value = data.records;
total.value = data.total;
} catch (error) {
if (isUnmounted) return;
console.error('获取公司列表失败:', error);
message.error('获取公司列表失败');
} finally {
if (!isUnmounted) {
loading.value = false;
}
}
}
// 处理删除公司
async function handleDelete(record: CompanyApiType.CompanyInfo) {
async function handleDelete(record: CompanyVO.CompanyInfoVO) {
try {
await deleteCompanyApi(record.id);
if (isUnmounted) return;
message.success('删除成功');
await fetchCompanyList();
} catch (error) {
if (isUnmounted) return;
console.error('删除公司失败:', error);
message.error('删除公司失败');
}
@@ -225,17 +278,31 @@ async function handleSubmit() {
try {
await formRef.value?.validate();
// 准备提交数据,转换日期格式
const submitData = {
...formData.value,
expireTime: formData.value.expireTime ? formData.value.expireTime.format('YYYY-MM-DD HH:mm:ss') : undefined,
};
if (isEdit.value && currentCompanyId.value) {
await updateCompanyApi(currentCompanyId.value, formData.value);
await updateCompanyApi(currentCompanyId.value, submitData);
if (isUnmounted) return;
message.success('更新成功');
} else {
await createCompanyApi(formData.value);
await createCompanyApi(submitData);
if (isUnmounted) return;
message.success('创建成功');
}
modalVisible.value = false;
await fetchCompanyList();
} catch (error) {
if (isUnmounted) return;
console.error('保存公司失败:', error);
message.error('保存公司失败');
}
@@ -261,16 +328,18 @@ fetchCompanyList();
<!-- 搜索表单 -->
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
<Form layout="inline" :model="searchForm">
<Form.Item label="公司名称" name="name">
<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"
/>
</Form.Item>
<Form.Item label="状态" name="status">
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
<Select
v-model:value="searchForm.status"
placeholder="请选择状态"
@@ -278,12 +347,12 @@ fetchCompanyList();
:options="statusOptions"
allow-clear
/>
</Form.Item>
<Form.Item>
</div>
<div style="display: flex; gap: 8px; align-items: end;">
<Button type="primary" @click="handleSearch">搜索</Button>
<Button @click="handleReset" class="ml-2">重置</Button>
</Form.Item>
</Form>
<Button @click="handleReset">重置</Button>
</div>
</div>
</div>
<!-- 数据表格 -->
@@ -328,19 +397,19 @@ fetchCompanyList();
<Input v-model:value="formData.contactPerson" placeholder="请输入联系人" />
</Form.Item>
<Form.Item label="联系电话" name="contactPhone">
<Form.Item label="联系电话" name="contactPhone" :rules="[{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码' }]">
<Input v-model:value="formData.contactPhone" placeholder="请输入联系电话" />
</Form.Item>
<Form.Item label="邮箱" name="email">
<Form.Item label="邮箱" name="email" :rules="[{ type: 'email', message: '请输入正确的邮箱地址' }]">
<Input v-model:value="formData.email" placeholder="请输入邮箱" />
</Form.Item>
<Form.Item label="Logo" name="logo">
<Form.Item label="Logo" name="logo" :rules="[{ type: 'url', message: '请输入正确的URL地址' }]">
<Input v-model:value="formData.logo" placeholder="请输入Logo地址" />
</Form.Item>
<Form.Item label="状态" name="status">
<Form.Item label="状态" name="status" :rules="[{ required: true, message: '请选择状态' }]">
<Select
v-model:value="formData.status"
placeholder="请选择状态"
@@ -9,14 +9,16 @@ import {
deleteDepartmentApi,
getDepartmentPageApi,
updateDepartmentApi,
type DepartmentApi as DepartmentApiType
} from '#/api/core/organization';
type DepartmentVO,
type DepartmentDTO
} from '#/api/org';
import type { PageQueryDTO } from '#/types/common';
defineOptions({ name: 'DepartmentManagement' });
// 响应式数据
const loading = ref(false);
const departmentList = ref<DepartmentApiType.DepartmentInfo[]>([]);
const departmentList = ref<DepartmentVO.DepartmentInfoVO[]>([]);
const total = ref(0);
const current = ref(1);
const pageSize = ref(10);
@@ -33,7 +35,7 @@ const searchForm = ref({
});
// 表单数据
const formData = ref<DepartmentApiType.CreateDepartmentParams>({
const formData = ref<DepartmentDTO.CreateDepartmentDTO>({
name: '',
parentId: undefined,
remark: '',
@@ -50,7 +52,7 @@ const statusOptions = [
const parentDepartmentOptions = computed(() => {
const options: Array<{ label: string; value: number | undefined }> = [{ label: '根部门', value: undefined }];
const addDepartmentOptions = (departments: DepartmentApiType.DepartmentInfo[], level = 0) => {
const addDepartmentOptions = (departments: DepartmentVO.DepartmentInfoVO[], level = 0) => {
departments.forEach(dept => {
const prefix = ' '.repeat(level);
options.push({
@@ -80,7 +82,7 @@ const columns = [
dataIndex: 'parentId',
key: 'parentId',
width: 150,
customRender: ({ record }: { record: DepartmentApiType.DepartmentInfo }) => {
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
if (!record.parentId) return '根部门';
const parent = findParentDepartment(departmentList.value, record.parentId);
return parent ? parent.name : '未知';
@@ -97,7 +99,7 @@ const columns = [
dataIndex: 'status',
key: 'status',
width: 100,
customRender: ({ record }: { record: DepartmentApiType.DepartmentInfo }) => {
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
return h('span', {
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
}, record.status === 1 ? '启用' : '禁用');
@@ -114,24 +116,24 @@ const columns = [
key: 'action',
width: 200,
fixed: 'right' as const,
customRender: ({ record }: { record: DepartmentApiType.DepartmentInfo }) => {
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
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: () => '删除' }),
]);
},
},
];
// 查找父部门
function findParentDepartment(departments: DepartmentApiType.DepartmentInfo[], parentId: number): DepartmentApiType.DepartmentInfo | null {
function findParentDepartment(departments: DepartmentVO.DepartmentInfoVO[], parentId: number): DepartmentVO.DepartmentInfoVO | null {
for (const dept of departments) {
if (dept.id === parentId) {
return dept;
@@ -148,10 +150,10 @@ function findParentDepartment(departments: DepartmentApiType.DepartmentInfo[], p
async function fetchDepartmentList() {
try {
loading.value = true;
const params = {
const params: PageQueryDTO<DepartmentDTO.DepartmentFiltersDTO> = {
page: current.value,
size: pageSize.value,
filter: {
pageSize: pageSize.value,
filters: {
name: searchForm.value.name || undefined,
status: searchForm.value.status,
},
@@ -205,7 +207,7 @@ function handleAdd() {
}
// 处理编辑部门
function handleEdit(record: DepartmentApiType.DepartmentInfo) {
function handleEdit(record: DepartmentVO.DepartmentInfoVO) {
modalTitle.value = '编辑部门';
isEdit.value = true;
currentDepartmentId.value = record.id;
@@ -219,7 +221,7 @@ function handleEdit(record: DepartmentApiType.DepartmentInfo) {
}
// 处理删除部门
async function handleDelete(record: DepartmentApiType.DepartmentInfo) {
async function handleDelete(record: DepartmentVO.DepartmentInfoVO) {
try {
await deleteDepartmentApi(record.id);
message.success('删除成功');
@@ -271,16 +273,18 @@ fetchDepartmentList();
<!-- 搜索表单 -->
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
<Form layout="inline" :model="searchForm">
<Form.Item label="部门名称" name="name">
<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"
/>
</Form.Item>
<Form.Item label="状态" name="status">
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
<Select
v-model:value="searchForm.status"
placeholder="请选择状态"
@@ -288,12 +292,12 @@ fetchDepartmentList();
:options="statusOptions"
allow-clear
/>
</Form.Item>
<Form.Item>
</div>
<div style="display: flex; gap: 8px; align-items: end;">
<Button type="primary" @click="handleSearch">搜索</Button>
<Button @click="handleReset" class="ml-2">重置</Button>
</Form.Item>
</Form>
<Button @click="handleReset">重置</Button>
</div>
</div>
</div>
<!-- 数据表格 -->
@@ -9,14 +9,16 @@ import {
deletePositionApi,
getPositionPageApi,
updatePositionApi,
type PositionApi as PositionApiType
} from '#/api/core/organization';
type PositionVO,
type PositionDTO
} from '#/api/org';
import type { PageQueryDTO } from '#/types/common';
defineOptions({ name: 'PositionManagement' });
// 响应式数据
const loading = ref(false);
const positionList = ref<PositionApiType.PositionInfo[]>([]);
const positionList = ref<PositionVO.PositionInfoVO[]>([]);
const total = ref(0);
const current = ref(1);
const pageSize = ref(10);
@@ -33,7 +35,7 @@ const searchForm = ref({
});
// 表单数据
const formData = ref<PositionApiType.CreatePositionParams>({
const formData = ref<PositionDTO.CreatePositionDTO>({
name: '',
code: '',
departmentId: undefined,
@@ -74,7 +76,7 @@ const columns = [
dataIndex: 'departmentId',
key: 'departmentId',
width: 150,
customRender: ({ record }: { record: PositionApiType.PositionInfo }) => {
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
if (!record.departmentId) return '-';
const dept = departmentOptions.value.find(d => d.value === record.departmentId);
return dept ? dept.label : '未知部门';
@@ -91,7 +93,7 @@ const columns = [
dataIndex: 'status',
key: 'status',
width: 100,
customRender: ({ record }: { record: PositionApiType.PositionInfo }) => {
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
return h('span', {
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
}, record.status === 1 ? '启用' : '禁用');
@@ -108,17 +110,17 @@ const columns = [
key: 'action',
width: 200,
fixed: 'right' as const,
customRender: ({ record }: { record: PositionApiType.PositionInfo }) => {
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
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: () => '删除' }),
]);
},
},
@@ -128,10 +130,10 @@ const columns = [
async function fetchPositionList() {
try {
loading.value = true;
const params = {
const params: PageQueryDTO<PositionDTO.PositionFiltersDTO> = {
page: current.value,
size: pageSize.value,
filter: {
pageSize: pageSize.value,
filters: {
name: searchForm.value.name || undefined,
status: searchForm.value.status,
},
@@ -186,7 +188,7 @@ function handleAdd() {
}
// 处理编辑岗位
function handleEdit(record: PositionApiType.PositionInfo) {
function handleEdit(record: PositionVO.PositionInfoVO) {
modalTitle.value = '编辑岗位';
isEdit.value = true;
currentPositionId.value = record.id;
@@ -201,7 +203,7 @@ function handleEdit(record: PositionApiType.PositionInfo) {
}
// 处理删除岗位
async function handleDelete(record: PositionApiType.PositionInfo) {
async function handleDelete(record: PositionVO.PositionInfoVO) {
try {
await deletePositionApi(record.id);
message.success('删除成功');
@@ -253,16 +255,18 @@ fetchPositionList();
<!-- 搜索表单 -->
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
<Form layout="inline" :model="searchForm">
<Form.Item label="岗位名称" name="name">
<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"
/>
</Form.Item>
<Form.Item label="状态" name="status">
</div>
<div>
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
<Select
v-model:value="searchForm.status"
placeholder="请选择状态"
@@ -270,12 +274,12 @@ fetchPositionList();
:options="statusOptions"
allow-clear
/>
</Form.Item>
<Form.Item>
</div>
<div style="display: flex; gap: 8px; align-items: end;">
<Button type="primary" @click="handleSearch">搜索</Button>
<Button @click="handleReset" class="ml-2">重置</Button>
</Form.Item>
</Form>
<Button @click="handleReset">重置</Button>
</div>
</div>
</div>
<!-- 数据表格 -->
@@ -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>