diff --git a/docs/en/guide/schema.md b/docs/en/guide/schema.md
index 327ec970..1dceb011 100644
--- a/docs/en/guide/schema.md
+++ b/docs/en/guide/schema.md
@@ -90,7 +90,8 @@ interface IElement {
SELECT = 'select',
CHECKBOX = 'checkbox',
RADIO = 'radio',
- DATE = 'date'
+ DATE = 'date',
+ NUMBER = 'number'
};
value: IElement[] | null;
placeholder?: string;
diff --git a/docs/guide/schema.md b/docs/guide/schema.md
index 488739cf..338f032a 100644
--- a/docs/guide/schema.md
+++ b/docs/guide/schema.md
@@ -90,7 +90,8 @@ interface IElement {
SELECT = 'select',
CHECKBOX = 'checkbox',
RADIO = 'radio'
- DATE = 'date'
+ DATE = 'date',
+ NUMBER = 'number'
};
value: IElement[] | null;
placeholder?: string;
diff --git a/index.html b/index.html
index 7990856a..96a52f12 100644
--- a/index.html
+++ b/index.html
@@ -280,6 +280,7 @@
- 文本
+ - 数值
- 列举
- 日期
- 复选框
diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts
index 03343ca3..8173d276 100644
--- a/src/editor/core/draw/control/Control.ts
+++ b/src/editor/core/draw/control/Control.ts
@@ -48,6 +48,7 @@ import { ControlBorder } from './richtext/Border'
import { SelectControl } from './select/SelectControl'
import { TextControl } from './text/TextControl'
import { DateControl } from './date/DateControl'
+import { NumberControl } from './number/NumberControl'
import { MoveDirection } from '../../../dataset/enum/Observer'
import {
CONTROL_CONTEXT_ATTR,
@@ -383,6 +384,8 @@ export class Control {
const dateControl = new DateControl(element, this)
this.activeControl = dateControl
dateControl.awake()
+ } else if (control.type === ControlType.NUMBER) {
+ this.activeControl = new NumberControl(element, this)
}
// 缓存控件数据
this.updateActiveControlValue()
@@ -763,7 +766,9 @@ export class Control {
const nextElement = elementList[j]
if (nextElement.controlId !== element.controlId) break
if (
- (type === ControlType.TEXT || type === ControlType.DATE) &&
+ (type === ControlType.TEXT ||
+ type === ControlType.DATE ||
+ type === ControlType.NUMBER) &&
nextElement.controlComponent === ControlComponent.VALUE
) {
textControlValue += nextElement.value
@@ -773,7 +778,11 @@ export class Control {
}
j++
}
- if (type === ControlType.TEXT || type === ControlType.DATE) {
+ if (
+ type === ControlType.TEXT ||
+ type === ControlType.DATE ||
+ type === ControlType.NUMBER
+ ) {
result.push({
...element.control,
zone,
@@ -917,6 +926,19 @@ export class Control {
} else {
date.clearSelect(controlContext, controlRule)
}
+ } else if (type === ControlType.NUMBER) {
+ const formatValue = Array.isArray(value) ? value : [{ value }]
+ formatElementList(formatValue, {
+ isHandleFirstElement: false,
+ editorOptions: this.options
+ })
+ const text = new NumberControl(element, this)
+ this.activeControl = text
+ if (value) {
+ text.setValue(formatValue, controlContext, controlRule)
+ } else {
+ text.clearValue(controlContext, controlRule)
+ }
}
// 模拟控件激活后销毁
this.activeControl = null
diff --git a/src/editor/core/draw/control/number/NumberControl.ts b/src/editor/core/draw/control/number/NumberControl.ts
new file mode 100644
index 00000000..07ecefb1
--- /dev/null
+++ b/src/editor/core/draw/control/number/NumberControl.ts
@@ -0,0 +1,3 @@
+import { TextControl } from '../text/TextControl'
+
+export class NumberControl extends TextControl {}
diff --git a/src/editor/dataset/enum/Control.ts b/src/editor/dataset/enum/Control.ts
index 232ae81d..b894c13f 100644
--- a/src/editor/dataset/enum/Control.ts
+++ b/src/editor/dataset/enum/Control.ts
@@ -3,7 +3,8 @@ export enum ControlType {
SELECT = 'select',
CHECKBOX = 'checkbox',
RADIO = 'radio',
- DATE = 'date'
+ DATE = 'date',
+ NUMBER = 'number'
}
export enum ControlComponent {
diff --git a/src/main.ts b/src/main.ts
index 197112f7..83faaae2 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -918,6 +918,48 @@ window.onload = function () {
}
})
break
+ case ControlType.NUMBER:
+ new Dialog({
+ title: '数值控件',
+ data: [
+ {
+ type: 'text',
+ label: '占位符',
+ name: 'placeholder',
+ required: true,
+ placeholder: '请输入占位符'
+ },
+ {
+ type: 'text',
+ label: '默认值',
+ name: 'value',
+ placeholder: '请输入默认值'
+ }
+ ],
+ onConfirm: payload => {
+ const placeholder = payload.find(
+ p => p.name === 'placeholder'
+ )?.value
+ if (!placeholder) return
+ const value = payload.find(p => p.name === 'value')?.value || ''
+ instance.command.executeInsertControl({
+ type: ElementType.CONTROL,
+ value: '',
+ control: {
+ type,
+ value: value
+ ? [
+ {
+ value
+ }
+ ]
+ : null,
+ placeholder
+ }
+ })
+ }
+ })
+ break
default:
break
}