From 440db738cb6723a621c5c083c630edd55489e184 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Fri, 15 Apr 2022 21:45:19 +0800 Subject: [PATCH] feat:add checkbox control menu --- index.html | 5 ++-- src/editor/core/draw/control/Control.ts | 1 + src/editor/interface/Control.ts | 2 +- src/editor/utils/element.ts | 2 +- src/main.ts | 36 +++++++++++++++++++++++-- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 68a38c4..d72c7e6 100644 --- a/index.html +++ b/index.html @@ -164,8 +164,9 @@
diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts index 0073a2a..a2ce8e8 100644 --- a/src/editor/core/draw/control/Control.ts +++ b/src/editor/core/draw/control/Control.ts @@ -274,6 +274,7 @@ export class Control { const elementList = this.getElementList() const startElement = elementList[startIndex] const control = startElement.control! + if (!control.placeholder) return const placeholderStrList = control.placeholder.split('') for (let p = 0; p < placeholderStrList.length; p++) { const value = placeholderStrList[p] diff --git a/src/editor/interface/Control.ts b/src/editor/interface/Control.ts index a691311..d14d7f6 100644 --- a/src/editor/interface/Control.ts +++ b/src/editor/interface/Control.ts @@ -23,7 +23,7 @@ export interface IControlCheckbox { export interface IControlBasic { type: ControlType; value: IElement[] | null; - placeholder: string; + placeholder?: string; conceptId?: string; prefix?: string; postfix?: string; diff --git a/src/editor/utils/element.ts b/src/editor/utils/element.ts index 88bf7f1..dcaa900 100644 --- a/src/editor/utils/element.ts +++ b/src/editor/utils/element.ts @@ -162,7 +162,7 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme } } } - } else { + } else if (placeholder) { // placeholder const thePlaceholderArgs: Pick = {} if (editorOptions && editorOptions.control) { diff --git a/src/main.ts b/src/main.ts index 6e28da9..b8969ad 100644 --- a/src/main.ts +++ b/src/main.ts @@ -415,7 +415,7 @@ window.onload = function () { switch (type) { case ControlType.TEXT: new Dialog({ - title: '文本型控件', + title: '文本控件', data: [{ type: 'text', label: '占位符', @@ -449,7 +449,7 @@ window.onload = function () { break case ControlType.SELECT: new Dialog({ - title: '列举型控件', + title: '列举控件', data: [{ type: 'text', label: '占位符', @@ -487,6 +487,38 @@ window.onload = function () { } }) break + case ControlType.CHECKBOX: + new Dialog({ + title: '复选框控件', + data: [{ + type: 'text', + label: '默认值', + name: 'code', + placeholder: '请输入默认值,多个值以英文逗号分割' + }, { + type: 'textarea', + label: '值集', + name: 'valueSets', + height: 100, + placeholder: `请输入值集JSON,例:\n[{\n"value":"有",\n"code":"98175"\n}]` + }], + onConfirm: (payload) => { + const valueSets = payload.find(p => p.name === 'valueSets')?.value + if (!valueSets) return + const code = payload.find(p => p.name === 'code')?.value + instance.command.executeInsertElementList([{ + type: ElementType.CONTROL, + value: '', + control: { + type, + code, + value: null, + valueSets: JSON.parse(valueSets) + } + }]) + } + }) + break default: break }