Skip to content

Commit

Permalink
fix: 修复 FormImageUpload 上传多张图片失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondYuan committed Feb 19, 2024
1 parent ded72c0 commit e8f63c9
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 6 deletions.
3 changes: 2 additions & 1 deletion compiled/alipay/src/Form/FormImageUpload/index.axml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
validateStatus="{{ validateStatus }}"
help="{{ help }}">
<image-upload
fileList="{{ formData.value }}"
ref="handleRef"
defaultFileList="{{ formData.value }}"
maxCount="{{ maxCount }}"
imageMode="{{ imageMode }}"
sourceType="{{ sourceType }}"
Expand Down
18 changes: 17 additions & 1 deletion compiled/alipay/src/Form/FormImageUpload/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import { useEvent } from 'functional-mini/component';
import { useEvent, useRef, useEffect } from 'functional-mini/component';
import { mountComponent } from '../../_util/component';
import { useComponentEvent } from '../../_util/hooks/useComponentEvent';
import { useHandleCustomEvent } from '../../_util/hooks/useHandleCustomEvent';
import { useFormItem } from '../use-form-item';
import { FormImageUploadDefaultProps, FormImageUploadProps } from './props';

interface ImageUploadRef {
update(value: string);
}

const FormImageUpload = (props: FormImageUploadProps) => {
const { formData, emit } = useFormItem(props);
const { triggerEvent } = useComponentEvent(props);

const imageUploadRef = useRef<ImageUploadRef>();

useHandleCustomEvent('handleRef', (imageUpload: ImageUploadRef) => {
imageUploadRef.current = imageUpload;

Check warning on line 19 in compiled/alipay/src/Form/FormImageUpload/index.ts

View check run for this annotation

Codecov / codecov/patch

compiled/alipay/src/Form/FormImageUpload/index.ts#L19

Added line #L19 was not covered by tests
});

useEffect(() => {
if (imageUploadRef.current) {
imageUploadRef.current.update(formData.value);

Check warning on line 24 in compiled/alipay/src/Form/FormImageUpload/index.ts

View check run for this annotation

Codecov / codecov/patch

compiled/alipay/src/Form/FormImageUpload/index.ts#L24

Added line #L24 was not covered by tests
}
}, [formData.value]);

useHandleCustomEvent('onChange', (value) => {
emit('onChange', value);
triggerEvent('change', value);
Expand Down
7 changes: 7 additions & 0 deletions compiled/alipay/src/ImageUpload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ const ImageUpload = (props: IUploaderProps) => {
triggerEvent('preview', file);
});

useEvent('update', (e) => {
if (isControlled) {
return;

Check warning on line 182 in compiled/alipay/src/ImageUpload/index.ts

View check run for this annotation

Codecov / codecov/patch

compiled/alipay/src/ImageUpload/index.ts#L182

Added line #L182 was not covered by tests
}
update(e);

Check warning on line 184 in compiled/alipay/src/ImageUpload/index.ts

View check run for this annotation

Codecov / codecov/patch

compiled/alipay/src/ImageUpload/index.ts#L184

Added line #L184 was not covered by tests
});

return {
mixin: {
value: fileList,
Expand Down
11 changes: 10 additions & 1 deletion compiled/wechat/src/Form/FormImageUpload/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEvent } from 'functional-mini/component';
import { useEvent, useRef, useEffect } from 'functional-mini/component';
import { mountComponent } from '../../_util/component';
import { useComponentEvent } from '../../_util/hooks/useComponentEvent';
import { useHandleCustomEvent } from '../../_util/hooks/useHandleCustomEvent';
Expand All @@ -7,6 +7,15 @@ import { FormImageUploadDefaultProps } from './props';
var FormImageUpload = function (props) {
var _a = useFormItem(props), formData = _a.formData, emit = _a.emit;
var triggerEvent = useComponentEvent(props).triggerEvent;
var imageUploadRef = useRef();
useHandleCustomEvent('handleRef', function (imageUpload) {
imageUploadRef.current = imageUpload;
});
useEffect(function () {
if (imageUploadRef.current) {
imageUploadRef.current.update(formData.value);
}
}, [formData.value]);
useHandleCustomEvent('onChange', function (value) {
emit('onChange', value);
triggerEvent('change', value);
Expand Down
3 changes: 2 additions & 1 deletion compiled/wechat/src/Form/FormImageUpload/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
validateStatus="{{ validateStatus }}"
help="{{ help }}">
<image-upload
fileList="{{ formData.value }}"
bind:ref="handleRef"
defaultFileList="{{ formData.value }}"
maxCount="{{ maxCount }}"
imageMode="{{ imageMode }}"
sourceType="{{ sourceType }}"
Expand Down
6 changes: 6 additions & 0 deletions compiled/wechat/src/ImageUpload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ var ImageUpload = function (props) {
var file = fileList.find(function (item) { return item.uid === uid; });
triggerEvent('preview', file);
});
useEvent('update', function (e) {
if (isControlled) {
return;
}
update(e);
});
return {
mixin: {
value: fileList,
Expand Down
3 changes: 2 additions & 1 deletion src/Form/FormImageUpload/index.axml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default (
help={help}
>
<ImageUpload
fileList={formData.value}
ref="handleRef"
defaultFileList={formData.value}
maxCount={maxCount}
imageMode={imageMode}
sourceType={sourceType}
Expand Down
18 changes: 17 additions & 1 deletion src/Form/FormImageUpload/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import { useEvent } from 'functional-mini/component';
import { useEvent, useRef, useEffect } from 'functional-mini/component';
import { mountComponent } from '../../_util/component';
import { useComponentEvent } from '../../_util/hooks/useComponentEvent';
import { useHandleCustomEvent } from '../../_util/hooks/useHandleCustomEvent';
import { useFormItem } from '../use-form-item';
import { FormImageUploadDefaultProps, FormImageUploadProps } from './props';

interface ImageUploadRef {
update(value: string);
}

const FormImageUpload = (props: FormImageUploadProps) => {
const { formData, emit } = useFormItem(props);
const { triggerEvent } = useComponentEvent(props);

const imageUploadRef = useRef<ImageUploadRef>();

useHandleCustomEvent('handleRef', (imageUpload: ImageUploadRef) => {
imageUploadRef.current = imageUpload;
});

useEffect(() => {
if (imageUploadRef.current) {
imageUploadRef.current.update(formData.value);
}
}, [formData.value]);

useHandleCustomEvent('onChange', (value) => {
emit('onChange', value);
triggerEvent('change', value);
Expand Down
7 changes: 7 additions & 0 deletions src/ImageUpload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ const ImageUpload = (props: IUploaderProps) => {
triggerEvent('preview', file);
});

useEvent('update', (e) => {
if (isControlled) {
return;
}
update(e);
});

return {
mixin: {
value: fileList,
Expand Down

0 comments on commit e8f63c9

Please sign in to comment.