mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 15:49:20 +08:00
1. 数据库菜单添加字段映射模板(ID=36)和订单状态映射模板(ID=37) 2. 前端新增字段映射模板管理页面 /config-management/field-mapping 3. 前端新增订单状态映射模板管理页面 /config-management/order-status-mapping 4. 新增共享表单组件 ImportMappingFormModal,支持编辑两种映射模板 5. 后端已有完整 CRUD 接口,无需额外开发
165 lines
4.5 KiB
Vue
165 lines
4.5 KiB
Vue
<script setup lang="ts">
|
||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||
import type { ImportMappingVO } from '#/api/ecommerce/import-mapping';
|
||
|
||
import { ref } from 'vue';
|
||
|
||
import { Page } from '@vben/common-ui';
|
||
import { createIconifyIcon } from '@vben/icons';
|
||
|
||
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||
|
||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||
import {
|
||
deleteImportMappingApi,
|
||
getImportMappingPageApi,
|
||
} from '#/api/ecommerce/import-mapping';
|
||
import {
|
||
ImportMappingType,
|
||
} from '#/api/ecommerce/import-mapping/types/types.enum';
|
||
|
||
import ImportMappingFormModal from '../import-mapping/components/ImportMappingFormModal.vue';
|
||
|
||
defineOptions({ name: 'FieldMappingConfig' });
|
||
|
||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||
|
||
const loading = ref(false);
|
||
const formModalRef = ref();
|
||
|
||
const gridOptions: VxeGridProps<any> = {
|
||
columns: [
|
||
{ type: 'seq', width: 80, title: '序号' },
|
||
{ field: 'name', title: '模板名称', minWidth: 'auto', showOverflow: 'tooltip' },
|
||
{ field: 'type', title: '类型', width: 120, slots: { default: 'type' } },
|
||
{
|
||
title: '映射字段数',
|
||
width: 120,
|
||
slots: { default: 'mappingCount' },
|
||
},
|
||
{ field: 'createTime', title: '创建时间', width: 180 },
|
||
{ field: 'updateTime', title: '更新时间', width: 180 },
|
||
{ title: '操作', width: 160, fixed: 'right', 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: false },
|
||
proxyConfig: {
|
||
ajax: {
|
||
query: async () => {
|
||
try {
|
||
loading.value = true;
|
||
const result = await getImportMappingPageApi({
|
||
page: 1,
|
||
pageSize: 100,
|
||
filters: { type: ImportMappingType.ORDER },
|
||
});
|
||
return { items: result.records || [], total: result.total || 0 };
|
||
} catch (error) {
|
||
message.error('获取字段映射模板列表失败');
|
||
return { items: [], total: 0 };
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
},
|
||
},
|
||
},
|
||
};
|
||
|
||
const [Grid, gridApi] = useVbenVxeGrid({ gridOptions, showSearchForm: false, tableTitle: '字段映射模板' });
|
||
|
||
function refresh() {
|
||
gridApi?.reload();
|
||
}
|
||
|
||
function handleAdd() {
|
||
formModalRef.value?.open(true);
|
||
}
|
||
|
||
function handleEdit(row: ImportMappingVO.ImportMappingInfoVO) {
|
||
formModalRef.value?.open(false, row);
|
||
}
|
||
|
||
async function handleDelete(row: ImportMappingVO.ImportMappingInfoVO) {
|
||
try {
|
||
await deleteImportMappingApi(row.id);
|
||
message.success('删除成功');
|
||
refresh();
|
||
} catch (error) {
|
||
message.error('删除失败');
|
||
}
|
||
}
|
||
|
||
function getMappingCount(mapping: string): number {
|
||
try {
|
||
const arr = JSON.parse(mapping);
|
||
return Array.isArray(arr) ? arr.length : 0;
|
||
} catch {
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
function getTypeName(type: ImportMappingType): string {
|
||
const map: Record<string, string> = {
|
||
[ImportMappingType.ORDER]: '订单字段',
|
||
[ImportMappingType.ORDER_STATUS]: '订单状态',
|
||
[ImportMappingType.PRODUCT]: '商品字段',
|
||
};
|
||
return map[type] || type;
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<Page title="字段映射模板" auto-content-height>
|
||
<template #description>
|
||
<div class="text-foreground/80 mt-2">
|
||
管理订单导入时的字段映射模板,支持创建、编辑和删除
|
||
</div>
|
||
</template>
|
||
|
||
<Grid :loading="loading">
|
||
<template #toolbar-tools>
|
||
<Space>
|
||
<Button type="primary" @click="handleAdd">
|
||
<PlusIcon />
|
||
新建模板
|
||
</Button>
|
||
</Space>
|
||
</template>
|
||
|
||
<template #type="{ row }: { row: ImportMappingVO.ImportMappingInfoVO }">
|
||
<Tag color="blue">{{ getTypeName(row.type) }}</Tag>
|
||
</template>
|
||
|
||
<template #mappingCount="{ row }: { row: ImportMappingVO.ImportMappingInfoVO }">
|
||
<Tag color="green">{{ getMappingCount(row.mapping) }} 个字段</Tag>
|
||
</template>
|
||
|
||
<template #action="{ row }: { row: ImportMappingVO.ImportMappingInfoVO }">
|
||
<Space>
|
||
<Button size="small" @click="handleEdit(row)">编辑</Button>
|
||
<Popconfirm title="确定删除该模板?" @confirm="handleDelete(row)">
|
||
<Button size="small" danger>删除</Button>
|
||
</Popconfirm>
|
||
</Space>
|
||
</template>
|
||
</Grid>
|
||
|
||
<ImportMappingFormModal
|
||
ref="formModalRef"
|
||
:type="ImportMappingType.ORDER"
|
||
@success="refresh"
|
||
/>
|
||
</Page>
|
||
</template>
|