文件上传更改
This commit is contained in:
parent
845ccfc730
commit
08193a7e76
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user