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 md5 from 'md5'
|
|
import { colorTransform } from '@/utils/option.js'
|
import { getTables } from '@/utils/utils-custom.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 uuid = config.uuid
|
let trail = md5(uuid).slice(-10) + 'mk'
|
uuid = uuid.replace(/.{12}$/, trail)
|
|
let _config = {
|
version: 1.0,
|
uuid: uuid,
|
MenuID: uuid,
|
fstMenuId: config.fstMenuId,
|
parentId: config.ParentId,
|
Template: 'BaseTable',
|
easyCode: config.easyCode,
|
enabled: false,
|
MenuName: config.MenuName + '_new',
|
MenuNo: config.MenuNo + '_new',
|
OpenType: 'newtab',
|
tables: config.tables || [],
|
urlFields: config.urlFields || [],
|
hidden: config.hidden || 'false',
|
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 errors = []
|
let mainTb = {name: '主表', uuid: Utils.getuuid(), useMSearch: 'false'}
|
|
let oldtabs = {
|
mainTable: mainTb.uuid
|
}
|
|
let tbl = this.getTable(config, mainTb, uuids, errors, formActions, popActions, oldtabs)
|
|
if (config.autoMatic && config.autoMatic.enable === 'true' && uuids[config.autoMatic.action]) {
|
_config.autoMatic = {...config.autoMatic}
|
_config.autoMatic.action = uuids[config.autoMatic.action]
|
|
if (tbl.action.filter(item => item.uuid === _config.autoMatic.action && (['pop', 'prompt', 'exec'].includes(item.OpenType) || (item.OpenType === 'funcbutton' && item.funcType === 'print'))).length === 0) {
|
_config.autoMatic = {enable: 'false'}
|
}
|
} else {
|
_config.autoMatic = {enable: 'false'}
|
}
|
|
_config.components.push(tbl)
|
|
let _tbs = []
|
if (config.tabgroups && config.tabgroups.length > 0) {
|
config.tabgroups.forEach(m => {
|
if (!m.sublist || m.sublist.length === 0) return
|
|
let tabs = {
|
uuid: Utils.getuuid(),
|
type: 'tabs',
|
subtype: 'tabletabs',
|
setting: {},
|
style: {},
|
subtabs: m.sublist.map(n => {
|
let tab = { uuid: Utils.getuuid(), label: n.label, icon: n.icon, permission: 'false', components: [
|
{
|
uuid: Utils.getuuid(),
|
linkTab: n.linkTab,
|
name: n.label,
|
useMSearch: n.searchPass === 'true' ? 'true' : 'false',
|
supModule: n.supMenu || '',
|
equalTab: n.equalTab && n.equalTab.length > 0 ? n.equalTab[0] : ''
|
}
|
]}
|
|
oldtabs[n.uuid] = tab.components[0].uuid
|
|
_tbs.push(tab.components[0])
|
|
return tab
|
})
|
}
|
|
_config.components.push(tabs)
|
})
|
}
|
|
if (_tbs.length > 0) {
|
let defers = _tbs.map((item, i) => {
|
return new Promise((resolve) => {
|
setTimeout(() => {
|
Api.getSystemConfig({
|
func: 'sPC_Get_LongParam',
|
MenuID: item.linkTab
|
}).then(res => {
|
if (res.status) {
|
let _LongParam = ''
|
if (res.LongParam) {
|
try {
|
_LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
|
} catch (e) {
|
console.warn('Parse Failure')
|
_LongParam = ''
|
}
|
}
|
|
if (_LongParam) {
|
_LongParam.uuid = item.linkTab
|
resolve(_LongParam)
|
} else {
|
resolve({uuid: item.linkTab, $empty: true})
|
}
|
} else {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
resolve({uuid: item.linkTab, $empty: true})
|
}
|
})
|
}, i * 50)
|
})
|
})
|
Promise.all(defers).then(res => {
|
let menus = {}
|
res.forEach(item => {
|
if (item && !item.$empty) {
|
menus[item.uuid] = item
|
}
|
})
|
|
_config.components = _config.components.map(item => {
|
if (item.type === 'tabs') {
|
item.subtabs = item.subtabs.map(tab => {
|
tab.components[0] = this.getTable(menus[tab.components[0].linkTab], tab.components[0], uuids, errors, formActions, popActions, oldtabs)
|
|
return tab
|
})
|
}
|
return item
|
})
|
|
this.setPopView(_resolve, _config, formActions, popActions, errors)
|
})
|
} else {
|
this.setPopView(_resolve, _config, formActions, popActions, errors)
|
}
|
}
|
|
setPopView = (_resolve, _config, formActions, popActions, errors) => {
|
if (popActions.length > 0) {
|
let defers = popActions.map((item, i) => {
|
return new Promise((resolve) => {
|
setTimeout(() => {
|
Api.getSystemConfig({
|
func: 'sPC_Get_LongParam',
|
MenuID: item.linkTab
|
}).then(res => {
|
if (res.status) {
|
let _LongParam = ''
|
if (res.LongParam) {
|
try {
|
_LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
|
} catch (e) {
|
console.warn('Parse Failure')
|
_LongParam = ''
|
}
|
}
|
|
if (_LongParam) {
|
_LongParam.uuid = item.uuid
|
resolve(_LongParam)
|
} else {
|
resolve({uuid: item.uuid, $empty: true})
|
}
|
} else {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
resolve({uuid: item.uuid, $empty: true})
|
}
|
})
|
}, i * 50)
|
})
|
})
|
Promise.all(defers).then(res => {
|
let menus = {}
|
res.forEach(item => {
|
if (item && !item.$empty) {
|
menus[item.uuid] = item
|
}
|
})
|
|
_config.components.forEach(item => {
|
if (item.type === 'tabs') {
|
item.subtabs.forEach(tab => {
|
tab.components[0].action.forEach(btn => {
|
if (btn.OpenType === 'popview') {
|
if (menus[btn.uuid]) {
|
let mainTb = {name: '主表', uuid: Utils.getuuid(), useMSearch: 'false'}
|
|
btn.config = {
|
uuid: btn.uuid,
|
MenuID: btn.uuid,
|
ParentId: tab.components[0].uuid,
|
enabled: false,
|
MenuName: btn.label,
|
tables: _config.tables || [],
|
Template: 'BaseTable',
|
components: [this.getTable(menus[btn.uuid], mainTb, {}, errors, formActions)],
|
viewType: 'popview',
|
style: { backgroundColor: '#ffffff', backgroundImage: '', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
|
}
|
} else {
|
errors.push(tab.label + '中按钮《' + btn.label + '》配置信息丢失')
|
}
|
}
|
})
|
tab.components[0].cols.forEach(col => {
|
if (col.type !== 'action') return
|
col.elements.forEach(btn => {
|
if (btn.OpenType === 'popview') {
|
if (menus[btn.uuid]) {
|
let mainTb = {name: '主表', uuid: Utils.getuuid(), useMSearch: 'false'}
|
|
btn.config = {
|
uuid: btn.uuid,
|
MenuID: btn.uuid,
|
ParentId: tab.components[0].uuid,
|
enabled: false,
|
MenuName: btn.label,
|
tables: _config.tables || [],
|
Template: 'BaseTable',
|
components: [this.getTable(menus[btn.uuid], mainTb, {}, errors, formActions)],
|
viewType: 'popview',
|
style: { backgroundColor: '#ffffff', backgroundImage: '', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
|
}
|
} else {
|
errors.push(tab.label + '中按钮《' + btn.label + '》配置信息丢失')
|
}
|
}
|
})
|
})
|
})
|
} else {
|
item.action.forEach(btn => {
|
if (btn.OpenType === 'popview') {
|
if (menus[btn.uuid]) {
|
let mainTb = {name: '主表', uuid: Utils.getuuid(), useMSearch: 'false'}
|
|
btn.config = {
|
uuid: btn.uuid,
|
MenuID: btn.uuid,
|
ParentId: item.uuid,
|
enabled: false,
|
MenuName: btn.label,
|
tables: _config.tables || [],
|
Template: 'BaseTable',
|
components: [this.getTable(menus[btn.uuid], mainTb, {}, errors, formActions)],
|
viewType: 'popview',
|
style: { backgroundColor: '#ffffff', backgroundImage: '', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
|
}
|
} else {
|
errors.push('主表中按钮《' + btn.label + '》配置信息丢失')
|
}
|
}
|
})
|
item.cols.forEach(col => {
|
if (col.type !== 'action') return
|
col.elements.forEach(btn => {
|
if (btn.OpenType === 'popview') {
|
if (menus[btn.uuid]) {
|
let mainTb = {name: '主表', uuid: Utils.getuuid(), useMSearch: 'false'}
|
|
btn.config = {
|
uuid: btn.uuid,
|
MenuID: btn.uuid,
|
ParentId: item.uuid,
|
enabled: false,
|
MenuName: btn.label,
|
tables: _config.tables || [],
|
Template: 'BaseTable',
|
components: [this.getTable(menus[btn.uuid], mainTb, {}, errors, formActions)],
|
viewType: 'popview',
|
style: { backgroundColor: '#ffffff', backgroundImage: '', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
|
}
|
} else {
|
errors.push('主表中按钮《' + btn.label + '》配置信息丢失')
|
}
|
}
|
})
|
})
|
}
|
})
|
|
this.setPopForm(_resolve, _config, formActions, errors)
|
})
|
} else {
|
this.setPopForm(_resolve, _config, formActions, errors)
|
}
|
}
|
|
setPopForm = (_resolve, _config, formActions, errors) => {
|
if (formActions.length > 0) {
|
let defers = formActions.map((item, i) => {
|
return new Promise((resolve) => {
|
setTimeout(() => {
|
Api.getSystemConfig({
|
func: 'sPC_Get_LongParam',
|
MenuID: item.origin
|
}).then(res => {
|
if (res.status) {
|
let _LongParam = ''
|
if (res.LongParam) {
|
try {
|
_LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
|
} catch (e) {
|
console.warn('Parse Failure')
|
_LongParam = ''
|
}
|
}
|
|
if (_LongParam) {
|
_LongParam.uuid = item.uuid
|
resolve(_LongParam)
|
} else {
|
resolve({uuid: item.uuid, $empty: true})
|
}
|
} else {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
resolve({uuid: item.uuid, $empty: true})
|
}
|
})
|
}, i * 50)
|
})
|
})
|
Promise.all(defers).then(res => {
|
let menus = {}
|
res.forEach(item => {
|
if (item && !item.$empty) {
|
menus[item.uuid] = item
|
}
|
})
|
|
_config.components.forEach(item => {
|
if (item.type === 'tabs') {
|
item.subtabs.forEach(tab => {
|
tab.components[0].action.forEach(btn => {
|
if (btn.OpenType === 'popview' && btn.config && btn.config.components[0]) {
|
this.setTbForm(btn.config.components[0], menus, errors, tab.components[0].name + '-' + btn.label)
|
} else if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
|
if (menus[btn.uuid]) {
|
btn.modal = {
|
setting: menus[btn.uuid].setting,
|
tables: [],
|
groups: [],
|
fields: menus[btn.uuid].fields || []
|
}
|
} else {
|
errors.push(tab.label + '中按钮《' + btn.label + '》配置信息丢失')
|
}
|
}
|
})
|
tab.components[0].cols.forEach(col => {
|
if (col.type !== 'action') return
|
col.elements.forEach(btn => {
|
if (btn.OpenType === 'popview' && btn.config && btn.config.components[0]) {
|
this.setTbForm(btn.config.components[0], menus, errors, tab.components[0].name + '-' + btn.label)
|
} else if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
|
if (menus[btn.uuid]) {
|
btn.modal = {
|
setting: menus[btn.uuid].setting,
|
tables: [],
|
groups: [],
|
fields: menus[btn.uuid].fields || []
|
}
|
} else {
|
errors.push(tab.label + '中按钮《' + btn.label + '》配置信息丢失')
|
}
|
}
|
})
|
})
|
})
|
} else {
|
item.action.forEach(btn => {
|
if (btn.OpenType === 'popview' && btn.config && btn.config.components[0]) {
|
this.setTbForm(btn.config.components[0], menus, errors, item.name + '-' + btn.label)
|
} else if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
|
if (menus[btn.uuid]) {
|
btn.modal = {
|
setting: menus[btn.uuid].setting,
|
tables: [],
|
groups: [],
|
fields: menus[btn.uuid].fields || []
|
}
|
} else {
|
errors.push('主表中按钮《' + btn.label + '》配置信息丢失')
|
}
|
}
|
})
|
item.cols.forEach(col => {
|
if (col.type !== 'action') return
|
col.elements.forEach(btn => {
|
if (btn.OpenType === 'popview' && btn.config && btn.config.components[0]) {
|
this.setTbForm(btn.config.components[0], menus, errors, item.name + '-' + btn.label)
|
} else if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
|
if (menus[btn.uuid]) {
|
btn.modal = {
|
setting: menus[btn.uuid].setting,
|
tables: [],
|
groups: [],
|
fields: menus[btn.uuid].fields || []
|
}
|
} else {
|
errors.push('主表中按钮《' + btn.label + '》配置信息丢失')
|
}
|
}
|
})
|
})
|
}
|
})
|
|
this.saveConfig(_resolve, _config, errors)
|
})
|
} else {
|
this.saveConfig(_resolve, _config, errors)
|
}
|
}
|
|
setTbForm = (item, menus, errors, name) => {
|
item.action.forEach(btn => {
|
if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
|
if (menus[btn.uuid]) {
|
btn.modal = {
|
setting: menus[btn.uuid].setting,
|
tables: [],
|
groups: [],
|
fields: menus[btn.uuid].fields || []
|
}
|
} else {
|
errors.push(name + '中按钮《' + btn.label + '》配置信息丢失')
|
}
|
}
|
})
|
item.cols.forEach(col => {
|
if (col.type !== 'action') return
|
col.elements.forEach(btn => {
|
if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
|
if (menus[btn.uuid]) {
|
btn.modal = {
|
setting: menus[btn.uuid].setting,
|
tables: [],
|
groups: [],
|
fields: menus[btn.uuid].fields || []
|
}
|
} else {
|
errors.push(name + '中按钮《' + btn.label + '》配置信息丢失')
|
}
|
}
|
})
|
})
|
}
|
|
saveConfig = (_resolve, _config, errors) => {
|
let err = errors.join(';')
|
let _this = this
|
|
if (err) {
|
_resolve()
|
confirm({
|
title: err + ',确定升级当前菜单吗?',
|
content: '',
|
onOk() {
|
return new Promise(resolve => {
|
_this.saveNewMenu(resolve, _config)
|
})
|
},
|
onCancel() {}
|
})
|
} else {
|
this.saveNewMenu(_resolve, _config)
|
}
|
}
|
|
saveNewMenu = (_resolve, _config) => {
|
_config.components.forEach(item => {
|
if (item.type === 'tabs') {
|
item.subtabs.forEach(tab => {
|
tab.components[0].action.forEach(btn => {
|
if (btn.OpenType === 'popview' && btn.config) {
|
btn.config.$tables = getTables(btn.config.components[0])
|
}
|
})
|
tab.components[0].cols.forEach(col => {
|
if (col.type !== 'action') return
|
col.elements.forEach(btn => {
|
if (btn.OpenType === 'popview' && btn.config) {
|
btn.config.$tables = getTables(btn.config.components[0])
|
}
|
})
|
})
|
|
tab.components[0].$tables = getTables(tab.components[0])
|
})
|
} else {
|
item.action.forEach(btn => {
|
if (btn.OpenType === 'popview' && btn.config) {
|
btn.config.$tables = getTables(btn.config.components[0])
|
}
|
})
|
item.cols.forEach(col => {
|
if (col.type !== 'action') return
|
col.elements.forEach(btn => {
|
if (btn.OpenType === 'popview' && btn.config) {
|
btn.config.$tables = getTables(btn.config.components[0])
|
}
|
})
|
})
|
|
item.$tables = getTables(item)
|
}
|
})
|
|
let tbs = []
|
_config.components.forEach(item => {
|
if (item.type === 'tabs') {
|
item.subtabs.forEach(tab => {
|
if (tab.components[0].$tables) {
|
tbs.push(...tab.components[0].$tables)
|
}
|
|
tab.components[0].errors = []
|
let columns = tab.components[0].columns.map(c => c.field)
|
if (tab.components[0].setting.interType === 'system' && tab.components[0].setting.execute !== 'false' && !tab.components[0].setting.dataresource) {
|
tab.components[0].errors.push({ level: 0, detail: '未设置数据源!'})
|
} else if (tab.components[0].setting.interType === 'system' && tab.components[0].setting.execute === 'false' && tab.components[0].scripts.filter(script => script.status !== 'false').length === 0) {
|
tab.components[0].errors.push({ level: 0, detail: '数据源中无可用脚本!'})
|
} else if (!tab.components[0].setting.primaryKey) {
|
tab.components[0].errors.push({ level: 0, detail: '未设置主键!'})
|
} else if (!columns.includes(tab.components[0].setting.primaryKey)) {
|
tab.components[0].errors.push({ level: 0, detail: '主键已失效!'})
|
} else if (!tab.components[0].setting.supModule) {
|
tab.components[0].errors.push({ level: 0, detail: '未设置上级组件!'})
|
}
|
})
|
} else {
|
if (item.$tables) {
|
tbs.push(...item.$tables)
|
}
|
|
item.errors = []
|
let columns = item.columns.map(c => c.field)
|
if (item.setting.interType === 'system' && item.setting.execute !== 'false' && !item.setting.dataresource) {
|
item.errors.push({ level: 0, detail: '未设置数据源!'})
|
} else if (item.setting.interType === 'system' && item.setting.execute === 'false' && item.scripts.filter(script => script.status !== 'false').length === 0) {
|
item.errors.push({ level: 0, detail: '数据源中无可用脚本!'})
|
} else if (!item.setting.primaryKey) {
|
item.errors.push({ level: 0, detail: '未设置主键!'})
|
} else if (!columns.includes(item.setting.primaryKey)) {
|
item.errors.push({ level: 0, detail: '主键已失效!'})
|
} else if (!item.setting.supModule) {
|
item.errors.push({ level: 0, detail: '未设置上级组件!'})
|
}
|
}
|
})
|
|
this.submitConfig(_resolve, _config, tbs)
|
}
|
|
submitConfig = (_resolve, config, tbs) => {
|
let arr = []
|
tbs = tbs.filter(tb => {
|
let _tb = tb.toLowerCase()
|
|
if (arr.includes(_tb)) return false
|
arr.push(_tb)
|
|
return true
|
})
|
tbs.sort()
|
if (tbs.length && sessionStorage.getItem('mk_tb_names')) {
|
let names = sessionStorage.getItem('mk_tb_names')
|
tbs = tbs.filter(tb => names.indexOf(',' + tb.toLowerCase() + ',') > -1)
|
}
|
tbs = tbs.map(tb => `'${tb}'`).join(';')
|
|
let key = md5(config.uuid + tbs.toLowerCase())
|
|
let urlparam = {
|
FstId: config.fstMenuId,
|
ParentId: config.parentId,
|
MenuID: config.uuid,
|
MenuName: config.MenuName,
|
MenuNo: config.MenuNo,
|
EasyCode: config.easyCode,
|
type: 'admin',
|
OpenType: config.OpenType,
|
PageParam: {Template: 'BaseTable', OpenType: 'newtab', hidden: config.hidden},
|
MenuType: 'BaseTable'
|
}
|
let url = window.btoa(window.encodeURIComponent(JSON.stringify(urlparam)))
|
config.tbkey = key
|
|
let param = {
|
func: 'sPC_TrdMenu_AddUpt',
|
FstID: config.fstMenuId || '',
|
SndID: config.parentId,
|
ParentID: config.parentId,
|
MenuID: config.uuid,
|
MenuNo: config.MenuNo || '',
|
EasyCode: config.easyCode || '',
|
Template: 'BaseTable',
|
MenuName: config.MenuName || '',
|
PageParam: JSON.stringify({Template: 'BaseTable', OpenType: config.OpenType, hidden: config.hidden}),
|
open_edition: '',
|
debug_md5: key,
|
debug_url: url,
|
debug_list: window.btoa(tbs),
|
LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config)))
|
}
|
|
param.LText = Utils.formatOptions(param.LText)
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
param.secretkey = Utils.encrypt(param.LText, param.timestamp)
|
|
new Promise(resolve => {
|
Api.getSystemConfig(param).then(res => {
|
resolve(res)
|
})
|
// }).then(res => { // 删除原菜单
|
// if (!res || !res.status) return res
|
|
// return Api.getSystemConfig({
|
// func: 'sPC_MainMenu_Del',
|
// MenuID: this.props.config.uuid
|
// })
|
}).then(res => {
|
if (!res) return
|
|
_resolve()
|
|
if (res.status) {
|
localStorage.setItem('menuUpdate', new Date().getTime())
|
|
notification.success({
|
top: 92,
|
message: '升级成功',
|
duration: 2
|
})
|
|
delete urlparam.type
|
delete urlparam.MenuType
|
|
let _param = window.btoa(window.encodeURIComponent(JSON.stringify(urlparam)))
|
|
// window.history.replaceState(null, null, window.location.href.split('#')[0] + `#/tabledesign/${_param}`)
|
// window.location.reload()
|
window.open(`#/tabledesign/${_param}`)
|
} else {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
getTable = (config, newCon, uuids, errors, formActions, popActions, oldtabs) => {
|
let _card = {
|
uuid: newCon.uuid,
|
type: 'table',
|
name: newCon.name,
|
format: 'array',
|
pageable: true,
|
switchable: true,
|
search: [],
|
action: [],
|
subtype: 'basetable',
|
setting: { useMSearch: newCon.useMSearch },
|
wrap: {},
|
style: {},
|
headerStyle: {},
|
columns: [],
|
cols: [],
|
scripts: []
|
}
|
|
if (!config) {
|
errors.push(newCon.name + '配置信息丢失')
|
return _card
|
}
|
|
if (newCon.supModule && oldtabs[newCon.supModule]) {
|
_card.setting.supModule = [oldtabs[newCon.supModule]]
|
} else {
|
_card.setting.supModule = ['empty']
|
}
|
|
_card.search = config.search.map(item => {
|
item.uuid = Utils.getuuid()
|
return item
|
})
|
|
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: 'rgba(0, 0, 0, 0.65)' }
|
|
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
|
|
_btn.show = 'button'
|
|
if (_btn.execSuccess === 'equaltab') {
|
_btn.execSuccess = 'grid'
|
_btn.syncComponent = []
|
|
if (newCon.equalTab && oldtabs && oldtabs[newCon.equalTab]) {
|
_btn.syncComponent.push(oldtabs[newCon.equalTab])
|
}
|
} else if (_btn.execSuccess === 'maingrid') {
|
_btn.execSuccess = 'mainline'
|
}
|
|
if (_btn.execError === 'equaltab') {
|
_btn.execError = 'grid'
|
} else if (_btn.execError === 'maingrid') {
|
_btn.execError = 'mainline'
|
}
|
|
if (_btn.popClose === 'equaltab') {
|
_btn.popClose = 'grid'
|
_btn.syncComponent = []
|
|
if (newCon.equalTab && oldtabs && oldtabs[newCon.equalTab]) {
|
_btn.syncComponent.push(oldtabs[newCon.equalTab])
|
}
|
} else if (_btn.popClose === 'maingrid') {
|
_btn.popClose = 'mainline'
|
}
|
|
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, name: newCon.name, label: btn.label})
|
} else if (btn.OpenType === 'popview') {
|
if (!popActions) return
|
|
popActions.push({origin: btn.uuid, linkTab: btn.linkTab || '', uuid: _btn.uuid, name: newCon.name, label: btn.label})
|
} else if (btn.OpenType === 'tab') {
|
if (btn.tabTemplate === 'FormTab' || !btn.linkmenu || btn.linkmenu.length !== 3) {
|
|
errors.push(newCon.name + '中按钮《' + btn.label + '》不在支持')
|
return
|
}
|
}
|
|
if (_btn.tabType === 'CommonTable' || _btn.tabType === 'SubTable') {
|
_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 === 'default') {
|
_btn.style = {color: 'rgba(0, 0, 0, 0.65)', backgroundColor: '#fff', borderColor: '#d9d9d9', marginRight: '15px'}
|
} else if (btn.class.indexOf('border') > -1) {
|
_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']
|
|
_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
|