Merge pull request #11209 from grzzzzzz77/feat-combo

feat: 增加combo组件unique配置项
This commit is contained in:
hsm-lv 2024-11-25 13:03:24 +08:00 committed by GitHub
commit b696b2a527
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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('labelRemark'),
getSchemaTpl('remark'), getSchemaTpl('remark'),