文件上传更改

This commit is contained in:
XaoLi717 2024-08-08 11:37:17 +08:00
parent 845ccfc730
commit 08193a7e76

View File

@ -81,6 +81,7 @@ const props = defineProps({
const uploadRef = ref<UploadInstance>()
const uploadList = ref<UploadUserFile[]>([])
const fileList = ref<UploadUserFile[]>([])
const MysqlUrl = ref<UploadUserFile[]>([])
const uploadNumber = ref<number>(0)
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)
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) {
// console.log("uploadList.value",uploadList.value)
fileList.value.push(...uploadList.value)
MysqlUrl.value.push(...uploadList.value)
// console.log("fileList.value111",fileList.value)
uploadList.value = []
uploadNumber.value = 0
emitUpdateModelValue()
@ -154,6 +159,7 @@ const handlePreview: UploadProps['onPreview'] = (uploadFile) => {
watch(
() => props.modelValue,
(val: string | string[]) => {
// console.log("val",val)
if (!val) {
fileList.value = [] // fix
return
@ -169,20 +175,21 @@ watch(
}
// 2
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 }
)
//
const emitUpdateModelValue = () => {
// 1
let result: string | string[] = fileList.value.map((file) => file.url!)
let result: string | string[] = MysqlUrl.value.map((file) => file.url!)
// 2
if (props.limit === 1 || isString(props.modelValue)) {
result = result.join(',')
}
// console.log("result",result)
emit('update:modelValue', result)
}
</script>