feat:format control data
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
export enum ControlType {
|
export enum ControlType {
|
||||||
TEXT = 'text',
|
TEXT = 'text',
|
||||||
SELECT = 'select'
|
SELECT = 'select'
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ControlComponent {
|
||||||
|
SUFFIX = 'suffix',
|
||||||
|
POSTFIX = 'postfix',
|
||||||
|
PLACEHOLDER = 'placeholder',
|
||||||
|
VALUE = 'value'
|
||||||
}
|
}
|
||||||
@@ -6,16 +6,21 @@ export interface IValueSet {
|
|||||||
code: string;
|
code: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IControl {
|
export interface IControlSelect {
|
||||||
|
valueSets: IValueSet[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IControlBasic {
|
||||||
type: ControlType;
|
type: ControlType;
|
||||||
value: IElement[] | null;
|
value: IElement[] | null;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
conceptId?: string;
|
conceptId?: string;
|
||||||
prefix?: string;
|
prefix?: string;
|
||||||
postfix?: string;
|
postfix?: string;
|
||||||
valueSets?: IValueSet[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type IControl = IControlBasic & Partial<IControlSelect>
|
||||||
|
|
||||||
export interface IControlOption {
|
export interface IControlOption {
|
||||||
placeholderColor?: string;
|
placeholderColor?: string;
|
||||||
bracketColor?: string;
|
bracketColor?: string;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ControlComponent } from '../dataset/enum/Control'
|
||||||
import { ElementType } from '../dataset/enum/Element'
|
import { ElementType } from '../dataset/enum/Element'
|
||||||
import { RowFlex } from '../dataset/enum/Row'
|
import { RowFlex } from '../dataset/enum/Row'
|
||||||
import { IControl } from './Control'
|
import { IControl } from './Control'
|
||||||
@@ -52,13 +53,19 @@ export interface ISeparator {
|
|||||||
dashArray?: number[];
|
dashArray?: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IControlElement {
|
||||||
|
control?: IControl;
|
||||||
|
controlId?: string;
|
||||||
|
controlComponent?: ControlComponent;
|
||||||
|
}
|
||||||
|
|
||||||
export type IElement = IElementBasic
|
export type IElement = IElementBasic
|
||||||
& IElementStyle
|
& IElementStyle
|
||||||
& ITable
|
& ITable
|
||||||
& IHyperlinkElement
|
& IHyperlinkElement
|
||||||
& ISuperscriptSubscript
|
& ISuperscriptSubscript
|
||||||
& ISeparator
|
& ISeparator
|
||||||
& { control?: IControl }
|
& IControlElement
|
||||||
|
|
||||||
export interface IElementMetrics {
|
export interface IElementMetrics {
|
||||||
width: number;
|
width: number;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { deepClone, getUUID } from '.'
|
|||||||
import { ElementType, IElement } from '..'
|
import { ElementType, IElement } from '..'
|
||||||
import { ZERO } from '../dataset/constant/Common'
|
import { ZERO } from '../dataset/constant/Common'
|
||||||
import { EDITOR_ELEMENT_ZIP_ATTR } from '../dataset/constant/Element'
|
import { EDITOR_ELEMENT_ZIP_ATTR } from '../dataset/constant/Element'
|
||||||
|
import { ControlComponent } from '../dataset/enum/Control'
|
||||||
|
|
||||||
export function formatElementList(elementList: IElement[], isHandleFirstElement = true) {
|
export function formatElementList(elementList: IElement[], isHandleFirstElement = true) {
|
||||||
if (isHandleFirstElement && elementList[0]?.value !== ZERO) {
|
if (isHandleFirstElement && elementList[0]?.value !== ZERO) {
|
||||||
@@ -59,6 +60,74 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
i--
|
i--
|
||||||
|
} else if (el.type === ElementType.CONTROL) {
|
||||||
|
const { prefix, postfix, value, placeholder } = el.control!
|
||||||
|
const controlId = getUUID()
|
||||||
|
// 移除父节点
|
||||||
|
elementList.splice(i, 1)
|
||||||
|
// 前缀
|
||||||
|
if (prefix) {
|
||||||
|
const prefixStrList = prefix.split('')
|
||||||
|
for (let p = 0; p < prefixStrList.length; p++) {
|
||||||
|
const value = prefixStrList[p]
|
||||||
|
elementList.splice(i, 0, {
|
||||||
|
controlId,
|
||||||
|
value,
|
||||||
|
type: el.type,
|
||||||
|
control: el.control,
|
||||||
|
controlComponent: ControlComponent.SUFFIX
|
||||||
|
})
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 值
|
||||||
|
if (value && value.length) {
|
||||||
|
for (let v = 0; v < value.length; v++) {
|
||||||
|
const element = value[v]
|
||||||
|
const valueStrList = element.value.split('')
|
||||||
|
for (let e = 0; e < valueStrList.length; e++) {
|
||||||
|
const value = valueStrList[e]
|
||||||
|
elementList.splice(i, 0, {
|
||||||
|
controlId,
|
||||||
|
value,
|
||||||
|
type: el.type,
|
||||||
|
control: el.control,
|
||||||
|
controlComponent: ControlComponent.VALUE
|
||||||
|
})
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// placeholder
|
||||||
|
const placeholderStrList = placeholder.split('')
|
||||||
|
for (let p = 0; p < placeholderStrList.length; p++) {
|
||||||
|
const value = placeholderStrList[p]
|
||||||
|
elementList.splice(i, 0, {
|
||||||
|
controlId,
|
||||||
|
value,
|
||||||
|
type: el.type,
|
||||||
|
control: el.control,
|
||||||
|
controlComponent: ControlComponent.PLACEHOLDER
|
||||||
|
})
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 后缀
|
||||||
|
if (postfix) {
|
||||||
|
const postfixStrList = postfix.split('')
|
||||||
|
for (let p = 0; p < postfixStrList.length; p++) {
|
||||||
|
const value = postfixStrList[p]
|
||||||
|
elementList.splice(i, 0, {
|
||||||
|
controlId,
|
||||||
|
value,
|
||||||
|
type: el.type,
|
||||||
|
control: el.control,
|
||||||
|
controlComponent: ControlComponent.POSTFIX
|
||||||
|
})
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i--
|
||||||
} else if ((!el.type || el.type === ElementType.TEXT) && el.value.length > 1) {
|
} else if ((!el.type || el.type === ElementType.TEXT) && el.value.length > 1) {
|
||||||
elementList.splice(i, 1)
|
elementList.splice(i, 1)
|
||||||
const valueList = el.value.split('')
|
const valueList = el.value.split('')
|
||||||
|
|||||||
Reference in New Issue
Block a user