Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6b9acf09
authored
Nov 09, 2024
by
huangxiaomin
Committed by
GitHub
Nov 09, 2024
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: add fieldMapToTime prop to FormRenderProps (#4838)
1 parent
2c6edafe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
2 deletions
packages/@core/ui-kit/form-ui/src/components/form-actions.vue
packages/@core/ui-kit/form-ui/src/types.ts
playground/src/views/examples/vxe-table/form.vue
packages/@core/ui-kit/form-ui/src/components/form-actions.vue
View file @
6b9acf0
...
@@ -52,20 +52,92 @@ async function handleSubmit(e: Event) {
...
@@ -52,20 +52,92 @@ async function handleSubmit(e: Event) {
if
(
!
valid
)
{
if
(
!
valid
)
{
return
;
return
;
}
}
await
unref
(
rootProps
).
handleSubmit
?.(
toRaw
(
form
.
values
));
const
values
=
handleRangeTimeValue
(
toRaw
(
form
.
values
));
await
unref
(
rootProps
).
handleSubmit
?.(
values
);
}
}
async
function
handleReset
(
e
:
Event
)
{
async
function
handleReset
(
e
:
Event
)
{
e
?.
preventDefault
();
e
?.
preventDefault
();
e
?.
stopPropagation
();
e
?.
stopPropagation
();
const
props
=
unref
(
rootProps
);
const
props
=
unref
(
rootProps
);
const
values
=
toRaw
(
form
.
values
);
// 清理时间字段
props
.
fieldMapToTime
&&
props
.
fieldMapToTime
.
forEach
(([
_
,
[
startTimeKey
,
endTimeKey
]])
=>
{
delete
values
[
startTimeKey
];
delete
values
[
endTimeKey
];
});
if
(
isFunction
(
props
.
handleReset
))
{
if
(
isFunction
(
props
.
handleReset
))
{
await
props
.
handleReset
?.(
form
.
values
);
await
props
.
handleReset
?.(
values
);
}
else
{
}
else
{
form
.
resetForm
();
form
.
resetForm
();
}
}
}
}
function
handleRangeTimeValue
(
values
:
Record
<
string
,
any
>
)
{
const
fieldMapToTime
=
unref
(
rootProps
).
fieldMapToTime
;
if
(
!
fieldMapToTime
)
return
values
;
if
(
!
Array
.
isArray
(
fieldMapToTime
))
{
return
values
;
}
fieldMapToTime
.
forEach
(
([
field
,
[
startTimeKey
,
endTimeKey
],
format
=
'YYYY-MM-DD'
])
=>
{
if
(
!
values
[
field
])
{
delete
values
[
field
];
return
;
}
const
[
startTime
,
endTime
]
=
values
[
field
];
const
[
startTimeFormat
,
endTimeFormat
]
=
Array
.
isArray
(
format
)
?
format
:
[
format
,
format
];
values
[
startTimeKey
]
=
startTime
?
formatTime
(
startTime
,
startTimeFormat
)
:
undefined
;
values
[
endTimeKey
]
=
endTime
?
formatTime
(
endTime
,
endTimeFormat
)
:
undefined
;
delete
values
[
field
];
},
);
return
values
;
}
function
formatTime
(
time
:
string
,
format
:
string
):
number
|
string
{
const
date
=
new
Date
(
time
);
const
timestamp
=
(
date
:
Date
)
=>
Math
.
floor
(
date
.
getTime
()
/
1000
);
if
(
format
===
'timestamp'
)
return
timestamp
(
date
);
if
(
format
===
'timestampStartDay'
)
return
timestamp
(
new
Date
(
date
.
getFullYear
(),
date
.
getMonth
(),
date
.
getDate
()),
);
const
padZero
=
(
num
:
number
)
=>
num
.
toString
().
padStart
(
2
,
'0'
);
const
replacements
:
Record
<
string
,
string
>
=
{
DD
:
padZero
(
date
.
getDate
()),
HH
:
padZero
(
date
.
getHours
()),
MM
:
padZero
(
date
.
getMonth
()
+
1
),
mm
:
padZero
(
date
.
getMinutes
()),
ss
:
padZero
(
date
.
getSeconds
()),
YYYY
:
date
.
getFullYear
().
toString
(),
};
return
format
.
replaceAll
(
/YYYY|MM|DD|HH|mm|ss/g
,
(
match
)
=>
replacements
[
match
]
||
match
,
);
}
watch
(
watch
(
()
=>
collapsed
.
value
,
()
=>
collapsed
.
value
,
()
=>
{
()
=>
{
...
...
packages/@core/ui-kit/form-ui/src/types.ts
View file @
6b9acf0
...
@@ -206,6 +206,12 @@ export type HandleResetFn = (
...
@@ -206,6 +206,12 @@ export type HandleResetFn = (
values
:
Record
<
string
,
any
>
,
values
:
Record
<
string
,
any
>
,
)
=>
Promise
<
void
>
|
void
;
)
=>
Promise
<
void
>
|
void
;
export
type
FieldMapToTime
=
[
string
,
[
string
,
string
],
([
string
,
string
]
|
string
)?,
][];
export
interface
FormSchema
<
export
interface
FormSchema
<
T
extends
BaseFormComponentType
=
BaseFormComponentType
,
T
extends
BaseFormComponentType
=
BaseFormComponentType
,
>
extends
FormCommonConfig
{
>
extends
FormCommonConfig
{
...
@@ -267,6 +273,10 @@ export interface FormRenderProps<
...
@@ -267,6 +273,10 @@ export interface FormRenderProps<
*/
*/
componentMap
:
Record
<
BaseFormComponentType
,
Component
>
;
componentMap
:
Record
<
BaseFormComponentType
,
Component
>
;
/**
/**
* 表单字段映射成时间格式
*/
fieldMapToTime
?:
FieldMapToTime
;
/**
* 表单实例
* 表单实例
*/
*/
form
?:
FormContext
<
GenericObject
>
;
form
?:
FormContext
<
GenericObject
>
;
...
...
playground/src/views/examples/vxe-table/form.vue
View file @
6b9acf0
...
@@ -21,6 +21,7 @@ interface RowType {
...
@@ -21,6 +21,7 @@ interface RowType {
const
formOptions
:
VbenFormProps
=
{
const
formOptions
:
VbenFormProps
=
{
// 默认展开
// 默认展开
collapsed
:
false
,
collapsed
:
false
,
fieldMapToTime
:
[[
'dateRangePicker'
,
[
'startTime'
,
'endTime'
],
'YYYY-MM'
]],
schema
:
[
schema
:
[
{
{
component
:
'Input'
,
component
:
'Input'
,
...
@@ -62,6 +63,11 @@ const formOptions: VbenFormProps = {
...
@@ -62,6 +63,11 @@ const formOptions: VbenFormProps = {
fieldName
:
'datePicker'
,
fieldName
:
'datePicker'
,
label
:
'Date'
,
label
:
'Date'
,
},
},
{
component
:
'RangePicker'
,
fieldName
:
'dateRangePicker'
,
label
:
'DateRange'
,
},
],
],
// 控制表单是否显示折叠按钮
// 控制表单是否显示折叠按钮
showCollapseButton
:
true
,
showCollapseButton
:
true
,
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment