mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 22:29:19 +08:00
fix: 修复前端 TypeScript 类型错误
- file-upload.ts: 重写上传逻辑,正确使用 files 数组和类型 - CompanyMenuDrawer/CompanyPermissionDrawer: 修复 Tree @check 事件类型 - 移除各页面未使用的导入和函数 - promotion-fee: 修复类型导出问题 - 修复 VxeGrid 配置重复和无效属性问题
This commit is contained in:
@@ -21,39 +21,52 @@ export async function uploadFileToOssFromSystem(
|
||||
dir: string = 'general',
|
||||
): Promise<UploadResult> {
|
||||
const signRes = await batchSignUrlApi({
|
||||
filenames: [file.name],
|
||||
dir,
|
||||
files: [{ filename: file.name, fileHash: '' }],
|
||||
});
|
||||
|
||||
const fileInfo = signRes.files[0];
|
||||
if (!fileInfo) {
|
||||
throw new Error('签名响应为空');
|
||||
}
|
||||
|
||||
// 已存在则直接返回
|
||||
if (signRes.existingFiles && signRes.existingFiles.length > 0) {
|
||||
const existing = signRes.existingFiles[0];
|
||||
if (fileInfo.exists && fileInfo.accessUrl && fileInfo.storagePath) {
|
||||
return {
|
||||
accessUrl: existing.accessUrl,
|
||||
storagePath: existing.storagePath,
|
||||
accessUrl: fileInfo.accessUrl,
|
||||
storagePath: fileInfo.storagePath,
|
||||
};
|
||||
}
|
||||
|
||||
// 前端直传 OSS
|
||||
const { uploadUrl, ossHeaders } = signRes.signUrls[0];
|
||||
await fetch(uploadUrl, {
|
||||
method: 'PUT',
|
||||
headers: ossHeaders,
|
||||
body: file,
|
||||
});
|
||||
if (fileInfo.uploadUrl && fileInfo.uploadHeaders) {
|
||||
await fetch(fileInfo.uploadUrl, {
|
||||
method: 'PUT',
|
||||
headers: fileInfo.uploadHeaders,
|
||||
body: file,
|
||||
});
|
||||
}
|
||||
|
||||
// 通知后端创建文件记录
|
||||
const createRes = await batchCreateOssFilesApi({
|
||||
filenames: [file.name],
|
||||
dir,
|
||||
ossKeys: [signRes.ossKeys[0]],
|
||||
accessUrls: [signRes.accessUrls[0]],
|
||||
fileSizes: [file.size],
|
||||
fileFormats: [file.name.split('.').pop() || ''],
|
||||
files: [
|
||||
{
|
||||
filename: file.name,
|
||||
fileHash: '',
|
||||
storagePath: fileInfo.storagePath || '',
|
||||
fileSize: file.size,
|
||||
mimeType: file.type,
|
||||
category: dir,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const firstFile = createRes[0];
|
||||
if (!firstFile) {
|
||||
throw new Error('文件记录创建失败');
|
||||
}
|
||||
|
||||
return {
|
||||
accessUrl: createRes[0].accessUrl,
|
||||
storagePath: createRes[0].storagePath,
|
||||
accessUrl: firstFile.accessUrl || '',
|
||||
storagePath: firstFile.storagePath || '',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user