From 38fc9e10f2b262db96e51b26adec4222733fa494 Mon Sep 17 00:00:00 2001 From: zhouhaibin Date: Wed, 18 Dec 2024 10:12:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=A8=A1=E6=9D=BF=E7=B3=BB=E7=BB=9F=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/upload/index.ts | 1 + .../Upload/src/components/UploadModal.vue | 33 +++++++++++++++++-- src/components/Upload/src/props.ts | 5 +++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/api/upload/index.ts b/src/api/upload/index.ts index 6842a60..7f0a2d7 100644 --- a/src/api/upload/index.ts +++ b/src/api/upload/index.ts @@ -15,6 +15,7 @@ export function uploadApi( // 固定url地址 url: '/resource/oss/upload', onUploadProgress, + timeout: 1000 * 60 * 10, }, params, ); diff --git a/src/components/Upload/src/components/UploadModal.vue b/src/components/Upload/src/components/UploadModal.vue index 10e1909..2e7b7fe 100644 --- a/src/components/Upload/src/components/UploadModal.vue +++ b/src/components/Upload/src/components/UploadModal.vue @@ -67,6 +67,8 @@ import FileList from './FileList.vue'; import { useI18n } from '@/hooks/web/useI18n'; import { get } from 'lodash-es'; + import { Modal } from 'ant-design-vue'; + import { createVNode } from 'vue'; const props = defineProps({ ...basicProps, @@ -74,6 +76,10 @@ type: Array as PropType, default: () => [], }, + beforeUploadPrompt: { + type: String as PropType, + default: null, + }, }); const emit = defineEmits(['change', 'register', 'delete']); @@ -124,9 +130,31 @@ }); // 上传前校验 - function beforeUpload(file: File) { + async function beforeUpload(file: File) { const { size, name } = file; - const { maxSize } = props; + const { maxSize, beforeUploadPrompt } = props; + if (beforeUploadPrompt) { + //弹出确实提示框 + try { + await new Promise((resolve, reject) => { + Modal.confirm({ + title: '提醒', + content: ( + createVNode('div', { style: 'color:red;font-weight: bold;font-size: 22px' }, beforeUploadPrompt) ), + onOk() { + resolve(true); + }, + onCancel() { + reject(false); + }, + }); + }); + // 用户点击了确认,继续执行 + } catch (error) { + // 发生错误或用户取消 + return false; + } + } // 设置最大值,则判断 if (maxSize && file.size / 1024 / 1024 >= maxSize) { createMessage.error(t('component.upload.maxSizeMultiple', [maxSize])); @@ -195,6 +223,7 @@ item.status = UploadResultStatus.SUCCESS; // ret为code msg data中的data!!!注意 item.response = ret; + console.log('item', item, ret); if (props.resultField) { // 适配预览组件而进行封装 item.response = { diff --git a/src/components/Upload/src/props.ts b/src/components/Upload/src/props.ts index 0795f59..33863b4 100644 --- a/src/components/Upload/src/props.ts +++ b/src/components/Upload/src/props.ts @@ -8,6 +8,7 @@ import { propTypes } from '@/utils/propTypes'; import { BasicColumn } from '@/components/Table'; import { IconEnum } from '@/enums/appEnum'; import { uploadApi } from '@/api/upload'; +import { s } from 'node_modules/vite/dist/node/types.d-aGj9QkWt'; type SortableOptions = Merge< Omit, @@ -127,6 +128,10 @@ export const uploadContainerProps = { type: Boolean as PropType, default: false, }, + beforeUploadPrompt:{ + type:String as PropType, + default:null, + }, ...previewType, };