Skip to content

Commit

Permalink
fix(ImagePicker):优化ImagePicker组件报错和文档示例
Browse files Browse the repository at this point in the history
  • Loading branch information
hy committed Apr 21, 2023
1 parent 1dfbab5 commit e0fd493
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions example/examples/src/routes/ImagePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export default function MenuDropdownView(props: ImagePickerProps) {
<Body>
<Card title="基础实例">
<ImagePicker
upload={(file: File[]) => {
upload={async (file: File[]) => {
let imageList: string[] = [];
file.forEach(file => imageList.push(file.uri));
await file.forEach(file => imageList.push(file.uri));
return imageList;
}}
selectionLimit={2}
Expand All @@ -44,9 +44,9 @@ export default function MenuDropdownView(props: ImagePickerProps) {
<ImagePicker
value={['https://wx3.sinaimg.cn/mw690/4718260ely1gt2cg7t5udj23dw1wkhdu.jpg']}
maxCount={2}
upload={(file: File[]) => {
upload={async (file: File[]) => {
let imageList: string[] = [];
file.forEach(file => imageList.push(file.uri));
await file.forEach(file => imageList.push(file.uri));
return imageList;
}}
/>
Expand All @@ -56,9 +56,9 @@ export default function MenuDropdownView(props: ImagePickerProps) {
</Card>
<Card title="上传前置处理">
<ImagePicker
upload={(file: File[]) => {
upload={async (file: File[]) => {
let imageList: string[] = [];
file.forEach(file => imageList.push(file.uri));
await file.forEach(file => imageList.push(file.uri));
return imageList;
}}
beforeUpload={(file: File[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export declare type ImagePickerProps = PropsWithChildren<{
/** 上传文件之前的钩子,参数为上传的文件,若返回 false 则停止上传,同时可以在里面执行一些上传提示操作 */
beforeUpload?: (file: File[]) => boolean | ((file: File) => Promise<boolean>);
/** 上传 */
upload?: (file: File[]) => string[];
upload?: (file: File[]) => Promise<string[]>;
/** 上传完成 */
uploadFinish?: (result?: string[] | undefined) => void;
/** 取消上传事件回调 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default function useImagePicker({
}
}
setLoading(true);
const result = upload?.(imageFiles);
const result = await upload?.(imageFiles);
setLoading(false);
uploadFinish?.(result);
setLaunchVisibleFalse();
Expand Down

0 comments on commit e0fd493

Please sign in to comment.