文件上传更改
This commit is contained in:
parent
845ccfc730
commit
08193a7e76
@ -81,6 +81,7 @@ const props = defineProps({
|
|||||||
const uploadRef = ref<UploadInstance>()
|
const uploadRef = ref<UploadInstance>()
|
||||||
const uploadList = ref<UploadUserFile[]>([])
|
const uploadList = ref<UploadUserFile[]>([])
|
||||||
const fileList = ref<UploadUserFile[]>([])
|
const fileList = ref<UploadUserFile[]>([])
|
||||||
|
const MysqlUrl = ref<UploadUserFile[]>([])
|
||||||
const uploadNumber = ref<number>(0)
|
const uploadNumber = ref<number>(0)
|
||||||
|
|
||||||
const { uploadUrl, httpRequest } = useUpload()
|
const { uploadUrl, httpRequest } = useUpload()
|
||||||
@ -122,9 +123,13 @@ const handleFileSuccess: UploadProps['onSuccess'] = (res: any): void => {
|
|||||||
// 删除自身
|
// 删除自身
|
||||||
const index = fileList.value.findIndex((item) => item.response?.data === res.data)
|
const index = fileList.value.findIndex((item) => item.response?.data === res.data)
|
||||||
fileList.value.splice(index, 1)
|
fileList.value.splice(index, 1)
|
||||||
uploadList.value.push({ name: res.data, url: res.data })
|
// console.log("res",res)
|
||||||
|
uploadList.value.push({ name: res.data[0]+"&&$#$"+res.data[1]+" ", url: res.data[0]+"&&$#$"+res.data[1]+" "})
|
||||||
if (uploadList.value.length == uploadNumber.value) {
|
if (uploadList.value.length == uploadNumber.value) {
|
||||||
|
// console.log("uploadList.value",uploadList.value)
|
||||||
fileList.value.push(...uploadList.value)
|
fileList.value.push(...uploadList.value)
|
||||||
|
MysqlUrl.value.push(...uploadList.value)
|
||||||
|
// console.log("fileList.value111",fileList.value)
|
||||||
uploadList.value = []
|
uploadList.value = []
|
||||||
uploadNumber.value = 0
|
uploadNumber.value = 0
|
||||||
emitUpdateModelValue()
|
emitUpdateModelValue()
|
||||||
@ -154,6 +159,7 @@ const handlePreview: UploadProps['onPreview'] = (uploadFile) => {
|
|||||||
watch(
|
watch(
|
||||||
() => props.modelValue,
|
() => props.modelValue,
|
||||||
(val: string | string[]) => {
|
(val: string | string[]) => {
|
||||||
|
// console.log("val",val)
|
||||||
if (!val) {
|
if (!val) {
|
||||||
fileList.value = [] // fix:处理掉缓存,表单重置后上传组件的内容并没有重置
|
fileList.value = [] // fix:处理掉缓存,表单重置后上传组件的内容并没有重置
|
||||||
return
|
return
|
||||||
@ -169,20 +175,21 @@ watch(
|
|||||||
}
|
}
|
||||||
// 情况2:数组
|
// 情况2:数组
|
||||||
fileList.value.push(
|
fileList.value.push(
|
||||||
...(val as string[]).map((url) => ({ name: url.substring(url.lastIndexOf('/') + 1), url }))
|
...(val as string[]).map((url) => ({ name: url.substring(url.indexOf("[")+1,url.indexOf("&&$#")), url:url.substring(url.indexOf("&&$#")+5,url.length-1) }))
|
||||||
)
|
)
|
||||||
|
// console.log( fileList.value)
|
||||||
},
|
},
|
||||||
{ immediate: true, deep: true }
|
{ immediate: true, deep: true }
|
||||||
)
|
)
|
||||||
// 发送文件链接列表更新
|
// 发送文件链接列表更新
|
||||||
const emitUpdateModelValue = () => {
|
const emitUpdateModelValue = () => {
|
||||||
// 情况1:数组结果
|
// 情况1:数组结果
|
||||||
let result: string | string[] = fileList.value.map((file) => file.url!)
|
let result: string | string[] = MysqlUrl.value.map((file) => file.url!)
|
||||||
// 情况2:逗号分隔的字符串
|
// 情况2:逗号分隔的字符串
|
||||||
if (props.limit === 1 || isString(props.modelValue)) {
|
if (props.limit === 1 || isString(props.modelValue)) {
|
||||||
result = result.join(',')
|
result = result.join(',')
|
||||||
}
|
}
|
||||||
|
// console.log("result",result)
|
||||||
emit('update:modelValue', result)
|
emit('update:modelValue', result)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user