From a7512adceca67aca1bddeee609166ae433ea7757 Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Sat, 5 Oct 2024 16:38:47 +0800 Subject: [PATCH] feat: oss --- apps/web-antd/src/api/system/oss/index.ts | 53 +++++ apps/web-antd/src/api/system/oss/model.d.ts | 28 +++ .../src/views/system/oss-config/data.tsx | 54 ++++- .../src/views/system/oss-config/index.vue | 185 +++++++++++++--- apps/web-antd/src/views/system/oss/data.tsx | 45 +++- apps/web-antd/src/views/system/oss/index.vue | 199 +++++++++++++++--- 6 files changed, 502 insertions(+), 62 deletions(-) create mode 100644 apps/web-antd/src/api/system/oss/index.ts create mode 100644 apps/web-antd/src/api/system/oss/model.d.ts diff --git a/apps/web-antd/src/api/system/oss/index.ts b/apps/web-antd/src/api/system/oss/index.ts new file mode 100644 index 00000000..139b9260 --- /dev/null +++ b/apps/web-antd/src/api/system/oss/index.ts @@ -0,0 +1,53 @@ +import type { OssFile } from './model'; + +import type { ID, IDS, PageQuery, PageResult } from '#/api/common'; + +import { ContentTypeEnum } from '#/api/helper'; +import { requestClient } from '#/api/request'; + +enum Api { + ossDownload = '/resource/oss/download', + ossInfo = '/resource/oss/listByIds', + ossList = '/resource/oss/list', + ossUpload = '/resource/oss/upload', + root = '/resource/oss', +} + +export function ossList(params?: PageQuery) { + return requestClient.get>(Api.ossList, { params }); +} + +export function ossInfo(ossIds: IDS) { + return requestClient.get(`${Api.ossInfo}/${ossIds}`); +} + +/** + * @deprecated + * @param file 文件 + * @returns void + */ +export function ossUpload(file: any) { + const formData = new FormData(); + formData.append('file', file); + return requestClient.postWithMsg(Api.ossUpload, formData, { + headers: { 'Content-Type': ContentTypeEnum.FORM_DATA }, + timeout: 30 * 1000, + }); +} + +/** + * 下载文件 返回为二进制 + * @param ossId ossId + * @returns blob + */ +export function ossDownload(ossId: ID) { + return requestClient.get(`${Api.ossDownload}/${ossId}`, { + responseType: 'blob', + timeout: 30 * 1000, + isTransformResponse: false, + }); +} + +export function ossRemove(ossIds: IDS) { + return requestClient.deleteWithMsg(`${Api.root}/${ossIds}`); +} diff --git a/apps/web-antd/src/api/system/oss/model.d.ts b/apps/web-antd/src/api/system/oss/model.d.ts new file mode 100644 index 00000000..6eb4f371 --- /dev/null +++ b/apps/web-antd/src/api/system/oss/model.d.ts @@ -0,0 +1,28 @@ +export interface OssFile { + ossId: string; + fileName: string; + originalName: string; + fileSuffix: string; + url: string; + createTime: string; + createBy: number; + createByName: string; + service: string; +} + +export interface OssConfig { + ossConfigId: number; + configKey: string; + accessKey: string; + secretKey: string; + bucketName: string; + prefix: string; + endpoint: string; + domain: string; + isHttps: string; + region: string; + status: string; + ext1: string; + remark: string; + accessPolicy: string; +} diff --git a/apps/web-antd/src/views/system/oss-config/data.tsx b/apps/web-antd/src/views/system/oss-config/data.tsx index e2ce1f0e..dd4d2d33 100644 --- a/apps/web-antd/src/views/system/oss-config/data.tsx +++ b/apps/web-antd/src/views/system/oss-config/data.tsx @@ -1,6 +1,8 @@ import { DictEnum } from '@vben/constants'; -import { type FormSchemaGetter, z } from '#/adapter'; +import { Tag } from 'ant-design-vue'; + +import { type FormSchemaGetter, type VxeGridProps, z } from '#/adapter'; import { getDictOptions } from '#/utils/dict'; const accessPolicyOptions = [ @@ -30,6 +32,56 @@ export const querySchema: FormSchemaGetter = () => [ }, ]; +export const columns: VxeGridProps['columns'] = [ + { type: 'checkbox', width: 60 }, + { + title: '配置名称', + field: 'configKey', + }, + { + title: '访问站点', + field: 'endpoint', + showOverflow: true, + }, + { + title: '桶名称', + field: 'bucketName', + }, + { + title: '域', + field: 'region', + }, + { + title: '权限桶类型', + field: 'accessPolicy', + slots: { + default: ({ row }) => { + const current = accessPolicyOptions.find( + (item) => item.value === row.accessPolicy, + ); + if (current) { + return {current.label}; + } + return '未知类型'; + }, + }, + }, + { + title: '是否默认', + field: 'status', + slots: { + default: 'status', + }, + }, + { + field: 'action', + fixed: 'right', + slots: { default: 'action' }, + title: '操作', + width: 180, + }, +]; + export const drawerSchema: FormSchemaGetter = () => [ { component: 'Input', diff --git a/apps/web-antd/src/views/system/oss-config/index.vue b/apps/web-antd/src/views/system/oss-config/index.vue index 97ba7b3e..b51d80b7 100644 --- a/apps/web-antd/src/views/system/oss-config/index.vue +++ b/apps/web-antd/src/views/system/oss-config/index.vue @@ -1,51 +1,174 @@ diff --git a/apps/web-antd/src/views/system/oss/data.tsx b/apps/web-antd/src/views/system/oss/data.tsx index 4333f5cb..e3f02143 100644 --- a/apps/web-antd/src/views/system/oss/data.tsx +++ b/apps/web-antd/src/views/system/oss/data.tsx @@ -1,4 +1,4 @@ -import type { FormSchemaGetter } from '#/adapter'; +import type { FormSchemaGetter, VxeGridProps } from '#/adapter'; export const querySchema: FormSchemaGetter = () => [ { @@ -27,3 +27,46 @@ export const querySchema: FormSchemaGetter = () => [ label: '创建时间', }, ]; + +export const columns: VxeGridProps['columns'] = [ + { type: 'checkbox', width: 60 }, + { + title: '文件名', + field: 'fileName', + showOverflow: true, + }, + { + title: '文件原名', + field: 'originalName', + showOverflow: true, + }, + { + title: '文件拓展名', + field: 'fileSuffix', + }, + { + title: '文件预览', + field: 'url', + showOverflow: true, + slots: { default: 'url' }, + }, + { + title: '创建时间', + field: 'createTime', + }, + { + title: '上传人', + field: 'createByName', + }, + { + title: '服务商', + field: 'service', + }, + { + field: 'action', + fixed: 'right', + slots: { default: 'action' }, + title: '操作', + width: 180, + }, +]; diff --git a/apps/web-antd/src/views/system/oss/index.vue b/apps/web-antd/src/views/system/oss/index.vue index 417faea2..7f314a7c 100644 --- a/apps/web-antd/src/views/system/oss/index.vue +++ b/apps/web-antd/src/views/system/oss/index.vue @@ -1,53 +1,194 @@