feat: 本次提交更新内容如下

保存版本
This commit is contained in:
笔记本里的永平
2025-07-15 14:58:42 +08:00
parent 721feafa7d
commit 4144b64ab8
2 changed files with 12 additions and 5 deletions

View File

@@ -49,7 +49,7 @@ function App() {
}, []); }, []);
return ( return (
<BrowserRouter> <BrowserRouter future={{ v7_startTransition: true, v7_relativeSplatPath: true }}>
<AuthProvider> <AuthProvider>
<WechatAccountProvider> <WechatAccountProvider>
<ToastProvider> <ToastProvider>

View File

@@ -12,6 +12,13 @@ interface UploadImageProps {
} }
const UploadImage: React.FC<UploadImageProps> = ({ value = [], onChange, ...props }) => { const UploadImage: React.FC<UploadImageProps> = ({ value = [], onChange, ...props }) => {
// 受控 files 状态
const [files, setFiles] = useState<TDesignUploadFile[]>(value.map(url => ({ url })));
// value 变化时同步 files
useEffect(() => {
setFiles(value.map(url => ({ url })));
}, [value]);
// 处理上传 // 处理上传
const requestMethod = async (file: TDesignUploadFile) => { const requestMethod = async (file: TDesignUploadFile) => {
@@ -22,6 +29,7 @@ const UploadImage: React.FC<UploadImageProps> = ({ value = [], onChange, ...prop
response: { response: {
url url
}, },
url,
}; };
} catch (e: any) { } catch (e: any) {
return { return {
@@ -34,21 +42,20 @@ const UploadImage: React.FC<UploadImageProps> = ({ value = [], onChange, ...prop
// 处理文件变更 // 处理文件变更
const handleChange = (newFiles: TDesignUploadFile[]) => { const handleChange = (newFiles: TDesignUploadFile[]) => {
console.log(newFiles); setFiles(newFiles);
const urls = newFiles.map(f => f.url).filter((url): url is string => Boolean(url)); const urls = newFiles.map(f => f.url).filter((url): url is string => Boolean(url));
onChange?.(urls); onChange?.(urls);
}; };
return ( return (
<Upload <Upload
files={files}
requestMethod={requestMethod} requestMethod={requestMethod}
onChange={handleChange} onChange={handleChange}
multiple multiple
accept={props.accept} accept={props.accept}
max={props.max} max={props.max}
disabled={props.disabled} disabled={props.disabled}
// 不传 filesUpload 组件自己管理
/> />
); );
}; };