Replies: 16 comments 5 replies
-
场景假设现在有一个表单: type IForm = {
/**
* 供应商
*/
supplierId: string
supplierName: string
/**
* 仓库
*/
cargoId: string
cargoName: string
}对应的,供应商从 SupplierPicker 组件中获取: type ISupplier = {
id:string
name: string
}
type SupplierPickerProps = {
value: ISupplier
onChange(value:ISupplier) => void
}仓库从 CargoPicker 组件中获取: type ICargo = {
id:string
name: string
}
type CargoPickerProps = {
value: ICargo
onChange(value:ICargo) => void
} |
Beta Was this translation helpful? Give feedback.
-
基础需求
实现const schema = {
type: 'object',
properties: {
'{id: supplierId, name: supplierName}': {
type: 'object',
title: '供应商',
'x-component': 'SupplierPicker'
},
'{id: cargoId, name: cargoId}': {
type: 'object',
title: '仓库',
'x-component': 'CargoPicker',
'x-reactions': [
{
dependencies: ['{id: supplierId, name: supplierName}'],
fulfill: {
state: {
disabled: '{{ !!$deps[0].id }}'
}
}
},
{
dependencies: ['{id: supplierId, name: supplierName}'],
when: '{{ $deps[0].modified }}',
fulfill: {
state: {
value: undefined
}
}
}
]
}
}
}总结
{
dependencies: ['{id: supplierId, name: supplierName}'],
fulfill: {
state: {
// 这里是写 id 呢,还是 supplierId ?我得测试,然后把规则背下来
disabled: '{{ !!$deps[0].??? }}'
}
}
} |
Beta Was this translation helpful? Give feedback.
-
进阶需求
type IContract = {
id: string
code: string
}
type ContractPicker = {
value: IContract
onChange: (value: IContract) => void
}
type IGoods = {
id: string
code: string
}
type GoodsPicker = {
value: IGoods[]
onChange: (values: IGoods[]) => void
}
type IForm = {
// ...
contractId: string
contractName: string
goodsList: { goodsId: string; goodsName: string }[]
}
实现 {
properties: {
'{id: contractId, name: contractName}': {
type: 'object',
title: '合同',
'x-component': 'ContractPicker',
'x-reactions': [
{
dependencies: ['{id: cargoId, name: cargoName}'],
fulfill: {
state: {
disabled: '{{ !!$deps[0].id }}'
}
}
},
{
dependencies: ['{id: cargoId, name: cargoName}'],
when: '{{ $deps[0].modified }}',
fulfill: {
state: {
value: undefined
}
}
}
]
},
// △:注意这里
goodsList: {
type: 'array',
title: '物资列表',
'x-component': 'GoodsPicker',
'x-reactions': [
{
dependencies: ['{id: contractId, name: contractName}'],
fulfill: {
state: {
disabled: '{{ !!$deps[0].id }}'
}
}
},
{
dependencies: ['{id: contractId, name: contractName}'],
when: '{{ $deps[0].modified }}',
fulfill: {
state: {
value: undefined
}
}
}
]
},
// △:注意这里
goodsListTable: {
type: 'array',
title: '',
'x-component': 'ArrayTable'
}
}
}问题描述GoodsPicker 是负责选取物资的,然后使用 ArrayTable 展示。这里就引入一个问题,多个 UI 对应一个 Field 时暂时没有好的解决办法。 现在得使用 Effects 进行同步,有点麻烦了,何况业务上还有其他的联动,导致一个字段的 effect 一大坨。 为什么不如果只是为了解决多个 UI 映射到一个 Field 的问题,可以把 ArrayTable 放到 GoodsPicker 组件里面维护,但是这样又会导致布局问题跟校验问题。
希望校验信息在 search icon 下面,而不是在 table 下方。 希望的功能多个 UI 能映射到同一个 Field。 总结
|
Beta Was this translation helpful? Give feedback.
-
综上所述
期望的效果// 解构模式
const schema1 = {
type: 'object',
properties: {
user: {
type: 'object',
alias: '{id: userId, name: userName}'
}
}
}
// 别名模式
const schema2 = {
type: 'object',
properties: {
goodsListPicker: {
type: 'object',
alias: 'goodsList'
},
goodsListTable: {
type: 'object',
alias: 'goodsList'
}
}
}实现方式略 |
Beta Was this translation helpful? Give feedback.
-
|
只能把业务中比较好描述的一些业务抽出来,现实系统中的表单关联比这个要复杂更多。如何方便优雅的使用字段解构功能是一个大问题,因为我不但想少干活,还想把他干漂亮 😄 |
Beta Was this translation helpful? Give feedback.
-
|
感觉你的需求可以考虑使用更标准的 #1147 |
Beta Was this translation helpful? Give feedback.
-
|
不一样啊,我没有需要复用的 json 片段。 我的主要问题字段解构
字段别名多 UI 映射到单个 Field 能力缺失。 |
Beta Was this translation helpful? Give feedback.
-
|
先回家吃饭啦。 |
Beta Was this translation helpful? Give feedback.
-
|
下面把跟大佬的聊天记录发出来供大家参考。 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
@liuweiGL 所以最后是按照作者说的那个办法去搞了么 |
Beta Was this translation helpful? Give feedback.
-
|
可不可以通过多定义几个hidden字段联动赋值来实现解构,让数据可追踪 |
Beta Was this translation helpful? Give feedback.





















Uh oh!
There was an error while loading. Please reload this page.
-
这是一篇小作文~
Beta Was this translation helpful? Give feedback.
All reactions