mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:59: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:
-87
@@ -1,87 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.BatchSortImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.CreateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.ImportFieldDefFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.UpdateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.vo.ImportFieldDefVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.service.ImportFieldDefService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 导入字段定义管理控制器
|
||||
*/
|
||||
@Tag(name = "电商-导入字段定义管理", description = "导入字段定义的增删改查接口")
|
||||
@RestController
|
||||
@RequestMapping("/ec/import-field-def")
|
||||
public class ImportFieldDefController {
|
||||
|
||||
private final ImportFieldDefService importFieldDefService;
|
||||
|
||||
public ImportFieldDefController(ImportFieldDefService importFieldDefService) {
|
||||
this.importFieldDefService = importFieldDefService;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建导入字段定义", description = "创建新的导入字段定义")
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "data:import", description = "创建导入字段定义", allowSuper = true)
|
||||
public ApiResponse<ImportFieldDefVO> createImportFieldDef(@Valid @RequestBody CreateImportFieldDefDTO createImportFieldDefDTO) {
|
||||
ImportFieldDefVO importFieldDefVO = importFieldDefService.createImportFieldDef(createImportFieldDefDTO);
|
||||
return ApiResponse.success("导入字段定义创建成功", importFieldDefVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新导入字段定义", description = "更新现有导入字段定义")
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "data:import", description = "更新导入字段定义", allowSuper = true)
|
||||
public ApiResponse<ImportFieldDefVO> updateImportFieldDef(
|
||||
@Valid @RequestBody UpdateImportFieldDefDTO updateImportFieldDefDTO,
|
||||
@Parameter(description = "字段定义ID") @PathVariable Long id) {
|
||||
ImportFieldDefVO importFieldDefVO = importFieldDefService.updateImportFieldDef(updateImportFieldDefDTO, id);
|
||||
return ApiResponse.success("导入字段定义更新成功", importFieldDefVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除导入字段定义", description = "删除指定导入字段定义")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission(value = "data:import", description = "删除导入字段定义", allowSuper = true)
|
||||
public ApiResponse<Void> deleteImportFieldDef(
|
||||
@Parameter(description = "字段定义ID") @PathVariable Long id) {
|
||||
importFieldDefService.deleteImportFieldDef(id);
|
||||
return ApiResponse.success("导入字段定义删除成功");
|
||||
}
|
||||
|
||||
@Operation(summary = "获取指定类型所有字段列表", description = "根据导入类型获取所有字段定义列表")
|
||||
@GetMapping("/all/{type}")
|
||||
@RequirePermission(value = "data:import", description = "获取字段定义列表", allowSuper = true)
|
||||
public ApiResponse<List<ImportFieldDefVO>> getFieldDefsByType(
|
||||
@Parameter(description = "导入类型", example = "product") @PathVariable String type) {
|
||||
List<ImportFieldDefVO> fieldDefVOs = importFieldDefService.getFieldDefsByType(type);
|
||||
return ApiResponse.success("获取字段定义列表成功", fieldDefVOs);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询导入字段定义", description = "分页查询导入字段定义,支持条件过滤")
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "data:import", description = "查询导入字段定义列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<ImportFieldDefVO>> getImportFieldDefPage(
|
||||
@Valid @RequestBody PageQueryDTO<ImportFieldDefFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<ImportFieldDefVO> result = importFieldDefService.getImportFieldDefPage(pageQueryDTO);
|
||||
return ApiResponse.success("获取导入字段定义列表成功", result);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量排序导入字段定义", description = "批量更新导入字段定义的排序值")
|
||||
@PostMapping("/batch-sort")
|
||||
@RequirePermission(value = "data:import", description = "批量排序导入字段定义", allowSuper = true)
|
||||
public ApiResponse<Void> batchSortImportFieldDef(@Valid @RequestBody BatchSortImportFieldDefDTO batchSortDTO) {
|
||||
importFieldDefService.batchSortImportFieldDef(batchSortDTO);
|
||||
return ApiResponse.success("批量排序成功");
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.po.ImportFieldDefPO;
|
||||
|
||||
/**
|
||||
* 导入字段定义Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface ImportFieldDefMapper extends BaseMapper<ImportFieldDefPO> {
|
||||
}
|
||||
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量导入字段定义排序DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "批量导入字段定义排序DTO")
|
||||
public class BatchSortImportFieldDefDTO {
|
||||
|
||||
/**
|
||||
* 排序项列表
|
||||
*/
|
||||
@Schema(description = "排序项列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Valid
|
||||
@NotNull(message = "排序项列表不能为空")
|
||||
private List<FieldDefSortItem> sortItems;
|
||||
|
||||
/**
|
||||
* 字段定义排序项
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "字段定义排序项")
|
||||
public static class FieldDefSortItem {
|
||||
|
||||
/**
|
||||
* 字段定义ID
|
||||
*/
|
||||
@Schema(description = "字段定义ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "字段定义ID不能为空")
|
||||
private Long fieldDefId;
|
||||
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
@Schema(description = "排序值", example = "0", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "排序值不能为空")
|
||||
@Min(value = 0, message = "排序值不能小于0")
|
||||
private Integer sort;
|
||||
}
|
||||
}
|
||||
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建导入字段定义DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建导入字段定义DTO")
|
||||
public class CreateImportFieldDefDTO {
|
||||
|
||||
/**
|
||||
* 导入类型(product-商品 order-订单)
|
||||
*/
|
||||
@Schema(description = "导入类型", example = "product", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = {"product", "order"})
|
||||
@NotBlank(message = "导入类型不能为空")
|
||||
@Pattern(regexp = "^(product|order)$", message = "导入类型只能是product或order")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 数据库字段名,如 name
|
||||
*/
|
||||
@Schema(description = "数据库字段名", example = "name", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "字段名不能为空")
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 中文字段名,如 商品名称
|
||||
*/
|
||||
@Schema(description = "中文字段名", example = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "字段标签不能为空")
|
||||
private String fieldLabel;
|
||||
|
||||
/**
|
||||
* 文件字段名,如 商品名称
|
||||
*/
|
||||
@Schema(description = "文件字段名", example = "商品名称")
|
||||
private String fileFieldName;
|
||||
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
@Schema(description = "是否必填", example = "true")
|
||||
@NotNull(message = "是否必填不能为空")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
@Schema(description = "数据类型", example = "string", defaultValue = "string")
|
||||
private String dataType;
|
||||
}
|
||||
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 导入字段定义过滤DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "导入字段定义过滤DTO")
|
||||
public class ImportFieldDefFilterDTO {
|
||||
|
||||
/**
|
||||
* 导入类型(product-商品 order-订单)
|
||||
*/
|
||||
@Schema(description = "导入类型", example = "product", allowableValues = {"product", "order"})
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 字段名(模糊查询)
|
||||
*/
|
||||
@Schema(description = "字段名(模糊查询)", example = "name")
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 字段标签(模糊查询)
|
||||
*/
|
||||
@Schema(description = "字段标签(模糊查询)", example = "商品")
|
||||
private String fieldLabel;
|
||||
}
|
||||
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更新导入字段定义DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新导入字段定义DTO")
|
||||
public class UpdateImportFieldDefDTO {
|
||||
|
||||
/**
|
||||
* 中文字段名,如 商品名称
|
||||
*/
|
||||
@Schema(description = "中文字段名", example = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "字段标签不能为空")
|
||||
private String fieldLabel;
|
||||
|
||||
/**
|
||||
* 文件字段名,如 商品名称
|
||||
*/
|
||||
@Schema(description = "文件字段名", example = "商品名称")
|
||||
private String fileFieldName;
|
||||
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
@Schema(description = "是否必填", example = "true")
|
||||
@NotNull(message = "是否必填不能为空")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
@Schema(description = "数据类型", example = "string")
|
||||
private String dataType;
|
||||
}
|
||||
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 导入字段定义实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("ec_import_field_defs")
|
||||
public class ImportFieldDefPO {
|
||||
|
||||
/**
|
||||
* 字段定义ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 导入类型(product-商品 order-订单)
|
||||
*/
|
||||
@TableField("type")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 数据库字段名,如 name
|
||||
*/
|
||||
@TableField("field_name")
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 中文字段名,如 商品名称
|
||||
*/
|
||||
@TableField("field_label")
|
||||
private String fieldLabel;
|
||||
|
||||
/**
|
||||
* 文件字段名,如 商品名称
|
||||
*/
|
||||
@TableField("file_field_name")
|
||||
private String fileFieldName;
|
||||
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
@TableField("required")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField("sort")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
@TableField("data_type")
|
||||
private String dataType;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "created_at", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 导入字段定义VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "导入字段定义VO")
|
||||
public class ImportFieldDefVO {
|
||||
|
||||
/**
|
||||
* 字段定义ID
|
||||
*/
|
||||
@Schema(description = "字段定义ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 导入类型(product-商品 order-订单)
|
||||
*/
|
||||
@Schema(description = "导入类型", example = "product")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 数据库字段名,如 name
|
||||
*/
|
||||
@Schema(description = "数据库字段名", example = "name")
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 中文字段名,如 商品名称
|
||||
*/
|
||||
@Schema(description = "中文字段名", example = "商品名称")
|
||||
private String fieldLabel;
|
||||
|
||||
/**
|
||||
* 文件字段名,如 商品名称
|
||||
*/
|
||||
@Schema(description = "文件字段名", example = "商品名称")
|
||||
private String fileFieldName;
|
||||
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
@Schema(description = "是否必填", example = "true")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
@Schema(description = "数据类型", example = "string")
|
||||
private String dataType;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.BatchSortImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.CreateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.ImportFieldDefFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.UpdateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.po.ImportFieldDefPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.vo.ImportFieldDefVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 导入字段定义服务接口
|
||||
*/
|
||||
public interface ImportFieldDefService extends IService<ImportFieldDefPO> {
|
||||
|
||||
/**
|
||||
* 创建导入字段定义
|
||||
*
|
||||
* @param createImportFieldDefDTO 创建导入字段定义DTO
|
||||
* @return 导入字段定义VO
|
||||
*/
|
||||
ImportFieldDefVO createImportFieldDef(CreateImportFieldDefDTO createImportFieldDefDTO);
|
||||
|
||||
/**
|
||||
* 更新导入字段定义
|
||||
*
|
||||
* @param updateImportFieldDefDTO 更新导入字段定义DTO
|
||||
* @param id 字段定义ID
|
||||
* @return 导入字段定义VO
|
||||
*/
|
||||
ImportFieldDefVO updateImportFieldDef(UpdateImportFieldDefDTO updateImportFieldDefDTO, Long id);
|
||||
|
||||
/**
|
||||
* 删除导入字段定义
|
||||
*
|
||||
* @param id 字段定义ID
|
||||
*/
|
||||
void deleteImportFieldDef(Long id);
|
||||
|
||||
/**
|
||||
* 获取指定类型所有字段列表
|
||||
*
|
||||
* @param type 导入类型
|
||||
* @return 字段定义VO列表
|
||||
*/
|
||||
List<ImportFieldDefVO> getFieldDefsByType(String type);
|
||||
|
||||
/**
|
||||
* 分页查询导入字段定义
|
||||
*
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<ImportFieldDefVO> getImportFieldDefPage(PageQueryDTO<ImportFieldDefFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 批量排序导入字段定义
|
||||
*
|
||||
* @param batchSortDTO 批量排序DTO
|
||||
*/
|
||||
void batchSortImportFieldDef(BatchSortImportFieldDefDTO batchSortDTO);
|
||||
}
|
||||
|
||||
-204
@@ -1,204 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.mapper.ImportFieldDefMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.BatchSortImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.CreateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.ImportFieldDefFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.UpdateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.po.ImportFieldDefPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.vo.ImportFieldDefVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.service.ImportFieldDefService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 导入字段定义服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class ImportFieldDefServiceImpl extends ServiceImpl<ImportFieldDefMapper, ImportFieldDefPO> implements ImportFieldDefService {
|
||||
|
||||
/**
|
||||
* 创建导入字段定义
|
||||
*
|
||||
* @param createImportFieldDefDTO 创建导入字段定义DTO
|
||||
* @return 导入字段定义VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public ImportFieldDefVO createImportFieldDef(CreateImportFieldDefDTO createImportFieldDefDTO) {
|
||||
// 验证同一类型、同一字段名是否已存在(根据唯一索引)
|
||||
LambdaQueryWrapper<ImportFieldDefPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImportFieldDefPO::getType, createImportFieldDefDTO.getType())
|
||||
.eq(ImportFieldDefPO::getFieldName, createImportFieldDefDTO.getFieldName());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("该类型的字段定义已存在");
|
||||
}
|
||||
|
||||
// 创建导入字段定义
|
||||
ImportFieldDefPO importFieldDefPO = new ImportFieldDefPO();
|
||||
BeanUtils.copyProperties(createImportFieldDefDTO, importFieldDefPO);
|
||||
|
||||
// 设置默认数据类型
|
||||
if (!StringUtils.hasText(importFieldDefPO.getDataType())) {
|
||||
importFieldDefPO.setDataType("string");
|
||||
}
|
||||
|
||||
// 设置默认排序值
|
||||
if (importFieldDefPO.getSort() == null) {
|
||||
importFieldDefPO.setSort(0);
|
||||
}
|
||||
|
||||
this.save(importFieldDefPO);
|
||||
|
||||
// 转换为VO返回
|
||||
return convertToVO(importFieldDefPO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新导入字段定义
|
||||
*
|
||||
* @param updateImportFieldDefDTO 更新导入字段定义DTO
|
||||
* @param id 字段定义ID
|
||||
* @return 导入字段定义VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public ImportFieldDefVO updateImportFieldDef(UpdateImportFieldDefDTO updateImportFieldDefDTO, Long id) {
|
||||
// 验证字段定义是否存在
|
||||
ImportFieldDefPO existingFieldDef = this.getById(id);
|
||||
if (existingFieldDef == null) {
|
||||
throw new BusinessException("导入字段定义不存在");
|
||||
}
|
||||
|
||||
// 更新字段定义
|
||||
ImportFieldDefPO importFieldDefPO = new ImportFieldDefPO();
|
||||
BeanUtils.copyProperties(updateImportFieldDefDTO, importFieldDefPO);
|
||||
importFieldDefPO.setId(id);
|
||||
|
||||
this.updateById(importFieldDefPO);
|
||||
|
||||
// 转换为VO返回
|
||||
return convertToVO(this.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除导入字段定义
|
||||
*
|
||||
* @param id 字段定义ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteImportFieldDef(Long id) {
|
||||
// 验证字段定义是否存在
|
||||
ImportFieldDefPO existingFieldDef = this.getById(id);
|
||||
if (existingFieldDef == null) {
|
||||
throw new BusinessException("导入字段定义不存在");
|
||||
}
|
||||
|
||||
// 删除字段定义
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类型所有字段列表
|
||||
*
|
||||
* @param type 导入类型
|
||||
* @return 字段定义VO列表
|
||||
*/
|
||||
@Override
|
||||
public List<ImportFieldDefVO> getFieldDefsByType(String type) {
|
||||
LambdaQueryWrapper<ImportFieldDefPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImportFieldDefPO::getType, type)
|
||||
.orderByAsc(ImportFieldDefPO::getSort)
|
||||
.orderByAsc(ImportFieldDefPO::getFieldName);
|
||||
|
||||
List<ImportFieldDefPO> fieldDefPOs = this.list(wrapper);
|
||||
|
||||
return fieldDefPOs.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询导入字段定义
|
||||
*
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果VO
|
||||
*/
|
||||
@Override
|
||||
public PageResultVO<ImportFieldDefVO> getImportFieldDefPage(PageQueryDTO<ImportFieldDefFilterDTO> pageQueryDTO) {
|
||||
ImportFieldDefFilterDTO filter = pageQueryDTO.getFilters();
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<ImportFieldDefPO> wrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
if (filter != null) {
|
||||
if (StringUtils.hasText(filter.getType())) {
|
||||
wrapper.eq(ImportFieldDefPO::getType, filter.getType());
|
||||
}
|
||||
if (StringUtils.hasText(filter.getFieldName())) {
|
||||
wrapper.like(ImportFieldDefPO::getFieldName, filter.getFieldName());
|
||||
}
|
||||
if (StringUtils.hasText(filter.getFieldLabel())) {
|
||||
wrapper.like(ImportFieldDefPO::getFieldLabel, filter.getFieldLabel());
|
||||
}
|
||||
}
|
||||
|
||||
// 按类型、排序和字段名排序
|
||||
wrapper.orderByAsc(ImportFieldDefPO::getType)
|
||||
.orderByAsc(ImportFieldDefPO::getSort)
|
||||
.orderByAsc(ImportFieldDefPO::getFieldName);
|
||||
|
||||
// 分页查询
|
||||
Page<ImportFieldDefPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
IPage<ImportFieldDefPO> pageResult = this.page(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<ImportFieldDefVO> voList = pageResult.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量排序导入字段定义
|
||||
*
|
||||
* @param batchSortDTO 批量排序DTO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void batchSortImportFieldDef(BatchSortImportFieldDefDTO batchSortDTO) {
|
||||
for (BatchSortImportFieldDefDTO.FieldDefSortItem sortItem : batchSortDTO.getSortItems()) {
|
||||
ImportFieldDefPO fieldDefPO = this.getById(sortItem.getFieldDefId());
|
||||
if (fieldDefPO == null) {
|
||||
throw new BusinessException("字段定义不存在,ID:" + sortItem.getFieldDefId());
|
||||
}
|
||||
|
||||
fieldDefPO.setSort(sortItem.getSort());
|
||||
this.updateById(fieldDefPO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
private ImportFieldDefVO convertToVO(ImportFieldDefPO importFieldDefPO) {
|
||||
ImportFieldDefVO importFieldDefVO = new ImportFieldDefVO();
|
||||
BeanUtils.copyProperties(importFieldDefPO, importFieldDefVO);
|
||||
return importFieldDefVO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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