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 @@
+
+
+
+
+
+
+
+
+
+
{{ getDisplayName(file) }}
+
+
+
+
+ -
+
+ {{ getDisplayName(file) }}
+
+
+
+
{{ emptyText }}
+
+
+
+
+
+
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();
}