feat: 添加新闻管理功能,包括新闻列表和添加新闻表单

This commit is contained in:
2026-01-19 19:40:02 +07:00
parent 26056e8e21
commit 07b75dc03e
11 changed files with 279 additions and 30 deletions

View File

@@ -36,27 +36,16 @@ const fileList = ref<UploadFileInfo[]>([]);
const loading = ref(false);
async function initFileList() {
const fileIds = props.modelValue.filter(id => id && id.trim() !== '');
const fileIds = props.modelValue.filter(url => url && url.trim() !== '');
if (!props.modelValue || fileIds.length === 0) {
fileList.value = [];
return;
}
loading.value = true;
try {
const { data } = await safeClient(client.api.file_storage.access_urls.post({ fileIds }));
fileList.value =
data.value?.map(item => ({
id: item.id,
name: item.fileName || item.id,
status: 'finished' as const,
url: item.url,
file: null as any
})) || [];
} catch (error) {
window.$message?.error('加载文件列表失败');
} finally {
loading.value = false;
} else {
fileList.value = props.modelValue.map(url => ({
id: url,
name: url.split('/').pop() || 'file',
url,
status: 'finished'
}));
}
}
@@ -96,19 +85,19 @@ async function handleCustomRequest({ file, onProgress, onFinish, onError }: Uplo
...props.fetchOptions
} as UploadFetchOptions;
const fileId = await uploadToS3(file.file as File, {
const res = await uploadToS3(file.file as File, {
fetchOptions: options,
onProgress: percent => {
onProgress({ percent });
}
});
// 直接修改 file 对象的 idNaiveUI 会自动同步到 fileList
file.id = fileId;
file.id = res.fileId;
file.status = 'finished';
file.url = fileId;
file.url = res.publicUrl;
const newFileIds = [...props.modelValue, fileId].filter(Boolean);
emit('update:modelValue', newFileIds);
const values = [...props.modelValue, res.publicUrl].filter(Boolean);
emit('update:modelValue', values);
onFinish();
window.$message?.success(`文件 ${file.name} 上传成功`);
@@ -119,8 +108,8 @@ async function handleCustomRequest({ file, onProgress, onFinish, onError }: Uplo
function handleRemove({ file }: { file: UploadFileInfo }) {
// 只删除上传成功的文件(有有效 id 的文件)
if (file.id && typeof file.id === 'string' && props.modelValue.includes(file.id)) {
const newFileIds = props.modelValue.filter(id => id !== file.id);
if (file.url && typeof file.url === 'string' && props.modelValue.includes(file.url)) {
const newFileIds = props.modelValue.filter(url => url !== file.url);
emit('update:modelValue', newFileIds);
}
return true;