import React, { Component } from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Modal, Button, notification } from 'antd'
|
import { VerticalRightOutlined } from '@ant-design/icons'
|
|
// import './index.scss'
|
|
const { confirm } = Modal
|
|
class LowerField extends Component {
|
static propTpyes = {
|
config: PropTypes.object,
|
updateConfig: PropTypes.func
|
}
|
|
trigger = () => {
|
const that = this
|
confirm({
|
content: `确定将字段转为小写吗?`,
|
onOk() {
|
that.exec()
|
},
|
onCancel() {}
|
})
|
}
|
|
exec = () => {
|
let config = fromJS(this.props.config).toJS()
|
|
let resetForm = (m) => {
|
if (m.field) {
|
m.field = m.field.toLowerCase()
|
}
|
if (m.type === 'split' && m.splitctrl) {
|
m.splitctrl = m.splitctrl.toLowerCase()
|
}
|
if (m.tabField) {
|
m.tabField = m.tabField.toLowerCase()
|
}
|
if (m.linkField) {
|
m.linkField = m.linkField.toLowerCase()
|
}
|
if (m.supField) {
|
m.supField = m.supField.toLowerCase()
|
}
|
if (m.phoneField) {
|
m.phoneField = m.phoneField.toLowerCase()
|
}
|
if (m.linkSubField) {
|
m.linkSubField = m.linkSubField.map(n => n.toLowerCase())
|
m.linkSubField = Array.from(new Set(m.linkSubField))
|
}
|
}
|
let resetMark = (m) => {
|
m.marks = m.marks.map(n => {
|
if (n.field && Array.isArray(n.field)) {
|
if (n.field[1] === 'static') {
|
n.field[0] = n.field[0] === '$Index' ? n.field[0] : n.field[0].toLowerCase()
|
} else {
|
n.field = n.field.map(p => p === '$Index' ? p : p.toLowerCase())
|
}
|
}
|
|
return n
|
})
|
}
|
let resetElement = (m) => {
|
if (m.field && m.field !== '$Index') {
|
m.field = m.field.toLowerCase()
|
}
|
if (m.posterField) {
|
m.posterField = m.posterField.toLowerCase()
|
}
|
if (m.bgImage) {
|
m.bgImage = m.bgImage.toLowerCase()
|
}
|
if (m.linkurl && /^[a-zA-Z0-9_]+$/.test(m.linkurl)) {
|
m.linkurl = m.linkurl.toLowerCase()
|
}
|
if (m.modal && m.modal.fields) {
|
if (m.modal.setting) {
|
if (m.modal.setting.focus) {
|
m.modal.setting.focus = m.modal.setting.focus.toLowerCase()
|
}
|
if (m.modal.setting.errFocus) {
|
m.modal.setting.errFocus = m.modal.setting.errFocus.toLowerCase()
|
}
|
}
|
m.modal.fields = m.modal.fields.map(col => {
|
resetForm(col)
|
return col
|
})
|
}
|
if (m.verify) {
|
if (m.verify.columns) {
|
m.verify.columns = m.verify.columns.map(col => {
|
if (col.Column) {
|
col.Column = col.Column.toLowerCase()
|
}
|
return col
|
})
|
}
|
if (m.verify.uniques) {
|
m.verify.uniques = m.verify.uniques.map(col => {
|
if (col.field) {
|
col.field = col.field.split(',').map(_field => {
|
if (_field === 'BID') return _field
|
return _field.toLowerCase()
|
}).join(',')
|
}
|
return col
|
})
|
}
|
if (m.verify.billcodes) {
|
m.verify.billcodes = m.verify.billcodes.map(col => {
|
if (col.field) {
|
col.field = col.field.toLowerCase()
|
}
|
if (col.linkField && col.linkField !== 'BID') {
|
col.linkField = col.linkField.toLowerCase()
|
}
|
return col
|
})
|
}
|
|
if (m.verify.accountfield && m.verify.accountfield !== 'BID') {
|
m.verify.accountfield = m.verify.accountfield.toLowerCase()
|
}
|
if (m.verify.voucher && m.verify.voucher.linkField && m.verify.voucher.linkField !== 'BID') {
|
m.verify.voucher.linkField = m.verify.voucher.linkField.toLowerCase()
|
}
|
}
|
if (m.controlField) {
|
m.controlField = m.controlField.toLowerCase()
|
}
|
|
if (m.marks && m.marks.length) {
|
resetMark(m)
|
}
|
if (m.config && m.config.components) {
|
m.config.components = _replace(m.config.components)
|
}
|
}
|
let _replace = (components) => {
|
return components.map(item => {
|
if (item.type === 'tabs') {
|
if (item.setting) {
|
if (item.setting.controlField) {
|
item.setting.controlField = item.setting.controlField.toLowerCase()
|
}
|
if (item.setting.selectField) {
|
item.setting.selectField = item.setting.selectField.toLowerCase()
|
}
|
}
|
item.subtabs.forEach(tab => {
|
tab.components = _replace(tab.components)
|
})
|
return item
|
} else if (item.type === 'group') {
|
item.components = _replace(item.components)
|
return item
|
}
|
|
if (item.columns) {
|
item.columns = item.columns.map(col => {
|
if (col.field) {
|
col.field = col.field.toLowerCase()
|
}
|
return col
|
})
|
}
|
if (item.setting && item.setting.primaryKey) {
|
item.setting.primaryKey = item.setting.primaryKey.toLowerCase()
|
}
|
if (item.subColumns) {
|
item.subColumns = item.subColumns.map(col => {
|
if (col.field) {
|
col.field = col.field.toLowerCase()
|
}
|
return col
|
})
|
}
|
if (item.search) {
|
if (item.type === 'topbar') {
|
if (item.search.fields) {
|
item.search.fields = item.search.fields.map(col => {
|
if (col.field) {
|
col.field = col.field.toLowerCase()
|
}
|
return col
|
})
|
}
|
if (item.search.groups) {
|
item.search.groups = item.search.groups.map(group => {
|
group.fields = group.fields.map(col => {
|
if (col.field) {
|
col.field = col.field.toLowerCase()
|
}
|
return col
|
})
|
return group
|
})
|
}
|
} else if (Array.isArray(item.search)) {
|
item.search = item.search.map(col => {
|
if (col.field) {
|
col.field = col.field.toLowerCase()
|
}
|
if (col.dateShift) {
|
col.dateShift = col.dateShift.toLowerCase()
|
}
|
return col
|
})
|
}
|
}
|
|
if (item.action) {
|
item.action.forEach(m => {
|
resetElement(m)
|
})
|
}
|
|
if (item.subcards) {
|
item.subcards.forEach(card => {
|
if (card.setting) {
|
if (card.setting.controlField && card.setting.controlField !== '$Index') {
|
card.setting.controlField = card.setting.controlField.toLowerCase()
|
}
|
if (card.setting.bgField) {
|
card.setting.bgField = card.setting.bgField.toLowerCase()
|
}
|
if (card.setting.menuType) {
|
card.setting.menuType = card.setting.menuType.toLowerCase()
|
}
|
}
|
if (card.elements) {
|
card.elements = card.elements.map(m => {
|
resetElement(m)
|
return m
|
})
|
}
|
|
if (card.backElements) {
|
card.backElements = card.backElements.map(m => {
|
resetElement(m)
|
return m
|
})
|
}
|
|
if (card.fields) {
|
card.fields = card.fields.map(m => {
|
resetForm(m)
|
return m
|
})
|
}
|
if (card.subButton) {
|
resetElement(card.subButton)
|
|
if (card.subButton.resetForms) {
|
card.subButton.resetForms = card.subButton.resetForms.map(n => n.toLowerCase())
|
}
|
}
|
})
|
}
|
|
if (item.elements) {
|
item.elements = item.elements.map(m => {
|
resetElement(m)
|
return m
|
})
|
}
|
|
if (item.plot) {
|
if (item.plot.Xaxis) {
|
item.plot.Xaxis = item.plot.Xaxis.toLowerCase()
|
}
|
// 统计图
|
if (item.plot.InfoValue) {
|
item.plot.InfoValue = item.plot.InfoValue.toLowerCase()
|
}
|
if (item.plot.InfoType) {
|
item.plot.InfoType = item.plot.InfoType.toLowerCase()
|
}
|
// 占比图
|
if (item.plot.valueField) {
|
item.plot.valueField = item.plot.valueField.toLowerCase()
|
}
|
if (item.plot.labelField) {
|
item.plot.labelField = item.plot.labelField.toLowerCase()
|
}
|
// 饼图
|
if (item.plot.type) {
|
item.plot.type = item.plot.type.toLowerCase()
|
}
|
// 散点图
|
if (item.plot.gender) {
|
item.plot.gender = item.plot.gender.toLowerCase()
|
}
|
if (item.plot.menuType) {
|
item.plot.menuType = item.plot.menuType.toLowerCase()
|
}
|
if (item.Yaxis) {
|
if (Array.isArray(item.Yaxis)) {
|
item.Yaxis = item.Yaxis.map(m => {
|
if (m) return m.toLowerCase()
|
return m
|
})
|
} else {
|
if (item.Yaxis) {
|
item.Yaxis = item.Yaxis.toLowerCase()
|
}
|
}
|
}
|
}
|
|
if (item.cols) {
|
let _update = (cols) => {
|
return cols.map(col => {
|
if (col.type === 'custom' && col.elements) {
|
if (col.sortField) {
|
col.sortField = col.sortField.toLowerCase()
|
}
|
col.elements = col.elements.map(m => {
|
resetElement(m)
|
return m
|
})
|
} else if (col.type === 'colspan') {
|
col.subcols = _update(col.subcols)
|
} else {
|
if (col.field) {
|
col.field = col.field.toLowerCase()
|
|
if (col.editable === 'true') {
|
if (col.linkSubField) {
|
col.linkSubField = col.linkSubField.map(n => n.toLowerCase())
|
col.linkSubField = Array.from(new Set(col.linkSubField))
|
}
|
if (col.clearField) {
|
col.clearField = col.clearField.toLowerCase()
|
}
|
if (col.ctrlField) {
|
col.ctrlField = col.ctrlField.toLowerCase()
|
}
|
}
|
}
|
|
if (col.marks && col.marks.length) {
|
resetMark(col)
|
}
|
}
|
|
return col
|
})
|
}
|
|
item.cols = _update(item.cols)
|
|
if (item.lineMarks) {
|
item.lineMarks = item.lineMarks.map(n => {
|
if (n.field && Array.isArray(n.field)) {
|
if (n.field[1] === 'static') {
|
n.field[0] = n.field[0] === '$Index' ? n.field[0] : n.field[0].toLowerCase()
|
} else {
|
n.field = n.field.map(p => p === '$Index' ? p : p.toLowerCase())
|
}
|
}
|
|
return n
|
})
|
}
|
}
|
|
if (item.subMenus) {
|
item.subMenus = item.subMenus.map(m => {
|
if (m.setting && m.setting.tip) {
|
m.setting.tip = m.setting.tip.toLowerCase()
|
}
|
return m
|
})
|
}
|
|
if (item.wrap) {
|
if (item.wrap.field) {
|
item.wrap.field = item.wrap.field.toLowerCase()
|
}
|
if (item.wrap.tipField) {
|
item.wrap.tipField = item.wrap.tipField.toLowerCase()
|
}
|
if (item.wrap.controlField) {
|
item.wrap.controlField = item.wrap.controlField.toLowerCase()
|
}
|
if (item.wrap.valueField) {
|
item.wrap.valueField = item.wrap.valueField.toLowerCase()
|
}
|
if (item.wrap.labelField) {
|
item.wrap.labelField = item.wrap.labelField.toLowerCase()
|
}
|
if (item.wrap.parentField) {
|
item.wrap.parentField = item.wrap.parentField.toLowerCase()
|
}
|
if (item.wrap.broadcast) {
|
item.wrap.broadcast = item.wrap.broadcast.toLowerCase()
|
}
|
if (item.wrap.jumpField) {
|
item.wrap.jumpField = item.wrap.jumpField.toLowerCase()
|
}
|
if (item.wrap.link) {
|
item.wrap.link = item.wrap.link.toLowerCase()
|
}
|
if (item.wrap.linkField) {
|
item.wrap.linkField = item.wrap.linkField.toLowerCase()
|
}
|
if (item.wrap.focus) {
|
item.wrap.focus = item.wrap.focus.toLowerCase()
|
}
|
if (item.wrap.refocus) {
|
item.wrap.refocus = item.wrap.refocus.toLowerCase()
|
}
|
if (item.wrap.statusControl) {
|
item.wrap.statusControl = item.wrap.statusControl.toLowerCase()
|
}
|
if (item.wrap.timeField) {
|
item.wrap.timeField = item.wrap.timeField.toLowerCase()
|
}
|
if (item.wrap.endField) {
|
item.wrap.endField = item.wrap.endField.toLowerCase()
|
}
|
if (item.wrap.remarkField) {
|
item.wrap.remarkField = item.wrap.remarkField.toLowerCase()
|
}
|
if (item.wrap.colorField) {
|
item.wrap.colorField = item.wrap.colorField.toLowerCase()
|
}
|
if (item.wrap.menuType) {
|
item.wrap.menuType = item.wrap.menuType.toLowerCase()
|
}
|
|
if (item.type === 'timeline') {
|
if (item.wrap.label) {
|
item.wrap.label = item.wrap.label.toLowerCase()
|
}
|
if (item.wrap.node) {
|
item.wrap.node = item.wrap.node.toLowerCase()
|
}
|
}
|
}
|
|
return item
|
})
|
}
|
|
config.components = _replace(config.components)
|
|
config.interfaces && config.interfaces.forEach(item => {
|
if (item.columns) {
|
item.columns = item.columns.map(col => {
|
if (col.field) {
|
col.field = col.field.toLowerCase()
|
}
|
return col
|
})
|
}
|
if (item.setting && item.setting.primaryKey) {
|
item.setting.primaryKey = item.setting.primaryKey.toLowerCase()
|
}
|
})
|
|
notification.success({
|
top: 92,
|
message: '转换已完成。',
|
duration: 3
|
})
|
|
this.props.updateConfig(config)
|
}
|
|
render() {
|
return (
|
<Button className="mk-border-purple" onClick={this.trigger}><VerticalRightOutlined style={{transform: 'rotate(270deg)'}}/> 字段转小写</Button>
|
)
|
}
|
}
|
|
export default LowerField
|