You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
3.6 KiB
144 lines
3.6 KiB
5 years ago
|
import _ from 'lodash'
|
||
5 years ago
|
import {inputComponents, selectComponents} from '@/components/generator/config'
|
||
|
import {jsonClone} from '@/utils/index'
|
||
5 years ago
|
|
||
|
/**
|
||
|
* 表单json转换为后台需要的对象
|
||
|
* @param item
|
||
|
*/
|
||
5 years ago
|
export function formItemConvertData(item, projectKey) {
|
||
5 years ago
|
console.log(item)
|
||
5 years ago
|
let data = {
|
||
|
'type': item.typeId,
|
||
5 years ago
|
'formItemId': item.__config__.formId,
|
||
5 years ago
|
'label': item.__config__.label,
|
||
5 years ago
|
'defaultValue': item.__config__.defaultValue,
|
||
5 years ago
|
'required': item.__config__.required,
|
||
|
'placeholder': item.placeholder,
|
||
5 years ago
|
'regList': item.__config__.regList,
|
||
|
'projectKey': projectKey
|
||
5 years ago
|
}
|
||
5 years ago
|
let expand = {}
|
||
5 years ago
|
let param = dataParams[item.typeId]
|
||
5 years ago
|
if (param) {
|
||
|
Object.keys(param).forEach(key => {
|
||
|
let value = _.get(item, param[key])
|
||
5 years ago
|
_.set(expand, key, value)
|
||
5 years ago
|
})
|
||
5 years ago
|
_.set(data, 'expand', expand)
|
||
5 years ago
|
}
|
||
5 years ago
|
return data
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
//类型关系map
|
||
|
let typeMap = new Map()
|
||
|
|
||
|
/**
|
||
|
* 后台存储的数据转换为elementui表单需要的Json
|
||
|
* @param data
|
||
|
*/
|
||
|
export function dbDataConvertForItemJson(data) {
|
||
|
if (!typeMap.size > 0) {
|
||
|
//根据类型获取默认数据
|
||
|
_.concat(inputComponents, selectComponents).forEach(item => {
|
||
|
typeMap.set(item.typeId, item)
|
||
|
})
|
||
|
}
|
||
|
const defaultJsonItem = typeMap.get(data.type)
|
||
|
let jsonItem = _.cloneDeep(defaultJsonItem)
|
||
|
let param = dataParams[data.type]
|
||
|
if (param) {
|
||
|
Object.keys(param).forEach(key => {
|
||
|
let value = _.get(data.expand, key)
|
||
|
_.set(jsonItem, param[key], value)
|
||
|
})
|
||
|
}
|
||
|
jsonItem.typeId = data.type
|
||
|
jsonItem.__config__.formId = data.formItemId
|
||
|
jsonItem.__config__.label = data.label
|
||
|
jsonItem.__config__.required = data.required
|
||
|
jsonItem.__config__.regList = data.regList
|
||
|
if (data.defaultValue) {
|
||
|
if (data.defaultValue.json) {
|
||
|
jsonItem.__config__.defaultValue = JSON.parse(data.defaultValue.value)
|
||
|
} else {
|
||
|
jsonItem.__config__.defaultValue = data.defaultValue.value
|
||
|
}
|
||
|
}
|
||
|
jsonItem.regList = data.regList
|
||
|
jsonItem.placeholder = data.placeholder
|
||
|
jsonItem.__vModel__ = 'field' + data.formItemId
|
||
|
return jsonItem
|
||
|
}
|
||
|
|
||
5 years ago
|
/**
|
||
5 years ago
|
* 不同属性的存在json的位置不用 使用变量记录key 通过lodash表达式获取 1 2 3 4 为typeId
|
||
5 years ago
|
* @type {{'1': {maxlength: string, prepend: string, append: string}}}
|
||
|
*/
|
||
5 years ago
|
|
||
5 years ago
|
let dataParams = {
|
||
5 years ago
|
//单行文本
|
||
5 years ago
|
1: {
|
||
|
'prepend': '__slot__.prepend',
|
||
|
'maxlength': 'maxlength',
|
||
|
'append': '__slot__.append'
|
||
5 years ago
|
},
|
||
|
// 多行文本
|
||
|
2: {
|
||
|
'minRows': 'autosize.minRows',
|
||
|
'maxRows': 'autosize.maxRows',
|
||
|
'maxlength': 'maxlength'
|
||
|
},
|
||
|
//计数器
|
||
|
4: {
|
||
|
'min': 'min',
|
||
5 years ago
|
'max': 'max',
|
||
5 years ago
|
'maxlength': 'maxlength',
|
||
|
'step': 'step',
|
||
|
'step-strictly': 'step-strictly',
|
||
|
'precision': 'precision',
|
||
|
'controls-position': 'controls-position'
|
||
|
},
|
||
|
//下拉选择
|
||
|
5: {
|
||
|
'options': '__slot__.options',
|
||
|
'filterable': 'filterable',
|
||
|
'multiple': 'multiple'
|
||
|
},
|
||
|
//级联选择
|
||
|
6: {
|
||
|
'options': 'options',
|
||
|
'filterable': 'filterable',
|
||
|
'multiple': 'props.props.multiple'
|
||
|
},
|
||
|
//单选框组
|
||
|
7: {
|
||
|
'options': '__slot__.options',
|
||
|
'filterable': 'filterable',
|
||
|
'multiple': 'props.props.multiple'
|
||
|
},
|
||
|
//单选框组
|
||
|
8: {
|
||
|
'options': '__slot__.options',
|
||
|
'max': 'max',
|
||
|
'min': 'min'
|
||
|
}, //开关
|
||
5 years ago
|
9: {},
|
||
5 years ago
|
//滑块
|
||
5 years ago
|
10: {
|
||
5 years ago
|
'min': 'min',
|
||
|
'max': 'max',
|
||
5 years ago
|
'step': 'step'
|
||
5 years ago
|
},//时间选择
|
||
5 years ago
|
11: {}
|
||
5 years ago
|
|
||
5 years ago
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|