Files
ecom-dmb/ecom-dmb-frontend/apps/web-antd/src/views/config/management/field-mapping/index.vue
T

174 lines
4.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<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 {
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 {
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>