From 41d4f9c506905b709da1a0c269393b4b248ed733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=9E=E5=AE=9D=E5=B1=B1?= <1253070437@qq.com> Date: Wed, 5 Jun 2024 16:09:00 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=9B=B4=E6=96=B0=E3=80=91=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E7=BB=84=E4=BB=B6=E4=B8=8E=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E7=BB=84=E4=BB=B6=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/XnFilePreview/index.vue | 32 +++++++++++-------- .../src/components/XnUpload/index.vue | 23 +++++++++++++ 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/snowy-admin-web/src/components/XnFilePreview/index.vue b/snowy-admin-web/src/components/XnFilePreview/index.vue index c7a6ed3e..f8af5d48 100644 --- a/snowy-admin-web/src/components/XnFilePreview/index.vue +++ b/snowy-admin-web/src/components/XnFilePreview/index.vue @@ -78,23 +78,29 @@ const fileType = ref() watch( () => props.src, - () => { - fileType.value = props.fileType.toLowerCase() - } + (newVal) => { + if (newVal) { + fileType.value = props.fileType.toLowerCase() + } + }, + { immediate: true, deep: true } ) watch( () => props.src, - () => { - if ( - fileType.value === 'doc' || - fileType.value === 'docx' || - fileType.value === 'xls' || - fileType.value === 'xlsx' || - fileType.value === 'pdf' - ) { - loading.value = true + (newVal) => { + if (newVal) { + if ( + fileType.value === 'doc' || + fileType.value === 'docx' || + fileType.value === 'xls' || + fileType.value === 'xlsx' || + fileType.value === 'pdf' + ) { + loading.value = true + } } - } + }, + { immediate: true, deep: true } ) // 渲染完成 const renderedHandler = () => { diff --git a/snowy-admin-web/src/components/XnUpload/index.vue b/snowy-admin-web/src/components/XnUpload/index.vue index baf5a8ee..a30a932b 100644 --- a/snowy-admin-web/src/components/XnUpload/index.vue +++ b/snowy-admin-web/src/components/XnUpload/index.vue @@ -333,4 +333,27 @@ emit('update:value', undefined) emit('onChange', undefined) } + // 通过DOM获取上传的文件 + const uploadFileList = () => { + if (fileList.value) { + const result = [] + // 只返回这些就够用了,其他基本用不到 + fileList.value.forEach((item) => { + const obj = { + name: item.name, + type: item.type, + size: item.size, + url: item.response.data + } + result.push(obj) + }) + return result + } else { + return [] + } + } + // 抛出这个获取文件列表的方法 + defineExpose({ + uploadFileList + }) </script>