mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 10:38:16 +08:00
Merge pull request #11209 from grzzzzzz77/feat-combo
feat: 增加combo组件unique配置项
This commit is contained in:
commit
b696b2a527
@ -518,6 +518,40 @@ export class ComboControlPlugin extends BasePlugin {
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
type: 'select',
|
||||
name: '__uniqueItems',
|
||||
label: '配置唯一项',
|
||||
source: '${items|pick:name}',
|
||||
pipeIn: (value: any, form: any) => {
|
||||
// 从 items 中获取设置了 unique: true 的项的 name
|
||||
const items = form.data.items || [];
|
||||
return items
|
||||
.filter((item: any) => item.unique)
|
||||
.map((item: any) => item.name);
|
||||
},
|
||||
onChange: (
|
||||
value: string[],
|
||||
oldValue: any,
|
||||
model: any,
|
||||
form: any
|
||||
) => {
|
||||
// 获取当前的 items
|
||||
const items = [...(form.data.items || [])];
|
||||
// 修改 items 中的 unique 属性
|
||||
const updatedItems = items.map(item => {
|
||||
if (value === item.name) {
|
||||
return {...item, unique: true};
|
||||
} else {
|
||||
const newItem = {...item};
|
||||
delete newItem.unique;
|
||||
return newItem;
|
||||
}
|
||||
});
|
||||
// 更新 items
|
||||
form.setValueByName('items', updatedItems);
|
||||
}
|
||||
},
|
||||
getSchemaTpl('labelRemark'),
|
||||
getSchemaTpl('remark'),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user