mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
feat: 文件路径改为 app/env/业务分组/年/hash,并收敛 category
This commit is contained in:
+4
@@ -8,12 +8,16 @@ import org.springframework.stereotype.Component;
|
||||
* 系统文件模块配置(sys.file)。
|
||||
* <p>
|
||||
* 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";
|
||||
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.file.model;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* 业务文件分组(落库 category,并作为对象路径中的 module 段)。
|
||||
* <p>
|
||||
* 取值: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;
|
||||
};
|
||||
}
|
||||
}
|
||||
+5
@@ -34,6 +34,11 @@ public class BatchSignUrlDTO {
|
||||
*/
|
||||
@NotBlank(message = "文件哈希值不能为空")
|
||||
private String fileHash;
|
||||
|
||||
/**
|
||||
* 业务分组:avatar / logo / image / video / file
|
||||
*/
|
||||
private String category;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
-21
@@ -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<SysFileMapper, SysFilePO> 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<SysFileMapper, SysFilePO> 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<SysFileMapper, SysFilePO> 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<SysFileMapper, SysFilePO> 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<SysFileMapper, SysFilePO> 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<SysFileMapper, SysFilePO> im
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
List<SysFileUploadVO> 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<SysFileMapper, SysFilePO> 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<SysFileMapper, SysFilePO> 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<SysFileMapper, SysFilePO> 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<SysFileMapper, SysFilePO> 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<SysFileVO> batchCreateOssFiles(BatchCreateOssFileDTO dto) {
|
||||
@@ -372,7 +371,7 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFilePO> 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<SysFileMapper, SysFilePO> 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);
|
||||
|
||||
+1
-1
@@ -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()) {
|
||||
|
||||
+71
@@ -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;
|
||||
|
||||
/**
|
||||
* 生成统一对象键 / 本地相对路径。
|
||||
* <p>
|
||||
* OSS:{app}/{env}/{module}/{yyyy}/{sha256}{ext}<br>
|
||||
* 本地: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('.'));
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -15,6 +15,8 @@ export namespace FileDTO {
|
||||
filename: string;
|
||||
/** 文件哈希值 */
|
||||
fileHash: string;
|
||||
/** 业务分组:avatar / logo / image / video / file */
|
||||
category?: string;
|
||||
}
|
||||
|
||||
/** 批量创建OSS文件记录请求参数 */
|
||||
|
||||
@@ -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];
|
||||
@@ -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<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const spark = new SparkMD5.ArrayBuffer();
|
||||
@@ -86,7 +92,8 @@ async function uploadViaMultipart(
|
||||
file: File,
|
||||
options?: UploadOptions,
|
||||
): Promise<FileVO.Info> {
|
||||
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<FileVO.Info> {
|
||||
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,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
+2
-1
@@ -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<number> {
|
||||
throw new Error(`图片文件丢失:${file.name || file.uid}`);
|
||||
}
|
||||
const info = await uploadFile(raw, {
|
||||
category: 'image',
|
||||
category: FileCategory.IMAGE,
|
||||
errorMessage: `图片上传失败:${raw.name}`,
|
||||
});
|
||||
if (!info?.id) {
|
||||
|
||||
+2
-1
@@ -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();
|
||||
|
||||
+2
-1
@@ -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();
|
||||
|
||||
+3
-2
@@ -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<number | undefined> {
|
||||
|
||||
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<number | undefined> {
|
||||
async function uploadSkuImageAndGetId(file: File): Promise<number | undefined> {
|
||||
try {
|
||||
const fileInfo = await uploadFile(file, {
|
||||
category: 'product-sku-image',
|
||||
category: FileCategory.IMAGE,
|
||||
errorMessage: 'SKU 图片上传失败',
|
||||
});
|
||||
return fileInfo.id;
|
||||
|
||||
@@ -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<number | undefined> {
|
||||
|
||||
try {
|
||||
const fileInfo = await uploadFile(newLogoFile.value, {
|
||||
category: 'shop-logo',
|
||||
category: FileCategory.LOGO,
|
||||
errorMessage: 'Logo上传失败',
|
||||
});
|
||||
return fileInfo.id;
|
||||
|
||||
+2
-1
@@ -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<number | undefined> {
|
||||
|
||||
try {
|
||||
const fileInfo = await uploadFile(newLogoFile.value, {
|
||||
category: 'company-logo',
|
||||
category: FileCategory.LOGO,
|
||||
errorMessage: 'Logo上传失败',
|
||||
});
|
||||
return fileInfo.id;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user