import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Icon, Tooltip, Modal, notification, Switch, message, Spin } from 'antd'
|
|
import Api from '@/api'
|
import options from '@/store/options.js'
|
import zhCN from '@/locales/zh-CN/model.js'
|
import enUS from '@/locales/en-US/model.js'
|
import { getColumnForm } from '@/templates/zshare/formconfig'
|
|
import ColumnForm from './columnform'
|
import ColspanForm from './colspanform'
|
import GridBtnForm from './gridbtnform'
|
import DragElement from './dragcolumn'
|
import MarkColumn from './markcolumn'
|
import './index.scss'
|
|
const { confirm } = Modal
|
|
class ColumnComponent extends Component {
|
static propTpyes = {
|
menu: PropTypes.object, // 三级菜单信息
|
config: PropTypes.object, // 配置信息
|
pasteContent: PropTypes.object, // 粘贴配置信息
|
sysRoles: PropTypes.array, // 角色列表,权限分配
|
updatecolumn: PropTypes.func // 更新
|
}
|
|
state = {
|
dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
|
columnlist: null, // 显示列
|
loading: false, // 查询显示列关联菜单
|
showField: false, // 显示列字段
|
modaltype: '', // 模态框控制
|
card: null // 编辑中元素
|
}
|
|
/**
|
* @description 显示列初始化
|
*/
|
UNSAFE_componentWillMount () {
|
this.setState({
|
columnlist: fromJS(this.props.config.columns).toJS()
|
})
|
}
|
|
/**
|
* @description 监听到显示列复制时,触发显示列编辑
|
*/
|
UNSAFE_componentWillReceiveProps (nextProps) {
|
const { config } = this.props
|
const { columnlist } = this.state
|
|
if (
|
nextProps.pasteContent &&
|
nextProps.pasteContent.columns &&
|
nextProps.pasteContent.copyType === 'columns' &&
|
nextProps.pasteContent.columns.length > 0
|
) {
|
if (columnlist.filter(col => !col.origin).length === 0) {
|
this.setState({columnlist: nextProps.pasteContent.columns}, () => {
|
this.props.updatecolumn({...config, columns: nextProps.pasteContent.columns})
|
})
|
}
|
} else if (!is(fromJS(nextProps.config.columns), fromJS(config.columns)) && !is(fromJS(nextProps.config.columns), fromJS(columnlist))) {
|
this.setState({columnlist: fromJS(nextProps.config.columns).toJS()})
|
}
|
}
|
|
/**
|
* @description 显示列顺序调整,或拖拽添加
|
*/
|
handleList = (list, card) => {
|
const { config } = this.props
|
|
if (card) {
|
this.setState({columnlist: list})
|
this.handleColumn(card)
|
} else {
|
this.setState({columnlist: list}, ()=> {
|
this.props.updatecolumn({...config, columns: list})
|
})
|
}
|
}
|
|
/**
|
* @description 显示列与合并列编辑,获取表单信息
|
*/
|
handleColumn = (card) => {
|
const { menu } = this.props
|
|
if (card.type !== 'colspan') {
|
let menulist = menu.fstMenuList.map(item => {
|
return {
|
value: item.MenuID,
|
label: item.text,
|
isLeaf: false
|
}
|
})
|
|
if ((card.type === 'text' || card.type === 'number') && card.linkmenu && card.linkmenu.length > 0) {
|
let _param = {
|
func: 'sPC_Get_FunMenu',
|
ParentID: card.linkmenu[0],
|
systemType: options.systemType,
|
debug: 'Y'
|
}
|
|
this.setState({
|
loading: true
|
})
|
|
Api.getSystemConfig(_param).then(result => {
|
if (result.status) {
|
menulist = menulist.map(item => {
|
if (item.value === card.linkmenu[0]) {
|
item.children = result.data.map(item => {
|
let submenu = {
|
value: item.ParentID,
|
label: item.MenuNameP,
|
children: item.FunMenu.map(cell => {
|
return {
|
value: cell.MenuID,
|
label: cell.MenuName,
|
MenuID: cell.MenuID,
|
MenuName: cell.MenuName,
|
MenuNo: cell.MenuNo,
|
Ot: cell.Ot,
|
PageParam: cell.PageParam,
|
LinkUrl: cell.LinkUrl,
|
disabled: cell.MenuID === menu.MenuID
|
}
|
})
|
}
|
|
return submenu
|
})
|
}
|
return item
|
})
|
} else {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
|
this.setState({
|
loading: false,
|
modaltype: 'columns',
|
card: card,
|
formlist: getColumnForm(card, this.props.sysRoles, menulist)
|
})
|
})
|
} else {
|
this.setState({
|
modaltype: 'columns',
|
card: card,
|
formlist: getColumnForm(card, this.props.sysRoles, menulist)
|
})
|
}
|
} else {
|
this.setState({
|
modaltype: 'colspan',
|
card: card
|
})
|
}
|
}
|
|
/**
|
* @description 设置标志
|
*/
|
markElement = (card) => {
|
this.setState({
|
modaltype: 'mark',
|
card: card
|
})
|
}
|
|
/**
|
* @description 操作列编辑
|
*/
|
handleGridBtn = () => {
|
this.setState({
|
modaltype: 'gridbtn'
|
})
|
}
|
|
/**
|
* @description 取消保存,如果元素为新添元素,则从序列中删除
|
*/
|
editModalCancel = () => {
|
const { card } = this.state
|
|
if (card.focus) {
|
let _columnlist = fromJS(this.state.columnlist).toJS()
|
|
_columnlist = _columnlist.filter(item => item.uuid !== card.uuid)
|
|
this.setState({
|
card: null,
|
modaltype: '',
|
columnlist: _columnlist
|
})
|
} else {
|
this.setState({
|
card: null,
|
modaltype: ''
|
})
|
}
|
}
|
|
/**
|
* @description 搜索修改后提交保存
|
* 1、去除系统默认显示列
|
* 2、字段及提示文字重复校验
|
* 3、更新下拉菜单可选集合
|
* 4、下拉菜单数据源语法验证
|
*/
|
handleSubmit = () => {
|
const { config } = this.props
|
const { modaltype, card } = this.state
|
|
let _columnlist = fromJS(this.state.columnlist).toJS()
|
|
if (modaltype === 'columns' || modaltype === 'colspan') {
|
this.columnFormRef.handleConfirm().then(res => {
|
let fieldrepet = false // 字段重复
|
let labelrepet = false // 提示文字重复
|
|
_columnlist = _columnlist.filter(item => !item.origin || item.uuid === res.uuid) // 去除初始列
|
|
_columnlist = _columnlist.map(item => {
|
if (item.uuid !== res.uuid && res.field && item.field) {
|
if (item.field === res.field) {
|
fieldrepet = true
|
} else if (item.label === res.label) {
|
labelrepet = true
|
}
|
}
|
|
if (item.uuid === res.uuid) {
|
return res
|
} else {
|
return item
|
}
|
})
|
|
if (fieldrepet) {
|
notification.warning({
|
top: 92,
|
message: this.state.dict['model.field.exist'] + ' !',
|
duration: 5
|
})
|
return
|
} else if (labelrepet) {
|
notification.warning({
|
top: 92,
|
message: this.state.dict['model.name.exist'] + ' !',
|
duration: 5
|
})
|
return
|
}
|
|
if (!card.focus && (card.type !== res.type || (res.field && card.field !== res.field))) {
|
let refers = []
|
_columnlist.forEach(column => {
|
if (column.marks && column.marks.filter(mark => mark.field === card.field || mark.contrastField === card.field).length > 0) {
|
refers.push(column.label)
|
}
|
})
|
|
if (refers.length > 0) {
|
notification.warning({
|
top: 92,
|
message: '显示列《' + refers.join('、') + '》标记中含有该字段,此次修改会导致标记失效,请修改《' + refers.join('、') + '》标记设置!',
|
duration: 5
|
})
|
}
|
}
|
|
this.setState({
|
card: null,
|
columnlist: _columnlist,
|
modaltype: ''
|
}, ()=> {
|
this.props.updatecolumn({...config, columns: _columnlist})
|
})
|
})
|
} else if (modaltype === 'gridbtn') {
|
this.gridBtnFormRef.handleConfirm().then(res => {
|
this.setState({
|
modaltype: ''
|
})
|
|
this.props.updatecolumn({...config, gridBtn: res})
|
})
|
}
|
}
|
|
/**
|
* @description 显示列删除
|
*/
|
deleteElement = (card) => {
|
const { config } = this.props
|
const { dict } = this.state
|
let _this = this
|
|
confirm({
|
content: dict['model.confirm'] + dict['model.delete'] + ` - ${card.label} ?`,
|
okText: dict['model.confirm'],
|
cancelText: this.state.dict['header.cancel'],
|
onOk() {
|
let _columnlist = fromJS(_this.state.columnlist).toJS()
|
|
_columnlist = _columnlist.filter(item => item.uuid !== card.uuid)
|
|
if (card.field) {
|
let refers = []
|
_columnlist.forEach(column => {
|
if (column.marks && column.marks.filter(mark => mark.field === card.field || mark.contrastField === card.field).length > 0) {
|
refers.push(column.label)
|
}
|
})
|
|
if (refers.length > 0) {
|
notification.warning({
|
top: 92,
|
message: '显示列《' + refers.join('、') + '》标记中含有该字段,删除会导致标记失效,请修改《' + refers.join('、') + '》标记设置!',
|
duration: 5
|
})
|
}
|
}
|
|
_this.setState({
|
columnlist: _columnlist
|
}, ()=> {
|
_this.props.updatecolumn({...config, columns: _columnlist})
|
})
|
},
|
onCancel() {}
|
})
|
}
|
|
/**
|
* @description 显示列复制
|
*/
|
copycolumn = () => {
|
const { columnlist } = this.state
|
|
let oInput = document.createElement('input')
|
let val = {
|
copyType: 'columns',
|
columns: columnlist
|
}
|
|
oInput.value = window.btoa(window.encodeURIComponent(JSON.stringify(val)))
|
document.body.appendChild(oInput)
|
oInput.select()
|
document.execCommand('Copy')
|
oInput.className = 'oInput'
|
oInput.style.display = 'none'
|
|
message.success('复制成功。')
|
|
document.body.removeChild(oInput)
|
}
|
|
/**
|
* @description 显示列字段名显示或隐藏控制
|
*/
|
onFieldChange = () => {
|
const { showField, columnlist } = this.state
|
|
if (!showField) {
|
let fields = []
|
columnlist.forEach(col => {
|
if (col.field) {
|
fields.push(col.field)
|
}
|
})
|
|
fields = fields.join(',')
|
|
let textArea = document.createElement('textarea')
|
textArea.value = fields
|
document.body.appendChild(textArea)
|
textArea.select()
|
|
try {
|
document.execCommand('copy')
|
document.body.removeChild(textArea)
|
} catch (err) {
|
document.body.removeChild(textArea)
|
}
|
}
|
|
this.setState({
|
showField: !showField
|
})
|
}
|
|
markSubmit = () => {
|
const { config } = this.props
|
const { card } = this.state
|
let _columnlist = fromJS(this.state.columnlist).toJS()
|
let _marks = this.refs.markRef.state.marks
|
|
if (_marks.length === 0) {
|
_marks = ''
|
}
|
|
_columnlist = _columnlist.map(item => {
|
if (item.uuid === card.uuid) {
|
item.marks = _marks
|
}
|
|
return item
|
})
|
|
this.setState({
|
card: null,
|
columnlist: _columnlist,
|
modaltype: ''
|
}, ()=> {
|
this.props.updatecolumn({...config, columns: _columnlist})
|
})
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
render() {
|
const { config } = this.props
|
const { modaltype, columnlist, dict, card } = this.state
|
|
return (
|
<div className="model-table-column-list">
|
<Tooltip placement="bottomLeft" overlayClassName="middle" title={dict['model.tooltip.column.guide']}>
|
<Icon type="question-circle" />
|
</Tooltip>
|
{columnlist && columnlist.length > 0 ?
|
<Icon className="column-copy" title="copy" type="copy" onClick={this.copycolumn} /> : null
|
}
|
<Switch checkedChildren="开" unCheckedChildren="关" defaultChecked={this.state.showField} onChange={this.onFieldChange} />
|
<DragElement
|
list={columnlist}
|
setting={config.setting}
|
gridBtn={config.gridBtn}
|
handleList={this.handleList}
|
handleMenu={this.handleColumn}
|
deleteMenu={this.deleteElement}
|
markMenu={this.markElement}
|
handleGridBtn={this.handleGridBtn}
|
showfield={this.state.showField}
|
placeholder={this.state.dict['header.form.column.placeholder']}
|
/>
|
{/* 显示列编辑 */}
|
<Modal
|
title={dict['header.modal.column.edit']}
|
visible={modaltype === 'columns'}
|
width={750}
|
maskClosable={false}
|
onOk={this.handleSubmit}
|
onCancel={this.editModalCancel}
|
destroyOnClose
|
>
|
<ColumnForm
|
dict={dict}
|
card={card}
|
MenuID={this.props.menu.MenuID}
|
inputSubmit={this.handleSubmit}
|
formlist={this.state.formlist}
|
wrappedComponentRef={(inst) => this.columnFormRef = inst}
|
/>
|
</Modal>
|
{/* 合并列编辑 */}
|
<Modal
|
title={dict['header.modal.colspan.edit']}
|
visible={modaltype === 'colspan'}
|
width={750}
|
maskClosable={false}
|
onOk={this.handleSubmit}
|
onCancel={this.editModalCancel}
|
destroyOnClose
|
>
|
<ColspanForm
|
dict={dict}
|
card={card}
|
inputSubmit={this.handleSubmit}
|
columns={columnlist}
|
wrappedComponentRef={(inst) => this.columnFormRef = inst}
|
/>
|
</Modal>
|
{/* 操作列编辑 */}
|
<Modal
|
title={dict['header.modal.gridbtn.edit']}
|
visible={modaltype === 'gridbtn'}
|
width={700}
|
maskClosable={false}
|
onOk={this.handleSubmit}
|
onCancel={this.editModalCancel}
|
destroyOnClose
|
>
|
<GridBtnForm
|
dict={dict}
|
inputSubmit={this.handleSubmit}
|
card={config.gridBtn}
|
wrappedComponentRef={(inst) => this.gridBtnFormRef = inst}
|
/>
|
</Modal>
|
{/* 按钮使用系统存储过程时,验证信息模态框 */}
|
<Modal
|
wrapClassName="model-table-column-mark-modal"
|
title={'标记设置'}
|
visible={modaltype === 'mark'}
|
width={'75vw'}
|
maskClosable={false}
|
style={{minWidth: '900px', maxWidth: '1200px'}}
|
okText={dict['header.submit']}
|
onOk={this.markSubmit}
|
onCancel={() => { this.setState({ modaltype: '' }) }}
|
destroyOnClose
|
>
|
<MarkColumn
|
ref="markRef"
|
card={card}
|
dict={dict}
|
columns={columnlist}
|
/>
|
</Modal>
|
{this.state.loading && <Spin size="large" />}
|
</div>
|
)
|
}
|
}
|
|
export default ColumnComponent
|