From f4d762d0d05939b10e644bb62c941e6a5b8da353 Mon Sep 17 00:00:00 2001 From: yinq Date: Fri, 5 Jun 2026 16:22:27 +0800 Subject: [PATCH] =?UTF-8?q?1.1.58=20=E9=82=AE=E5=AF=84=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=9A=84=E9=99=84=E4=BB=B6=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E9=A2=84=E8=A7=88=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/FileUpload/index.vue | 25 ++++ src/components/OssFilePreview/index.vue | 164 ++++++++++++++++++++++ src/utils/ossPreview.ts | 37 +++++ src/views/oa/crm/crmMailingApply/edit.vue | 7 +- 4 files changed, 230 insertions(+), 3 deletions(-) create mode 100644 src/components/OssFilePreview/index.vue create mode 100644 src/utils/ossPreview.ts diff --git a/src/components/FileUpload/index.vue b/src/components/FileUpload/index.vue index c8a08e0..683a731 100644 --- a/src/components/FileUpload/index.vue +++ b/src/components/FileUpload/index.vue @@ -35,11 +35,20 @@
  • {{ getFileName(file.name) }}
    + 预览 下载 删除
  • + + @@ -47,6 +56,7 @@ import { propTypes } from '@/utils/propTypes'; import { delOss, listByIds } from '@/api/system/oss'; import { globalHeaders } from '@/utils/request'; +import { isImageFileName } from '@/utils/ossPreview'; const props = defineProps({ modelValue: { @@ -75,6 +85,9 @@ const uploadFileUrl = ref(baseUrl + '/resource/oss/upload'); // 上传文件服 const headers = ref(globalHeaders()); const fileList = ref([]); +const previewVisible = ref(false); +const previewUrlList = ref([]); +const previewIndex = ref(0); const showTip = computed(() => props.isShowTip && (props.fileType || props.fileSize)); const fileUploadRef = ref(); @@ -183,6 +196,18 @@ const handleDownload = (file: any) => { } }; +const isImageFile = (file: any) => isImageFileName(file.name); + +const handlePreview = (file: any) => { + const imageFiles = fileList.value.filter((item) => isImageFile(item) && item.url); + previewUrlList.value = imageFiles.map((item) => item.url); + previewIndex.value = Math.max( + imageFiles.findIndex((item) => item.url === file.url), + 0 + ); + previewVisible.value = true; +}; + // 删除文件 const handleDelete = (index: number) => { const ossId = fileList.value[index].ossId; diff --git a/src/components/OssFilePreview/index.vue b/src/components/OssFilePreview/index.vue new file mode 100644 index 0000000..e9e9f1b --- /dev/null +++ b/src/components/OssFilePreview/index.vue @@ -0,0 +1,164 @@ + + + + + diff --git a/src/utils/ossPreview.ts b/src/utils/ossPreview.ts new file mode 100644 index 0000000..06a4dd1 --- /dev/null +++ b/src/utils/ossPreview.ts @@ -0,0 +1,37 @@ +/** 支持预览的图片扩展名 */ +export const IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp']; + +/** 根据文件名判断是否为可预览图片 */ +export function isImageFileName(fileName?: string): boolean { + if (!fileName) { + return false; + } + const ext = fileName.split('.').pop()?.toLowerCase() || ''; + return IMAGE_EXTENSIONS.includes(ext); +} + +/** 根据 OSS 文件信息判断是否为可预览图片 */ +export function isImageOssFile(file?: { fileSuffix?: string; originalName?: string; name?: string; url?: string }): boolean { + if (!file) { + return false; + } + if (file.fileSuffix) { + const suffix = file.fileSuffix.startsWith('.') ? file.fileSuffix.slice(1) : file.fileSuffix; + return IMAGE_EXTENSIONS.includes(suffix.toLowerCase()); + } + return isImageFileName(file.originalName || file.name); +} + +/** 从 ossId 字符串或数组中解析 ID 列表 */ +export function parseOssIds(value?: string | number | Array): string[] { + if (value === undefined || value === null || value === '') { + return []; + } + if (Array.isArray(value)) { + return value.map((item) => String(item)).filter(Boolean); + } + return String(value) + .split(',') + .map((item) => item.trim()) + .filter(Boolean); +} diff --git a/src/views/oa/crm/crmMailingApply/edit.vue b/src/views/oa/crm/crmMailingApply/edit.vue index dd7fafa..b7b0935 100644 --- a/src/views/oa/crm/crmMailingApply/edit.vue +++ b/src/views/oa/crm/crmMailingApply/edit.vue @@ -27,7 +27,7 @@ - + @@ -155,7 +155,7 @@ :disabled="!isFormEditable" :isShowTip="true" /> -
    提示:请上传邮寄实物图片和快递单截图
    +
    提示:请上传邮寄实物图片和快递单截图,图片可点击预览
    @@ -362,6 +362,7 @@ const initFormData: CrmMailingApplyForm = { const data = reactive<{ form: CrmMailingApplyForm; rules: any }>({ form: { ...initFormData }, rules: { + mailingApplyCode: [{ required: true, message: '邮寄申请编号不能为空', trigger: 'blur' }], applicationDate: [{ required: true, message: '申请日期不能为空', trigger: 'blur' }], handlerId: [{ required: true, message: '经手人不能为空', trigger: 'change' }], province: [{ required: true, message: '省份不能为空', trigger: 'blur' }], @@ -596,7 +597,7 @@ const submitForm = async (status: string, mode: boolean) => { try { if (status === 'draft') { - await mailingApplyFormRef.value.validateField(['applicationDate', 'handlerId', 'province', 'weight', 'mailingType', 'mailingFee', 'itemInfo']); + await mailingApplyFormRef.value.validateField(['mailingApplyCode', 'applicationDate', 'handlerId', 'province', 'weight', 'mailingType', 'mailingFee', 'itemInfo']); } else { await mailingApplyFormRef.value.validate(); }