修复验收图片多选暂存
This commit is contained in:
@@ -89,7 +89,10 @@ export default function ImageUpload({
|
||||
message.error(error instanceof Error ? error.message : '上传失败')
|
||||
}
|
||||
}
|
||||
if (next.length > valueRef.current.length) onChange?.(next)
|
||||
if (next.length > valueRef.current.length) {
|
||||
valueRef.current = next
|
||||
onChange?.(next)
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadFiles(files: File[]) {
|
||||
@@ -141,7 +144,10 @@ export default function ImageUpload({
|
||||
const customRequest: UploadProps['customRequest'] = async (options) => {
|
||||
try {
|
||||
const uploaded = await uploadFile(options.file as File, scene, scope)
|
||||
onChange?.([...value, uploaded].slice(-maxCount))
|
||||
// 多文件选择会并发执行 customRequest,必须以 ref 中的最新列表累加,避免后完成的上传覆盖前面的图片。
|
||||
const next = [...valueRef.current, uploaded].slice(0, maxCount)
|
||||
valueRef.current = next
|
||||
onChange?.(next)
|
||||
options.onSuccess?.(uploaded)
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '上传失败')
|
||||
@@ -160,14 +166,17 @@ export default function ImageUpload({
|
||||
>
|
||||
<Upload
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
multiple
|
||||
listType="picture-card"
|
||||
fileList={fileList}
|
||||
maxCount={maxCount}
|
||||
customRequest={customRequest}
|
||||
onRemove={(file) => {
|
||||
onChange?.(
|
||||
value.filter((item) => (item.objectKey || item.url) !== file.uid),
|
||||
const next = valueRef.current.filter(
|
||||
(item) => (item.objectKey || item.url) !== file.uid,
|
||||
)
|
||||
valueRef.current = next
|
||||
onChange?.(next)
|
||||
return true
|
||||
}}
|
||||
showUploadList={{ showPreviewIcon: false }}
|
||||
|
||||
Reference in New Issue
Block a user