mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 03:49:19 +08:00
feat: 文件路径改为 app/env/业务分组/年/hash,并收敛 category
This commit is contained in:
@@ -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