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
cb35341b
Commit
cb35341b
authored
Apr 24, 2021
by
Vben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(form): ensure that the DateTime component checked properly,fix #511
parent
16ecf718
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
10 deletions
+43
-10
FormItem.vue
src/components/Form/src/components/FormItem.vue
+2
-4
helper.ts
src/components/Form/src/helper.ts
+20
-4
useFormEvents.ts
src/components/Form/src/hooks/useFormEvents.ts
+6
-1
RuleForm.vue
src/views/demo/form/RuleForm.vue
+15
-1
No files found.
src/components/Form/src/components/FormItem.vue
View file @
cb35341b
...
...
@@ -170,8 +170,8 @@
if
(
component
.
includes
(
'
Input
'
)
||
component
.
includes
(
'
Textarea
'
))
{
rule
.
whitespace
=
true
;
}
setComponentRuleType
(
rule
,
component
);
const
valueFormat
=
unref
(
getComponentsProps
)?.
valueFormat
;
setComponentRuleType
(
rule
,
component
,
valueFormat
);
}
}
...
...
@@ -203,9 +203,7 @@
if
(
propsData
[
eventKey
])
{
propsData
[
eventKey
](
e
);
}
const
target
=
e
?
e
.
target
:
null
;
const
value
=
target
?
(
isCheck
?
target
.
checked
:
target
.
value
)
:
e
;
props
.
setFormModel
(
field
,
value
);
},
...
...
src/components/Form/src/helper.ts
View file @
cb35341b
import
type
{
ValidationRule
}
from
'
ant-design-vue/lib/form/Form
'
;
import
type
{
ComponentType
}
from
'
./types/index
'
;
import
{
useI18n
}
from
'
/@/hooks/web/useI18n
'
;
import
{
isNumber
}
from
'
/@/utils/is
'
;
import
{
dateUtil
}
from
'
/@/utils/dateUtil
'
;
import
{
isNumber
,
isObject
}
from
'
/@/utils/is
'
;
const
{
t
}
=
useI18n
();
...
...
@@ -28,13 +29,19 @@ export function createPlaceholderMessage(component: ComponentType) {
return
''
;
}
const
DATE_TYPE
=
[
'
DatePicker
'
,
'
MonthPicker
'
,
'
WeekPicker
'
,
'
TimePicker
'
];
function
genType
()
{
return
[
'
DatePicker
'
,
'
MonthPicker
'
,
'
RangePicker
'
,
'
WeekPicker
'
,
'
Tim
ePicker
'
];
return
[
...
DATE_TYPE
,
'
Rang
ePicker
'
];
}
export
function
setComponentRuleType
(
rule
:
ValidationRule
,
component
:
ComponentType
)
{
export
function
setComponentRuleType
(
rule
:
ValidationRule
,
component
:
ComponentType
,
valueFormat
:
string
)
{
if
([
'
DatePicker
'
,
'
MonthPicker
'
,
'
WeekPicker
'
,
'
TimePicker
'
].
includes
(
component
))
{
rule
.
type
=
'
object
'
;
rule
.
type
=
valueFormat
?
'
string
'
:
'
object
'
;
}
else
if
([
'
RangePicker
'
,
'
Upload
'
,
'
CheckboxGroup
'
,
'
TimePicker
'
].
includes
(
component
))
{
rule
.
type
=
'
array
'
;
}
else
if
([
'
InputNumber
'
].
includes
(
component
))
{
...
...
@@ -42,6 +49,15 @@ export function setComponentRuleType(rule: ValidationRule, component: ComponentT
}
}
export
function
processDateValue
(
attr
:
Recordable
,
component
:
string
)
{
const
{
valueFormat
,
value
}
=
attr
;
if
(
valueFormat
)
{
attr
.
value
=
isObject
(
value
)
?
dateUtil
(
value
).
format
(
valueFormat
)
:
value
;
}
else
if
(
DATE_TYPE
.
includes
(
component
)
&&
value
)
{
attr
.
value
=
dateUtil
(
attr
.
value
);
}
}
export
function
handleInputNumberValue
(
component
?:
ComponentType
,
val
?:
any
)
{
if
(
!
component
)
return
val
;
if
([
'
Input
'
,
'
InputPassword
'
,
'
InputSearch
'
,
'
InputTextArea
'
].
includes
(
component
))
{
...
...
src/components/Form/src/hooks/useFormEvents.ts
View file @
cb35341b
...
...
@@ -73,7 +73,12 @@ export function useFormEvents({
}
formModel
[
key
]
=
arr
;
}
else
{
formModel
[
key
]
=
value
?
dateUtil
(
value
)
:
null
;
const
{
componentProps
}
=
schema
||
{};
let
_props
=
componentProps
as
any
;
if
(
typeof
componentProps
===
'
function
'
)
{
_props
=
_props
();
}
formModel
[
key
]
=
value
?
(
_props
?.
valueFormat
?
value
:
dateUtil
(
value
))
:
null
;
}
}
else
{
formModel
[
key
]
=
value
;
...
...
src/views/demo/form/RuleForm.vue
View file @
cb35341b
...
...
@@ -55,6 +55,18 @@
},
required
:
true
,
},
{
field
:
'
field33
'
,
component
:
'
DatePicker
'
,
label
:
'
字段33
'
,
colProps
:
{
span
:
8
,
},
componentProps
:
{
valueFormat
:
'
YYYY-MM-DD
'
,
},
rules
:
[{
required
:
true
,
type
:
'
string
'
}],
},
{
field
:
'
field44
'
,
component
:
'
InputCountDown
'
,
...
...
@@ -95,7 +107,7 @@
],
},
{
field
:
'
field44
'
,
field
:
'
field44
1
'
,
component
:
'
Input
'
,
label
:
'
自定义校验
'
,
colProps
:
{
...
...
@@ -198,6 +210,8 @@
field1
:
1111
,
field5
:
[
'
1
'
],
field7
:
'
1
'
,
field33
:
'
2020-12-12
'
,
field3
:
'
2020-12-12
'
,
});
}
return
{
...
...
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