diff --git a/src/api/infra/category/index.ts b/src/api/infra/category/index.ts index b422d2d4..ab520c05 100644 --- a/src/api/infra/category/index.ts +++ b/src/api/infra/category/index.ts @@ -1,43 +1,43 @@ -import request from '@/config/axios' - -// 文件目录 VO -export interface CategoryVO { - id: number // 主键 - code: string // 编号 - name: string // 文件夹名称 - parentId: number // 父id - description: string // 描述 -} - -// 文件目录 API -export const CategoryApi = { - // 查询文件目录列表 - getCategoryList: async (params) => { - return await request.get({ url: `/infra/category/list`, params }) - }, - - // 查询文件目录详情 - getCategory: async (id: number) => { - return await request.get({ url: `/infra/category/get?id=` + id }) - }, - - // 新增文件目录 - createCategory: async (data: CategoryVO) => { - return await request.post({ url: `/infra/category/create`, data }) - }, - - // 修改文件目录 - updateCategory: async (data: CategoryVO) => { - return await request.put({ url: `/infra/category/update`, data }) - }, - - // 删除文件目录 - deleteCategory: async (id: number) => { - return await request.delete({ url: `/infra/category/delete?id=` + id }) - }, - - // 导出文件目录 Excel - exportCategory: async (params) => { - return await request.download({ url: `/infra/category/export-excel`, params }) - }, -} \ No newline at end of file +import request from '@/config/axios' + +// 文件目录 VO +export interface CategoryVO { + id: number // 主键 + code: string // 编号 + name: string // 文件夹名称 + parentId: number // 父id + description: string // 描述 +} + +// 文件目录 API +export const CategoryApi = { + // 查询文件目录列表 + getCategoryList: async (params?: any) => { + return await request.get({ url: `/infra/category/list`, params }) + }, + + // 查询文件目录详情 + getCategory: async (id: number) => { + return await request.get({ url: `/infra/category/get?id=` + id }) + }, + + // 新增文件目录 + createCategory: async (data: CategoryVO) => { + return await request.post({ url: `/infra/category/create`, data }) + }, + + // 修改文件目录 + updateCategory: async (data: CategoryVO) => { + return await request.put({ url: `/infra/category/update`, data }) + }, + + // 删除文件目录 + deleteCategory: async (id: number) => { + return await request.delete({ url: `/infra/category/delete?id=` + id }) + }, + + // 导出文件目录 Excel + exportCategory: async (params?: any) => { + return await request.download({ url: `/infra/category/export-excel`, params }) + } +} diff --git a/src/api/infra/file/index.ts b/src/api/infra/file/index.ts index 75bd6124..f6ddba67 100644 --- a/src/api/infra/file/index.ts +++ b/src/api/infra/file/index.ts @@ -4,6 +4,7 @@ export interface FilePageReqVO extends PageParam { path?: string type?: string createTime?: Date[] + categoryId?: number } // 文件预签名地址 Response VO @@ -45,6 +46,6 @@ export const updateFile = (data: any) => { } // 上传文件 -export const updateFileEx = (data: any) => { - return request.upload({ url: '/infra/file/uploadEx', data }) +export const updateFileEx = (data: any, params?: any) => { + return request.upload({ url: '/infra/file/uploadEx', params, data }) } diff --git a/src/components/UploadFile/src/useUpload.ts b/src/components/UploadFile/src/useUpload.ts index d22240a3..d63a5ed6 100644 --- a/src/components/UploadFile/src/useUpload.ts +++ b/src/components/UploadFile/src/useUpload.ts @@ -14,7 +14,7 @@ export const useUpload = () => { // 是否使用前端直连上传 const isClientUpload = UPLOAD_TYPE.CLIENT === import.meta.env.VITE_UPLOAD_TYPE // 重写ElUpload上传方法 - const httpRequest = async (options: UploadRequestOptions) => { + const httpRequest = async (options: UploadRequestOptions, params?: any) => { // 模式一:前端上传 if (isClientUpload) { // 1.1 生成文件名称 @@ -22,21 +22,23 @@ export const useUpload = () => { // 1.2 获取文件预签名地址 const presignedInfo = await FileApi.getFilePresignedUrl(fileName) // 1.3 上传文件(不能使用 ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传,Minio 不支持) - return axios.put(presignedInfo.uploadUrl, options.file, { - headers: { - 'Content-Type': options.file.type, - } - }).then(() => { - // 1.4. 记录文件信息到后端(异步) - createFile(presignedInfo, fileName, options.file) - // 通知成功,数据格式保持与后端上传的返回结果一致 - return { data: presignedInfo.url } - }) + return axios + .put(presignedInfo.uploadUrl, options.file, { + headers: { + 'Content-Type': options.file.type + } + }) + .then(() => { + // 1.4. 记录文件信息到后端(异步) + createFile(presignedInfo, fileName, options.file) + // 通知成功,数据格式保持与后端上传的返回结果一致 + return { data: presignedInfo.url } + }) } else { // 模式二:后端上传 // 重写 el-upload httpRequest 文件上传成功会走成功的钩子,失败走失败的钩子 return new Promise((resolve, reject) => { - FileApi.updateFileEx({ file: options.file }) + FileApi.updateFileEx({ file: options.file }, params) .then((res) => { if (res.code === 0) { resolve(res) diff --git a/src/views/infra/category/CategoryForm.vue b/src/views/infra/category/CategoryForm.vue index 31b1adfc..898c3e8b 100644 --- a/src/views/infra/category/CategoryForm.vue +++ b/src/views/infra/category/CategoryForm.vue @@ -62,13 +62,13 @@ const formRef = ref() // 表单 Ref const categoryTree = ref() // 树形结构 /** 打开弹窗 */ -const open = async (type: string, id?: number) => { +const open = async (type: string, id: number) => { dialogVisible.value = true dialogTitle.value = t('action.' + type) formType.value = type resetForm() // 修改时,设置数据 - if (id) { + if (type === 'update') { formLoading.value = true try { formData.value = await CategoryApi.getCategory(id) @@ -76,6 +76,10 @@ const open = async (type: string, id?: number) => { formLoading.value = false } } + // 新增时,设置默认上一级 + else{ + formData.value.parentId = id; + } await getCategoryTree() } defineExpose({ open }) // 提供 open 方法,用于打开弹窗 diff --git a/src/views/infra/category/FolderTree.vue b/src/views/infra/category/FolderTree.vue new file mode 100644 index 00000000..d210f6ce --- /dev/null +++ b/src/views/infra/category/FolderTree.vue @@ -0,0 +1,201 @@ + + + + + diff --git a/src/views/infra/category/index.vue b/src/views/infra/category/index.vue index 8b27f69a..dbc716ed 100644 --- a/src/views/infra/category/index.vue +++ b/src/views/infra/category/index.vue @@ -1,199 +1,186 @@