diff --git a/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/controller/FileController.java b/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/controller/FileController.java index 2cdf2ee6..c27020d4 100644 --- a/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/controller/FileController.java +++ b/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/controller/FileController.java @@ -4,16 +4,14 @@ import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.cloud.kicc.system.api.entity.File; -import com.cloud.kicc.system.api.entity.Role; -import com.cloud.kicc.system.api.entity.RoleMenu; -import com.cloud.kicc.system.service.FileService; import com.cloud.kicc.common.core.api.R; import com.cloud.kicc.common.core.constant.AppConstants; import com.cloud.kicc.common.log.annotation.SysLog; import com.cloud.kicc.common.security.annotation.Inner; +import com.cloud.kicc.system.api.entity.File; +import com.cloud.kicc.system.api.entity.Role; +import com.cloud.kicc.system.service.FileService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; @@ -24,7 +22,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; -import java.util.Arrays; /** *

@@ -44,7 +41,7 @@ public class FileController { private LambdaQueryWrapper getQueryWrapper(File file) { return new LambdaQueryWrapper() - .like(StrUtil.isNotBlank(file.getFileName()), File::getFileName, file.getFileName()); + .like(StrUtil.isNotBlank(file.getOriginal()), File::getOriginal, file.getOriginal()); } @GetMapping("/list") @@ -60,13 +57,14 @@ public class FileController { } @Inner(false) - @GetMapping("/{bucket}/{fileName}") + @GetMapping("/getFile/{bucket}/{fileName}") public void getById(@PathVariable String bucket, @PathVariable String fileName, HttpServletResponse response) { fileService.getFile(bucket, fileName, response); } /** 获取上传模板 */ @SneakyThrows + @Inner(false) @GetMapping("/local/{fileName}") public void localFile(@PathVariable String fileName, HttpServletResponse response) { ClassPathResource resource = new ClassPathResource("file/" + fileName); @@ -76,7 +74,7 @@ public class FileController { @SysLog("删除文件管理") @DeleteMapping("/remove/{ids:[\\w,]+}") - @PreAuthorize("@pms.hasPermission('sys_file_del')") + @PreAuthorize("@pms.hasPermission('file_del')") @ApiOperation(value = "通过id删除文件管理", notes = "通过id删除文件管理") public R remove(@PathVariable String[] ids) { for (int i = 0; i < ids.length; ++i) { diff --git a/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/FileService.java b/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/FileService.java index 31515d87..d5865830 100644 --- a/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/FileService.java +++ b/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/FileService.java @@ -37,6 +37,6 @@ public interface FileService extends IService { * @param id * @return Boolean */ - Boolean deleteFile(String id); + void deleteFile(String id); } diff --git a/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/impl/FileServiceImpl.java b/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/impl/FileServiceImpl.java index a9c70ce2..9c347956 100644 --- a/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/impl/FileServiceImpl.java +++ b/kicc-platform/kicc-platform-biz/kicc-system-biz/src/main/java/com/cloud/kicc/system/service/impl/FileServiceImpl.java @@ -3,6 +3,7 @@ package com.cloud.kicc.system.service.impl; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.amazonaws.services.s3.model.S3Object; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -44,7 +45,7 @@ public class FileServiceImpl extends ServiceImpl implements Fi Map resultMap = new HashMap<>(4); resultMap.put("bucketName", ossProperties.getBucketName()); resultMap.put("fileName", fileName); - resultMap.put("url", String.format("/admin/sys-file/%s/%s", ossProperties.getBucketName(), fileName)); + resultMap.put("url", String.format("/system_proxy/system/file/%s/%s", ossProperties.getBucketName(), fileName)); try { ossTemplate.putObject(ossProperties.getBucketName(), fileName, file.getContentType(), file.getInputStream()); // 文件管理数据记录,收集管理追踪文件 @@ -69,10 +70,12 @@ public class FileServiceImpl extends ServiceImpl implements Fi @Override @SneakyThrows @Transactional(rollbackFor = Exception.class) - public Boolean deleteFile(String id) { + public void deleteFile(String id) { File file = this.getById(id); - ossTemplate.removeObject(ossProperties.getBucketName(), file.getFileName()); - return this.removeById(id); + if (ObjectUtil.isNotEmpty(file)) { + ossTemplate.removeObject(ossProperties.getBucketName(), file.getFileName()); + this.removeById(id); + } } /** diff --git a/kicc-ui/src/api/platform/system/controller/file.ts b/kicc-ui/src/api/platform/system/controller/file.ts index ccab8f5d..d6fb0537 100644 --- a/kicc-ui/src/api/platform/system/controller/file.ts +++ b/kicc-ui/src/api/platform/system/controller/file.ts @@ -5,10 +5,13 @@ */ import type { FileParams, FileResult } from '/@/api/platform/system/entity/file'; import { defHttp } from '/@/utils/http/axios'; +import { downloadByUrl } from '/@/utils/file/download'; +import { useGlobSetting } from '/@/hooks/setting'; +const { apiUrl } = useGlobSetting(); enum Api { list = '/system_proxy/system/file/list', - get = '/system_proxy/system/file', + get = '/system_proxy/system/file/getFile', getLocal = '/system_proxy/system/file/local', del = '/system_proxy/system/file/remove' } @@ -17,7 +20,7 @@ enum Api { export const listFile = (params?: Partial) => defHttp.get({ url: Api.list, params }, { isReturnResultResponse: true }); /** 获取文件 */ -export const getFile = (bucket: string, fileName: string) => defHttp.get({ url: `${Api.get}/${bucket}/${fileName}` }); +export const getFile = (bucket: string, fileName: string) => Promise.resolve(downloadByUrl({ url: `${apiUrl}/${Api.get}/${bucket}/${fileName}`, fileName: fileName })); /** 获取本地模板文件 */ export const getLocalFile = (fileName: string) => defHttp.get({ url: `${Api.getLocal}/${fileName}` }); diff --git a/kicc-ui/src/components/Upload/src/BasicUpload.vue b/kicc-ui/src/components/Upload/src/BasicUpload.vue index 5504df89..c80e3f50 100644 --- a/kicc-ui/src/components/Upload/src/BasicUpload.vue +++ b/kicc-ui/src/components/Upload/src/BasicUpload.vue @@ -1,6 +1,6 @@ - - + diff --git a/kicc-ui/src/components/Upload/src/ThumbUrl.vue b/kicc-ui/src/components/Upload/src/ThumbUrl.vue index 4529358d..75c45c1c 100644 --- a/kicc-ui/src/components/Upload/src/ThumbUrl.vue +++ b/kicc-ui/src/components/Upload/src/ThumbUrl.vue @@ -1,29 +1,29 @@ diff --git a/kicc-ui/src/components/Upload/src/UploadModal.vue b/kicc-ui/src/components/Upload/src/UploadModal.vue index be8d174d..eca44287 100644 --- a/kicc-ui/src/components/Upload/src/UploadModal.vue +++ b/kicc-ui/src/components/Upload/src/UploadModal.vue @@ -7,7 +7,8 @@ :closeFunc="handleCloseFunc" :maskClosable="false" :keyboard="false" - wrapClassName="upload-modal" + :showOkBtn="showUploadSaveBtn" + class="upload-modal" :okButtonProps="getOkButtonProps" :cancelButtonProps="{ disabled: isUploadingRef }" @register="register" @@ -35,6 +36,7 @@ :accept="getStringAccept" :multiple="multiple" :before-upload="beforeUpload" + :show-upload-list="false" class="upload-modal-toolbar__btn" > @@ -46,23 +48,25 @@ diff --git a/kicc-ui/src/components/Upload/src/UploadPreviewModal.vue b/kicc-ui/src/components/Upload/src/UploadPreviewModal.vue index 650f6bcc..61095b11 100644 --- a/kicc-ui/src/components/Upload/src/UploadPreviewModal.vue +++ b/kicc-ui/src/components/Upload/src/UploadPreviewModal.vue @@ -2,7 +2,7 @@ diff --git a/kicc-ui/src/components/Upload/src/data.tsx b/kicc-ui/src/components/Upload/src/data.tsx index be5d3a08..bb4a1f7b 100644 --- a/kicc-ui/src/components/Upload/src/data.tsx +++ b/kicc-ui/src/components/Upload/src/data.tsx @@ -1,6 +1,9 @@ import type { BasicColumn, ActionItem } from '/@/components/Table'; import { FileItem, PreviewFileItem, UploadResultStatus } from './typing'; -import { isImgTypeByName } from './helper'; +import { + // checkImgType, + isImgTypeByName, +} from './helper'; import { Progress, Tag } from 'ant-design-vue'; import TableAction from '/@/components/Table/src/components/TableAction.vue'; import ThumbUrl from './ThumbUrl.vue'; @@ -89,6 +92,12 @@ export function createActionColumn(handleRemove: Function): BasicColumn { onClick: handleRemove.bind(null, record), }, ]; + // if (checkImgType(record)) { + // actions.unshift({ + // label: t('component.upload.preview'), + // onClick: handlePreview.bind(null, record), + // }); + // } return ; }, }; @@ -114,9 +123,9 @@ export function createPreviewColumns(): BasicColumn[] { } export function createPreviewActionColumn({ - handleRemove, - handleDownload, -}: { + handleRemove, + handleDownload, + }: { handleRemove: Fn; handleDownload: Fn; }): BasicColumn { diff --git a/kicc-ui/src/components/Upload/src/helper.ts b/kicc-ui/src/components/Upload/src/helper.ts index 53d00416..a0c574b7 100644 --- a/kicc-ui/src/components/Upload/src/helper.ts +++ b/kicc-ui/src/components/Upload/src/helper.ts @@ -1,5 +1,6 @@ export function checkFileType(file: File, accepts: string[]) { const newTypes = accepts.join('|'); + // const reg = /\.(jpg|jpeg|png|gif|txt|doc|docx|xls|xlsx|xml)$/i; const reg = new RegExp('\\.(' + newTypes + ')$', 'i'); return reg.test(file.name); diff --git a/kicc-ui/src/components/Upload/src/props.ts b/kicc-ui/src/components/Upload/src/props.ts index e1061fca..568366c0 100644 --- a/kicc-ui/src/components/Upload/src/props.ts +++ b/kicc-ui/src/components/Upload/src/props.ts @@ -34,6 +34,18 @@ export const basicProps = { default: null, required: true, }, + name: { + type: String as PropType, + default: 'file', + }, + showUploadSaveBtn: { + type: Boolean as PropType, + default: false, + }, + filename: { + type: String as PropType, + default: null, + }, }; export const uploadContainerProps = { diff --git a/kicc-ui/src/components/Upload/src/typing.ts b/kicc-ui/src/components/Upload/src/typing.ts index 72eaea12..c6301100 100644 --- a/kicc-ui/src/components/Upload/src/typing.ts +++ b/kicc-ui/src/components/Upload/src/typing.ts @@ -1,4 +1,4 @@ -import { UploadResult } from '/@/api/platform/core/entity/upload'; +import { UploadApiResult } from '/@/api/sys/model/uploadModel'; export enum UploadResultStatus { SUCCESS = 'success', @@ -14,7 +14,7 @@ export interface FileItem { percent: number; file: File; status?: UploadResultStatus; - responseData?: UploadResult; + responseData?: UploadApiResult; uuid: string; } @@ -26,28 +26,28 @@ export interface PreviewFileItem { export interface FileBasicColumn { /** - * 表格单元格的渲染器。返回值应该是 VNode,或者 colSpanrowSpan 配置的对象 + * Renderer of the table cell. The return value should be a VNode, or an object for colSpan/rowSpan config * @type Function | ScopedSlot */ customRender?: Function; /** - * 本栏目标题 + * Title of this column * @type any (string | slot) */ title: string; /** - * 此列的宽度 + * Width of this column * @type string | number */ width?: number; /** - * 数据记录的显示字段,可以设置为 a.b.c + * Display field of the data record, could be set like a.b.c * @type string */ dataIndex: string; /** - * 指定内容如何对齐 + * specify how content is aligned * @default 'left' * @type string */ diff --git a/kicc-ui/src/components/Upload/src/useUpload.ts b/kicc-ui/src/components/Upload/src/useUpload.ts index 213cc3a2..c8dab627 100644 --- a/kicc-ui/src/components/Upload/src/useUpload.ts +++ b/kicc-ui/src/components/Upload/src/useUpload.ts @@ -2,11 +2,11 @@ import { Ref, unref, computed } from 'vue'; import { useI18n } from '/@/hooks/web/useI18n'; const { t } = useI18n(); export function useUploadType({ - acceptRef, - helpTextRef, - maxNumberRef, - maxSizeRef, -}: { + acceptRef, + helpTextRef, + maxNumberRef, + maxSizeRef, + }: { acceptRef: Ref; helpTextRef: Ref; maxNumberRef: Ref; @@ -22,7 +22,13 @@ export function useUploadType({ }); const getStringAccept = computed(() => { return unref(getAccept) - .map((item) => `.${item}`) + .map((item) => { + if (item.indexOf('/') > 0 || item.startsWith('.')) { + return item; + } else { + return `.${item}`; + } + }) .join(','); }); diff --git a/kicc-ui/src/utils/http/axios/Axios.ts b/kicc-ui/src/utils/http/axios/Axios.ts index 894673f0..1f7a62fb 100644 --- a/kicc-ui/src/utils/http/axios/Axios.ts +++ b/kicc-ui/src/utils/http/axios/Axios.ts @@ -115,11 +115,17 @@ export class VAxios { /** 上传文件 */ uploadFile(config: AxiosRequestConfig, params: UploadFileParams) { const formData = new window.FormData(); + const customFilename = params.name || 'file'; + + if (params.filename) { + formData.append(customFilename, params.file, params.filename); + } else { + formData.append(customFilename, params.file); + } if (params.data) { Object.keys(params.data).forEach((key) => { - if (!params.data) return; - const value = params.data[key]; + const value = params.data![key]; if (Array.isArray(value)) { value.forEach((item) => { formData.append(`${key}[]`, item); @@ -127,15 +133,9 @@ export class VAxios { return; } - formData.append(key, params.data[key]); + formData.append(key, params.data![key]); }); } - formData.append(params.name || 'file', params.file, params.filename); - const customParams = omit(params, 'file', 'filename', 'file'); - - Object.keys(customParams).forEach((key) => { - formData.append(key, customParams[key]); - }); return this.axiosInstance.request({ ...config, diff --git a/kicc-ui/src/views/system/file/file.data.ts b/kicc-ui/src/views/system/file/file.data.ts new file mode 100644 index 00000000..59f16cee --- /dev/null +++ b/kicc-ui/src/views/system/file/file.data.ts @@ -0,0 +1,54 @@ +/** + * @program: kicc-ui + * @description: 文件模块动态渲染配置 + * @author: entfrm开发团队-王翔 + * @create: 2022/4/21 + */ + +import { BasicColumn } from '/@/components/Table'; +import { FormSchema } from '/@/components/Table'; + +/** 表格列配置 */ +export const columns: BasicColumn[] = [ + { + title: '源文件名称', + dataIndex: 'original' + }, + { + title: '空间名称', + dataIndex: 'bucketName' + }, + { + title: '文件名称', + dataIndex: 'fileName' + }, + { + title: '文件类型', + dataIndex: 'type' + }, + { + title: '文件大小', + dataIndex: 'fileSize' + }, + { + title: '上传人', + dataIndex: 'createByName' + }, + { + title: '创建时间', + dataIndex: 'createTime' + } +]; + +/** 搜索表单配置 */ +export const searchFormSchema: FormSchema[] = [ + { + field: 'original', + label: '源文件名称', + component: 'Input', + componentProps: { + placeholder: '请输入源文件名称', + }, + colProps: { span: 6 } + } +]; diff --git a/kicc-ui/src/views/system/file/index.vue b/kicc-ui/src/views/system/file/index.vue new file mode 100644 index 00000000..f8206ad0 --- /dev/null +++ b/kicc-ui/src/views/system/file/index.vue @@ -0,0 +1,143 @@ + + +