import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Modal, Button, notification } from 'antd'
|
|
// import './index.scss'
|
|
const { confirm } = Modal
|
|
class DelExtraDb extends Component {
|
static propTpyes = {
|
config: PropTypes.object,
|
updateConfig: PropTypes.func
|
}
|
|
trigger = () => {
|
const that = this
|
confirm({
|
title: '确定要清除外库吗?',
|
content: '配置中的@db@将被清除',
|
okText: '确定',
|
cancelText: '取消',
|
onOk() {
|
that.exec()
|
},
|
onCancel() {}
|
})
|
}
|
|
checkBtn = (cell) => {
|
if (cell.modal && cell.modal.fields && cell.modal.fields.length) {
|
cell.modal.fields = cell.modal.fields.map(n => {
|
if (n.dataSource) {
|
n.dataSource = n.dataSource.replace(/@db@/ig, '')
|
}
|
return n
|
})
|
}
|
if (cell.sql) {
|
cell.sql = cell.sql.replace(/@db@/ig, '')
|
}
|
if (cell.cbTable) {
|
cell.cbTable = cell.cbTable.replace(/@db@/ig, '')
|
}
|
if (cell.sheet) {
|
cell.sheet = cell.sheet.replace(/@db@/ig, '')
|
}
|
if (cell.verify) {
|
if (cell.verify.scripts) {
|
cell.verify.scripts = cell.verify.scripts.map(n => {
|
if (n.sql) {
|
n.sql = n.sql.replace(/@db@/ig, '')
|
}
|
return n
|
})
|
}
|
if (cell.verify.cbScripts) {
|
cell.verify.cbScripts = cell.verify.cbScripts.map(n => {
|
if (n.sql) {
|
n.sql = n.sql.replace(/@db@/ig, '')
|
}
|
return n
|
})
|
}
|
if (cell.verify.customverifys) {
|
cell.verify.customverifys = cell.verify.customverifys.map(n => {
|
if (n.sql) {
|
n.sql = n.sql.replace(/@db@/ig, '')
|
}
|
return n
|
})
|
}
|
}
|
}
|
|
exec = () => {
|
let config = fromJS(this.props.config).toJS()
|
|
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.setting) {
|
if (item.setting.tableName) {
|
item.setting.tableName = item.setting.tableName.replace(/@db@/ig, '')
|
}
|
if (item.setting.dataresource) {
|
item.setting.dataresource = item.setting.dataresource.replace(/@db@/ig, '')
|
}
|
if (item.scripts) {
|
item.scripts = item.scripts.map(cell => {
|
cell.sql = cell.sql.replace(/@db@/ig, '')
|
return cell
|
})
|
}
|
}
|
|
if (item.search) {
|
if (Array.isArray(item.search)) {
|
item.search = item.search.map(col => {
|
if (col.dataSource) {
|
col.dataSource = col.dataSource.replace(/@db@/ig, '')
|
}
|
return col
|
})
|
} else if (item.search.fields) {
|
item.search.fields = item.search.fields.map(col => {
|
if (col.dataSource) {
|
col.dataSource = col.dataSource.replace(/@db@/ig, '')
|
}
|
return col
|
})
|
if (item.search.groups) {
|
item.search.groups = item.search.groups.map(group => {
|
if (group.fields) {
|
group.fields = group.fields.map(col => {
|
if (col.dataSource) {
|
col.dataSource = col.dataSource.replace(/@db@/ig, '')
|
}
|
return col
|
})
|
}
|
return group
|
})
|
}
|
}
|
}
|
|
if (item.action) {
|
item.action.forEach(m => {
|
this.checkBtn(m)
|
|
if (m.config && m.config.components) {
|
m.config.components = _replace(m.config.components)
|
}
|
})
|
}
|
|
if (item.subcards) {
|
item.subcards.forEach(card => {
|
if (card.subButton) {
|
this.checkBtn(card.subButton)
|
}
|
if (card.elements) { // 卡片
|
card.elements = card.elements.map(m => {
|
if (m.eleType !== 'button') return m
|
|
this.checkBtn(m)
|
|
if (m.config && m.config.components) {
|
m.config.components = _replace(m.config.components)
|
}
|
return m
|
})
|
}
|
|
if (card.backElements) { // 卡片
|
card.backElements = card.backElements.map(m => {
|
if (m.eleType !== 'button') return m
|
|
this.checkBtn(m)
|
|
if (m.config && m.config.components) {
|
m.config.components = _replace(m.config.components)
|
}
|
return m
|
})
|
}
|
|
if (card.fields) { // 表单
|
card.fields = card.fields.map(m => {
|
if (m.dataSource) {
|
m.dataSource = m.dataSource.replace(/@db@/ig, '')
|
}
|
return m
|
})
|
}
|
})
|
}
|
|
if (item.elements) {
|
item.elements = item.elements.map(m => {
|
if (m.eleType !== 'button') return m
|
|
this.checkBtn(m)
|
|
if (m.config && m.config.components) {
|
m.config.components = _replace(m.config.components)
|
}
|
return m
|
})
|
}
|
|
if (item.cols) {
|
let _update = (cols) => {
|
return cols.map(col => {
|
if (col.type === 'custom' && col.elements) {
|
col.elements = col.elements.map(m => {
|
if (m.eleType !== 'button') return m
|
|
this.checkBtn(m)
|
|
if (m.config && m.config.components) {
|
m.config.components = _replace(m.config.components)
|
}
|
|
return m
|
})
|
} else if (col.type === 'colspan') {
|
col.subcols = _update(col.subcols)
|
}
|
|
return col
|
})
|
}
|
|
item.cols = _update(item.cols)
|
}
|
|
if (item.subtype === 'editable' && item.submit) {
|
if (item.submit.sheet) {
|
item.submit.sheet = item.submit.sheet.replace(/@db@/ig, '')
|
}
|
if (item.submit.scripts) {
|
item.submit.scripts = item.submit.scripts.map(n => {
|
if (n.sql) {
|
n.sql = n.sql.replace(/@db@/ig, '')
|
}
|
return n
|
})
|
}
|
}
|
|
return item
|
})
|
}
|
|
config.components = _replace(config.components)
|
|
config.interfaces && config.interfaces.forEach(item => {
|
if (item.setting) {
|
if (item.setting.tableName) {
|
item.setting.tableName = item.setting.tableName.replace(/@db@/ig, '')
|
}
|
if (item.setting.dataresource) {
|
item.setting.dataresource = item.setting.dataresource.replace(/@db@/ig, '')
|
}
|
if (item.scripts) {
|
item.scripts = item.scripts.map(cell => {
|
cell.sql = cell.sql.replace(/@db@/ig, '')
|
return cell
|
})
|
}
|
}
|
})
|
|
notification.success({
|
top: 92,
|
message: '外库已清除。',
|
duration: 3
|
})
|
this.props.updateConfig(config)
|
}
|
|
render() {
|
// <HddOutlined />
|
return (
|
<Button className="mk-border-yellow" icon="hdd" onClick={this.trigger}>清除外库</Button>
|
)
|
}
|
}
|
|
export default DelExtraDb
|