import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Modal, Button, notification } from 'antd'
|
import { ArrowUpOutlined } from '@ant-design/icons'
|
// import moment from 'moment'
|
|
import { colorTransform } from '@/utils/option.js'
|
// import Api from '@/api'
|
import Utils from '@/utils/utils.js'
|
import './index.scss'
|
|
const { confirm } = Modal
|
|
class UpdateTable extends Component {
|
static propTpyes = {
|
config: PropTypes.object
|
}
|
|
state = {}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
trigger = () => {
|
const { config } = this.props
|
const _this = this
|
|
if (!config.enabled) {
|
notification.warning({
|
top: 92,
|
message: '未启用菜单不可升级!',
|
duration: 5
|
})
|
return
|
}
|
|
confirm({
|
title: '确定升级当前菜单吗?',
|
content: '',
|
onOk() {
|
return new Promise(resolve => {
|
_this.execUpdate(resolve)
|
})
|
},
|
onCancel() {}
|
})
|
}
|
|
execUpdate = (_resolve) => {
|
const { config } = this.props
|
|
let _config = {
|
version: 1.0,
|
uuid: config.uuid,
|
MenuID: config.uuid,
|
parentId: config.ParentId,
|
Template: 'BaseTable',
|
easyCode: config.easyCode,
|
enabled: false,
|
MenuName: config.MenuName,
|
MenuNo: config.MenuNo,
|
tables: config.tables || [],
|
urlFields: config.urlFields || [],
|
hidden: config.hidden,
|
autoMatic: {},
|
Remark: config.Remark,
|
components: [],
|
viewType: 'menu',
|
style: { backgroundColor: '#ffffff', paddingTop: '16px', paddingBottom: '80px', paddingLeft: '16px', paddingRight: '16px'},
|
}
|
|
let uuids = {}
|
let formActions = []
|
let popActions = []
|
|
let tbl = this.getTable(config, uuids, formActions, popActions)
|
|
if (config.autoMatic && config.autoMatic.enable === 'true' && uuids[config.autoMatic.action]) {
|
_config.autoMatic = {...config.autoMatic}
|
_config.autoMatic.action = uuids[config.autoMatic.action]
|
} else {
|
_config.autoMatic = {enable: 'false'}
|
}
|
|
_config.components.push(tbl)
|
|
console.log(config)
|
console.log(_config)
|
|
setTimeout(() => {
|
_resolve()
|
}, 5000)
|
}
|
|
getTable = (config, uuids, formActions, popActions) => {
|
let _card = {
|
uuid: Utils.getuuid(),
|
type: 'table',
|
format: 'array',
|
pageable: true,
|
switchable: true,
|
search: config.search.map(item => {
|
item.uuid = Utils.getuuid()
|
return item
|
}),
|
action: [],
|
subtype: 'basetable',
|
setting: { },
|
wrap: { },
|
style: {},
|
headerStyle: {},
|
columns: [],
|
cols: [],
|
scripts: []
|
}
|
|
let _cols = {}
|
let _colspan = []
|
let lineMarks = []
|
config.columns.forEach(col => {
|
if (col.type === 'colspan') {
|
_colspan.push(col.subfield.split(', '))
|
}
|
if (!col.field) return
|
|
let _col = fromJS(col).toJS()
|
|
if (_col.marks) {
|
_col.marks = []
|
col.marks.forEach(m => {
|
if (m.signType === 'card') return
|
|
let field = []
|
field.push(m.field)
|
field.push(m.contrastType)
|
|
if (m.contrastField) {
|
field.push(m.contrastField)
|
}
|
let color = '#1890ff'
|
if (m.color && m.color[1]) {
|
color = colorTransform[m.color[1]]
|
}
|
let signType = ['font']
|
if (m.signType === 'background') {
|
signType = ['background']
|
} else if (m.signType === 'icon') {
|
if (m.position === 'back') {
|
signType = ['iconback']
|
} else {
|
signType = ['iconfront']
|
}
|
signType.push(m.iconType)
|
signType.push(m.icon)
|
}
|
|
if (m.signType === 'line') {
|
lineMarks.push({
|
$index: lineMarks.length + 1,
|
field: field,
|
color: color,
|
contrastValue: m.contrastValue || '',
|
match: m.match,
|
signType: ['background']
|
})
|
} else {
|
_col.marks.push({
|
$index: _col.marks.length + 1,
|
field: field,
|
color: color,
|
contrastValue: m.contrastValue || '',
|
match: m.match,
|
signType: signType
|
})
|
}
|
})
|
}
|
|
_cols[col.field] = _col
|
})
|
|
config.columns.forEach(col => {
|
if (col.type === 'index') {
|
_card.cols.push(fromJS(col).toJS())
|
} else if (col.field && _cols[col.field]) {
|
let _col = fromJS(_cols[col.field]).toJS()
|
|
if (_colspan.includes(col.field)) {
|
_col.Hide = 'true'
|
}
|
|
_card.cols.push(_col)
|
}
|
|
if (col.type === 'colspan') {
|
let ucol = {
|
Align: col.Align,
|
Hide: col.Hide,
|
label: col.label,
|
marks: [],
|
isSub: false,
|
uuid: col.uuid,
|
blacklist: []
|
}
|
if (col.unfold === 'true') {
|
ucol.type = 'colspan'
|
ucol.subcols = []
|
|
col.subfield.split(', ').forEach(sub => {
|
if (_cols[sub]) {
|
let _col = fromJS(_cols[sub]).toJS()
|
_col.Hide = 'false'
|
_col.isSub = true
|
_col.uuid = Utils.getuuid()
|
|
ucol.subcols.push(_col)
|
}
|
})
|
|
if (ucol.subcols.length > 0) {
|
_card.cols.push(ucol)
|
}
|
} else {
|
ucol.Width = 120
|
ucol.type = 'custom'
|
ucol.elements = []
|
ucol.style = {paddingTop: '12px', paddingLeft: '8px', paddingBottom: '12px', paddingRight: '8px'}
|
|
col.subfield.split(', ').forEach(sub => {
|
if (_cols[sub]) {
|
let _col = {
|
copyable: 'false',
|
datatype: 'dynamic',
|
eleType: _cols[sub].type !== 'number' ? 'text' : 'number',
|
field: sub,
|
height: 1,
|
innerHeight: 21,
|
marks: _cols[sub].marks || null,
|
noValue: 'show',
|
style: {},
|
width: 24,
|
uuid: Utils.getuuid()
|
}
|
|
ucol.elements.push(_col)
|
}
|
})
|
|
if (ucol.elements.length > 0) {
|
_card.cols.push(ucol)
|
}
|
}
|
}
|
})
|
|
_card.lineMarks = lineMarks
|
_card.columns = []
|
_card.absFields = []
|
_card.cols.forEach(col => {
|
if (!col.field) return
|
if (['text', 'picture', 'video', 'textarea'].includes(col.type)) {
|
_card.columns.push({
|
datatype: `Nvarchar(${col.fieldlength || 50})`,
|
field: col.field,
|
fieldlength: col.fieldlength || 50,
|
label: col.label,
|
type: 'text',
|
uuid: col.uuid
|
})
|
} else if (col.type === 'link') {
|
_card.columns.push({
|
datatype: `Nvarchar(${col.fieldlength || 50})`,
|
field: col.field,
|
fieldlength: col.fieldlength || 50,
|
label: col.label,
|
type: 'text',
|
uuid: col.uuid
|
})
|
if (col.nameField) {
|
_card.columns.push({
|
datatype: `Nvarchar(${col.fieldlength || 50})`,
|
field: col.nameField,
|
fieldlength: col.fieldlength || 50,
|
label: col.label + '(名称)',
|
type: 'text',
|
uuid: col.uuid + 'name'
|
})
|
}
|
} else if (col.type === 'number') {
|
_card.columns.push({
|
datatype: `Decimal(18,${col.decimal || 0})`,
|
field: col.field,
|
decimal: col.decimal || 0,
|
label: col.label,
|
type: 'number',
|
uuid: col.uuid
|
})
|
|
if (col.format === 'abs') {
|
_card.absFields.push(col.field)
|
}
|
}
|
})
|
|
if (_card.absFields.length) {
|
_card.absFields = Array.from(new Set(_card.absFields))
|
} else {
|
_card.absFields = null
|
}
|
|
let colbtns = []
|
let colors = { primary: '#1890ff', yellow: '#c49f47', orange: 'orange', danger: '#ff4d4f', green: '#26C281', dgreen: '#32c5d2', purple: '#8E44AD', cyan: '#13c2c2', gray: '#666666', default: '#333333' }
|
|
config.action.forEach(btn => {
|
let _c = btn.class ? btn.class.replace('border-', '') : ''
|
let color = colors[_c] || '#1890ff'
|
let _btn = fromJS(btn).toJS()
|
_btn.uuid = Utils.getuuid()
|
delete _btn.position
|
delete _btn.linkTab
|
|
uuids[btn.uuid] = _btn.uuid
|
|
if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
|
|
formActions.push({origin: btn.uuid, uuid: _btn.uuid})
|
} else if (btn.OpenType === 'popview') {
|
|
popActions.push({origin: btn.uuid, linkTab: btn.linkTab || '', uuid: _btn.uuid})
|
} else if (btn.OpenType === 'tab') {
|
if (btn.tabTemplate === 'FormTab' || !btn.linkmenu || btn.linkmenu.length !== 3) {
|
return
|
}
|
}
|
|
if (_btn.tabType === 'CommonTable') {
|
_btn.tabType = 'BaseTable'
|
}
|
|
if (btn.position === 'grid') {
|
_btn.eleType = 'button'
|
_btn.width = 24
|
_btn.style = {color: color, backgroundColor: 'transparent', borderColor: 'transparent'}
|
colbtns.push(_btn)
|
} else {
|
if (btn.class.indexOf('border') > -1 || btn.class === 'default') {
|
_btn.style = {color: color, backgroundColor: '#fff', borderColor: color, marginRight: '15px'}
|
} else {
|
_btn.style = {color: '#fff', backgroundColor: color, borderColor: color, marginRight: '15px'}
|
}
|
_card.action.push(_btn)
|
}
|
})
|
|
if (colbtns.length > 0) {
|
_card.cols.push({
|
Align: 'left',
|
label: '操作',
|
marks: [],
|
isSub: false,
|
uuid: Utils.getuuid(),
|
type: 'action',
|
Width: 120,
|
elements: colbtns,
|
style: {paddingTop: '12px', paddingLeft: '8px', paddingBottom: '12px', paddingRight: '8px'}
|
})
|
}
|
|
let sets = ['tableName', 'interType', 'sysInterface', 'innerFunc', 'interface', 'proInterface', 'outerFunc', 'dataresource', ['queryType', 'query'], 'primaryKey', 'order', 'execute', ['laypage', 'true'], ['pageSize', 10], ['onload', 'true']]
|
let wraps = ['tableType', ['bordered', 'true'], 'actionfixed', ['size', 'middle'], ['selected', 'false'], ['tableMode', 'compatible'], ['mask', 'show'], ['borderColor', '#e8e8e8'], 'height', 'controlField', 'controlVal']
|
// useMSearch supModule
|
_card.scripts = config.setting.scripts
|
|
sets.forEach(n => {
|
if (n === 'interType' && !['system', 'inner', 'outer'].includes(config.setting.interType)) {
|
_card.setting.interType = 'system'
|
} else if (typeof(n) === 'string') {
|
_card.setting[n] = config.setting[n] || ''
|
} else {
|
_card.setting[n[0]] = config.setting[n[0]] || n[1]
|
}
|
})
|
wraps.forEach(w => {
|
if (typeof(w) === 'string') {
|
_card.wrap[w] = config.setting[w] || ''
|
} else {
|
_card.wrap[w[0]] = config.setting[w[0]] || w[1]
|
}
|
})
|
|
if (config.setting.doubleClick && uuids[config.setting.doubleClick]) {
|
_card.wrap.doubleClick = uuids[config.setting.doubleClick]
|
} else {
|
_card.wrap.doubleClick = ''
|
}
|
|
return _card
|
}
|
|
render() {
|
return (
|
<div style={{display: 'inline-block'}}>
|
<Button className="mk-border-purple" onClick={this.trigger}><ArrowUpOutlined /> 升级</Button>
|
</div>
|
)
|
}
|
}
|
|
export default UpdateTable
|