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 resetElement = (m) => {
|
if (m.datatype === 'dynamic' && m.field) {
|
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) {
|
m.modal.fields = m.modal.fields.map(col => {
|
if (col.field) {
|
col.field = col.field.toLowerCase()
|
}
|
if (col.type === 'split' && col.splitctrl) {
|
col.splitctrl = col.splitctrl.toLowerCase()
|
}
|
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.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.config && m.config.components) {
|
m.config.components = _replace(m.config.components)
|
}
|
}
|
let _replace = (components) => {
|
return components.map(item => {
|
if (item.type === 'tabs') {
|
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()
|
}
|
return col
|
})
|
}
|
}
|
|
if (item.action) {
|
item.action.forEach(m => {
|
resetElement(m)
|
})
|
}
|
|
if (item.subcards) {
|
item.subcards.forEach(card => {
|
if (card.setting && card.setting.controlField) {
|
card.setting.controlField = card.setting.controlField.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 => {
|
if (m.field) {
|
m.field = m.field.toLowerCase()
|
}
|
if (m.type === 'split' && m.splitctrl) {
|
m.splitctrl = m.splitctrl.toLowerCase()
|
}
|
return m
|
})
|
}
|
})
|
}
|
|
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.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) {
|
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()
|
}
|
|
return col
|
})
|
}
|
|
item.cols = _update(item.cols)
|
}
|
|
if (item.wrap) {
|
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()
|
}
|
}
|
|
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
|