mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 14:29:19 +08:00
refactor: 删除动态导入字段定义模块(importfielddef),已由 OrderFieldVO 硬编码替代
- 删除后端 importfielddef 整个模块(controller/service/mapper/model) - 删除前端 import-field-def API 模块 - 删除前端 system/field 字段管理 CRUD 页面及路由 - ImportMappingFormModal 改用 getOrderFieldsApi
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
import type { ImportFieldDefDTO, ImportFieldDefVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 导入字段定义管理API
|
||||
*/
|
||||
|
||||
/**
|
||||
* 创建导入字段定义
|
||||
*/
|
||||
export async function createImportFieldDefApi(
|
||||
data: ImportFieldDefDTO.CreateImportFieldDefDTO,
|
||||
) {
|
||||
return requestClient.post<ImportFieldDefVO.ImportFieldDefInfoVO>(
|
||||
'/ec/import-field-def/create',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新导入字段定义
|
||||
*/
|
||||
export async function updateImportFieldDefApi(
|
||||
id: number,
|
||||
data: ImportFieldDefDTO.UpdateImportFieldDefDTO,
|
||||
) {
|
||||
return requestClient.put<ImportFieldDefVO.ImportFieldDefInfoVO>(
|
||||
`/ec/import-field-def/update/${id}`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除导入字段定义
|
||||
*/
|
||||
export async function deleteImportFieldDefApi(id: number) {
|
||||
return requestClient.delete(`/ec/import-field-def/delete/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类型所有字段列表
|
||||
*/
|
||||
export async function getFieldDefsByTypeApi(type: string) {
|
||||
return requestClient.get<ImportFieldDefVO.ImportFieldDefInfoVO[]>(
|
||||
`/ec/import-field-def/all/${type}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询导入字段定义
|
||||
*/
|
||||
export async function getImportFieldDefPageApi(
|
||||
params: PageQueryDTO<ImportFieldDefDTO.ImportFieldDefFilterDTO>,
|
||||
) {
|
||||
return requestClient.post<
|
||||
PageResultVO<ImportFieldDefVO.ImportFieldDefInfoVO>
|
||||
>('/ec/import-field-def/list', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量排序导入字段定义
|
||||
*/
|
||||
export async function batchSortImportFieldDefApi(
|
||||
data: ImportFieldDefDTO.BatchSortImportFieldDefDTO,
|
||||
) {
|
||||
return requestClient.post('/ec/import-field-def/batch-sort', data);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
/**
|
||||
* 导入字段定义模块API导出
|
||||
*/
|
||||
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -1,6 +0,0 @@
|
||||
/**
|
||||
* 导入字段定义模块类型定义导出
|
||||
*/
|
||||
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -1,61 +0,0 @@
|
||||
/**
|
||||
* 导入字段定义模块DTO类型定义
|
||||
*/
|
||||
|
||||
export namespace ImportFieldDefDTO {
|
||||
/** 创建导入字段定义参数 */
|
||||
export interface CreateImportFieldDefDTO {
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type: string;
|
||||
/** 数据库字段名,如 name */
|
||||
fieldName: string;
|
||||
/** 中文字段名,如 商品名称 */
|
||||
fieldLabel: string;
|
||||
/** 文件字段名,如 商品名称 */
|
||||
fileFieldName?: string;
|
||||
/** 是否必填 */
|
||||
required: boolean;
|
||||
/** 排序 */
|
||||
sort?: number;
|
||||
/** 数据类型(string, number, date等) */
|
||||
dataType?: string;
|
||||
}
|
||||
|
||||
/** 更新导入字段定义参数 */
|
||||
export interface UpdateImportFieldDefDTO {
|
||||
/** 中文字段名,如 商品名称 */
|
||||
fieldLabel: string;
|
||||
/** 文件字段名,如 商品名称 */
|
||||
fileFieldName?: string;
|
||||
/** 是否必填 */
|
||||
required: boolean;
|
||||
/** 排序 */
|
||||
sort?: number;
|
||||
/** 数据类型(string, number, date等) */
|
||||
dataType?: string;
|
||||
}
|
||||
|
||||
/** 导入字段定义过滤条件 */
|
||||
export interface ImportFieldDefFilterDTO {
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type?: string;
|
||||
/** 字段名(模糊查询) */
|
||||
fieldName?: string;
|
||||
/** 字段标签(模糊查询) */
|
||||
fieldLabel?: string;
|
||||
}
|
||||
|
||||
/** 批量导入字段定义排序参数 */
|
||||
export interface BatchSortImportFieldDefDTO {
|
||||
/** 排序项列表 */
|
||||
sortItems: FieldDefSortItem[];
|
||||
}
|
||||
|
||||
/** 字段定义排序项 */
|
||||
export interface FieldDefSortItem {
|
||||
/** 字段定义ID */
|
||||
fieldDefId: number;
|
||||
/** 排序值 */
|
||||
sort: number;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* 导入字段定义模块VO类型定义
|
||||
*/
|
||||
|
||||
export namespace ImportFieldDefVO {
|
||||
/** 导入字段定义信息 */
|
||||
export interface ImportFieldDefInfoVO {
|
||||
/** 字段定义ID */
|
||||
id: number;
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type: string;
|
||||
/** 数据库字段名,如 name */
|
||||
fieldName: string;
|
||||
/** 中文字段名,如 商品名称 */
|
||||
fieldLabel: string;
|
||||
/** 文件字段名,如 商品名称 */
|
||||
fileFieldName?: string;
|
||||
/** 是否必填 */
|
||||
required: boolean;
|
||||
/** 排序 */
|
||||
sort?: number;
|
||||
/** 数据类型(string, number, date等) */
|
||||
dataType?: string;
|
||||
/** 创建时间 */
|
||||
createdAt: string;
|
||||
/** 更新时间 */
|
||||
updatedAt: string;
|
||||
}
|
||||
}
|
||||
@@ -32,16 +32,6 @@ const routes: RouteRecordRaw[] = [
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: 'SystemPlatformField',
|
||||
path: '/platform-admin/field',
|
||||
component: () => import('#/views/system/field/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:database',
|
||||
title: '字段管理',
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'SystemPlatformAccountSuper',
|
||||
path: '/platform-admin/account-super',
|
||||
|
||||
+1
-3
@@ -10,7 +10,6 @@ import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, message, Select } from 'ant-design-vue';
|
||||
|
||||
import { getFieldDefsByTypeApi } from '#/api/ecommerce/import-field-def';
|
||||
import { getOrderFieldsApi } from '#/api/ecommerce/order';
|
||||
import {
|
||||
createImportMappingApi,
|
||||
@@ -73,8 +72,7 @@ async function fetchFieldDefs() {
|
||||
if (props.type === MappingTypeEnum.ORDER) {
|
||||
fieldDefs.value = (await getOrderFieldsApi()) || [];
|
||||
} else {
|
||||
const result = await getFieldDefsByTypeApi('product');
|
||||
fieldDefs.value = result || [];
|
||||
fieldDefs.value = [];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取字段定义失败:', error);
|
||||
|
||||
+1
-1
@@ -1179,7 +1179,7 @@ const handleCreateTask = async () => {
|
||||
});
|
||||
message.destroy();
|
||||
|
||||
// 构建字段映射 JSON(基于 ImportFieldDefInfoVO 结构)
|
||||
// 构建字段映射 JSON
|
||||
const mappingItems: FieldMappingItem[] = Object.values(fieldMappings.value)
|
||||
.filter((m) => m.mappedHeader)
|
||||
.map((m) => ({
|
||||
|
||||
@@ -1,273 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type {
|
||||
ImportFieldDefDTO,
|
||||
ImportFieldDefVO,
|
||||
} from '#/api/ecommerce/import-field-def/types';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Select,
|
||||
Switch,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createImportFieldDefApi,
|
||||
updateImportFieldDefApi,
|
||||
} from '#/api/ecommerce/import-field-def';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'FieldFormModal' });
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建Vben Modal实例
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
title: '字段管理',
|
||||
draggable: true,
|
||||
contentClass: 'px-6 py-4',
|
||||
onConfirm: handleSubmit,
|
||||
onCancel: close,
|
||||
onOpenChange: (isOpen: boolean) => {
|
||||
if (!isOpen) {
|
||||
resetForm();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const isEdit = ref(false);
|
||||
const currentFieldData = ref<ImportFieldDefVO.ImportFieldDefInfoVO | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
type: string;
|
||||
fieldName: string;
|
||||
fieldLabel: string;
|
||||
fileFieldName?: string;
|
||||
required: boolean;
|
||||
sort?: number;
|
||||
dataType?: string;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<FormData>({
|
||||
type: 'product',
|
||||
fieldName: '',
|
||||
fieldLabel: '',
|
||||
fileFieldName: '',
|
||||
required: false,
|
||||
sort: 0,
|
||||
dataType: 'string',
|
||||
});
|
||||
|
||||
// 字段类型选项
|
||||
const typeOptions = [
|
||||
{ label: '商品', value: 'product' },
|
||||
{ label: '订单', value: 'order' },
|
||||
];
|
||||
|
||||
// 数据类型选项
|
||||
const dataTypeOptions = [
|
||||
{ label: '字符串', value: 'string' },
|
||||
{ label: '数字', value: 'number' },
|
||||
{ label: '日期', value: 'date' },
|
||||
{ label: '布尔', value: 'boolean' },
|
||||
];
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
type: 'product',
|
||||
fieldName: '',
|
||||
fieldLabel: '',
|
||||
fileFieldName: '',
|
||||
required: false,
|
||||
sort: 0,
|
||||
dataType: 'string',
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function close() {
|
||||
modalApi.close();
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(
|
||||
edit: boolean,
|
||||
fieldData?: ImportFieldDefVO.ImportFieldDefInfoVO,
|
||||
) {
|
||||
isEdit.value = edit;
|
||||
currentFieldData.value = fieldData || null;
|
||||
|
||||
// 更新模态框标题
|
||||
modalApi.setState({
|
||||
title: edit ? '编辑字段' : '添加字段',
|
||||
});
|
||||
|
||||
resetForm();
|
||||
|
||||
if (edit && fieldData) {
|
||||
// 编辑模式,填充表单数据
|
||||
formData.value = {
|
||||
type: fieldData.type,
|
||||
fieldName: fieldData.fieldName,
|
||||
fieldLabel: fieldData.fieldLabel,
|
||||
fileFieldName: fieldData.fileFieldName ?? '',
|
||||
required: fieldData.required,
|
||||
sort: fieldData.sort ?? 0,
|
||||
dataType: fieldData.dataType ?? 'string',
|
||||
};
|
||||
}
|
||||
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
|
||||
// 设置模态框为loading状态
|
||||
modalApi.setState({ confirmLoading: true });
|
||||
|
||||
if (isEdit.value && currentFieldData.value) {
|
||||
// 更新字段
|
||||
const updateData: ImportFieldDefDTO.UpdateImportFieldDefDTO = {
|
||||
fieldLabel: formData.value.fieldLabel,
|
||||
fileFieldName: formData.value.fileFieldName,
|
||||
required: formData.value.required,
|
||||
sort: formData.value.sort,
|
||||
dataType: formData.value.dataType,
|
||||
};
|
||||
await updateImportFieldDefApi(currentFieldData.value.id, updateData);
|
||||
message.success('更新字段成功');
|
||||
} else {
|
||||
// 创建字段
|
||||
const createData: ImportFieldDefDTO.CreateImportFieldDefDTO = {
|
||||
type: formData.value.type,
|
||||
fieldName: formData.value.fieldName,
|
||||
fieldLabel: formData.value.fieldLabel,
|
||||
fileFieldName: formData.value.fileFieldName,
|
||||
required: formData.value.required,
|
||||
sort: formData.value.sort,
|
||||
dataType: formData.value.dataType,
|
||||
};
|
||||
await createImportFieldDefApi(createData);
|
||||
message.success('创建字段成功');
|
||||
}
|
||||
|
||||
close();
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('提交字段失败:', error);
|
||||
message.error('提交字段失败');
|
||||
} finally {
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({
|
||||
open,
|
||||
close,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
class="space-y-5"
|
||||
>
|
||||
<Form.Item
|
||||
v-if="!isEdit"
|
||||
label="导入类型"
|
||||
name="type"
|
||||
:rules="[{ required: true, message: '请选择导入类型' }]"
|
||||
>
|
||||
<Select
|
||||
v-model:value="formData.type"
|
||||
placeholder="请选择导入类型"
|
||||
:options="typeOptions"
|
||||
class="w-full"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
v-if="!isEdit"
|
||||
label="字段名"
|
||||
name="fieldName"
|
||||
:rules="[{ required: true, message: '请输入字段名' }]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.fieldName"
|
||||
placeholder="请输入字段名(如:name)"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="字段标签"
|
||||
name="fieldLabel"
|
||||
:rules="[{ required: true, message: '请输入字段标签' }]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.fieldLabel"
|
||||
placeholder="请输入字段标签(如:商品名称)"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="文件字段名" name="fileFieldName">
|
||||
<Input
|
||||
v-model:value="formData.fileFieldName"
|
||||
placeholder="请输入文件字段名(如:商品名称)"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="数据类型" name="dataType">
|
||||
<Select
|
||||
v-model:value="formData.dataType"
|
||||
placeholder="请选择数据类型"
|
||||
:options="dataTypeOptions"
|
||||
class="w-full"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="是否必填" name="required">
|
||||
<Switch
|
||||
v-model:checked="formData.required"
|
||||
checked-children="必填"
|
||||
un-checked-children="可选"
|
||||
class="w-12"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="排序" name="sort">
|
||||
<InputNumber
|
||||
v-model:value="formData.sort"
|
||||
placeholder="请输入排序"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -1,386 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type {
|
||||
ImportFieldDefDTO,
|
||||
ImportFieldDefVO,
|
||||
} from '#/api/ecommerce/import-field-def/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, onMounted, 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 {
|
||||
batchSortImportFieldDefApi,
|
||||
deleteImportFieldDefApi,
|
||||
getImportFieldDefPageApi,
|
||||
} from '#/api/ecommerce/import-field-def';
|
||||
|
||||
import FieldFormModal from './components/FieldFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'FieldManagement' });
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const fieldFormModalRef = ref();
|
||||
|
||||
// 字段类型选项
|
||||
const typeOptions = [
|
||||
{ label: '商品', value: 'product' },
|
||||
{ label: '订单', value: 'order' },
|
||||
];
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 60,
|
||||
title: '序号',
|
||||
dragSort: true, // 启用拖拽排序
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
title: '导入类型',
|
||||
minWidth: 100,
|
||||
slots: { default: 'type' },
|
||||
},
|
||||
{
|
||||
field: 'fieldName',
|
||||
title: '字段名',
|
||||
minWidth: 150,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'fieldLabel',
|
||||
title: '字段标签',
|
||||
minWidth: 150,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'dataType',
|
||||
title: '数据类型',
|
||||
minWidth: 100,
|
||||
slots: { default: 'dataType' },
|
||||
},
|
||||
{
|
||||
field: 'required',
|
||||
title: '是否必填',
|
||||
minWidth: 100,
|
||||
slots: { default: 'required' },
|
||||
},
|
||||
{
|
||||
field: 'sort',
|
||||
title: '排序',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'createdAt',
|
||||
title: '创建时间',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 150,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
rowConfig: {
|
||||
isHover: true,
|
||||
drag: true, // 启用行拖拽
|
||||
},
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
rowDragConfig: {
|
||||
isPeerDrag: true, // 启用同层级拖拽限制
|
||||
},
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
export: true,
|
||||
},
|
||||
data: [],
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page, form }: any) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<ImportFieldDefDTO.ImportFieldDefFilterDTO> =
|
||||
{
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
type: form?.type || undefined,
|
||||
fieldName: form?.fieldName || undefined,
|
||||
fieldLabel: form?.fieldLabel || undefined,
|
||||
},
|
||||
};
|
||||
const data = await getImportFieldDefPageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取字段列表失败:', error);
|
||||
message.error('获取字段列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择导入类型',
|
||||
options: typeOptions,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'type',
|
||||
label: '导入类型',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入字段名',
|
||||
},
|
||||
fieldName: 'fieldName',
|
||||
label: '字段名',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入字段标签',
|
||||
},
|
||||
fieldName: 'fieldLabel',
|
||||
label: '字段标签',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理添加字段
|
||||
function handleAdd() {
|
||||
fieldFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑字段
|
||||
function handleEdit(record: ImportFieldDefVO.ImportFieldDefInfoVO) {
|
||||
fieldFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除字段
|
||||
async function handleDelete(record: ImportFieldDefVO.ImportFieldDefInfoVO) {
|
||||
try {
|
||||
await deleteImportFieldDefApi(record.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除字段失败:', error);
|
||||
message.error('删除字段失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 防重复调用标志
|
||||
let isUpdating = false;
|
||||
|
||||
// 处理拖拽排序
|
||||
const handleDragSort = async (_params: any) => {
|
||||
// 防止重复调用
|
||||
if (isUpdating) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
isUpdating = true;
|
||||
|
||||
// 获取当前表格数据
|
||||
const tableDataResult = gridApi.grid.getTableData();
|
||||
const tableData = tableDataResult?.tableData || [];
|
||||
|
||||
// 构建排序数据,直接按表格中的顺序排序
|
||||
const sortItems: ImportFieldDefDTO.FieldDefSortItem[] = tableData.map(
|
||||
(item: ImportFieldDefVO.ImportFieldDefInfoVO, index: number) => ({
|
||||
fieldDefId: item.id,
|
||||
sort: index + 1, // 排序值从1开始
|
||||
}),
|
||||
);
|
||||
|
||||
// 调用排序接口
|
||||
await batchSortImportFieldDefApi({ sortItems });
|
||||
|
||||
// 排序成功后不需要重新加载数据,因为表格数据已经更新
|
||||
} catch (error: any) {
|
||||
console.error('拖拽排序失败:', error);
|
||||
if (error?.message) {
|
||||
message.error(error.message);
|
||||
} else {
|
||||
message.error('排序更新失败');
|
||||
}
|
||||
// 排序失败时重新加载数据,恢复原始状态
|
||||
gridApi.reload();
|
||||
} finally {
|
||||
isUpdating = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 获取类型标签
|
||||
function getTypeLabel(type: string) {
|
||||
const typeMap: Record<string, string> = {
|
||||
product: '商品',
|
||||
order: '订单',
|
||||
};
|
||||
return typeMap[type] || type;
|
||||
}
|
||||
|
||||
// 获取类型颜色
|
||||
function getTypeColor(type: string) {
|
||||
const colorMap: Record<string, string> = {
|
||||
product: 'blue',
|
||||
order: 'green',
|
||||
};
|
||||
return colorMap[type] || 'default';
|
||||
}
|
||||
|
||||
// 获取数据类型标签
|
||||
function getDataTypeLabel(dataType?: string) {
|
||||
if (!dataType) return '-';
|
||||
const typeMap: Record<string, string> = {
|
||||
string: '字符串',
|
||||
number: '数字',
|
||||
date: '日期',
|
||||
boolean: '布尔',
|
||||
};
|
||||
return typeMap[dataType] || dataType;
|
||||
}
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '字段管理',
|
||||
gridEvents: {
|
||||
// 拖拽排序事件
|
||||
rowDragend: handleDragSort,
|
||||
} as any,
|
||||
});
|
||||
|
||||
// 添加Grid组件的ref
|
||||
const gridRef = ref();
|
||||
|
||||
// 在组件挂载后绑定拖拽事件
|
||||
onMounted(() => {
|
||||
// 延迟绑定,确保Grid组件完全初始化
|
||||
setTimeout(() => {
|
||||
if (gridRef.value) {
|
||||
// 尝试直接绑定VxeTable的拖拽事件
|
||||
const vxeGrid = gridRef.value;
|
||||
if (vxeGrid && vxeGrid.$refs && vxeGrid.$refs.grid) {
|
||||
const grid = vxeGrid.$refs.grid;
|
||||
// 绑定拖拽事件
|
||||
grid.on('row-drag-end', (params: any) => {
|
||||
handleDragSort(params);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="字段管理" auto-content-height>
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid ref="gridRef" :loading="loading">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加字段
|
||||
</Button>
|
||||
<div class="text-sm text-gray-500">💡 提示:可直接拖拽行进行排序</div>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 导入类型列 -->
|
||||
<template #type="{ row }: { row: any }">
|
||||
<Tag :color="getTypeColor(row.type)">
|
||||
{{ getTypeLabel(row.type) }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 数据类型列 -->
|
||||
<template #dataType="{ row }: { row: any }">
|
||||
<Tag>{{ getDataTypeLabel(row.dataType) }}</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 是否必填列 -->
|
||||
<template #required="{ row }: { row: any }">
|
||||
<Tag :color="row.required ? 'red' : 'default'">
|
||||
{{ row.required ? '必填' : '可选' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)">
|
||||
<EditIcon class="h-3 w-3" />
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个字段吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger>
|
||||
<TrashIcon class="h-3 w-3" />
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 字段表单模态框 -->
|
||||
<FieldFormModal ref="fieldFormModalRef" @success="handleModalSuccess" />
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user