diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/config/SysFileProperties.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/config/SysFileProperties.java index 8022aae3..95eadcd6 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/config/SysFileProperties.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/config/SysFileProperties.java @@ -8,12 +8,16 @@ import org.springframework.stereotype.Component; * 系统文件模块配置(sys.file)。 *

* storage-type 决定物理存储位置;upload-mode 决定前端上传路径,二者独立配置。 + * 对象路径:{app-name}/{spring.profiles.active}/{category}/{yyyy}/{hash}{ext}。 */ @Data @Component @ConfigurationProperties(prefix = "sys.file") public class SysFileProperties { + /** 应用名(对象路径首段) */ + private String appName = "ecom-dmb"; + /** 存储方式:local | oss */ private String storageType = "local"; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/model/FileCategory.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/model/FileCategory.java new file mode 100644 index 00000000..9143fda3 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/model/FileCategory.java @@ -0,0 +1,41 @@ +package top.xyquan.ecomdmbbackend.modules.sys.file.model; + +import org.springframework.util.StringUtils; + +/** + * 业务文件分组(落库 category,并作为对象路径中的 module 段)。 + *

+ * 取值:avatar / logo / image / video / file。 + */ +public final class FileCategory { + + public static final String AVATAR = "avatar"; + public static final String LOGO = "logo"; + public static final String IMAGE = "image"; + public static final String VIDEO = "video"; + /** 文档、导入文件等非媒体 */ + public static final String FILE = "file"; + + public static final String DEFAULT = FILE; + + private FileCategory() { + } + + /** + * 规范为业务分组码;未知或空回退为 file。兼容旧细粒度 category。 + */ + public static String normalize(String raw) { + if (!StringUtils.hasText(raw)) { + return DEFAULT; + } + String v = raw.trim().toLowerCase(); + return switch (v) { + case AVATAR, LOGO, IMAGE, VIDEO, FILE -> v; + case "user-avatar" -> AVATAR; + case "company-logo", "shop-logo" -> LOGO; + case "product-main-image", "product-sku-image" -> IMAGE; + case "order-import", "ad-fee-import" -> FILE; + default -> DEFAULT; + }; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/model/dto/BatchSignUrlDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/model/dto/BatchSignUrlDTO.java index a7ff85ca..f491a10f 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/model/dto/BatchSignUrlDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/model/dto/BatchSignUrlDTO.java @@ -34,6 +34,11 @@ public class BatchSignUrlDTO { */ @NotBlank(message = "文件哈希值不能为空") private String fileHash; + + /** + * 业务分组:avatar / logo / image / video / file + */ + private String category; } } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/service/impl/SysFileServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/service/impl/SysFileServiceImpl.java index 7b4bc240..35e9c91c 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/service/impl/SysFileServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/service/impl/SysFileServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.web.multipart.MultipartFile; 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.sys.file.model.FileCategory; import top.xyquan.ecomdmbbackend.modules.sys.file.mapper.SysFileMapper; import top.xyquan.ecomdmbbackend.modules.sys.file.model.dto.BatchCreateOssFileDTO; import top.xyquan.ecomdmbbackend.modules.sys.file.model.dto.BatchSignUrlDTO; @@ -24,12 +25,12 @@ import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileVO; import top.xyquan.ecomdmbbackend.modules.sys.file.service.OssService; import top.xyquan.ecomdmbbackend.modules.sys.file.service.SysFileService; import top.xyquan.ecomdmbbackend.modules.sys.file.support.FileStorageSupport; +import top.xyquan.ecomdmbbackend.modules.sys.file.support.StoragePathBuilder; import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; import top.xyquan.ecomdmbbackend.utils.FileHashUtils; import top.xyquan.ecomdmbbackend.utils.SysFileUtils; import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -43,13 +44,16 @@ public class SysFileServiceImpl extends ServiceImpl im private final CurrentUserContext currentUserContext; private final OssService ossService; private final FileStorageSupport fileStorageSupport; + private final StoragePathBuilder storagePathBuilder; public SysFileServiceImpl(CurrentUserContext currentUserContext, OssService ossService, - FileStorageSupport fileStorageSupport) { + FileStorageSupport fileStorageSupport, + StoragePathBuilder storagePathBuilder) { this.currentUserContext = currentUserContext; this.ossService = ossService; this.fileStorageSupport = fileStorageSupport; + this.storagePathBuilder = storagePathBuilder; } @Override @@ -104,7 +108,8 @@ public class SysFileServiceImpl extends ServiceImpl im if (FileStorageSupport.STORAGE_LOCAL.equals(resolvedStorageType) || (FileStorageSupport.STORAGE_LOCAL.equals(storageType) && !FileStorageSupport.STORAGE_OSS.equals(resolvedStorageType))) { - String relativePath = generateStoragePath(file.getOriginalFilename(), fileHash); + String relativePath = storagePathBuilder.build( + file.getOriginalFilename(), fileHash, FileCategory.DEFAULT); storagePath = fileStorageSupport.persist(relativePath, file); resolvedStorageType = storageType; } @@ -120,6 +125,7 @@ public class SysFileServiceImpl extends ServiceImpl im sysFile.setMimeType(file.getContentType()); sysFile.setFileSize(file.getSize()); sysFile.setFileHash(fileHash); + sysFile.setCategory(FileCategory.DEFAULT); sysFile.setUploadBy(userId); sysFile.setUploadTime(LocalDateTime.now()); sysFile.setUpdateTime(null); @@ -133,7 +139,8 @@ public class SysFileServiceImpl extends ServiceImpl im } if (storagePath == null) { - String relativePath = generateStoragePath(file.getOriginalFilename(), fileHash); + String relativePath = storagePathBuilder.build( + file.getOriginalFilename(), fileHash, FileCategory.DEFAULT); storagePath = fileStorageSupport.persist(relativePath, file); SysFilePO sysFile = new SysFilePO(); @@ -145,6 +152,7 @@ public class SysFileServiceImpl extends ServiceImpl im sysFile.setMimeType(file.getContentType()); sysFile.setFileSize(file.getSize()); sysFile.setFileHash(fileHash); + sysFile.setCategory(FileCategory.DEFAULT); sysFile.setUploadBy(userId); this.save(sysFile); @@ -171,6 +179,7 @@ public class SysFileServiceImpl extends ServiceImpl im Long userId = currentUserContext.getCurrentUserId(); List result = new ArrayList<>(); String storageType = fileStorageSupport.storageType(); + String normalizedCategory = FileCategory.normalize(category); for (MultipartFile file : files) { if (file.isEmpty()) { continue; } String fileHash = FileHashUtils.calculateFileHash(file); @@ -188,7 +197,8 @@ public class SysFileServiceImpl extends ServiceImpl im result.add(convertToUploadVO(existingFile)); continue; } - String relativePath = generateStoragePath(file.getOriginalFilename(), fileHash); + String relativePath = storagePathBuilder.build( + file.getOriginalFilename(), fileHash, normalizedCategory); String storagePath = fileStorageSupport.persist(relativePath, file); SysFilePO sysFile = new SysFilePO(); sysFile.setCompanyId(companyId); @@ -199,7 +209,7 @@ public class SysFileServiceImpl extends ServiceImpl im sysFile.setMimeType(file.getContentType()); sysFile.setFileSize(file.getSize()); sysFile.setFileHash(fileHash); - sysFile.setCategory(category); + sysFile.setCategory(normalizedCategory); sysFile.setUploadBy(userId); sysFile.setUploadTime(LocalDateTime.now()); this.save(sysFile); @@ -290,7 +300,8 @@ public class SysFileServiceImpl extends ServiceImpl im if (otherCompanyFile == null) { // 文件不存在,返回OSS Header签名信息(不创建记录) signInfo.setExists(false); - String storagePath = generateStoragePath(item.getFilename(), item.getFileHash()); + String storagePath = storagePathBuilder.build( + item.getFilename(), item.getFileHash(), item.getCategory()); OssPostPolicyVO uploadPolicy = ossService.generateUploadPolicy(storagePath, 120); if (uploadPolicy != null && uploadPolicy.getUrl() != null) { signInfo.setUploadUrl(uploadPolicy.getUrl()); @@ -308,18 +319,6 @@ public class SysFileServiceImpl extends ServiceImpl im return result; } - /** - * 生成存储路径(用于OSS签名URL生成) - */ - private String generateStoragePath(String originalFilename, String fileHash) { - String datePath = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM")); - String extension = getFileExtension(originalFilename); - String filename = fileHash + extension; - - // OSS和本地存储都使用相同的路径格式,只是前缀不同 - return "uploads/" + datePath + "/" + filename; - } - @Override @Transactional public List batchCreateOssFiles(BatchCreateOssFileDTO dto) { @@ -372,7 +371,7 @@ public class SysFileServiceImpl extends ServiceImpl im sysFile.setMimeType(item.getMimeType()); sysFile.setFileSize(item.getFileSize()); sysFile.setFileHash(item.getFileHash()); - sysFile.setCategory(item.getCategory()); + sysFile.setCategory(FileCategory.normalize(item.getCategory())); sysFile.setTags(item.getTags()); sysFile.setRemark(item.getRemark()); sysFile.setUploadBy(userId); @@ -392,7 +391,7 @@ public class SysFileServiceImpl extends ServiceImpl im sysFile.setMimeType(item.getMimeType()); sysFile.setFileSize(item.getFileSize()); sysFile.setFileHash(item.getFileHash()); - sysFile.setCategory(item.getCategory()); + sysFile.setCategory(FileCategory.normalize(item.getCategory())); sysFile.setTags(item.getTags()); sysFile.setRemark(item.getRemark()); sysFile.setUploadBy(userId); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/support/FileStorageSupport.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/support/FileStorageSupport.java index f658c9f7..11444aec 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/support/FileStorageSupport.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/support/FileStorageSupport.java @@ -70,7 +70,7 @@ public class FileStorageSupport { /** * 写入物理存储并返回应写入 sys_file.storage_path 的值。 * - * @param relativePath 统一相对路径,如 uploads/2026/03/xxx.png + * @param relativePath OSS 为 app/env/module/yyyy/hash.ext;本地为 uploads/... */ public String persist(String relativePath, MultipartFile file) { if (isOssStorage()) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/support/StoragePathBuilder.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/support/StoragePathBuilder.java new file mode 100644 index 00000000..1ffeab37 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/file/support/StoragePathBuilder.java @@ -0,0 +1,71 @@ +package top.xyquan.ecomdmbbackend.modules.sys.file.support; + +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import top.xyquan.ecomdmbbackend.modules.sys.file.config.SysFileProperties; +import top.xyquan.ecomdmbbackend.modules.sys.file.model.FileCategory; + +import java.time.Year; + +/** + * 生成统一对象键 / 本地相对路径。 + *

+ * OSS:{app}/{env}/{module}/{yyyy}/{sha256}{ext}
+ * 本地:uploads/{app}/{env}/{module}/{yyyy}/{sha256}{ext} + */ +@Component +public class StoragePathBuilder { + + private final SysFileProperties sysFileProperties; + private final Environment environment; + private final FileStorageSupport fileStorageSupport; + + public StoragePathBuilder(SysFileProperties sysFileProperties, + Environment environment, + FileStorageSupport fileStorageSupport) { + this.sysFileProperties = sysFileProperties; + this.environment = environment; + this.fileStorageSupport = fileStorageSupport; + } + + /** + * @param originalFilename 原始文件名(取扩展名) + * @param fileHash 内容哈希 + * @param category 业务分组(会 normalize) + * @return 写入 sys_file.storage_path 前的相对路径(本地无 ./ 前缀,由 persist 补) + */ + public String build(String originalFilename, String fileHash, String category) { + String app = StringUtils.hasText(sysFileProperties.getAppName()) + ? sysFileProperties.getAppName().trim() + : "ecom-dmb"; + String env = resolveEnv(); + String module = FileCategory.normalize(category); + String year = String.valueOf(Year.now().getValue()); + String filename = fileHash + extension(originalFilename); + String objectKey = app + "/" + env + "/" + module + "/" + year + "/" + filename; + if (fileStorageSupport.isOssStorage()) { + return objectKey; + } + return "uploads/" + objectKey; + } + + private String resolveEnv() { + String[] profiles = environment.getActiveProfiles(); + if (profiles.length > 0 && StringUtils.hasText(profiles[0])) { + return profiles[0].trim().toLowerCase(); + } + String[] defaults = environment.getDefaultProfiles(); + if (defaults.length > 0 && StringUtils.hasText(defaults[0])) { + return defaults[0].trim().toLowerCase(); + } + return "default"; + } + + private static String extension(String filename) { + if (!StringUtils.hasText(filename) || !filename.contains(".")) { + return ""; + } + return filename.substring(filename.lastIndexOf('.')); + } +} diff --git a/ecom-dmb-backend/src/main/resources/application.yml b/ecom-dmb-backend/src/main/resources/application.yml index 58f699fe..92c859ce 100644 --- a/ecom-dmb-backend/src/main/resources/application.yml +++ b/ecom-dmb-backend/src/main/resources/application.yml @@ -135,9 +135,10 @@ oss: bucket-name: xyquan enabled: false -# 系统文件:storage-type 决定落盘位置,upload-mode 决定前端上传路径 +# 系统文件:路径 = {app-name}/{profile}/{category}/{yyyy}/{hash}{ext};本地再加 uploads/ sys: file: + app-name: ecom-dmb storage-type: local upload-mode: multipart max-size-mb: 50 diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/sys/file/types/types.dto.ts b/ecom-dmb-frontend/apps/web-antd/src/api/sys/file/types/types.dto.ts index 786f79b7..548963e5 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/sys/file/types/types.dto.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/sys/file/types/types.dto.ts @@ -15,6 +15,8 @@ export namespace FileDTO { filename: string; /** 文件哈希值 */ fileHash: string; + /** 业务分组:avatar / logo / image / video / file */ + category?: string; } /** 批量创建OSS文件记录请求参数 */ diff --git a/ecom-dmb-frontend/apps/web-antd/src/constants/file-category.ts b/ecom-dmb-frontend/apps/web-antd/src/constants/file-category.ts new file mode 100644 index 00000000..f36061ae --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/constants/file-category.ts @@ -0,0 +1,14 @@ +/** + * 业务文件分组(与后端 FileCategory / 对象路径 module 段一致) + */ +export const FileCategory = { + AVATAR: 'avatar', + LOGO: 'logo', + IMAGE: 'image', + VIDEO: 'video', + /** 文档、导入等非媒体 */ + FILE: 'file', +} as const; + +export type FileCategoryCode = + (typeof FileCategory)[keyof typeof FileCategory]; diff --git a/ecom-dmb-frontend/apps/web-antd/src/utils/upload-file.ts b/ecom-dmb-frontend/apps/web-antd/src/utils/upload-file.ts index 8ef647f8..3fb06086 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/utils/upload-file.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/utils/upload-file.ts @@ -2,6 +2,7 @@ * 统一文件上传:按系统配置在 multipart(后端)与 direct(OSS 直传)间分流 */ import type { FileVO } from '#/api/sys/file/types'; +import type { FileCategoryCode } from '#/constants/file-category'; import { message } from 'ant-design-vue'; import SparkMD5 from 'spark-md5'; @@ -11,15 +12,20 @@ import { batchSignUrlApi, batchUploadFilesApi, } from '#/api/sys/file'; +import { FileCategory } from '#/constants/file-category'; import { useAppConfigStore } from '#/store/app-config'; export interface UploadOptions { - /** 文件分类 */ - category?: string; + /** 业务分组:avatar / logo / image / video / file */ + category?: FileCategoryCode | string; /** 错误提示消息 */ errorMessage?: string; } +function resolveCategory(category?: string): string { + return category?.trim() || FileCategory.FILE; +} + function calculateFileHash(file: File): Promise { return new Promise((resolve, reject) => { const spark = new SparkMD5.ArrayBuffer(); @@ -86,7 +92,8 @@ async function uploadViaMultipart( file: File, options?: UploadOptions, ): Promise { - const uploaded = await batchUploadFilesApi([file], options?.category); + const category = resolveCategory(options?.category); + const uploaded = await batchUploadFilesApi([file], category); const first = uploaded[0]; if (!first) { throw new Error('文件上传失败'); @@ -114,9 +121,10 @@ async function uploadViaDirect( file: File, options?: UploadOptions, ): Promise { + const category = resolveCategory(options?.category); const fileHash = await calculateFileHash(file); const signResponse = await batchSignUrlApi({ - files: [{ filename: file.name, fileHash }], + files: [{ filename: file.name, fileHash, category }], }); const signInfo = signResponse.files?.[0]; @@ -152,7 +160,7 @@ async function uploadViaDirect( storagePath: signInfo.storagePath, fileSize: file.size, mimeType: file.type, - category: options?.category, + category, }, ], }); diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue index a0fc6186..0833a844 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue @@ -51,6 +51,7 @@ import { import { getPddShopPageApi } from '#/api/channel/pdd/shop'; import { getProductPageApi } from '#/api/ec/product'; import { getProductSkuPageApi } from '#/api/ec/product/sku'; +import { FileCategory } from '#/constants/file-category'; import { uploadFile } from '#/utils/upload-file'; defineOptions({ name: 'PddGoodsPublishModal' }); @@ -1262,7 +1263,7 @@ async function uploadUploadFile(file: UploadFile): Promise { throw new Error(`图片文件丢失:${file.name || file.uid}`); } const info = await uploadFile(raw, { - category: 'image', + category: FileCategory.IMAGE, errorMessage: `图片上传失败:${raw.name}`, }); if (!info?.id) { diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/import/ad-fee/components/ImportTaskWizard.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/import/ad-fee/components/ImportTaskWizard.vue index a87dce8d..d94f3f92 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ec/import/ad-fee/components/ImportTaskWizard.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/import/ad-fee/components/ImportTaskWizard.vue @@ -21,6 +21,7 @@ import { getShopPageApi } from '#/api/ec/shop'; import { createImportTaskApi } from '#/api/ec/import/task'; import { useImportTaskStore } from '#/store'; import { PermissionGate } from '#/components/permission'; +import { FileCategory } from '#/constants/file-category'; import { uploadFile } from '#/utils/upload-file'; import dayjs from 'dayjs'; @@ -432,7 +433,7 @@ const handleCreateTask = async () => { message.loading('正在上传文件...', 0); const patchedFile = buildPatchedCsv(); const fileInfo = await uploadFile(patchedFile, { - category: 'ad-fee-import', + category: FileCategory.FILE, errorMessage: '文件上传失败,请重试', }); message.destroy(); diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/import/order/components/ImportTaskWizard.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/import/order/components/ImportTaskWizard.vue index 6dcd7c2c..06622362 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ec/import/order/components/ImportTaskWizard.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/import/order/components/ImportTaskWizard.vue @@ -35,6 +35,7 @@ import { getAllOrderStatusListApi } from '#/api/ec/order/status'; import { getShopPageApi } from '#/api/ec/shop'; import { useImportTaskStore } from '#/store'; import { PermissionGate } from '#/components/permission'; +import { FileCategory } from '#/constants/file-category'; import { uploadFile } from '#/utils/upload-file'; import { createPatchedFile } from '../utils/skuCodePatch'; @@ -1181,7 +1182,7 @@ const handleCreateTask = async () => { // 先上传文件到 OSS(使用统一文件系统) message.loading('正在上传文件...', 0); const fileInfo = await uploadFile(selectedFile.value, { - category: 'order-import', + category: FileCategory.FILE, errorMessage: '文件上传失败,请重试', }); message.destroy(); diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/product/list/components/ProductFormModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/product/list/components/ProductFormModal.vue index a9e2ffcd..9e43073d 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ec/product/list/components/ProductFormModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/product/list/components/ProductFormModal.vue @@ -22,6 +22,7 @@ import { import { getCategoryTreeApi } from '#/api/ec/product/category'; import { createProductApi, updateProductApi } from '#/api/ec/product'; import { getProductSkuPageApi } from '#/api/ec/product/sku'; +import { FileCategory } from '#/constants/file-category'; import { uploadFile } from '#/utils/upload-file'; import CategoryFormModal from '#/views/ec/product/category/components/CategoryFormModal.vue'; import ProductSkuCostDrawer from './ProductSkuCostDrawer.vue'; @@ -1056,7 +1057,7 @@ async function uploadImageAndGetId(): Promise { try { const fileInfo = await uploadFile(newImageFile.value, { - category: 'product-main-image', + category: FileCategory.IMAGE, errorMessage: '主图上传失败', }); return fileInfo.id; @@ -1069,7 +1070,7 @@ async function uploadImageAndGetId(): Promise { async function uploadSkuImageAndGetId(file: File): Promise { try { const fileInfo = await uploadFile(file, { - category: 'product-sku-image', + category: FileCategory.IMAGE, errorMessage: 'SKU 图片上传失败', }); return fileInfo.id; diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/list/components/ShopFormModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/list/components/ShopFormModal.vue index aaac1e9c..ee73cb33 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/list/components/ShopFormModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/list/components/ShopFormModal.vue @@ -10,6 +10,7 @@ import { Button, Form, Input, message, Select } from 'ant-design-vue'; import { createShopApi, updateShopApi } from '#/api/ec/shop'; import { getPlatformListApi } from '#/api/ec/platform'; +import { FileCategory } from '#/constants/file-category'; import { uploadFile } from '#/utils/upload-file'; interface Emits { @@ -240,7 +241,7 @@ async function uploadLogoAndGetId(): Promise { try { const fileInfo = await uploadFile(newLogoFile.value, { - category: 'shop-logo', + category: FileCategory.LOGO, errorMessage: 'Logo上传失败', }); return fileInfo.id; diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/org/company/components/CompanyFormModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/org/company/components/CompanyFormModal.vue index f401f33d..3027a184 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/org/company/components/CompanyFormModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/org/company/components/CompanyFormModal.vue @@ -20,6 +20,7 @@ import { createCompanyApi, updateCompanyApi, } from '#/api/company'; +import { FileCategory } from '#/constants/file-category'; import { uploadFile } from '#/utils/upload-file'; interface Emits { @@ -272,7 +273,7 @@ async function uploadLogoAndGetId(): Promise { try { const fileInfo = await uploadFile(newLogoFile.value, { - category: 'company-logo', + category: FileCategory.LOGO, errorMessage: 'Logo上传失败', }); return fileInfo.id; diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/sys/profile/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/sys/profile/index.vue index 971dc2a2..e9ac591f 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/sys/profile/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/sys/profile/index.vue @@ -8,6 +8,7 @@ import { Page } from '@vben/common-ui'; import { Button, Form, Input, message, Spin, Upload } from 'ant-design-vue'; import { getUserInfoApi, updateUserInfoApi } from '#/api/sys/user'; +import { FileCategory } from '#/constants/file-category'; import { uploadFile } from '#/utils/upload-file'; defineOptions({ name: 'PersonalProfile' }); @@ -88,7 +89,7 @@ async function handleSubmit() { avatarLoading.value = true; try { const fileInfo = await uploadFile(pendingAvatarFile.value, { - category: 'user-avatar', + category: FileCategory.AVATAR, errorMessage: '头像上传失败', }); formData.avatarImageId = fileInfo.id;