|
@@ -6,15 +6,30 @@ import { fileApi } from '../api/file';
|
|
|
|
|
|
|
|
// 上传接口由 fileApi.upload 固定使用 /admin-api/infra/file/upload(axios baseURL + /infra/file/upload)
|
|
// 上传接口由 fileApi.upload 固定使用 /admin-api/infra/file/upload(axios baseURL + /infra/file/upload)
|
|
|
|
|
|
|
|
-function toFileList(value: string | string[] | undefined): UploadFile[] {
|
|
|
|
|
|
|
+function normalizeUrl(item: unknown): { url: string; name?: string } | null {
|
|
|
|
|
+ if (item == null) return null;
|
|
|
|
|
+ if (typeof item === 'string' && item !== '') return { url: item };
|
|
|
|
|
+ if (typeof item === 'object' && item !== null) {
|
|
|
|
|
+ const o = item as Record<string, unknown>;
|
|
|
|
|
+ const url = o.url;
|
|
|
|
|
+ const str = typeof url === 'string' ? url : undefined;
|
|
|
|
|
+ if (str) return { url: str, name: typeof o.name === 'string' ? o.name : undefined };
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function toFileList(value: string | string[] | Record<string, unknown>[] | undefined): UploadFile[] {
|
|
|
if (value == null || value === '') return [];
|
|
if (value == null || value === '') return [];
|
|
|
- const urls = Array.isArray(value) ? value : [value];
|
|
|
|
|
- return urls.filter(Boolean).map((url, i) => ({
|
|
|
|
|
- uid: `-${i}-${url}`,
|
|
|
|
|
- name: url.split('/').pop() || `文件${i + 1}`,
|
|
|
|
|
- status: 'done' as const,
|
|
|
|
|
- url: url,
|
|
|
|
|
- }));
|
|
|
|
|
|
|
+ const list = Array.isArray(value) ? value : [value];
|
|
|
|
|
+ return list
|
|
|
|
|
+ .map((item) => normalizeUrl(item))
|
|
|
|
|
+ .filter((item): item is { url: string; name?: string } => item != null)
|
|
|
|
|
+ .map((item, i) => ({
|
|
|
|
|
+ uid: `-${i}-${item.url}`,
|
|
|
|
|
+ name: item.name ?? (typeof item.url === 'string' ? item.url.split('/').pop() : undefined) ?? `文件${i + 1}`,
|
|
|
|
|
+ status: 'done' as const,
|
|
|
|
|
+ url: item.url,
|
|
|
|
|
+ }));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function extractUrls(fileList: UploadFile[]): string[] {
|
|
function extractUrls(fileList: UploadFile[]): string[] {
|