feat:format control data

This commit is contained in:
黄云飞
2022-03-31 17:46:50 +08:00
parent 66319d5405
commit 666a880c4f
4 changed files with 91 additions and 3 deletions
+69
View File
@@ -2,6 +2,7 @@ import { deepClone, getUUID } from '.'
import { ElementType, IElement } from '..'
import { ZERO } from '../dataset/constant/Common'
import { EDITOR_ELEMENT_ZIP_ATTR } from '../dataset/constant/Element'
import { ControlComponent } from '../dataset/enum/Control'
export function formatElementList(elementList: IElement[], isHandleFirstElement = true) {
if (isHandleFirstElement && elementList[0]?.value !== ZERO) {
@@ -59,6 +60,74 @@ export function formatElementList(elementList: IElement[], isHandleFirstElement
}
}
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) {
elementList.splice(i, 1)
const valueList = el.value.split('')