Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
najiu-frontend
najiu-admin-template
Commits
c639e493
Commit
c639e493
authored
Apr 22, 2021
by
zuihou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(form): adding resetSchema method
parent
7e2668f6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
0 deletions
+29
-0
BasicForm.vue
src/components/Form/src/BasicForm.vue
+2
-0
useForm.ts
src/components/Form/src/hooks/useForm.ts
+5
-0
useFormEvents.ts
src/components/Form/src/hooks/useFormEvents.ts
+21
-0
form.ts
src/components/Form/src/types/form.ts
+1
-0
No files found.
src/components/Form/src/BasicForm.vue
View file @
c639e493
...
...
@@ -168,6 +168,7 @@
validateFields
,
getFieldsValue
,
updateSchema
,
resetSchema
,
appendSchemaByField
,
removeSchemaByFiled
,
resetFields
,
...
...
@@ -230,6 +231,7 @@
setFieldsValue
,
resetFields
,
updateSchema
,
resetSchema
,
setProps
,
removeSchemaByFiled
,
appendSchemaByField
,
...
...
src/components/Form/src/hooks/useForm.ts
View file @
c639e493
...
...
@@ -65,6 +65,11 @@ export function useForm(props?: Props): UseFormReturnType {
form
.
updateSchema
(
data
);
},
resetSchema
:
async
(
data
:
Partial
<
FormSchema
>
|
Partial
<
FormSchema
>
[])
=>
{
const
form
=
await
getForm
();
form
.
resetSchema
(
data
);
},
clearValidate
:
async
(
name
?:
string
|
string
[])
=>
{
const
form
=
await
getForm
();
form
.
clearValidate
(
name
);
...
...
src/components/Form/src/hooks/useFormEvents.ts
View file @
c639e493
...
...
@@ -137,6 +137,26 @@ export function useFormEvents({
schemaRef
.
value
=
schemaList
;
}
async
function
resetSchema
(
data
:
Partial
<
FormSchema
>
|
Partial
<
FormSchema
>
[])
{
let
updateData
:
Partial
<
FormSchema
>
[]
=
[];
if
(
isObject
(
data
))
{
updateData
.
push
(
data
as
FormSchema
);
}
if
(
isArray
(
data
))
{
updateData
=
[...
data
];
}
const
hasField
=
updateData
.
every
((
item
)
=>
Reflect
.
has
(
item
,
'
field
'
)
&&
item
.
field
);
if
(
!
hasField
)
{
error
(
'
All children of the form Schema array that need to be updated must contain the `field` field
'
);
return
;
}
schemaRef
.
value
=
updateData
as
FormSchema
[];
}
async
function
updateSchema
(
data
:
Partial
<
FormSchema
>
|
Partial
<
FormSchema
>
[])
{
let
updateData
:
Partial
<
FormSchema
>
[]
=
[];
if
(
isObject
(
data
))
{
...
...
@@ -227,6 +247,7 @@ export function useFormEvents({
validateFields
,
getFieldsValue
,
updateSchema
,
resetSchema
,
appendSchemaByField
,
removeSchemaByFiled
,
resetFields
,
...
...
src/components/Form/src/types/form.ts
View file @
c639e493
...
...
@@ -31,6 +31,7 @@ export interface FormActionType {
getFieldsValue
:
()
=>
Recordable
;
clearValidate
:
(
name
?:
string
|
string
[])
=>
Promise
<
void
>
;
updateSchema
:
(
data
:
Partial
<
FormSchema
>
|
Partial
<
FormSchema
>
[])
=>
Promise
<
void
>
;
resetSchema
:
(
data
:
Partial
<
FormSchema
>
|
Partial
<
FormSchema
>
[])
=>
Promise
<
void
>
;
setProps
:
(
formProps
:
Partial
<
FormProps
>
)
=>
Promise
<
void
>
;
removeSchemaByFiled
:
(
field
:
string
|
string
[])
=>
Promise
<
void
>
;
appendSchemaByField
:
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment