From 490bb901e175abe1d2b4c198a7c0a0424218c6df Mon Sep 17 00:00:00 2001 From: owen Date: Sun, 4 Feb 2024 19:41:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E8=AE=BE=E6=96=BD?= =?UTF-8?q?=EF=BC=9A=E5=A2=9E=E5=8A=A0=E5=89=8D=E7=AB=AF=E7=9B=B4=E8=BF=9E?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E5=88=B0S3=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.dev | 2 + .env.local | 2 + .env.prod | 2 + .env.stage | 2 + .env.test | 2 + src/api/infra/file/index.ts | 21 +++++ src/components/UploadFile/src/UploadFile.vue | 22 +++-- src/components/UploadFile/src/UploadImg.vue | 12 +-- src/components/UploadFile/src/UploadImgs.vue | 13 +-- src/components/UploadFile/src/useUpload.ts | 87 ++++++++++++++++++++ src/views/infra/file/FileForm.vue | 15 ++-- src/views/infra/file/index.vue | 13 ++- 12 files changed, 152 insertions(+), 41 deletions(-) create mode 100644 src/components/UploadFile/src/useUpload.ts diff --git a/.env.dev b/.env.dev index 3c41cc68..689718b2 100644 --- a/.env.dev +++ b/.env.dev @@ -7,6 +7,8 @@ VITE_DEV=true VITE_BASE_URL='http://api-dashboard.yudao.iocoder.cn' # VITE_BASE_URL='http://dofast.demo.huizhizao.vip:20001' +# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务 +VITE_UPLOAD_TYPE=server # 上传路径 VITE_UPLOAD_URL='http://api-dashboard.yudao.iocoder.cn/admin-api/infra/file/upload' diff --git a/.env.local b/.env.local index 2eb968c4..28f37538 100644 --- a/.env.local +++ b/.env.local @@ -6,6 +6,8 @@ VITE_DEV=true # 请求路径 VITE_BASE_URL='http://localhost:48080' +# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务 +VITE_UPLOAD_TYPE=server # 上传路径 VITE_UPLOAD_URL='http://localhost:48080/admin-api/infra/file/upload' diff --git a/.env.prod b/.env.prod index 070b43a7..35d729c3 100644 --- a/.env.prod +++ b/.env.prod @@ -6,6 +6,8 @@ VITE_DEV=false # 请求路径 VITE_BASE_URL='http://localhost:48080' +# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务 +VITE_UPLOAD_TYPE=server # 上传路径 VITE_UPLOAD_URL='http://localhost:48080/admin-api/infra/file/upload' diff --git a/.env.stage b/.env.stage index c0edf340..26f9516b 100644 --- a/.env.stage +++ b/.env.stage @@ -6,6 +6,8 @@ VITE_DEV=false # 请求路径 VITE_BASE_URL='http://api-dashboard.yudao.iocoder.cn' +# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务 +VITE_UPLOAD_TYPE=server # 上传路径 VITE_UPLOAD_URL='http://api-dashboard.yudao.iocoder.cn/admin-api/infra/file/upload' diff --git a/.env.test b/.env.test index 217ac6e2..addbfb4e 100644 --- a/.env.test +++ b/.env.test @@ -6,6 +6,8 @@ VITE_DEV=false # 请求路径 VITE_BASE_URL='http://localhost:48080' +# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务 +VITE_UPLOAD_TYPE=server # 上传路径 VITE_UPLOAD_URL='http://localhost:48080/admin-api/infra/file/upload' diff --git a/src/api/infra/file/index.ts b/src/api/infra/file/index.ts index f64bc0d6..7f543745 100644 --- a/src/api/infra/file/index.ts +++ b/src/api/infra/file/index.ts @@ -6,6 +6,14 @@ export interface FilePageReqVO extends PageParam { createTime?: Date[] } +// 文件预签名地址 Response VO +export interface FilePresignedUrlRespVO { + // 文件配置编号 + configId: number + // 文件预签名地址 + url: string +} + // 查询文件列表 export const getFilePage = (params: FilePageReqVO) => { return request.get({ url: '/infra/file/page', params }) @@ -15,3 +23,16 @@ export const getFilePage = (params: FilePageReqVO) => { export const deleteFile = (id: number) => { return request.delete({ url: '/infra/file/delete?id=' + id }) } + +// 获取文件预签名地址 +export const getFilePresignedUrl = (fileName: string) => { + return request.get({ + url: '/infra/file/presigned-url', + params: { fileName } + }) +} + +// 创建文件 +export const createFile = (data: any) => { + return request.post({ url: '/infra/file/create', data }) +} diff --git a/src/components/UploadFile/src/UploadFile.vue b/src/components/UploadFile/src/UploadFile.vue index a0ef08d6..576dc054 100644 --- a/src/components/UploadFile/src/UploadFile.vue +++ b/src/components/UploadFile/src/UploadFile.vue @@ -3,11 +3,10 @@ @@ -36,9 +36,10 @@