mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
wip: 数据导入
This commit is contained in:
+9
@@ -9,6 +9,7 @@ import top.xyquan.ecomdmbbackend.common.annotation.RequireRole;
|
||||
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.model.dto.importfielddef.BatchSortImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.CreateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.ImportFieldDefFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.UpdateImportFieldDefDTO;
|
||||
@@ -75,5 +76,13 @@ public class ImportFieldDefController {
|
||||
PageResultVO<ImportFieldDefVO> result = importFieldDefService.getImportFieldDefPage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量排序导入字段定义", description = "批量更新导入字段定义的排序值")
|
||||
@PostMapping("/batch-sort")
|
||||
@RequireRole(description = "批量排序导入字段定义", allowUser = false)
|
||||
public ApiResponse<Void> batchSortImportFieldDef(@Valid @RequestBody BatchSortImportFieldDefDTO batchSortDTO) {
|
||||
importFieldDefService.batchSortImportFieldDef(batchSortDTO);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef;
|
||||
|
||||
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 = "排序项列表", required = true)
|
||||
@Valid
|
||||
@NotNull(message = "排序项列表不能为空")
|
||||
private List<FieldDefSortItem> sortItems;
|
||||
|
||||
/**
|
||||
* 字段定义排序项
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "字段定义排序项")
|
||||
public static class FieldDefSortItem {
|
||||
|
||||
/**
|
||||
* 字段定义ID
|
||||
*/
|
||||
@Schema(description = "字段定义ID", example = "1", required = true)
|
||||
@NotNull(message = "字段定义ID不能为空")
|
||||
private Long fieldDefId;
|
||||
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
@Schema(description = "排序值", example = "0", required = true)
|
||||
@NotNull(message = "排序值不能为空")
|
||||
@Min(value = 0, message = "排序值不能小于0")
|
||||
private Integer sort;
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -42,6 +42,12 @@ public class CreateImportFieldDefDTO {
|
||||
@NotNull(message = "是否必填不能为空")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
|
||||
+6
@@ -26,6 +26,12 @@ public class UpdateImportFieldDefDTO {
|
||||
@NotNull(message = "是否必填不能为空")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
|
||||
+6
@@ -44,6 +44,12 @@ public class ImportFieldDefPO {
|
||||
@TableField("required")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField("sort")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
|
||||
+6
@@ -42,6 +42,12 @@ public class ImportFieldDefVO {
|
||||
@Schema(description = "是否必填", example = "true")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
|
||||
+8
@@ -3,6 +3,7 @@ package top.xyquan.ecomdmbbackend.modules.ecom.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.model.dto.importfielddef.BatchSortImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.CreateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.ImportFieldDefFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.UpdateImportFieldDefDTO;
|
||||
@@ -55,5 +56,12 @@ public interface ImportFieldDefService extends IService<ImportFieldDefPO> {
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<ImportFieldDefVO> getImportFieldDefPage(PageQueryDTO<ImportFieldDefFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 批量排序导入字段定义
|
||||
*
|
||||
* @param batchSortDTO 批量排序DTO
|
||||
*/
|
||||
void batchSortImportFieldDef(BatchSortImportFieldDefDTO batchSortDTO);
|
||||
}
|
||||
|
||||
|
||||
+28
-1
@@ -12,6 +12,7 @@ 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.mapper.ImportFieldDefMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.BatchSortImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.CreateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.ImportFieldDefFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.UpdateImportFieldDefDTO;
|
||||
@@ -53,6 +54,11 @@ public class ImportFieldDefServiceImpl extends ServiceImpl<ImportFieldDefMapper,
|
||||
if (!StringUtils.hasText(importFieldDefPO.getDataType())) {
|
||||
importFieldDefPO.setDataType("string");
|
||||
}
|
||||
|
||||
// 设置默认排序值
|
||||
if (importFieldDefPO.getSort() == null) {
|
||||
importFieldDefPO.setSort(0);
|
||||
}
|
||||
|
||||
this.save(importFieldDefPO);
|
||||
|
||||
@@ -115,6 +121,7 @@ public class ImportFieldDefServiceImpl extends ServiceImpl<ImportFieldDefMapper,
|
||||
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);
|
||||
@@ -149,8 +156,9 @@ public class ImportFieldDefServiceImpl extends ServiceImpl<ImportFieldDefMapper,
|
||||
}
|
||||
}
|
||||
|
||||
// 按类型和字段名排序
|
||||
// 按类型、排序和字段名排序
|
||||
wrapper.orderByAsc(ImportFieldDefPO::getType)
|
||||
.orderByAsc(ImportFieldDefPO::getSort)
|
||||
.orderByAsc(ImportFieldDefPO::getFieldName);
|
||||
|
||||
// 分页查询
|
||||
@@ -165,6 +173,25 @@ public class ImportFieldDefServiceImpl extends ServiceImpl<ImportFieldDefMapper,
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -244,6 +244,7 @@ CREATE TABLE `ec_import_field_defs` (
|
||||
`field_name` varchar(100) NOT NULL COMMENT '数据库字段名,如 name',
|
||||
`field_label` varchar(100) NOT NULL COMMENT '中文字段名,如 商品名称',
|
||||
`required` tinyint(1) DEFAULT 0 COMMENT '是否必填',
|
||||
`sort` int unsigned DEFAULT 0 COMMENT '排序',
|
||||
`data_type` varchar(50) DEFAULT 'string' COMMENT 'string, number, date等',
|
||||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
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/list-by-type/all/${type}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询导入字段定义
|
||||
*/
|
||||
export async function getImportFieldDefPageApi(
|
||||
params: PageQueryDTO<ImportFieldDefDTO.ImportFieldDefFilterDTO>,
|
||||
) {
|
||||
return requestClient.post<
|
||||
PageResultVO<ImportFieldDefVO.ImportFieldDefInfoVO>
|
||||
>('/ec/import-field-def/page', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量排序导入字段定义
|
||||
*/
|
||||
export async function batchSortImportFieldDefApi(
|
||||
data: ImportFieldDefDTO.BatchSortImportFieldDefDTO,
|
||||
) {
|
||||
return requestClient.post('/ec/import-field-def/batch-sort', data);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 导入字段定义模块API导出
|
||||
*/
|
||||
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 导入字段定义模块类型定义导出
|
||||
*/
|
||||
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 导入字段定义模块DTO类型定义
|
||||
*/
|
||||
|
||||
export namespace ImportFieldDefDTO {
|
||||
/** 创建导入字段定义参数 */
|
||||
export interface CreateImportFieldDefDTO {
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type: string;
|
||||
/** 数据库字段名,如 name */
|
||||
fieldName: string;
|
||||
/** 中文字段名,如 商品名称 */
|
||||
fieldLabel: string;
|
||||
/** 是否必填 */
|
||||
required: boolean;
|
||||
/** 排序 */
|
||||
sort?: number;
|
||||
/** 数据类型(string, number, date等) */
|
||||
dataType?: string;
|
||||
}
|
||||
|
||||
/** 更新导入字段定义参数 */
|
||||
export interface UpdateImportFieldDefDTO {
|
||||
/** 中文字段名,如 商品名称 */
|
||||
fieldLabel: 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 导入字段定义模块VO类型定义
|
||||
*/
|
||||
|
||||
export namespace ImportFieldDefVO {
|
||||
/** 导入字段定义信息 */
|
||||
export interface ImportFieldDefInfoVO {
|
||||
/** 字段定义ID */
|
||||
id: number;
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type: string;
|
||||
/** 数据库字段名,如 name */
|
||||
fieldName: string;
|
||||
/** 中文字段名,如 商品名称 */
|
||||
fieldLabel: string;
|
||||
/** 是否必填 */
|
||||
required: boolean;
|
||||
/** 排序 */
|
||||
sort?: number;
|
||||
/** 数据类型(string, number, date等) */
|
||||
dataType?: string;
|
||||
/** 创建时间 */
|
||||
createdAt: string;
|
||||
/** 更新时间 */
|
||||
updatedAt: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import type { ImportMappingDTO, ImportMappingVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 导入映射管理API
|
||||
*/
|
||||
|
||||
/**
|
||||
* 创建导入映射模板
|
||||
*/
|
||||
export async function createImportMappingApi(
|
||||
data: ImportMappingDTO.CreateImportMappingDTO,
|
||||
) {
|
||||
return requestClient.post<ImportMappingVO.ImportMappingInfoVO>(
|
||||
'/ec/import-mapping/create',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新导入映射模板
|
||||
*/
|
||||
export async function updateImportMappingApi(
|
||||
id: number,
|
||||
data: ImportMappingDTO.UpdateImportMappingDTO,
|
||||
) {
|
||||
return requestClient.put<ImportMappingVO.ImportMappingInfoVO>(
|
||||
`/ec/import-mapping/update/${id}`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除导入映射
|
||||
*/
|
||||
export async function deleteImportMappingApi(id: number) {
|
||||
return requestClient.delete(`/ec/import-mapping/delete/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取导入映射列表
|
||||
*/
|
||||
export async function getImportMappingPageApi(
|
||||
params: PageQueryDTO<ImportMappingDTO.ImportMappingFilterDTO>,
|
||||
) {
|
||||
return requestClient.post<PageResultVO<ImportMappingVO.ImportMappingInfoVO>>(
|
||||
'/ec/import-mapping/page',
|
||||
params,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 导入映射模块API导出
|
||||
*/
|
||||
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 导入映射模块类型定义导出
|
||||
*/
|
||||
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 导入映射模块DTO类型定义
|
||||
*/
|
||||
|
||||
export namespace ImportMappingDTO {
|
||||
/** 创建导入映射参数 */
|
||||
export interface CreateImportMappingDTO {
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type: string;
|
||||
/** 字段映射(JSON格式) */
|
||||
mapping: string;
|
||||
}
|
||||
|
||||
/** 更新导入映射参数 */
|
||||
export interface UpdateImportMappingDTO {
|
||||
/** 字段映射(JSON格式) */
|
||||
mapping: string;
|
||||
}
|
||||
|
||||
/** 导入映射过滤条件 */
|
||||
export interface ImportMappingFilterDTO {
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type?: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 导入映射模块VO类型定义
|
||||
*/
|
||||
|
||||
export namespace ImportMappingVO {
|
||||
/** 导入映射信息 */
|
||||
export interface ImportMappingInfoVO {
|
||||
/** 映射ID */
|
||||
id: number;
|
||||
/** 所属公司ID */
|
||||
companyId?: number;
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type: string;
|
||||
/** 字段映射(JSON格式) */
|
||||
mapping: string;
|
||||
/** 创建时间 */
|
||||
createTime: string;
|
||||
/** 更新时间 */
|
||||
updateTime: string;
|
||||
/** 创建人ID */
|
||||
createBy?: number;
|
||||
/** 更新人ID */
|
||||
updateBy?: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { ImportTaskDTO, ImportTaskVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 导入任务管理API
|
||||
*/
|
||||
|
||||
/**
|
||||
* 创建导入任务
|
||||
*/
|
||||
export async function createImportTaskApi(
|
||||
data: ImportTaskDTO.CreateImportTaskDTO,
|
||||
) {
|
||||
return requestClient.post<ImportTaskVO.ImportTaskInfoVO>(
|
||||
'/ec/import-task/create',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取导入任务列表
|
||||
*/
|
||||
export async function getImportTaskPageApi(
|
||||
params: PageQueryDTO<ImportTaskDTO.ImportTaskFilterDTO>,
|
||||
) {
|
||||
return requestClient.post<PageResultVO<ImportTaskVO.ImportTaskInfoVO>>(
|
||||
'/ec/import-task/page',
|
||||
params,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 导入任务模块API导出
|
||||
*/
|
||||
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 导入任务模块类型定义导出
|
||||
*/
|
||||
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 导入任务模块DTO类型定义
|
||||
*/
|
||||
|
||||
export namespace ImportTaskDTO {
|
||||
/** 创建导入任务参数 */
|
||||
export interface CreateImportTaskDTO {
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type: string;
|
||||
/** 原始文件名 */
|
||||
fileName: string;
|
||||
/** 存储路径 */
|
||||
filePath: string;
|
||||
/** 字段映射记录(JSON字符串) */
|
||||
mapping?: string;
|
||||
}
|
||||
|
||||
/** 导入任务过滤条件 */
|
||||
export interface ImportTaskFilterDTO {
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type?: string;
|
||||
/** 任务状态 */
|
||||
status?: string;
|
||||
/** 文件名(模糊查询) */
|
||||
fileName?: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 导入任务模块VO类型定义
|
||||
*/
|
||||
|
||||
export namespace ImportTaskVO {
|
||||
/** 导入任务信息 */
|
||||
export interface ImportTaskInfoVO {
|
||||
/** 主键ID */
|
||||
id: number;
|
||||
/** 所属公司ID */
|
||||
companyId?: number;
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type: string;
|
||||
/** 原始文件名 */
|
||||
fileName: string;
|
||||
/** 存储路径 */
|
||||
filePath: string;
|
||||
/** 任务状态 */
|
||||
status: string;
|
||||
/** 总行数 */
|
||||
totalCount?: number;
|
||||
/** 成功行数 */
|
||||
successCount?: number;
|
||||
/** 失败行数 */
|
||||
failCount?: number;
|
||||
/** 字段映射记录(JSON字符串) */
|
||||
mapping?: string;
|
||||
/** 错误信息或备注 */
|
||||
message?: string;
|
||||
/** 创建时间 */
|
||||
createTime: string;
|
||||
/** 更新时间 */
|
||||
updateTime: string;
|
||||
/** 创建人ID */
|
||||
createBy?: number;
|
||||
/** 更新人ID */
|
||||
updateBy?: number;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
/**
|
||||
* 电商模块API导出
|
||||
*/
|
||||
|
||||
// 订单状态相关API
|
||||
export * from './order-status.apis';
|
||||
|
||||
// 订单相关API
|
||||
export * from './order.apis';
|
||||
|
||||
// 推广费类型相关API
|
||||
export * from './promotion-fee-type.apis';
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 订单状态管理模块API导出
|
||||
*/
|
||||
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 订单状态管理模块类型定义导出
|
||||
*/
|
||||
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 订单管理模块API导出
|
||||
*/
|
||||
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 订单管理模块类型定义导出
|
||||
*/
|
||||
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
+18
@@ -51,3 +51,21 @@ export namespace OrderVO {
|
||||
costTotal: number;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量导入结果相关VO类型定义
|
||||
*/
|
||||
|
||||
export namespace BatchImportResultVO {
|
||||
/** 批量导入结果 */
|
||||
export interface Info {
|
||||
/** 总数量 */
|
||||
totalCount: number;
|
||||
/** 成功数量 */
|
||||
successCount: number;
|
||||
/** 失败数量 */
|
||||
failureCount: number;
|
||||
/** 失败详情 */
|
||||
failureDetails: string[];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 推广费类型管理模块API导出
|
||||
*/
|
||||
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 推广费类型管理模块类型定义导出
|
||||
*/
|
||||
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* 电商模块类型定义导出
|
||||
*/
|
||||
|
||||
// DTO类型导出
|
||||
export * from './dto.order';
|
||||
export * from './dto.order-status';
|
||||
export * from './dto.promotion-fee-type';
|
||||
|
||||
export * from './vo.batch-import-result';
|
||||
// VO类型导出
|
||||
export * from './vo.order';
|
||||
export * from './vo.order-status';
|
||||
export * from './vo.promotion-fee-type';
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* 批量导入结果相关VO类型定义
|
||||
*/
|
||||
|
||||
export namespace BatchImportResultVO {
|
||||
/** 批量导入结果 */
|
||||
export interface Info {
|
||||
/** 总数量 */
|
||||
totalCount: number;
|
||||
/** 成功数量 */
|
||||
successCount: number;
|
||||
/** 失败数量 */
|
||||
failureCount: number;
|
||||
/** 失败详情 */
|
||||
failureDetails: string[];
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* 用于匹配CSV数据中的实体(店铺、商品、规格、订单状态)到数据库中的ID
|
||||
*/
|
||||
|
||||
import type { OrderDTO } from '#/api/ecommerce/types';
|
||||
import type { OrderDTO } from '#/api/ecommerce/order';
|
||||
import type { ProductVO } from '#/api/shop/product/types';
|
||||
import type { ShopVO } from '#/api/shop/shop/types';
|
||||
|
||||
|
||||
+8
-2
@@ -1,5 +1,8 @@
|
||||
<script lang="ts" setup>
|
||||
import type { OrderStatusDTO, OrderStatusVO } from '#/api/ecommerce/types';
|
||||
import type {
|
||||
OrderStatusDTO,
|
||||
OrderStatusVO,
|
||||
} from '#/api/ecommerce/order-status/types';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
@@ -12,7 +15,10 @@ import {
|
||||
Switch,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { createOrderStatusApi, updateOrderStatusApi } from '#/api/ecommerce';
|
||||
import {
|
||||
createOrderStatusApi,
|
||||
updateOrderStatusApi,
|
||||
} from '#/api/ecommerce/order-status';
|
||||
|
||||
const emit = defineEmits<{
|
||||
cancel: [];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/types';
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
@@ -13,7 +13,7 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteOrderStatusApi,
|
||||
getAllOrderStatusListApi,
|
||||
} from '#/api/ecommerce';
|
||||
} from '#/api/ecommerce/order-status';
|
||||
|
||||
import OrderStatusFormModal from './components/OrderStatusFormModal.vue';
|
||||
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
import type {
|
||||
PromotionFeeTypeDTO,
|
||||
PromotionFeeTypeVO,
|
||||
} from '#/api/ecommerce/types';
|
||||
} from '#/api/ecommerce/promotion-fee-type';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
import {
|
||||
createPromotionFeeTypeApi,
|
||||
updatePromotionFeeTypeApi,
|
||||
} from '#/api/ecommerce';
|
||||
} from '#/api/ecommerce/promotion-fee-type';
|
||||
|
||||
const emit = defineEmits<{
|
||||
cancel: [];
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { PromotionFeeTypeVO } from '#/api/ecommerce/types';
|
||||
import type { PromotionFeeTypeVO } from '#/api/ecommerce/promotion-fee-type';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
@@ -13,7 +13,7 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deletePromotionFeeTypeApi,
|
||||
getAllPromotionFeeTypeListApi,
|
||||
} from '#/api/ecommerce';
|
||||
} from '#/api/ecommerce/promotion-fee-type';
|
||||
|
||||
import PromotionFeeTypeFormModal from './components/PromotionFeeTypeFormModal.vue';
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import type { OrderDTO, OrderStatusVO, OrderVO } from '#/api/ecommerce/types';
|
||||
import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
|
||||
import type { ShopVO } from '#/api/shop/shop/types';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
@@ -15,11 +16,8 @@ import {
|
||||
} from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
createOrderApi,
|
||||
getActiveOrderStatusListApi,
|
||||
updateOrderApi,
|
||||
} from '#/api/ecommerce';
|
||||
import { createOrderApi, updateOrderApi } from '#/api/ecommerce/order';
|
||||
import { getActiveOrderStatusListApi } from '#/api/ecommerce/order-status';
|
||||
import { getShopPageApi } from '#/api/shop/shop';
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { OrderDTO, OrderStatusVO, OrderVO } from '#/api/ecommerce/types';
|
||||
import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
|
||||
import type { ShopVO } from '#/api/shop/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
@@ -12,11 +13,8 @@ import { createIconifyIcon } from '@vben/icons';
|
||||
import { Button, message, Space, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteOrderApi,
|
||||
getActiveOrderStatusListApi,
|
||||
getOrderPageApi,
|
||||
} from '#/api/ecommerce';
|
||||
import { deleteOrderApi, getOrderPageApi } from '#/api/ecommerce/order';
|
||||
import { getActiveOrderStatusListApi } from '#/api/ecommerce/order-status';
|
||||
import { getShopPageApi } from '#/api/shop/shop';
|
||||
|
||||
import OrderFormModal from './components/OrderFormModal.vue';
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import type { PromotionFeeTypeVO } from '#/api/ecommerce/types';
|
||||
import type { PromotionFeeTypeVO } from '#/api/ecommerce/promotion-fee-type';
|
||||
import type {
|
||||
PromotionFeeDTO,
|
||||
PromotionFeeVO,
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
Select,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { getActivePromotionFeeTypeListApi } from '#/api/ecommerce';
|
||||
import { getActivePromotionFeeTypeListApi } from '#/api/ecommerce/promotion-fee-type';
|
||||
import {
|
||||
createPromotionFeeApi,
|
||||
updatePromotionFeeApi,
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
<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;
|
||||
required: boolean;
|
||||
sort?: number;
|
||||
dataType?: string;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<FormData>({
|
||||
type: 'product',
|
||||
fieldName: '',
|
||||
fieldLabel: '',
|
||||
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: '',
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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="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>
|
||||
@@ -0,0 +1,377 @@
|
||||
<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, Space, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
batchSortImportFieldDefApi,
|
||||
deleteImportFieldDefApi,
|
||||
getImportFieldDefPageApi,
|
||||
} from '#/api/ecommerce/import-field-def';
|
||||
|
||||
// @ts-expect-error - Vue SFC 类型声明
|
||||
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: '序号',
|
||||
},
|
||||
{
|
||||
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,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
resizable: true,
|
||||
rowConfig: {
|
||||
drag: true, // 启用行拖拽
|
||||
},
|
||||
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 typeGroups: Record<string, ImportFieldDefVO.ImportFieldDefInfoVO[]> =
|
||||
{};
|
||||
tableData.forEach((item: ImportFieldDefVO.ImportFieldDefInfoVO) => {
|
||||
const type = item.type;
|
||||
if (!typeGroups[type]) {
|
||||
typeGroups[type] = [];
|
||||
}
|
||||
typeGroups[type].push(item);
|
||||
});
|
||||
|
||||
// 为每个类型组构建排序数据
|
||||
const sortItems: ImportFieldDefDTO.FieldDefSortItem[] = [];
|
||||
Object.values(typeGroups).forEach((group) => {
|
||||
group.forEach((item, index) => {
|
||||
sortItems.push({
|
||||
fieldDefId: item.id,
|
||||
sort: index + 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 调用排序接口
|
||||
await batchSortImportFieldDefApi({ sortItems });
|
||||
|
||||
message.success('排序更新成功');
|
||||
} 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,
|
||||
});
|
||||
|
||||
// 在组件挂载后初始化
|
||||
onMounted(() => {
|
||||
// 组件挂载完成
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="字段管理" auto-content-height>
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid :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>
|
||||
<Button size="small" danger @click="handleDelete(row)">
|
||||
<TrashIcon class="h-3 w-3" />
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 字段表单模态框 -->
|
||||
<FieldFormModal ref="fieldFormModalRef" @success="handleModalSuccess" />
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user