xinnian999 / vue-form-craft

基于vue3的一款开箱即用表单方案
283 stars 21 forks source link

数据层级问题,是否可以增加一个对象容器组件来解决呢? #31

Closed fssgh closed 3 days ago

fssgh commented 2 weeks ago

数据层级问题,是否可以增加一个对象容器组件来解决呢?这样表格界面的层级结构与表单数据层级结构就一致了

xinnian999 commented 2 weeks ago

是否可以理解为,想让数据按对象的指定路径保存,而不是都保存在第一级?

fssgh commented 2 weeks ago

是的,或者是否可以使用表单父级的布局容器的唯一key自动组装,来完成表单数据的层级结构呢?

xinnian999 commented 2 weeks ago

https://xinnian999.github.io/vue-form-craft/zh/deepName.html 这个提供了一种方案

fssgh commented 2 weeks ago

name 字段扩展为魔法字段的这种方案,好像不太方便,如:当要改变一个卡片下表单结构时,要重复修改下片下的多个表单name字段。。。

xinnian999 commented 2 weeks ago

那我增加一个对象容器,这个容器的值保存为一个对象。可以拖入子字段的,子字段的数据都保存在这个对象里,对吧?

fssgh commented 2 weeks ago

对对对,还想问一下,层级结构的表单数据,可以回显到表单上吗?

xinnian999 commented 2 weeks ago

如果是name设置的深层数据,回显肯定没问题的

fssgh commented 2 weeks ago

那可以给每个组件增加一个key字段名称属性,然后通过key值设置自动组装表单中的name设置为深层数据,这样是不是改动就不大。

xinnian999 commented 2 weeks ago

不是很好弄,现在所有容器组件都是不会联动表单数据的,只用于纯布局。 所以表单不管怎么布局怎么嵌套,数据默认都是扁平化的,这是为了方便处理表单联动。 目前只可以通过name自由组装数据,或者在表单提交前手动处理。 但你提出的【增加一个对象容器组件】我可以实现一下,这个不会影响其他的功能

fssgh commented 2 weeks ago

好的,期待对象容器组件

xinnian999 commented 1 week ago

对象容器组件加了,v4.6.1

fssgh commented 4 days ago

@xinnian999 对象容器组件有个问题,在对象容器组件里内嵌对象容器组件,子对象容器组件模拟提交表单数据的数据结构没有内嵌到父对象容器表单值中,内嵌自增容器是可以的。

xinnian999 commented 4 days ago

@xinnian999 对象容器组件有个问题,在对象容器组件里内嵌对象容器组件,子对象容器组件模拟提交表单数据的数据结构没有内嵌到父对象容器表单值中,内嵌自增容器是可以的。

确实嵌套使用有bug,刚刚fix了,更新一下v4.6.2版本

fssgh commented 4 days ago

我在在线演示上跑,嵌套好像还是有问题,如:tabs中每个选项卡使用一个对象容器时,表单结果值没有组装到对象容器中。

xinnian999 commented 4 days ago

我在在线演示上跑,嵌套好像还是有问题,如:tabs中每个选项卡使用一个对象容器时,表单结果值没有组装到对象容器中。

我没有复现出来呢,你schema发给我一下

fssgh commented 4 days ago

{ "labelWidth": 150, "labelAlign": "right", "size": "default", "scrollToError": true, "items": [ { "children": [ { "label": "选项卡1", "name": "name1", "children": [ { "props": { "align": "left", "gap": 20 }, "children": [ { "props": { "header": "卡片" }, "component": "Card", "designKey": "design-2smD", "name": "form-2KFv", "children": [ { "props": { "align": "left", "gap": 20 }, "children": [ { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-mmYO", "name": "a" }, { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-kMt1", "name": "b" }, { "props": { "header": "卡片" }, "component": "Card", "designKey": "design-NzTR", "name": "form-KCMI", "children": [ { "props": { "align": "left", "gap": 20 }, "children": [ { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-zDg6", "name": "a" }, { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-8I40", "name": "b" } ], "hideLabel": true, "component": "ObjGroup", "designKey": "design-GD4P", "name": "fff" } ] } ], "hideLabel": true, "component": "ObjGroup", "designKey": "design-kRRV", "name": "aaa" } ] } ], "hideLabel": true, "component": "ObjGroup", "designKey": "design-7TBt", "name": "aaa" } ] }, { "label": "选项卡2", "name": "name2", "children": [ { "props": { "align": "left", "gap": 20 }, "children": [ { "props": { "header": "卡片" }, "component": "Card", "designKey": "design-yla6", "name": "form-0RoX", "children": [ { "props": { "align": "left", "gap": 20 }, "children": [ { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-D2Ra", "name": "a" }, { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-KN7j", "name": "b" }, { "label": "自增容器", "children": [ { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-polt", "name": "a" }, { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-hKY0", "name": "b" }, { "props": { "header": "卡片" }, "component": "Card", "designKey": "design-wgDu", "name": "form-7KZB", "children": [ { "props": { "align": "left", "gap": 20 }, "children": [ { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-L5Pg", "name": "a" }, { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-QAzh", "name": "b" } ], "hideLabel": true, "component": "ObjGroup", "designKey": "design-pSlt", "name": "ccc" } ] } ], "props": { "mode": "card" }, "component": "FormList", "designKey": "design-cjVP", "name": "eee" } ], "hideLabel": true, "component": "ObjGroup", "designKey": "design-BvIk", "name": "bbb" } ] } ], "hideLabel": true, "component": "ObjGroup", "designKey": "design-2Ayf", "name": "bbb" } ] } ], "props": { "defaultKey": "name1", "tabPosition": "left" }, "component": "Tabs", "designKey": "design-AAcb", "name": "form-Z4uH" } ] }

fssgh commented 4 days ago

schema如上,嵌套结构还是有问题

xinnian999 commented 4 days ago

看起来是因为中间隔了一层卡片导致的数据没链接上,我再让它穿透一下

xinnian999 commented 3 days ago

fix了,v4.6.3再试试吧

fssgh commented 3 days ago

{ "labelWidth": 150, "labelAlign": "right", "size": "default", "scrollToError": true, "items": [ { "children": [ { "label": "选项卡1", "name": "name1", "children": [] }, { "label": "选项卡2", "name": "name2", "children": [ { "props": { "header": "卡片" }, "component": "Card", "designKey": "design-E1L4", "name": "form-2oSF", "children": [ { "props": { "align": "left", "gap": 20 }, "children": [ { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-OG4m", "name": "a" }, { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-lkXJ", "name": "b" }, { "label": "自增容器", "children": [ { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-E4wo", "name": "a" }, { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-xaFF", "name": "b" }, { "props": { "header": "卡片" }, "component": "Card", "designKey": "design-uO9v", "name": "form-oyyS", "children": [ { "props": { "align": "left", "gap": 20 }, "children": [ { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-UnP9", "name": "a" }, { "label": "单行文本", "props": { "placeholder": "请输入文本" }, "component": "Input", "designKey": "design-dKih", "name": "b" } ], "hideLabel": true, "component": "ObjGroup", "designKey": "design-SCqi", "name": "fff" } ] } ], "props": { "mode": "card" }, "component": "FormList", "designKey": "design-MWai", "name": "eee" } ], "hideLabel": true, "component": "ObjGroup", "designKey": "design-gnQI", "name": "ccc" } ] } ] } ], "props": { "defaultKey": "name1", "tabPosition": "left" }, "component": "Tabs", "designKey": "design-XOgc", "name": "form-Jr6C" } ] }

fssgh commented 3 days ago

自增容器里嵌对象容器时,好像还是不对,数据结构没有嵌上

xinnian999 commented 3 days ago

自增容器里嵌对象容器时,好像还是不对,数据结构没有嵌上

又fix了,v4.6.5。再试试

fssgh commented 3 days ago

完美了,全自动无限层嵌套,666