fix(projects): 修复未清空文件列表,上传回显问题
This commit is contained in:
parent
85c8a9fffa
commit
229e00443f
@ -20,44 +20,45 @@ const fileList = ref<UploadFileInfo[]>([]);
|
|||||||
|
|
||||||
async function handleFetchOssList(ossIds: string[]) {
|
async function handleFetchOssList(ossIds: string[]) {
|
||||||
startLoading();
|
startLoading();
|
||||||
const { error, data } = await fetchGetOssListByIds(ossIds);
|
try {
|
||||||
if (error) return;
|
const { error, data } = await fetchGetOssListByIds(ossIds);
|
||||||
fileList.value = data.map(item => ({
|
if (error) return;
|
||||||
id: String(item.ossId),
|
fileList.value = data.map(item => ({
|
||||||
url: item.url,
|
id: String(item.ossId),
|
||||||
name: item.originalName,
|
url: item.url,
|
||||||
status: 'finished'
|
name: item.originalName,
|
||||||
}));
|
status: 'finished'
|
||||||
endLoading();
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
window.$message?.error(`获取文件列表失败: ${error}`);
|
||||||
|
} finally {
|
||||||
|
endLoading();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
value,
|
value,
|
||||||
async val => {
|
async val => {
|
||||||
const ossIds = val?.split(',')?.filter(item => isNotNull(item)) || [];
|
const ossIds = val?.split(',')?.filter(item => isNotNull(item)) || [];
|
||||||
const fileIds = new Set(fileList.value.filter(item => item.status === 'finished').map(item => item.id));
|
|
||||||
if (ossIds.every(item => fileIds.has(item))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (ossIds.length === 0) {
|
if (ossIds.length === 0) {
|
||||||
fileList.value = [];
|
fileList.value = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const fileIds = new Set(fileList.value.filter(item => item.status === 'finished').map(item => item.id));
|
||||||
|
if (ossIds.every(item => fileIds.has(item))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
await handleFetchOssList(ossIds);
|
await handleFetchOssList(ossIds);
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(fileList, val => {
|
||||||
fileList,
|
value.value = val
|
||||||
val => {
|
.filter(item => item.status === 'finished')
|
||||||
value.value = val
|
.map(item => item.id)
|
||||||
.filter(item => item.status === 'finished')
|
.join(',');
|
||||||
.map(item => item.id)
|
});
|
||||||
.join(',');
|
|
||||||
},
|
|
||||||
{ deep: true }
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -28,7 +28,9 @@ const accept = computed(() => (props.uploadType === 'file' ? AcceptType.File : A
|
|||||||
|
|
||||||
const fileList = ref<UploadFileInfo[]>([]);
|
const fileList = ref<UploadFileInfo[]>([]);
|
||||||
|
|
||||||
function handleUpdateModelWhenUpload() {}
|
function handleUpdateModelWhenUpload() {
|
||||||
|
fileList.value = [];
|
||||||
|
}
|
||||||
|
|
||||||
function closeDrawer() {
|
function closeDrawer() {
|
||||||
visible.value = false;
|
visible.value = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user