Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-vue-admin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-vue-admin
Commits
79eb909c
Unverified
提交
79eb909c
authored
3月 19, 2022
作者:
lee
提交者:
GitHub
3月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: make fields key of form deconstructable (#1663)
Co-authored-by: liheng.wu <liheng.wu@tcl.com>
上级
92722093
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
58 行增加
和
1 行删除
+58
-1
useFormValues.ts
src/components/Form/src/hooks/useFormValues.ts
+41
-1
index.vue
src/views/demo/form/index.vue
+17
-0
没有找到文件。
src/components/Form/src/hooks/useFormValues.ts
浏览文件 @
79eb909c
...
...
@@ -11,6 +11,43 @@ interface UseFormValuesContext {
getProps
:
ComputedRef
<
FormProps
>
;
formModel
:
Recordable
;
}
/**
* @desription deconstruct array-link key. This method will mutate the target.
*/
function
tryDeconstructArray
(
key
:
string
,
value
:
any
,
target
:
Recordable
)
{
const
pattern
=
/^
\[(
.+
)\]
$/
;
if
(
pattern
.
test
(
key
))
{
const
match
=
key
.
match
(
pattern
);
if
(
match
&&
match
[
1
])
{
const
keys
=
match
[
1
].
split
(
','
);
value
=
Array
.
isArray
(
value
)
?
value
:
[
value
];
keys
.
forEach
((
k
,
index
)
=>
{
set
(
target
,
k
.
trim
(),
value
[
index
]);
});
return
true
;
}
}
}
/**
* @desription deconstruct object-link key. This method will mutate the target.
*/
function
tryDeconstructObject
(
key
:
string
,
value
:
any
,
target
:
Recordable
)
{
const
pattern
=
/^
\{(
.+
)\}
$/
;
if
(
pattern
.
test
(
key
))
{
const
match
=
key
.
match
(
pattern
);
if
(
match
&&
match
[
1
])
{
const
keys
=
match
[
1
].
split
(
','
);
value
=
isObject
(
value
)
?
value
:
{};
keys
.
forEach
((
k
)
=>
{
set
(
target
,
k
.
trim
(),
value
[
k
.
trim
()]);
});
return
true
;
}
}
}
export
function
useFormValues
({
defaultValueRef
,
getSchema
,
...
...
@@ -41,7 +78,10 @@ export function useFormValues({
if
(
isString
(
value
))
{
value
=
value
.
trim
();
}
set
(
res
,
key
,
value
);
if
(
!
tryDeconstructArray
(
key
,
value
,
res
)
&&
!
tryDeconstructObject
(
key
,
value
,
res
))
{
// 没有解构成功的,按原样赋值
set
(
res
,
key
,
value
);
}
}
return
handleRangeTimeValue
(
res
);
}
...
...
src/views/demo/form/index.vue
浏览文件 @
79eb909c
...
...
@@ -531,6 +531,22 @@
},
},
{
field
:
'divider-deconstruct'
,
component
:
'Divider'
,
label
:
'字段解构'
,
helpMessage
:
[
'如果组件的值是 array 或者 object'
,
'可以根据 ES6 的解构语法分别取值'
],
},
{
field
:
'[startTime, endTime]'
,
label
:
'时间范围'
,
component
:
'RangePicker'
,
componentProps
:
{
format
:
'YYYY-MM-DD HH:mm:ss'
,
placeholder
:
[
'开始时间'
,
'结束时间'
],
showTime
:
{
format
:
'HH:mm:ss'
},
},
},
{
field
:
'divider-others'
,
component
:
'Divider'
,
label
:
'其它'
,
...
...
@@ -602,6 +618,7 @@
keyword
.
value
=
''
;
},
handleSubmit
:
(
values
:
any
)
=>
{
console
.
log
(
'values'
,
values
);
createMessage
.
success
(
'click search,values:'
+
JSON
.
stringify
(
values
));
},
check
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论