mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:19:19 +08:00
feat(config): 新增字段映射模板和订单状态映射模板管理页面
1. 数据库菜单添加字段映射模板(ID=36)和订单状态映射模板(ID=37) 2. 前端新增字段映射模板管理页面 /config-management/field-mapping 3. 前端新增订单状态映射模板管理页面 /config-management/order-status-mapping 4. 新增共享表单组件 ImportMappingFormModal,支持编辑两种映射模板 5. 后端已有完整 CRUD 接口,无需额外开发
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
<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>
|
||||
+267
@@ -0,0 +1,267 @@
|
||||
<script setup lang="ts">
|
||||
import type { ImportFieldDefVO } from '#/api/ecommerce/import-field-def';
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
|
||||
import type { ImportMappingType } from '#/api/ecommerce/import-mapping/types/types.enum';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Form,
|
||||
Input,
|
||||
message,
|
||||
Select,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createImportMappingApi,
|
||||
updateImportMappingApi,
|
||||
} from '#/api/ecommerce/import-mapping';
|
||||
import {
|
||||
getFieldDefsByTypeApi,
|
||||
} from '#/api/ecommerce/import-field-def';
|
||||
import { getAllOrderStatusListApi } from '#/api/ecommerce/order-status';
|
||||
|
||||
import {
|
||||
ImportMappingType as MappingTypeEnum,
|
||||
} from '#/api/ecommerce/import-mapping/types/types.enum';
|
||||
|
||||
defineOptions({ name: 'ImportMappingFormModal' });
|
||||
|
||||
// Props: 传入模板类型
|
||||
const props = defineProps<{
|
||||
type: ImportMappingType;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
}>();
|
||||
|
||||
// 弹窗
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[700px]',
|
||||
showCancelButton: true,
|
||||
showConfirmButton: true,
|
||||
onConfirm: handleConfirm,
|
||||
onCancel() {
|
||||
resetForm();
|
||||
modalApi.close();
|
||||
},
|
||||
});
|
||||
|
||||
// 状态
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const editId = ref<number | undefined>();
|
||||
const templateName = ref('');
|
||||
|
||||
// 字段映射相关(ORDER 类型)
|
||||
interface FieldMappingItem {
|
||||
fieldName: string;
|
||||
fieldLabel: string;
|
||||
fileFieldName?: string;
|
||||
required: boolean;
|
||||
}
|
||||
const fieldDefs = ref<ImportFieldDefVO.ImportFieldDefInfoVO[]>([]);
|
||||
const fieldMappings = ref<Record<string, string>>({});
|
||||
|
||||
// 订单状态映射相关(ORDER_STATUS 类型)
|
||||
interface StatusMappingItem {
|
||||
csvStatus: string;
|
||||
mappedStatusId: number;
|
||||
}
|
||||
const orderStatusList = ref<OrderStatusVO.Info[]>([]);
|
||||
const statusMappings = ref<StatusMappingItem[]>([]);
|
||||
|
||||
// 获取字段定义(仅 ORDER 类型)
|
||||
async function fetchFieldDefs() {
|
||||
try {
|
||||
const typeStr = props.type === MappingTypeEnum.ORDER ? 'order' : 'product';
|
||||
const result = await getFieldDefsByTypeApi(typeStr);
|
||||
fieldDefs.value = result || [];
|
||||
} catch (error) {
|
||||
console.error('获取字段定义失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单状态列表(仅 ORDER_STATUS 类型)
|
||||
async function fetchOrderStatuses() {
|
||||
try {
|
||||
const result = await getAllOrderStatusListApi();
|
||||
orderStatusList.value = result || [];
|
||||
} catch (error) {
|
||||
console.error('获取订单状态列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 打开弹窗
|
||||
async function open(isNew: boolean, record?: ImportMappingVO.ImportMappingInfoVO) {
|
||||
isEdit.value = !isNew;
|
||||
editId.value = record?.id;
|
||||
modalApi.open();
|
||||
|
||||
if (props.type === MappingTypeEnum.ORDER_STATUS) {
|
||||
await fetchOrderStatuses();
|
||||
} else {
|
||||
await fetchFieldDefs();
|
||||
}
|
||||
|
||||
if (isNew) {
|
||||
// 新建:初始化空映射
|
||||
templateName.value = '';
|
||||
if (props.type === MappingTypeEnum.ORDER_STATUS) {
|
||||
statusMappings.value = [];
|
||||
} else {
|
||||
fieldMappings.value = {};
|
||||
}
|
||||
} else if (record) {
|
||||
// 编辑:解析现有映射
|
||||
templateName.value = record.name;
|
||||
try {
|
||||
const mappingArr = JSON.parse(record.mapping);
|
||||
if (props.type === MappingTypeEnum.ORDER_STATUS) {
|
||||
statusMappings.value = mappingArr || [];
|
||||
} else {
|
||||
const mapping: Record<string, string> = {};
|
||||
(mappingArr || []).forEach((item: FieldMappingItem) => {
|
||||
mapping[item.fieldName] = item.fileFieldName || '';
|
||||
});
|
||||
fieldMappings.value = mapping;
|
||||
}
|
||||
} catch {
|
||||
if (props.type === MappingTypeEnum.ORDER_STATUS) {
|
||||
statusMappings.value = [];
|
||||
} else {
|
||||
fieldMappings.value = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
templateName.value = '';
|
||||
fieldMappings.value = {};
|
||||
statusMappings.value = [];
|
||||
fieldDefs.value = [];
|
||||
orderStatusList.value = [];
|
||||
}
|
||||
|
||||
// 确认保存
|
||||
async function handleConfirm() {
|
||||
if (!templateName.value.trim()) {
|
||||
message.warning('请输入模板名称');
|
||||
return;
|
||||
}
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
let mappingJson = '[]';
|
||||
if (props.type === MappingTypeEnum.ORDER_STATUS) {
|
||||
// 过滤掉未映射的
|
||||
const validMappings = statusMappings.value.filter((m) => m.mappedStatusId);
|
||||
mappingJson = JSON.stringify(validMappings);
|
||||
} else {
|
||||
const items: FieldMappingItem[] = fieldDefs.value
|
||||
.filter((f) => fieldMappings.value[f.fieldName])
|
||||
.map((f) => ({
|
||||
fieldName: f.fieldName,
|
||||
fieldLabel: f.fieldLabel,
|
||||
fileFieldName: fieldMappings.value[f.fieldName],
|
||||
required: f.required,
|
||||
}));
|
||||
mappingJson = JSON.stringify(items);
|
||||
}
|
||||
|
||||
if (isEdit.value && editId.value) {
|
||||
await updateImportMappingApi(editId.value, {
|
||||
name: templateName.value.trim(),
|
||||
mapping: mappingJson,
|
||||
});
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createImportMappingApi({
|
||||
type: props.type,
|
||||
name: templateName.value.trim(),
|
||||
mapping: mappingJson,
|
||||
});
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
resetForm();
|
||||
modalApi.close();
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '保存失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :loading="loading" :title="isEdit ? '编辑映射模板' : '新建映射模板'" :confirm-text="isEdit ? '保存' : '创建'">
|
||||
<Form :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
|
||||
<Form.Item label="模板名称" required>
|
||||
<Input
|
||||
v-model:value="templateName"
|
||||
placeholder="请输入模板名称"
|
||||
:maxlength="50"
|
||||
show-count
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<!-- 订单状态映射编辑 -->
|
||||
<Form.Item v-if="type === MappingTypeEnum.ORDER_STATUS" label="状态映射" :wrapper-col="{ span: 20 }">
|
||||
<div class="max-h-[400px] overflow-y-auto space-y-2">
|
||||
<div
|
||||
v-for="(item, idx) in statusMappings"
|
||||
:key="idx"
|
||||
class="flex items-center space-x-2 rounded border p-2"
|
||||
>
|
||||
<span class="w-[200px] truncate text-gray-600">{{ item.csvStatus }}</span>
|
||||
<span class="text-gray-400">→</span>
|
||||
<Select
|
||||
v-model:value="item.mappedStatusId"
|
||||
placeholder="选择订单状态"
|
||||
class="flex-1"
|
||||
show-search
|
||||
allow-clear
|
||||
:options="orderStatusList.map((s) => ({ label: s.statusName, value: s.id }))"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="statusMappings.length === 0" class="py-4 text-center text-gray-400">
|
||||
暂无映射数据
|
||||
</div>
|
||||
</div>
|
||||
</Form.Item>
|
||||
|
||||
<!-- 字段映射编辑(只读展示) -->
|
||||
<Form.Item v-else label="字段映射" :wrapper-col="{ span: 20 }">
|
||||
<div class="max-h-[400px] overflow-y-auto space-y-2">
|
||||
<div
|
||||
v-for="field in fieldDefs"
|
||||
:key="field.id"
|
||||
class="flex items-center space-x-2 rounded border p-2"
|
||||
:class="{ 'border-red-200 bg-red-50': field.required && !fieldMappings[field.fieldName] }"
|
||||
>
|
||||
<span class="w-[140px]">
|
||||
{{ field.fieldLabel }}
|
||||
<span v-if="field.required" class="text-red-500">*</span>
|
||||
</span>
|
||||
<Input
|
||||
v-model:value="fieldMappings[field.fieldName]"
|
||||
placeholder="CSV列名(如:商品名称)"
|
||||
class="flex-1"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
<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: 'OrderStatusMappingConfig' });
|
||||
|
||||
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_STATUS },
|
||||
});
|
||||
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="orange">{{ 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_STATUS"
|
||||
@success="refresh"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user