mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2025-02-17 17:40:31 +08:00
add resetForm method
This commit is contained in:
parent
8ec7837d3d
commit
b677bf1ecc
@ -53,6 +53,18 @@
|
||||
wait: {},
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
event: 'onSubmit',
|
||||
componentId: 'form',
|
||||
method: {
|
||||
name: 'resetForm',
|
||||
},
|
||||
wait: {
|
||||
type: 'delay',
|
||||
time: 1000,
|
||||
},
|
||||
disabled: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -6,9 +6,11 @@ import Slot from '../_internal/Slot';
|
||||
import { Button } from '@chakra-ui/react';
|
||||
import { stateStore } from '../../store';
|
||||
import { watch } from '@vue-reactivity/watch';
|
||||
import { apiService } from '../../api-service';
|
||||
|
||||
const FormImpl: ComponentImplementation<Record<string, string>> = ({
|
||||
mergeState,
|
||||
subscribeMethods,
|
||||
slotsMap,
|
||||
callbackMap,
|
||||
}) => {
|
||||
@ -26,6 +28,20 @@ const FormImpl: ComponentImplementation<Record<string, string>> = ({
|
||||
);
|
||||
}, [slotsMap]);
|
||||
|
||||
useEffect(() => {
|
||||
subscribeMethods({
|
||||
resetForm() {
|
||||
formControlIds.forEach(fcId => {
|
||||
const inputId = stateStore[fcId].inputId;
|
||||
apiService.send('uiMethod', {
|
||||
componentId: inputId,
|
||||
name: 'resetInputValue',
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
}, [formControlIds]);
|
||||
|
||||
useEffect(() => {
|
||||
const stops: ReturnType<typeof watch>[] = [];
|
||||
formControlIds.forEach((fcId, i) => {
|
||||
@ -89,7 +105,11 @@ export default {
|
||||
state: Type.Object({
|
||||
data: Type.Any(),
|
||||
}),
|
||||
methods: [],
|
||||
methods: [
|
||||
{
|
||||
name: 'resetForm',
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
impl: FormImpl,
|
||||
|
@ -85,6 +85,9 @@ const Input: ComponentImplementation<{
|
||||
setInputValue({ value }) {
|
||||
setValue(value);
|
||||
},
|
||||
resetInputValue() {
|
||||
setValue(initialValue || '');
|
||||
},
|
||||
});
|
||||
}, []);
|
||||
|
||||
@ -184,6 +187,9 @@ export default {
|
||||
value: Type.String(),
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: 'resetInputValue',
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
|
Loading…
Reference in New Issue
Block a user