From e8ee651e5c9bf8a4e3bb45d78458866cbca68311 Mon Sep 17 00:00:00 2001
From: bubu <3357025395@qq.com>
Date: Sat, 29 Mar 2025 10:16:45 +0800
Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8D=87=E7=BA=A7=E3=80=91=E6=94=AF?=
=?UTF-8?q?=E6=8C=81=E8=A7=86=E9=A2=91=E4=B8=8A=E4=BC=A0=E3=80=81=E8=A7=86?=
=?UTF-8?q?=E9=A2=91=E9=A2=84=E8=A7=88=E3=80=81=E4=B8=8A=E4=BC=A0=E6=88=90?=
=?UTF-8?q?=E5=8A=9F=E4=BA=8B=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/components/XnUpload/README.md | 2 +-
.../src/components/XnUpload/index.vue | 84 ++++++++++++++-----
2 files changed, 65 insertions(+), 21 deletions(-)
diff --git a/snowy-admin-web/src/components/XnUpload/README.md b/snowy-admin-web/src/components/XnUpload/README.md
index d4246536..1e574978 100644
--- a/snowy-admin-web/src/components/XnUpload/README.md
+++ b/snowy-admin-web/src/components/XnUpload/README.md
@@ -31,7 +31,7 @@
|----|--------|---------------------------------------|-----------------------------|
| 1 | value | 根据uploadResultType、completeResult 而定 | 当选择用户后通过v-model:value绑定到组件上 |
| 2 | onChange | 根据uploadResultType、completeResult 而定 | 通过@onChange 方法返回上传的数据 |
-
+| 3 | onSuccessful | fileUrl | 通过@onSuccessful 方法接收上传成功的文件url |
### slot定义
| 序号 | 插槽名 | 用途 |
diff --git a/snowy-admin-web/src/components/XnUpload/index.vue b/snowy-admin-web/src/components/XnUpload/index.vue
index 7ad914c1..ed37ee68 100644
--- a/snowy-admin-web/src/components/XnUpload/index.vue
+++ b/snowy-admin-web/src/components/XnUpload/index.vue
@@ -18,6 +18,27 @@
+
+
+
+
{{ props.uploadText }}
+
+
+
{{ props.uploadText }}
-
-
+
+
+
+
+
+
+
+
+
+
+ 暂不支持该文件预览
+
{
- const isPNG = file.type.startsWith('image/')
- if (!isPNG) {
- message.warning('只能上传图片类型文件')
+ if (props.uploadMode == 'image') {
+ const isPNG = file.type.startsWith('image/')
+ if (!isPNG) {
+ message.warning('只能上传图片类型文件')
+ }
+ return isPNG || Upload.LIST_IGNORE
+ }
+ else if (props.uploadMode == 'video') {
+ const isVideo = file.type.startsWith('video/')
+ if (!isVideo) {
+ message.warning('只能上传视频类型文件')
+ }
+ return isVideo || Upload.LIST_IGNORE
}
- return isPNG || Upload.LIST_IGNORE
}
- // 预览图片
+ // 预览资源
const handlePreview = async (file) => {
previewVisible.value = true
previewTitle.value = file.name
// 如果返回的是id
if (props.uploadResultType === 'id') {
- previewImage.value = sysConfig.API_URL + props.uploadIdDownloadUrl + file.response.data
+ previewObj.value = sysConfig.API_URL + props.uploadIdDownloadUrl + file.response.data
} else {
- previewImage.value = file.response.data
+ previewObj.value = file.response.data
}
}
// 关闭预览窗口
const handleCancel = () => {
previewVisible.value = false
previewTitle.value = ''
- previewImage.value = ''
+ previewObj.value = ''
}
// 上传事件
const handleChange = (uploads) => {
@@ -308,6 +348,7 @@
data.response.data + (resultIntervalValue.value ? ',' + resultIntervalValue.value : '')
})
emit('update:value', resultIntervalValue)
+ emit('onSuccessful',resultIntervalValue)
emit('onChange', resultIntervalValue)
} else if (props.uploadResultCategory === 'array') {
if (props.completeResult) {
@@ -319,13 +360,16 @@
}
})
emit('update:value', newResult)
+ emit('onSuccessful',newResult)
emit('onChange', newResult)
- } else {
+ }
+ else {
const resultArrayValue = ref([])
result.forEach((data) => {
resultArrayValue.value.push(data.response.data)
})
emit('update:value', resultArrayValue)
+ emit('onSuccessful',resultArrayValue)
emit('onChange', resultArrayValue)
}
}