fix(projects): 修复未清空文件列表,上传回显问题

This commit is contained in:
AN 2025-07-02 10:26:42 +08:00
parent 85c8a9fffa
commit 229e00443f
2 changed files with 27 additions and 24 deletions

View File

@ -20,6 +20,7 @@ const fileList = ref<UploadFileInfo[]>([]);
async function handleFetchOssList(ossIds: string[]) { async function handleFetchOssList(ossIds: string[]) {
startLoading(); startLoading();
try {
const { error, data } = await fetchGetOssListByIds(ossIds); const { error, data } = await fetchGetOssListByIds(ossIds);
if (error) return; if (error) return;
fileList.value = data.map(item => ({ fileList.value = data.map(item => ({
@ -28,36 +29,36 @@ async function handleFetchOssList(ossIds: string[]) {
name: item.originalName, name: item.originalName,
status: 'finished' status: 'finished'
})); }));
} catch (error) {
window.$message?.error(`获取文件列表失败: ${error}`);
} finally {
endLoading(); 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,
val => {
value.value = val value.value = val
.filter(item => item.status === 'finished') .filter(item => item.status === 'finished')
.map(item => item.id) .map(item => item.id)
.join(','); .join(',');
}, });
{ deep: true }
);
</script> </script>
<template> <template>

View File

@ -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;