import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { connect } from 'react-redux'
|
import { is, fromJS } from 'immutable'
|
import { DndProvider } from 'react-dnd'
|
import HTML5Backend from 'react-dnd-html5-backend'
|
import { Button, Card, Modal, Collapse, notification, Spin, Icon, Switch, Tooltip, Col } from 'antd'
|
import moment from 'moment'
|
|
import Api from '@/api'
|
import Utils from '@/utils/utils.js'
|
import zhCN from '@/locales/zh-CN/model.js'
|
import enUS from '@/locales/en-US/model.js'
|
import { getMainMenuForm } from '@/templates/zshare/formconfig'
|
|
import asyncComponent from '@/utils/asyncComponent'
|
import TableComponent from '@/templates/sharecomponent/tablecomponent'
|
import FieldsComponent from '@/templates/sharecomponent/fieldscomponent'
|
import ChartGroupComponent from '@/templates/sharecomponent/chartgroupcomponent'
|
import SearchComponent from '@/templates/sharecomponent/searchcomponent'
|
import ActionComponent from '@/templates/sharecomponent/actioncomponent'
|
import ColumnComponent from '@/templates/sharecomponent/columncomponent'
|
import TabsComponent from '@/templates/sharecomponent/tabscomponent'
|
import ChartComponent from '@/templates/sharecomponent/chartcomponent'
|
|
import MenuForm from '@/templates/zshare/menuform'
|
import EditComponent from '@/templates/zshare/editcomponent'
|
import SourceElement from '@/templates/zshare/dragsource'
|
import Source from './source'
|
import './index.scss'
|
|
const { Panel } = Collapse
|
const { confirm } = Modal
|
const CommonDict = (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS
|
const SettingComponent = asyncComponent(() => import('@/templates/sharecomponent/settingcomponent'))
|
|
class ComTableConfig extends Component {
|
static propTpyes = {
|
menu: PropTypes.any,
|
optionLibs: PropTypes.any,
|
reloadmenu: PropTypes.func,
|
handleView: PropTypes.func
|
}
|
|
state = {
|
dict: CommonDict, // 字典
|
config: null, // 页面配置
|
tableFields: [], // 表格显示列
|
fields: null, // 搜索条件及显示列,可选字段
|
menuformlist: null, // 基本信息表单字段
|
formlist: null, // 搜索条件、按钮、显示列表单字段
|
card: null, // 编辑元素
|
menuloading: false, // 菜单保存中
|
menucloseloading: false, // 菜单关闭时,选择保存
|
loading: false, // 加载中,页面spin
|
closeVisible: false, // 关闭模态框
|
tables: [], // 可用表名
|
originMenu: null, // 原始菜单
|
originActions: null, // 原始按钮信息,使用已有用户模板
|
delActions: [], // 删除按钮列表
|
copyActions: [], // 复制按钮组
|
tabviews: [], // 所有标签页
|
optionLibs: null, // 自定义下拉选项库
|
thawButtons: [], // 已选择要解冻的按钮
|
activeKey: '0', // 默认展开基本信息
|
chartview: null, // 当前视图
|
pasteContent: null // 粘贴配置信息
|
}
|
|
/**
|
* @description 数据预处理
|
* 1、设置页面配置信息,新建或无配置信息时(切换模板后无配置信息),使用模板默认配置
|
* 2、设置操作类型、原始菜单信息(每次保存后重置)、已使用表及基本信息表单
|
*/
|
UNSAFE_componentWillMount () {
|
const { menu, optionLibs } = this.props
|
|
let _LongParam = menu.LongParam
|
let _config = ''
|
|
if (!_LongParam) {
|
_config = fromJS(Source.baseConfig).toJS()
|
if (!menu.isSubtable) { // 不是选择主子表时,隐藏标签页
|
_config.tabs = []
|
}
|
_config.isAdd = true
|
} else {
|
_config = _LongParam
|
_config.search.forEach(item => {
|
if (
|
(item.type === 'select' || item.type === 'multiselect' || item.type === 'link') &&
|
item.resourceType === '0' &&
|
item.options && item.options.length > 0
|
) {
|
optionLibs.set(menu.MenuID + item.uuid, {
|
uuid: menu.MenuID + item.uuid,
|
label: item.label,
|
parname: menu.MenuName,
|
type: 'search',
|
options: item.options
|
})
|
}
|
})
|
}
|
|
// 配置默认值,兼容
|
_config.tabs = _config.tabs || []
|
_config.Template = 'CommonTable'
|
_config.easyCode = _config.easyCode || ''
|
|
if (!_config.tabgroups) {
|
_config.tabgroups = [{ uuid: 'tabs', sublist: [] }]
|
} else if (typeof(_config.tabgroups[0]) === 'string') {
|
let _tabgroups = []
|
_config.tabgroups.forEach(groupId => {
|
let _group = {
|
uuid: groupId,
|
sublist: fromJS(_config[groupId]).toJS()
|
}
|
|
delete _config[groupId]
|
|
_tabgroups.push(_group)
|
})
|
|
_config.tabgroups = _tabgroups
|
}
|
|
// 兼容图表
|
if (!_config.charts) {
|
_config.expand = false
|
_config.charts = [{
|
uuid: Utils.getuuid(),
|
label: '',
|
title: '',
|
chartType: 'table',
|
icon: 'table',
|
Hide: 'false',
|
blacklist: []
|
}]
|
}
|
|
let _oriActions = []
|
if (_config.type === 'user') {
|
_config.action = _config.action.map(item => {
|
let uuid = Utils.getuuid()
|
|
if (item.linkTab) {
|
item.linkTab = ''
|
}
|
|
if (item.OpenType === 'pop') { // 含有子配置项的按钮(表单)
|
_oriActions.push({
|
prebtn: fromJS(item).toJS(),
|
curuuid: uuid,
|
Template: 'Modal'
|
})
|
} else if (item.OpenType === 'tab' || item.OpenType === 'blank') { // 含有子配置项的按钮(标签后当前页打开)
|
_oriActions.push({
|
prebtn: fromJS(item).toJS(),
|
curuuid: uuid,
|
Template: item.tabTemplate
|
})
|
}
|
|
item.uuid = uuid
|
return item
|
})
|
|
// 重置标签ID
|
_config.tabgroups.forEach(group => {
|
group.sublist = group.sublist.map(tab => {
|
tab.uuid = Utils.getuuid()
|
|
if (tab.linkTab) {
|
tab.linkTab = ''
|
}
|
|
return tab
|
})
|
})
|
}
|
|
this.setState({
|
chartview: _config.charts[0].uuid,
|
config: _config,
|
activeKey: menu.activeKey || '0',
|
optionLibs: optionLibs,
|
originActions: _oriActions,
|
originMenu: fromJS(menu).toJS(),
|
menuformlist: getMainMenuForm(menu, _config)
|
})
|
}
|
|
/**
|
* @description 加载完成后, 获取所有标签页信息
|
*/
|
componentDidMount () {
|
this.reloadTab(false)
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
/**
|
* @description 加载或刷新标签信息
|
*/
|
reloadTab = (type) => {
|
this.setState({
|
loading: type,
|
tabviews: []
|
})
|
Api.getSystemConfig({func: 'sPC_Get_UserTemp', TypeCharTwo: 'tab'}).then(res => {
|
if (res.status) {
|
this.setState({
|
loading: false,
|
tabviews: res.UserTemp.map(temp => {
|
return {
|
uuid: temp.MenuID,
|
value: temp.MenuID,
|
text: temp.MenuName,
|
type: temp.Template,
|
MenuNo: temp.MenuNo
|
}
|
})
|
})
|
|
if (type) {
|
notification.success({
|
top: 92,
|
message: '刷新成功。',
|
duration: 2
|
})
|
}
|
} else {
|
this.setState({
|
loading: false
|
})
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
/**
|
* @description 三级菜单切换模板
|
*/
|
changeTemplate = () => {
|
this.props.handleView({tabview: 'template'})
|
}
|
|
getFuncNames = (data, funcNames, tableNames) => {
|
data.forEach(item => {
|
if (item.subfuncs) {
|
this.getFuncNames(item.subfuncs, funcNames, tableNames)
|
} else {
|
if (item.tableName) {
|
tableNames.push(item.tableName)
|
}
|
if (item.innerFunc) {
|
funcNames.push({func: item.innerFunc, label: item.label || ''})
|
}
|
|
if (item.callbackFunc) {
|
funcNames.push({func: item.callbackFunc, label: item.label || ''})
|
}
|
}
|
})
|
|
return {
|
func: funcNames,
|
table: tableNames
|
}
|
}
|
|
/**
|
* @description 三级菜单保存
|
*/
|
submitConfig = () => {
|
const { menu } = this.props
|
const { originMenu, delActions, thawButtons } = this.state
|
|
let config = fromJS(this.state.config).toJS()
|
|
this.menuformRef.handleConfirm().then(res => {
|
if (config.isAdd) {
|
config.search = config.search.filter(item => !item.origin)
|
config.action = config.action.filter(item => !item.origin)
|
config.columns = config.columns.filter(item => !item.origin)
|
config.tabgroups[0].sublist = config.tabgroups[0].sublist.filter(item => !item.origin)
|
}
|
|
if (config.type === 'user') { // 使用已有菜单时,默认添加关联标签id
|
config.action = config.action.map(item => {
|
if (item.OpenType === 'popview' && !item.linkTab) {
|
item.linkTab = Utils.getuuid()
|
}
|
return item
|
})
|
|
config.tabgroups.forEach(group => {
|
group.sublist = group.sublist.map(tab => {
|
if (!tab.linkTab) {
|
tab.linkTab = Utils.getuuid()
|
}
|
return tab
|
})
|
})
|
}
|
|
let _LongParam = ''
|
let _config = {...config, easyCode: res.easyCode}
|
let _pageParam = {...menu.PageParam, OpenType: res.opentype}
|
|
// 未设置数据源或标签不合法时,启用状态为false
|
let vresult = this.verifyconfig(_config)
|
if (vresult !== true) {
|
_config.enabled = false
|
}
|
|
_config.funcs = [] // 页面及子页面存储过程集
|
|
_config.funcs.push({
|
type: 'view',
|
subtype: 'view',
|
uuid: menu.MenuID,
|
intertype: _config.setting.interType || 'inner',
|
interface: _config.setting.interface || '',
|
tableName: _config.setting.tableName || '',
|
innerFunc: _config.setting.innerFunc || '',
|
outerFunc: _config.setting.outerFunc || ''
|
})
|
|
_config.action.forEach(item => {
|
let tablename = item.OpenType === 'excelIn' ? (item.sheet || '') : (item.sql || '')
|
|
if (item.OpenType === 'excelOut' && item.intertype === 'inner' && !item.innerFunc) {
|
tablename = _config.setting.tableName || ''
|
}
|
|
if (item.OpenType === 'tab' || item.OpenType === 'blank') {
|
_config.funcs.push({
|
type: 'tab',
|
subtype: 'btn',
|
uuid: item.uuid,
|
label: item.label,
|
linkTab: item.uuid
|
})
|
} else if (item.OpenType === 'popview') {
|
_config.funcs.push({
|
type: 'tab',
|
subtype: 'btn',
|
uuid: item.uuid,
|
label: item.label,
|
linkTab: item.linkTab
|
})
|
} else if (['pop', 'prompt', 'exec', 'excelIn', 'excelOut'].includes(item.OpenType)) {
|
_config.funcs.push({
|
type: 'button',
|
subtype: 'btn',
|
uuid: item.uuid,
|
label: item.label,
|
tableName: tablename,
|
intertype: item.intertype,
|
interface: item.interface || '',
|
innerFunc: item.innerFunc || '',
|
outerFunc: item.outerFunc || '',
|
callbackFunc: item.callbackFunc || ''
|
})
|
}
|
})
|
|
_config.tabgroups.forEach(group => {
|
group.sublist.forEach(tab => {
|
_config.funcs.push({
|
type: 'tab',
|
subtype: 'tab',
|
uuid: tab.uuid,
|
label: tab.label,
|
linkTab: tab.linkTab
|
})
|
})
|
})
|
|
if (this.state.closeVisible) { // 显示关闭对话框时,模态框中保存按钮,显示保存中状态
|
this.setState({
|
menucloseloading: true
|
})
|
} else {
|
this.setState({
|
menuloading: true
|
})
|
}
|
|
new Promise(resolve => {
|
let deffers = []
|
_config.funcs.forEach(item => {
|
if (item.type === 'tab') {
|
let deffer = new Promise(resolve => {
|
Api.getSystemConfig({
|
func: 'sPC_Get_LongParam',
|
MenuID: item.linkTab
|
}).then(result => {
|
if (result.status && result.LongParam) {
|
let _LongParam = ''
|
|
if (result.LongParam) {
|
try {
|
_LongParam = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
|
} catch (e) {
|
console.warn('Parse Failure')
|
_LongParam = ''
|
}
|
}
|
|
if (_LongParam) {
|
item.menuNo = _LongParam.tabNo || ''
|
item.subfuncs = _LongParam.funcs || []
|
}
|
}
|
resolve()
|
})
|
})
|
|
deffers.push(deffer)
|
}
|
})
|
|
if (deffers.length === 0) {
|
resolve()
|
} else {
|
Promise.all(deffers).then(() => {
|
resolve()
|
})
|
}
|
}).then(() => {
|
// 保存时删除配置类型,system 、user
|
delete _config.type
|
delete _config.isAdd
|
|
try {
|
_LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
|
} catch (e) {
|
notification.warning({
|
top: 92,
|
message: '编译错误',
|
duration: 5
|
})
|
this.setState({
|
menucloseloading: false,
|
menuloading: false
|
})
|
return
|
}
|
|
let _sort = 0
|
let btntabs = []
|
|
let btnParam = { // 添加菜单按钮
|
func: 'sPC_Button_AddUpt',
|
Type: 40, // 添加菜单下的按钮type为40,按钮下的按钮type为60
|
ParentID: menu.MenuID,
|
MenuNo: res.MenuNo,
|
Template: menu.PageParam.Template || '',
|
PageParam: '',
|
LongParam: '',
|
LText: []
|
}
|
|
_config.action.forEach(item => {
|
_sort++
|
if (item.OpenType === 'popview') {
|
btntabs.push({
|
uuid: item.uuid,
|
linkTab: item.linkTab,
|
label: item.label,
|
sort: _sort
|
})
|
}
|
|
btnParam.LText.push(`select '${item.uuid}' as menuid, '${item.label}' as menuname, '${_sort * 10}' as Sort`)
|
})
|
|
btnParam.LText = btnParam.LText.join(' union all ')
|
btnParam.LText = Utils.formatOptions(btnParam.LText)
|
btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
|
btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
|
|
let tabParam = { // 添加菜单tab页
|
func: 'sPC_sMenusTab_AddUpt',
|
MenuID: menu.MenuID
|
}
|
|
let _LText = []
|
|
btntabs.forEach(item => {
|
_LText.push(`select '${item.uuid}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${item.sort * 10}' as Sort`)
|
})
|
_config.tabgroups.forEach(group => {
|
group.sublist.forEach(item => {
|
_sort++
|
_LText.push(`select '${menu.MenuID}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${_sort * 10}' as Sort`)
|
})
|
})
|
|
_LText = _LText.join(' union all ')
|
|
tabParam.LText = Utils.formatOptions(_LText)
|
tabParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
|
tabParam.secretkey = Utils.encrypt(tabParam.LText, tabParam.timestamp)
|
|
let _vals = this.getFuncNames(_config.funcs, [], [])
|
let _tables = Array.from(new Set(_vals.table))
|
|
let param = {
|
func: 'sPC_TrdMenu_AddUpt',
|
FstID: res.fstMenuId,
|
SndID: res.parentId,
|
ParentID: res.parentId,
|
MenuID: menu.MenuID,
|
MenuNo: res.MenuNo,
|
EasyCode: res.easyCode,
|
Template: menu.PageParam.Template || '',
|
MenuName: res.MenuName,
|
PageParam: JSON.stringify(_pageParam),
|
LongParam: _LongParam,
|
LText: _vals.func.map(item => `select '${menu.MenuID}' as MenuID,'${item.func}' as ProcName,'${item.label}' as MenuName`),
|
LTexttb: _tables.map(item => `select '${menu.MenuID}' as MenuID,'${item}' as tbName`)
|
}
|
|
if (menu.menuSort) { // 菜单新建时设置排序
|
param.Sort = menu.menuSort
|
}
|
|
param.LText = param.LText.join(' union all ')
|
param.LText = Utils.formatOptions(param.LText)
|
param.LTexttb = param.LTexttb.join(' union all ')
|
param.LTexttb = Utils.formatOptions(param.LTexttb)
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
|
param.secretkey = Utils.encrypt(param.LText, param.timestamp)
|
|
// 有按钮或标签删除时,先进行删除操作
|
// 删除成功后,保存页面配置
|
new Promise(resolve => {
|
if (delActions.length > 0) {
|
let deffers = delActions.map(item => {
|
let _param = {
|
func: 'sPC_MainMenu_Del',
|
MenuID: item.card.uuid
|
}
|
|
if (item.type === 'action') {
|
let _ParentParam = null
|
|
try {
|
_ParentParam = window.btoa(window.encodeURIComponent(JSON.stringify(item.card)))
|
} catch (e) {
|
console.warn('Stringify Failure')
|
_ParentParam = null
|
}
|
|
if (_ParentParam) { // 删除按钮时,保存按钮配置信息,用于恢复按钮
|
_param.ParentParam = _ParentParam
|
}
|
}
|
|
return new Promise(resolve => {
|
Api.getSystemConfig(_param).then(response => {
|
resolve(response)
|
})
|
})
|
})
|
Promise.all(deffers).then(result => {
|
let error = null
|
result.forEach(response => {
|
if (!response.status) {
|
error = response
|
}
|
})
|
|
if (error) {
|
this.setState({
|
menuloading: false,
|
menucloseloading: false
|
})
|
notification.warning({
|
top: 92,
|
message: error.message,
|
duration: 5
|
})
|
resolve(false)
|
} else {
|
this.setState({
|
delActions: []
|
})
|
resolve(true)
|
}
|
})
|
} else if (delActions.length === 0) {
|
resolve(true)
|
}
|
}).then(resp => {
|
if (resp === false) return
|
|
if (thawButtons.length > 0) {
|
let defers = thawButtons.map(item => {
|
return new Promise((resolve) => {
|
Api.getSystemConfig({
|
func: 'sPC_MainMenu_ReDel',
|
MenuID: item
|
}).then(res => {
|
if (res.status) {
|
resolve('')
|
} else {
|
resolve(res.message)
|
}
|
})
|
})
|
})
|
|
return Promise.all(defers)
|
} else {
|
return true
|
}
|
}).then(res => {
|
if (res === true || res === false) return res
|
|
let msg = res.filter(Boolean)[0]
|
if (msg) {
|
notification.warning({
|
top: 92,
|
message: msg,
|
duration: 5
|
})
|
return false
|
} else {
|
this.setState({
|
thawButtons: []
|
})
|
return true
|
}
|
}).then(resp => {
|
if (resp === false) return
|
let localParam = fromJS(param).toJS()
|
|
Api.getSystemConfig(param).then(response => {
|
if (response.status) {
|
let _FMenu = originMenu.fstMenuList.filter(fstM => fstM.MenuID === res.fstMenuId)[0]
|
let _supMenuList = []
|
if (_FMenu) {
|
_supMenuList = _FMenu.options
|
}
|
|
this.setState({
|
config: _config,
|
originMenu: {
|
...originMenu,
|
LongParam: _config,
|
PageParam: _pageParam,
|
MenuName: res.MenuName,
|
MenuNo: res.MenuNo,
|
ParentID: res.parentId,
|
fstMenuId: res.fstMenuId,
|
supMenuList: _supMenuList
|
}
|
})
|
|
this.props.reloadmenu()
|
|
this.submitAction(btnParam, tabParam)
|
|
localParam.func = 'sPC_TrdMenu_AddUpt_For_Local'
|
delete localParam.LongParam
|
delete localParam.PageParam
|
delete localParam.Template
|
delete localParam.Sort
|
|
Api.getLocalConfig(localParam)
|
} else {
|
this.setState({
|
menuloading: false,
|
menucloseloading: false
|
})
|
notification.warning({
|
top: 92,
|
message: response.message,
|
duration: 5
|
})
|
}
|
})
|
})
|
})
|
}, () => {
|
notification.warning({
|
top: 92,
|
message: this.state.dict['header.menu.basemsg'],
|
duration: 5
|
})
|
})
|
}
|
|
/**
|
* @description 保存或修改菜单按钮集
|
*/
|
submitAction = (btnParam, tabParam) => {
|
const { config } = this.state
|
|
new Promise(resolve => {
|
let deffers = []
|
|
if (tabParam.LText) {
|
let defer = new Promise(resolve => {
|
Api.getSystemConfig(tabParam).then(result => {
|
resolve(result)
|
})
|
})
|
deffers.push(defer)
|
}
|
|
if (btnParam.LText) {
|
let defer = new Promise(resolve => {
|
Api.getSystemConfig(btnParam).then(result => {
|
if (result.status) {
|
this.setState({ // 保存成功后清空复制列表
|
copyActions: []
|
})
|
}
|
resolve(result)
|
})
|
})
|
deffers.push(defer)
|
}
|
|
if (deffers.length === 0) {
|
resolve(true)
|
} else {
|
Promise.all(deffers).then(result => {
|
let error = false
|
result.forEach(res => {
|
if (!res.status) {
|
error = res
|
}
|
})
|
|
if (error) {
|
notification.warning({
|
top: 92,
|
message: error.message,
|
duration: 5
|
})
|
resolve(false)
|
} else {
|
resolve(true)
|
}
|
})
|
}
|
}).then(response => {
|
if (response === false) return response
|
|
if (!this.state.originActions || this.state.originActions.length === 0) return 'true'
|
|
let oriActions = []
|
this.state.originActions.forEach(item => {
|
let curBtn = config.action.filter(cell => item.curuuid === cell.uuid)[0] // 查看初始化按钮是否存在
|
if (!curBtn) return
|
if (curBtn.OpenType !== item.prebtn.OpenType) return
|
|
oriActions.push({
|
prebtn: item.prebtn,
|
curBtn: curBtn
|
})
|
})
|
|
if (oriActions.length === 0) return 'true'
|
|
oriActions.forEach(action => {
|
if (!action.prebtn || !action.prebtn.uuid) return
|
|
Api.getSystemConfig({
|
func: 'sPC_Get_LongParam',
|
MenuID: action.prebtn.uuid
|
}).then(result => {
|
if (result.status && result.LongParam) {
|
let _LongParam = ''
|
let _temp = ''
|
|
if (result.LongParam) {
|
let _subconfig = ''
|
try {
|
_subconfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
|
_temp = _subconfig.type
|
} catch (e) {
|
console.warn('Parse Failure')
|
_subconfig = ''
|
}
|
|
if (_temp === 'FormTab') {
|
try {
|
_subconfig.action = _subconfig.action.map(_btn => {
|
_btn.uuid = Utils.getuuid()
|
|
return _btn
|
})
|
|
// 兼容已有结构
|
if (!_subconfig.tabgroups) {
|
_subconfig.tabgroups = [{ uuid: 'tabs', sublist: [] }]
|
} else if (typeof(_subconfig.tabgroups[0]) === 'string') {
|
let _tabgroups = []
|
_subconfig.tabgroups.forEach(groupId => {
|
let _group = {
|
uuid: groupId,
|
sublist: fromJS(_subconfig[groupId]).toJS()
|
}
|
delete _subconfig[groupId]
|
_tabgroups.push(_group)
|
})
|
_subconfig.tabgroups = _tabgroups
|
}
|
|
_subconfig.tabgroups.forEach(group => {
|
group.sublist = group.sublist.map(_tab => {
|
_tab.uuid = Utils.getuuid()
|
_tab.linkTab = Utils.getuuid()
|
|
return _tab
|
})
|
})
|
_subconfig = window.btoa(window.encodeURIComponent(JSON.stringify(_subconfig)))
|
} catch {
|
console.warn('Stringify Failure')
|
_subconfig = ''
|
}
|
|
_LongParam = _subconfig
|
} else if (_subconfig) {
|
_LongParam = result.LongParam
|
}
|
}
|
|
if (_LongParam) {
|
let param = {
|
func: 'sPC_ButtonParam_AddUpt',
|
ParentID: this.props.menu.MenuID,
|
MenuID: action.curBtn.uuid,
|
MenuNo: this.props.menu.MenuNo,
|
Template: _temp,
|
MenuName: action.curBtn.label,
|
PageParam: JSON.stringify({Template: _temp}),
|
LongParam: _LongParam
|
}
|
Api.getSystemConfig(param).then(() => {})
|
}
|
}
|
})
|
})
|
return 'true'
|
}).then(response => {
|
if (response === 'true') {
|
notification.success({
|
top: 92,
|
message: '保存成功',
|
duration: 2
|
})
|
if (this.state.closeVisible) {
|
this.props.handleView()
|
} else {
|
this.setState({
|
originActions: [],
|
menuloading: false,
|
menucloseloading: false
|
})
|
}
|
} else {
|
this.setState({
|
menuloading: false,
|
menucloseloading: false
|
})
|
}
|
})
|
}
|
|
/**
|
* @description 点击返回时,判断配置保存状态
|
*/
|
cancelConfig = () => {
|
const { menu } = this.props
|
const { config, originMenu } = this.state
|
|
let _this = this
|
|
if (config.isAdd) {
|
confirm({
|
content: '菜单尚未提交,确定放弃保存吗?',
|
okText: this.state.dict['model.confirm'],
|
cancelText: this.state.dict['header.cancel'],
|
onOk() {
|
_this.props.handleView()
|
},
|
onCancel() {}
|
})
|
} else {
|
this.menuformRef.handleConfirm().then(res => {
|
let _config = {...config, easyCode: res.easyCode}
|
let _pageParam = {...menu.PageParam, OpenType: res.opentype}
|
let _originMenu = {
|
...originMenu,
|
LongParam: _config,
|
PageParam: _pageParam,
|
MenuName: res.MenuName,
|
MenuNo: res.MenuNo,
|
ParentID: res.parentId,
|
fstMenuId: res.fstMenuId
|
}
|
|
if (!is(fromJS(originMenu), fromJS(_originMenu))) {
|
this.setState({
|
closeVisible: true
|
})
|
} else {
|
this.props.handleView()
|
}
|
}, () => {
|
this.setState({
|
closeVisible: true
|
})
|
})
|
}
|
}
|
|
/**
|
* @description 设置可配置按钮
|
*/
|
setSubConfig = (item, type) => {
|
const { menu } = this.props
|
const { config, originMenu, optionLibs, activeKey } = this.state
|
|
if (!originMenu.MenuID) { // menuID不存在时,为新建菜单,提示菜单尚未保存
|
notification.warning({
|
top: 92,
|
message: this.state.dict['header.menu.config.notsave'],
|
duration: 5
|
})
|
} else {
|
this.menuformRef.handleConfirm().then(res => {
|
let _config = {...config, easyCode: res.easyCode}
|
let _pageParam = {...menu.PageParam, OpenType: res.opentype}
|
let _originMenu = {
|
...originMenu,
|
LongParam: _config,
|
PageParam: _pageParam,
|
MenuName: res.MenuName,
|
MenuNo: res.MenuNo,
|
ParentID: res.parentId,
|
fstMenuId: res.fstMenuId
|
}
|
|
if (!is(fromJS(originMenu), fromJS(_originMenu))) { // 菜单信息变化时,提示保存
|
notification.warning({
|
top: 92,
|
message: this.state.dict['header.menu.config.update'],
|
duration: 5
|
})
|
return
|
}
|
|
// 菜单信息验证通过后,跳转子配置页面
|
let _view = ''
|
let uuid = item.uuid
|
let isbutton = true
|
let _btnTab = null
|
|
if (type === 'button' && item.OpenType === 'pop') {
|
_view = 'Modal' // 表单页面
|
} else if (type === 'button' && (item.OpenType === 'tab' || item.OpenType === 'blank')) {
|
_view = item.tabTemplate // 新标签页模板
|
_btnTab = item
|
} else if (type === 'button' && item.OpenType === 'popview') {
|
_view = item.tabType // 新弹窗标签模板
|
uuid = item.linkTab
|
isbutton = false
|
} else if (type === 'tab') {
|
_view = item.type // 标签模板
|
uuid = item.linkTab
|
isbutton = false
|
}
|
|
// 保存当前打开页签
|
_originMenu.activeKey = activeKey
|
|
let param = {
|
optionLibs: optionLibs,
|
editMenu: _originMenu,
|
editTab: !isbutton ? item : '',
|
tabConfig: null,
|
editSubTab: null,
|
subTabConfig: null,
|
btnTab: _btnTab,
|
btnTabConfig: null,
|
editAction: isbutton ? item : '',
|
subConfig: '',
|
tabview: _view
|
}
|
|
this.setState({
|
loading: true
|
})
|
|
Api.getSystemConfig({
|
func: 'sPC_Get_LongParam',
|
MenuID: uuid
|
}).then(res => {
|
if (res.status) {
|
this.setState({
|
loading: false
|
})
|
let _LongParam = ''
|
if (res.LongParam) {
|
try {
|
_LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
|
} catch (e) {
|
console.warn('Parse Failure')
|
_LongParam = ''
|
}
|
}
|
|
if (_LongParam && param.tabview === 'Modal' && _LongParam.type === 'Modal') {
|
param.subConfig = _LongParam
|
} else if (_LongParam && param.tabview === 'FormTab' && _LongParam.type === 'FormTab') {
|
param.subConfig = _LongParam
|
} else if (_LongParam && param.tabview === 'SubTable' && _LongParam.Template === 'SubTable') {
|
param.subConfig = _LongParam
|
}
|
|
this.props.handleView(param)
|
} else {
|
this.setState({
|
loading: false
|
})
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
}
|
})
|
}, () => {
|
notification.warning({
|
top: 92,
|
message: this.state.dict['header.menu.config.update'],
|
duration: 5
|
})
|
})
|
}
|
}
|
|
/**
|
* @description 页面启用停止切换
|
*/
|
onEnabledChange = () => {
|
const { config } = this.state
|
|
let _enabled = !config.enabled
|
let result = this.verifyconfig(config)
|
if (_enabled && result !== true) {
|
notification.warning({
|
top: 92,
|
message: result,
|
duration: 5
|
})
|
return
|
}
|
|
this.setState({
|
config: {...config, enabled: _enabled}
|
})
|
}
|
|
/**
|
* @description 校验配置信息的合法性
|
*/
|
verifyconfig = (config) => {
|
let tabinvalid = true
|
if (config.tabgroups.length > 1) {
|
config.tabgroups.forEach(group => {
|
if (group.sublist.length === 0) {
|
tabinvalid = false
|
}
|
})
|
}
|
|
if (config.setting.interType === 'inner' && !config.setting.innerFunc && !config.setting.dataresource) {
|
return '菜单尚未设置数据源,不可启用!'
|
} else if (!config.setting.primaryKey) {
|
return '菜单尚未设置主键,不可启用!'
|
} else if (!tabinvalid) {
|
return '菜单标签页设置错误(存在多行标签时,行标签不可为空)!'
|
} else {
|
return true
|
}
|
}
|
|
/**
|
* @description 选择不保存时,如有复制按钮,则删除
|
*/
|
notsave = () => {
|
this.state.copyActions.forEach(item => {
|
let _param = {
|
func: 'sPC_MainMenu_Del',
|
MenuID: item
|
}
|
Api.getSystemConfig(_param)
|
})
|
this.props.handleView()
|
}
|
|
/**
|
* @description 编辑功能完成更新,包括解冻按钮、粘贴、替换等
|
*/
|
editConfig = (res) => {
|
if (res.type === 'thaw') {
|
this.setState({
|
thawButtons: res.thawButtons,
|
config: res.config
|
})
|
} else if (res.type === 'paste') {
|
this.setState({
|
pasteContent: res.content
|
}, () => {
|
this.setState({
|
pasteContent: null
|
})
|
})
|
}
|
}
|
|
/**
|
* @description 更新搜索条件配置信息
|
*/
|
updatesearch = (config, options) => {
|
const { optionLibs } = this.state
|
|
this.setState({
|
config: config,
|
optionLibs: options || optionLibs
|
})
|
}
|
|
/**
|
* @description 更新按钮配置信息
|
*/
|
updateaction = (config, copyId, delcard) => {
|
const { copyActions, delActions } = this.state
|
|
this.setState({
|
config: config,
|
copyActions: copyId ? [...copyActions, copyId] : copyActions,
|
delActions: delcard ? [...delActions, delcard] : delActions
|
})
|
}
|
|
/**
|
* @description 更新图表组配置信息
|
*/
|
updatechartgroup = (config, _chartview) => {
|
this.setState({
|
config: config,
|
chartview: _chartview
|
})
|
}
|
|
/**
|
* @description 更新常用表信息,快捷添加后更新配置信息
|
*/
|
updatetable = (config, fields) => {
|
const { tableFields } = this.state
|
|
this.setState({
|
config: config,
|
tableFields: fields ? fields : tableFields
|
})
|
}
|
|
/**
|
* @description 更新标签配置信息
|
*/
|
updatetabs = (config, delcards) => {
|
const { delActions } = this.state
|
|
this.setState({
|
config: config,
|
delActions: delcards ? [...delActions, ...delcards] : delActions
|
})
|
}
|
|
/**
|
* @description 更新配置信息
|
*/
|
updateconfig = (config) => {
|
this.setState({
|
config: config
|
})
|
}
|
|
render () {
|
const { activeKey, config, chartview } = this.state
|
|
const confActions = config.action.filter(_action => !_action.origin && ['pop', 'popview', 'blank', 'tab'].includes(_action.OpenType))
|
|
let configTabs = []
|
config.tabgroups.forEach(group => {
|
configTabs.push(...group.sublist)
|
})
|
|
return (
|
<div className="common-table-board">
|
<DndProvider backend={HTML5Backend}>
|
{/* 工具栏 */}
|
<div className="tools">
|
<Collapse accordion defaultActiveKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
|
{/* 基本信息 */}
|
<Panel forceRender={true} header={this.state.dict['header.menu.basedata']} key="0" id="main-basedata">
|
{/* 菜单信息 */}
|
<MenuForm
|
dict={this.state.dict}
|
formlist={this.state.menuformlist}
|
wrappedComponentRef={(inst) => this.menuformRef = inst}
|
/>
|
{/* 表名添加 */}
|
<TableComponent
|
config={config}
|
containerId="main-basedata"
|
selectedTables={config.tables || []}
|
updatetable={this.updatetable}
|
/>
|
</Panel>
|
{/* 搜索条件添加 */}
|
<Panel header={this.state.dict['header.menu.search']} key="1">
|
<div className="search-element">
|
{Source.searchItems.map((item, index) => {
|
return (<SourceElement key={index} content={item}/>)
|
})}
|
</div>
|
<FieldsComponent
|
config={config}
|
type="search"
|
tableFields={this.state.tableFields}
|
updatefield={this.updateconfig}
|
/>
|
</Panel>
|
{/* 按钮添加 */}
|
<Panel header={this.state.dict['header.menu.action']} key="2">
|
<div className="search-element">
|
{Source.actionItems.map((item, index) => {
|
return (<SourceElement key={index} content={item}/>)
|
})}
|
</div>
|
<div className="config-btn">
|
{confActions.length > 0 ?
|
<p className="config-btn-title">
|
<Tooltip placement="topLeft" title="点击按钮,可完成或查看按钮配置信息。">
|
<Icon type="question-circle" />
|
</Tooltip>
|
{this.state.dict['header.menu.action.configurable']}
|
</p> : null
|
}
|
</div>
|
{confActions.map((item, index) => {
|
return (
|
<div key={index}>
|
<Button
|
icon={item.icon}
|
style={{marginBottom: '10px'}}
|
className={'config-button mk-btn mk-' + item.class}
|
onClick={() => this.setSubConfig(item, 'button')}
|
>{item.label}</Button>
|
</div>
|
)
|
})}
|
</Panel>
|
{/* 添加显示列 */}
|
<Panel header={this.state.dict['header.menu.column']} key="3">
|
<div className="search-element">
|
{Source.columnItems.map((item, index) => {
|
return (<SourceElement key={index} content={item}/>)
|
})}
|
</div>
|
<FieldsComponent
|
config={config}
|
type="columns"
|
tableFields={this.state.tableFields}
|
updatefield={this.updateconfig}
|
/>
|
</Panel>
|
{/* 添加标签 */}
|
<Panel header={this.state.dict['header.menu.tab']} key="4">
|
<div className="search-element">
|
{Source.tabItems.map((item, index) => {
|
return (<SourceElement key={index} content={item}/>)
|
})}
|
</div>
|
{configTabs.length > 0 ?
|
<p className="config-btn-title">
|
<Tooltip placement="topLeft" title="点击按钮,可完成或查看标签配置信息。">
|
<Icon type="question-circle" />
|
</Tooltip>
|
{this.state.dict['header.menu.tab.configurable']}
|
</p> : null
|
}
|
{configTabs.map((item, index) => {
|
return (
|
<div key={index}>
|
<Button
|
className="config-button"
|
icon={item.icon}
|
style={{marginBottom: '10px'}}
|
onClick={() => this.setSubConfig(item, 'tab')}
|
>{item.label}</Button>
|
</div>
|
)
|
})}
|
</Panel>
|
</Collapse>
|
</div>
|
<div className="setting">
|
<Card title={
|
<div>
|
{this.state.dict['header.menu.page.configurable']}
|
<Icon type="redo" style={{marginLeft: '10px'}} title="刷新标签列表" onClick={() => this.reloadTab(true)} />
|
</div>
|
} bordered={false} extra={
|
<div>
|
<EditComponent dict={this.state.dict} type="maintable" config={this.state.config} MenuID={this.props.menu.MenuID} thawButtons={this.state.thawButtons} refresh={this.editConfig}/>
|
<Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={this.state.config.enabled} onChange={this.onEnabledChange} />
|
<Button type="primary" onClick={this.changeTemplate}>{this.state.dict['header.menu.template.change']}</Button>
|
<Button type="primary" onClick={this.submitConfig} loading={this.state.menuloading}>{this.state.dict['header.save']}</Button>
|
<Button onClick={this.cancelConfig}>{this.state.dict['header.return']}</Button>
|
</div>
|
} style={{ width: '100%' }}>
|
<SettingComponent
|
type="main"
|
config={config}
|
MenuID={this.props.menu.MenuID}
|
menuformRef={this.menuformRef}
|
permFuncField={this.props.permFuncField}
|
updatesetting={this.updateconfig}
|
/>
|
<SearchComponent
|
menu={{MenuID: this.props.menu.MenuID, MenuName: this.props.menu.MenuName}}
|
config={config}
|
pasteContent={this.state.pasteContent}
|
sysRoles={this.props.sysRoles}
|
optionLibs={this.state.optionLibs}
|
updatesearch={this.updatesearch}
|
/>
|
<div className="chart-view" style={{position: 'relative'}}>
|
{/* 视图组 */}
|
<ChartGroupComponent
|
config={config}
|
sysRoles={this.props.sysRoles}
|
updatechartgroup={this.updatechartgroup}
|
/>
|
{config.charts.map(item => {
|
if (!config.expand && chartview !== item.uuid) return ''
|
|
if (item.chartType === 'table') {
|
return (
|
<Col span={item.width || 24} key={item.uuid}>
|
{config.charts.length > 1 && item.title ? <p className="chart-title">{item.title}</p> : null}
|
<ActionComponent
|
type="main"
|
menu={{ MenuID: this.props.menu.MenuID, MenuName: this.props.menu.MenuName, MenuNo: this.props.menu.MenuNo }}
|
config={config}
|
tabs={this.state.tabviews}
|
menuformRef={this.menuformRef}
|
pasteContent={this.state.pasteContent}
|
usefulFields={this.props.permFuncField}
|
setSubConfig={(_btn) => this.setSubConfig(_btn, 'button')}
|
updateaction={this.updateaction}
|
/>
|
<ColumnComponent
|
config={config}
|
menu={this.props.menu}
|
sysRoles={this.props.sysRoles}
|
pasteContent={this.state.pasteContent}
|
updatecolumn={this.updateconfig}
|
/>
|
</Col>
|
)
|
} else {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<ChartComponent
|
plot={item}
|
config={config}
|
plotchange={this.updateconfig}
|
/>
|
</Col>
|
)
|
}
|
})}
|
</div>
|
{/* 标签组 */}
|
<TabsComponent
|
type="main"
|
config={config}
|
tabs={this.state.tabviews}
|
setSubConfig={(item) => this.setSubConfig(item, 'tab')}
|
updatetabs={this.updatetabs}
|
/>
|
</Card>
|
</div>
|
</DndProvider>
|
{/* 返回时未保存提示 */}
|
<Modal
|
bodyStyle={{textAlign: 'center', color: '#000000', fontSize: '16px'}}
|
closable={false}
|
maskClosable={false}
|
visible={this.state.closeVisible}
|
onCancel={() => { this.setState({closeVisible: false}) }}
|
footer={[
|
<Button key="save" className="mk-btn mk-green" loading={this.state.menucloseloading} onClick={this.submitConfig}>{this.state.dict['header.save']}</Button>,
|
<Button key="notsave" className="mk-btn mk-yellow" onClick={this.notsave}>{this.state.dict['header.notsave']}</Button>,
|
<Button key="cancel" onClick={() => { this.setState({closeVisible: false}) }}>{this.state.dict['header.cancel']}</Button>
|
]}
|
destroyOnClose
|
>
|
{this.state.dict['header.menu.config.placeholder']}
|
</Modal>
|
{this.state.loading && <Spin size="large" />}
|
</div>
|
)
|
}
|
}
|
|
const mapStateToProps = (state) => {
|
return {
|
sysRoles: state.sysRoles,
|
permFuncField: state.permFuncField
|
}
|
}
|
|
const mapDispatchToProps = () => {
|
return {}
|
}
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ComTableConfig)
|