From 6e11496f9c2496728f341eb6bb24d2c0ae46a5d3 Mon Sep 17 00:00:00 2001 From: yanxiong Date: Wed, 13 Jul 2022 19:12:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=201.=E6=96=B0=E5=A2=9E=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=20maxCount=20=EF=BC=8C=E7=94=A8=E4=BA=8E=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=BD=93=E5=89=8D=E6=9C=80=E5=A4=A7=E7=BB=98=E5=88=B6?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mode/base-mode.ts | 9 ++++++--- src/typings/drawer.ts | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mode/base-mode.ts b/src/mode/base-mode.ts index 7ab8e99..aad30f4 100644 --- a/src/mode/base-mode.ts +++ b/src/mode/base-mode.ts @@ -91,18 +91,20 @@ export abstract class BaseMode< */ get addable() { const data = this.getData(); - const { multiple } = this.options; + const { multiple, maxCount } = this.options; const drawItem = data.find((item) => item.properties.isDraw); if (!this.enabled) { return false; } - if (multiple || drawItem) { + if ((multiple && maxCount <= 0) || drawItem) { return true; } if (!multiple && this.addCount >= 1) { return false; } - + if (maxCount > 0 && this.getData().length >= maxCount) { + return false; + } return true; } @@ -446,6 +448,7 @@ export abstract class BaseMode< disableEditable: false, popup: true, helper: {}, + maxCount: -1, } as IBaseModeOptions; } diff --git a/src/typings/drawer.ts b/src/typings/drawer.ts index 13a91ad..889bdd8 100644 --- a/src/typings/drawer.ts +++ b/src/typings/drawer.ts @@ -38,6 +38,7 @@ export interface IBaseModeOptions { autoActive: boolean; multiple: boolean; helper: any | boolean; + maxCount: number; popup: PopupOptions | boolean; history: HistoryConfig | false; keyboard: KeyBoardConfig | false; From 3a0d591fe04e7b19baf7fec2f58feb79f57dbd14 Mon Sep 17 00:00:00 2001 From: yanxiong Date: Wed, 13 Jul 2022 19:17:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?perf:=20=E9=81=BF=E5=85=8D=20getData=20?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mode/base-mode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mode/base-mode.ts b/src/mode/base-mode.ts index 13c9373..da714f4 100644 --- a/src/mode/base-mode.ts +++ b/src/mode/base-mode.ts @@ -102,7 +102,7 @@ export abstract class BaseMode< if (!multiple && this.addCount >= 1) { return false; } - if (maxCount > 0 && this.getData().length >= maxCount) { + if (maxCount > 0 && data.length >= maxCount) { return false; } return true;