From aa5ce484a9b83b28c7f583dad7a283d3e889dc21 Mon Sep 17 00:00:00 2001 From: grz <12345> Date: Sat, 16 Nov 2024 14:30:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0combo=E7=BB=84?= =?UTF-8?q?=E4=BB=B6unique=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../amis-editor/src/plugin/Form/Combo.tsx | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/amis-editor/src/plugin/Form/Combo.tsx b/packages/amis-editor/src/plugin/Form/Combo.tsx index e9eae0c17..e0b5f1b82 100644 --- a/packages/amis-editor/src/plugin/Form/Combo.tsx +++ b/packages/amis-editor/src/plugin/Form/Combo.tsx @@ -514,6 +514,41 @@ export class ComboControlPlugin extends BasePlugin { ] }, + { + type: 'select', + name: 'uniqueItems', + label: '配置唯一项', + multiple: true, + 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.includes(item.name)) { + return {...item, unique: true}; + } else { + const newItem = {...item}; + delete newItem.unique; + return newItem; + } + }); + // 更新 items + form.setValueByName('items', updatedItems); + } + }, getSchemaTpl('labelRemark'), getSchemaTpl('remark'), From 9a3feb762b46d70c55e4c9dcea28fac0a2965ff1 Mon Sep 17 00:00:00 2001 From: grz <12345> Date: Mon, 18 Nov 2024 21:22:45 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-editor/src/plugin/Form/Combo.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/amis-editor/src/plugin/Form/Combo.tsx b/packages/amis-editor/src/plugin/Form/Combo.tsx index e0b5f1b82..cb6d64c61 100644 --- a/packages/amis-editor/src/plugin/Form/Combo.tsx +++ b/packages/amis-editor/src/plugin/Form/Combo.tsx @@ -516,9 +516,8 @@ export class ComboControlPlugin extends BasePlugin { { type: 'select', - name: 'uniqueItems', + name: '__uniqueItems', label: '配置唯一项', - multiple: true, source: '${items|pick:name}', pipeIn: (value: any, form: any) => { // 从 items 中获取设置了 unique: true 的项的 name From 7192f814790a206eb037d90679cdc405703d155e Mon Sep 17 00:00:00 2001 From: guruize162 Date: Tue, 19 Nov 2024 13:40:49 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix=20:=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-editor/src/plugin/Form/Combo.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amis-editor/src/plugin/Form/Combo.tsx b/packages/amis-editor/src/plugin/Form/Combo.tsx index cb6d64c61..4e1b4a390 100644 --- a/packages/amis-editor/src/plugin/Form/Combo.tsx +++ b/packages/amis-editor/src/plugin/Form/Combo.tsx @@ -536,7 +536,7 @@ export class ComboControlPlugin extends BasePlugin { const items = [...(form.data.items || [])]; // 修改 items 中的 unique 属性 const updatedItems = items.map(item => { - if (value.includes(item.name)) { + if (value === item.name) { return {...item, unique: true}; } else { const newItem = {...item};