import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Modal, notification, Button } from 'antd'
|
import moment from 'moment'
|
|
import Utils, { FuncUtils } from '@/utils/utils.js'
|
import { getActionForm, getBaseTableActionForm } from './formconfig'
|
import asyncSpinComponent from '@/utils/asyncSpinComponent'
|
|
import MKEmitter from '@/utils/events.js'
|
import ActionForm from './actionform'
|
import MenuUtils from '@/utils/utils-custom.js'
|
import CreateFunc from '@/templates/zshare/createfunc'
|
import DragElement from './dragaction'
|
import './index.scss'
|
|
const { confirm } = Modal
|
const VerifyCard = asyncSpinComponent(() => import('@/templates/zshare/verifycard'))
|
const VerifyPrint = asyncSpinComponent(() => import('@/templates/sharecomponent/actioncomponent/verifyprint'))
|
const VerifyExcelIn = asyncSpinComponent(() => import('@/templates/sharecomponent/actioncomponent/verifyexcelin'))
|
const VerifyExcelOut = asyncSpinComponent(() => import('@/templates/sharecomponent/actioncomponent/verifyexcelout'))
|
const VerifyMegvii = asyncSpinComponent(() => import('@/templates/sharecomponent/actioncomponent/verifymegvii'))
|
|
class ActionComponent extends Component {
|
static propTpyes = {
|
config: PropTypes.object, // 菜单配置信息
|
setSubConfig: PropTypes.func, // 设置子配置信息
|
updateaction: PropTypes.func // 菜单配置更新
|
}
|
|
state = {
|
appType: sessionStorage.getItem('appType'),
|
card: null, // 编辑中元素
|
formlist: null, // 表单信息
|
actionlist: null, // 按钮组
|
visible: false, // 模态框控制
|
profVisible: false, // 验证信息模态框
|
record: null
|
}
|
|
/**
|
* @description 搜索条件初始化
|
*/
|
UNSAFE_componentWillMount () {
|
const { config } = this.props
|
|
let actionlist = fromJS(config.action).toJS() || []
|
|
this.setState({
|
actionlist: actionlist.map(item => {
|
if (item.btnstyle) { // 兼容
|
item.style = item.style || {}
|
item.style = {...item.style, ...item.btnstyle}
|
delete item.btnstyle
|
}
|
|
return item
|
})
|
})
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('revertBtn', this.revertBtn)
|
MKEmitter.addListener('addButton', this.addButton)
|
MKEmitter.addListener('submitModal', this.handleSave)
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props.config), fromJS(nextProps.config)) || !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('revertBtn', this.revertBtn)
|
MKEmitter.removeListener('addButton', this.addButton)
|
MKEmitter.removeListener('submitModal', this.handleSave)
|
}
|
|
revertBtn = (id) => {
|
if (id && id !== this.props.config.uuid) return
|
|
this.setState({
|
actionlist: fromJS(this.props.config.action).toJS()
|
})
|
}
|
|
handleSave = (componentId, btnId, modal) => {
|
const { config } = this.props
|
|
if (config.uuid !== componentId) return
|
|
const { actionlist } = this.state
|
|
let _index = actionlist.findIndex(cell => cell.uuid === btnId)
|
|
if (_index === -1) return
|
|
let _actionlist = actionlist.map(cell => {
|
if (cell.uuid === btnId) {
|
cell.modal = modal
|
}
|
|
return cell
|
})
|
|
this.setState({
|
actionlist: _actionlist
|
}, () => {
|
this.props.updateaction({...config, action: _actionlist})
|
})
|
}
|
|
getStyle = (style) => {
|
const { config } = this.props
|
const { card, actionlist } = this.state
|
|
let _card = fromJS(card).toJS()
|
_card.style = style
|
|
let _actionlist = actionlist.map(cell => {
|
if (cell.uuid === _card.uuid) return _card
|
return cell
|
})
|
|
this.setState({
|
actionlist: _actionlist
|
}, () => {
|
this.props.updateaction({...config, action: _actionlist})
|
})
|
}
|
|
changeBtnStyle = (element) => {
|
let _style = element.style ? fromJS(element.style).toJS() : {}
|
let options = ['font', 'border', 'background', 'margin', 'padding']
|
|
this.setState({
|
card: element
|
})
|
|
MKEmitter.emit('changeStyle', options, _style, this.getStyle)
|
}
|
|
addButton = (cardId, element) => {
|
if (cardId !== this.props.config.uuid) return
|
|
const { actionlist } = this.state
|
|
this.setState({actionlist: [...actionlist, element]})
|
this.handleAction(element)
|
}
|
|
/**
|
* @description 按钮顺序调整,或拖拽添加
|
*/
|
handleList = (list, card) => {
|
const { config } = this.props
|
|
if (card) {
|
this.setState({actionlist: list})
|
this.handleAction(card)
|
} else {
|
this.setState({actionlist: list}, () => {
|
this.props.updateaction({...config, action: list})
|
})
|
}
|
}
|
|
/**
|
* @description 按钮编辑,获取按钮表单信息
|
*/
|
handleAction = (card) => {
|
const { config } = this.props
|
|
let usefulFields = sessionStorage.getItem('permFuncField')
|
if (usefulFields) {
|
try {
|
usefulFields = JSON.parse(usefulFields)
|
} catch (e) {
|
usefulFields = []
|
}
|
} else {
|
usefulFields = []
|
}
|
|
let ableField = usefulFields.join(', ')
|
let msg = `函数名称需以${ableField}等字符开始;`
|
let functip = <div>
|
<p style={{marginBottom: '5px'}}>{msg}</p>
|
</div>
|
|
if (!ableField) { // 无字段限制
|
functip = ''
|
}
|
|
let supId = ''
|
if (config.setting && config.setting.supModule) {
|
let pid = config.setting.supModule[config.setting.supModule.length - 1]
|
if (pid && pid !== 'empty') {
|
supId = pid
|
} else {
|
supId = ''
|
}
|
}
|
|
let modules = MenuUtils.getSubModules(window.GLOB.customMenu.components, config.uuid, supId)
|
|
if (config.subtype === 'basetable') {
|
delete card.eleType // 区分按钮位置
|
|
this.setState({
|
visible: true,
|
card: card,
|
formlist: getBaseTableActionForm(card, functip, config, usefulFields, modules)
|
})
|
} else {
|
let anchors = MenuUtils.getAnchors(window.GLOB.customMenu.components, config.uuid) || []
|
|
this.setState({
|
visible: true,
|
card: card,
|
formlist: getActionForm(card, functip, config, usefulFields, modules, anchors)
|
})
|
}
|
}
|
|
/**
|
* @description 取消保存,如果元素为新添元素,则从序列中删除
|
*/
|
editModalCancel = () => {
|
const { card } = this.state
|
|
if (card.focus) {
|
let actionlist = fromJS(this.state.actionlist).toJS()
|
|
actionlist = actionlist.filter(item => item.uuid !== card.uuid)
|
|
this.setState({
|
card: null,
|
actionlist: actionlist,
|
visible: false
|
})
|
} else {
|
this.setState({
|
card: null,
|
visible: false
|
})
|
}
|
}
|
|
/**
|
* @description 按钮修改后提交保存
|
*/
|
handleSubmit = () => {
|
const { config } = this.props
|
let color = { primary: '#1890ff', yellow: '#c49f47', orange: 'orange', danger: '#ff4d4f', green: '#26C281', dgreen: '#32c5d2', purple: '#8E44AD', cyan: '#13c2c2', gray: '#E7E7EF', default: 'rgba(0, 0, 0, 0.65)' }
|
let _actionlist = fromJS(this.state.actionlist).toJS()
|
|
this.actionFormRef.handleConfirm().then(btn => {
|
_actionlist = _actionlist.filter(item => !item.origin || item.uuid === btn.uuid)
|
|
if ((btn.OpenType === 'excelIn' || btn.OpenType === 'excelOut') && (!btn.verify || !btn.verify.columns) && (config.subtype === 'basetable' || config.subtype === 'normaltable')) {
|
let columns = []
|
let maps = []
|
let labels = {}
|
if (config.subtype === 'normaltable') {
|
config.columns.forEach(col => {
|
labels[col.field] = col.label
|
})
|
}
|
|
if (btn.OpenType === 'excelOut') {
|
let pushcol = (item) => {
|
let cell = {
|
Column: item.field,
|
Text: item.label,
|
Width: 20,
|
abs: 'false',
|
output: 'true',
|
required: 'false',
|
type: 'text',
|
uuid: Utils.getuuid()
|
}
|
|
if (item.type === 'number') {
|
cell.type = 'number'
|
cell.decimal = item.decimal
|
}
|
|
columns.push(cell)
|
}
|
|
config.cols.forEach(item => {
|
if (item.Hide === 'true') return
|
|
if (config.subtype === 'normaltable') {
|
if (item.type === 'colspan') {
|
item.subcols.forEach(cell => {
|
if (!cell.field || cell.Hide === 'true' || maps.includes(cell.field)) return
|
maps.push(cell.field)
|
|
pushcol(cell)
|
})
|
} else if (item.type === 'custom') {
|
item.elements.forEach(cell => {
|
if (!cell.field || maps.includes(cell.field)) return
|
maps.push(cell.field)
|
|
pushcol({...cell, label: labels[cell.field]})
|
})
|
}
|
}
|
|
if (!item.field || maps.includes(item.field)) return
|
maps.push(item.field)
|
|
pushcol(item)
|
})
|
|
btn.verify = btn.verify || {enable: 'false', dataType: 'default', scripts: []}
|
btn.verify.columns = columns
|
} else {
|
let pushcol = (item) => {
|
let _type = 'Nvarchar(50)'
|
let _limit = '50'
|
if (item.type === 'number' && !item.decimal) {
|
_type = 'Int'
|
_limit = ''
|
} else if (item.type === 'number') {
|
_type = 'Decimal(18,' + item.decimal + ')'
|
_limit = item.decimal
|
}
|
|
let _cell = {
|
uuid: Utils.getuuid(),
|
Column: item.field,
|
Text: item.label,
|
type: _type,
|
limit: _limit,
|
import: 'true',
|
required: 'true'
|
}
|
|
if (_type !== 'Nvarchar(50)') {
|
_cell.min = 0
|
_cell.max = 999999
|
}
|
|
columns.push(_cell)
|
}
|
|
config.cols.forEach(item => {
|
if (item.Hide === 'true') return
|
|
if (config.subtype === 'normaltable') {
|
if (item.type === 'colspan') {
|
item.subcols.forEach(cell => {
|
if (!cell.field || cell.Hide === 'true' || maps.includes(cell.field)) return
|
maps.push(cell.field)
|
|
pushcol(cell)
|
})
|
} else if (item.type === 'custom') {
|
item.elements.forEach(cell => {
|
if (!cell.field || maps.includes(cell.field)) return
|
maps.push(cell.field)
|
|
pushcol({...cell, label: labels[cell.field]})
|
})
|
}
|
}
|
|
if (!item.field || maps.includes(item.field)) return
|
maps.push(item.field)
|
|
pushcol(item)
|
})
|
|
btn.verify = btn.verify || {sheet: 'Sheet1', default: 'true', range: 1, scripts: [], uniques: []}
|
btn.verify.columns = columns
|
}
|
}
|
|
let labelrepet = false
|
_actionlist = _actionlist.map(item => {
|
if (item.uuid !== btn.uuid && item.label === btn.label) {
|
labelrepet = true
|
}
|
|
if (item.uuid === btn.uuid) {
|
if (config.subtype === 'basetable') {
|
let _c = btn.class.replace('border-', '')
|
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[_c], backgroundColor: '#fff', borderColor: color[_c], marginRight: '15px'}
|
} else if (btn.class === 'gray') {
|
btn.style = {color: 'rgba(0, 0, 0, 0.65)', backgroundColor: color[_c], borderColor: color[_c], marginRight: '15px'}
|
} else {
|
btn.style = {color: '#fff', backgroundColor: color[_c], borderColor: color[_c], marginRight: '15px'}
|
}
|
} else {
|
btn.style = item.style || {}
|
if (btn.class) {
|
if (btn.class !== item.class || btn.show !== item.show || !btn.style.color || (item.focus && !btn.style.color)) {
|
if (btn.show === 'icon') {
|
btn.style.color = color[btn.class]
|
btn.style.backgroundColor = 'transparent'
|
} else if (btn.class === 'default') {
|
btn.style.color = 'rgba(0, 0, 0, 0.65)'
|
btn.style.backgroundColor = '#fff'
|
btn.style.borderColor = '#d9d9d9'
|
} else if (btn.class.indexOf('border') > -1) {
|
let _c = btn.class.replace('border-', '')
|
btn.style.color = color[_c]
|
btn.style.backgroundColor = '#fff'
|
btn.style.borderColor = color[_c]
|
} else if (btn.class === 'gray') {
|
btn.style.color = 'rgba(0, 0, 0, 0.65)'
|
btn.style.backgroundColor = color[btn.class]
|
btn.style.borderColor = color[btn.class]
|
} else {
|
btn.style.color = '#ffffff'
|
btn.style.backgroundColor = color[btn.class]
|
btn.style.borderColor = color[btn.class]
|
}
|
}
|
} else if (btn.color) {
|
btn.style = {}
|
}
|
}
|
|
btn.updateTime = moment().format('YYYY-MM-DD HH:mm')
|
return btn
|
} else {
|
return item
|
}
|
})
|
|
if (labelrepet) {
|
notification.warning({
|
top: 92,
|
message: '名称已存在!',
|
duration: 5
|
})
|
return
|
}
|
|
this.setState({
|
actionlist: _actionlist,
|
visible: false
|
}, () => {
|
this.props.updateaction({...config, action: _actionlist})
|
})
|
})
|
}
|
|
/**
|
* @description 按钮删除
|
*/
|
deleteElement = (card) => {
|
const { config } = this.props
|
let _this = this
|
|
confirm({
|
content: `确定删除 - ${card.label} ?`,
|
onOk() {
|
let _actionlist = fromJS(_this.state.actionlist).toJS()
|
|
_actionlist = _actionlist.filter(item => item.uuid !== card.uuid)
|
|
_this.setState({
|
actionlist: _actionlist
|
}, () => {
|
_this.props.updateaction({...config, action: _actionlist})
|
})
|
},
|
onCancel() {}
|
})
|
}
|
|
/**
|
* @description 验证信息配置
|
*/
|
profileAction = (element) => {
|
this.setState({
|
profVisible: true,
|
card: element
|
})
|
}
|
|
/**
|
* @description 验证信息保存
|
*/
|
verifySubmit = () => {
|
const { config } = this.props
|
const { card } = this.state
|
|
this.verifyRef.handleConfirm().then(res => {
|
let _actionlist = fromJS(this.state.actionlist).toJS()
|
_actionlist = _actionlist.filter(item => !item.origin || item.uuid === card.uuid)
|
|
_actionlist = _actionlist.map(item => {
|
if (item.uuid === card.uuid) {
|
item.verify = res
|
item.updateTime = moment().format('YYYY-MM-DD HH:mm')
|
}
|
|
return item
|
})
|
|
this.setState({
|
actionlist: _actionlist,
|
profVisible: false
|
}, () => {
|
this.props.updateaction({...config, action: _actionlist})
|
})
|
})
|
}
|
|
/**
|
* @description 创建按钮存储过程
|
*/
|
creatFunc = () => {
|
const menu = window.GLOB.customMenu
|
let _config = fromJS(this.props.config).toJS()
|
|
this.actionFormRef.handleConfirm().then(res => {
|
let btn = res // 按钮信息
|
let newLText = '' // 创建存储过程sql
|
let DelText = '' // 删除存储过程sql
|
|
// 创建存储过程,必须填写内部函数名
|
if (btn.intertype !== 'inner') {
|
notification.warning({
|
top: 92,
|
message: '使用内部函数时,才可以创建存储过程!',
|
duration: 5
|
})
|
return
|
}
|
|
if (btn.OpenType === 'pop') {
|
let _param = {
|
funcName: btn.innerFunc,
|
name: _config.setting.tableName || '',
|
fields: btn.modal ? btn.modal.fields : [],
|
menuNo: menu.MenuNo
|
}
|
newLText = Utils.formatOptions(FuncUtils.getfunc(_param, btn, menu, _config))
|
DelText = Utils.formatOptions(FuncUtils.dropfunc(btn.innerFunc))
|
} else if (btn.OpenType === 'excelIn') {
|
let _param = {
|
funcName: btn.innerFunc,
|
menuNo: menu.MenuNo
|
}
|
newLText = Utils.formatOptions(FuncUtils.getexcelInfunc(_param, btn, menu))
|
DelText = Utils.formatOptions(FuncUtils.dropfunc(btn.innerFunc))
|
} else if (btn.OpenType === 'excelOut') {
|
newLText = Utils.formatOptions(FuncUtils.getTableFunc(btn.innerFunc, menu, _config)) // 创建存储过程sql
|
DelText = Utils.formatOptions(FuncUtils.dropfunc(btn.innerFunc))
|
} else {
|
let _param = {
|
funcName: btn.innerFunc,
|
name: _config.setting.tableName || '',
|
fields: '',
|
menuNo: menu.MenuNo
|
}
|
newLText = Utils.formatOptions(FuncUtils.getfunc(_param, btn, menu, _config))
|
DelText = Utils.formatOptions(FuncUtils.dropfunc(btn.innerFunc))
|
}
|
|
this.refs.btnCreatFunc.exec(btn.innerFunc, newLText, DelText)
|
})
|
}
|
|
/**
|
* @description 按钮双击触发子配置
|
*/
|
btnDoubleClick = (element) => {
|
if (sessionStorage.getItem('style-control') && sessionStorage.getItem('style-control') === 'true') return
|
|
if (element.OpenType === 'pop' || element.OpenType === 'popview' || element.execMode === 'pop') {
|
this.props.setSubConfig(element)
|
} else if (element.OpenType === 'innerpage' && element.pageTemplate === 'linkpage') {
|
MKEmitter.emit('changeEditMenu', {MenuID: element.linkmenu})
|
} else if (element.OpenType === 'funcbutton' && (element.funcType === 'copyurl' || element.funcType === 'scan') && element.linkmenu) {
|
MKEmitter.emit('changeEditMenu', {MenuID: element.linkmenu})
|
} else {
|
this.handleAction(element)
|
}
|
}
|
|
dropButton = (id) => {
|
let config = fromJS(this.props.config).toJS()
|
|
let btn = null
|
let _col = null
|
if (config.type === 'table') {
|
config.cols.forEach(col => {
|
if (col.type !== 'custom') return
|
|
col.elements = col.elements.filter(item => {
|
if (item.uuid === id) {
|
btn = item
|
_col = col
|
}
|
return item.uuid !== id
|
})
|
})
|
} else if (config.type === 'card' && config.subcards) {
|
config.subcards.forEach(scard => {
|
scard.elements = scard.elements.filter(item => {
|
if (item.uuid === id) {
|
btn = item
|
_col = scard
|
}
|
return item.uuid !== id
|
})
|
scard.backElements = scard.backElements.filter(item => {
|
if (item.uuid === id) {
|
btn = item
|
_col = scard
|
}
|
return item.uuid !== id
|
})
|
return scard
|
})
|
}
|
|
if (!btn) return
|
|
config.action.push(btn)
|
|
MKEmitter.emit('cardDelElement', _col.uuid, btn.uuid)
|
|
this.setState({
|
actionlist: config.action
|
}, () => {
|
this.props.updateaction(config)
|
})
|
}
|
|
getVerify = (card) => {
|
const { config } = this.props
|
|
if (!card) return null
|
|
if (['pop', 'prompt', 'exec'].includes(card.OpenType)) {
|
return <VerifyCard
|
card={card}
|
config={config}
|
columns={config.columns}
|
wrappedComponentRef={(inst) => this.verifyRef = inst}
|
/>
|
} else if (card.OpenType === 'excelIn') {
|
return <VerifyExcelIn
|
card={card}
|
columns={config.columns}
|
wrappedComponentRef={(inst) => this.verifyRef = inst}
|
/>
|
} else if (card.OpenType === 'excelOut') {
|
return <VerifyExcelOut
|
card={card}
|
config={config}
|
wrappedComponentRef={(inst) => this.verifyRef = inst}
|
/>
|
} else if (card.OpenType === 'funcbutton' && card.funcType === 'print') {
|
return <VerifyPrint
|
card={card}
|
columns={config.columns}
|
wrappedComponentRef={(inst) => this.verifyRef = inst}
|
/>
|
} else if (card.OpenType === 'funcbutton' && card.funcType === 'megvii') {
|
return <VerifyMegvii
|
card={card}
|
columns={config.columns}
|
wrappedComponentRef={(inst) => this.verifyRef = inst}
|
/>
|
}
|
}
|
|
render() {
|
const { config } = this.props
|
const { actionlist, visible, appType, card, profVisible, record } = this.state
|
|
return (
|
<div className={'model-menu-action-list length' + actionlist.length}>
|
<DragElement
|
list={actionlist}
|
type={appType === 'mob' || config.subtype === 'basetable' ? config.subtype : ''}
|
handleList={this.handleList}
|
dropButton={this.dropButton}
|
handleMenu={this.handleAction}
|
deleteMenu={this.deleteElement}
|
profileMenu={this.profileAction}
|
changeBtnStyle={this.changeBtnStyle}
|
doubleClickCard={this.btnDoubleClick}
|
/>
|
{/* 编辑按钮:复制、编辑 */}
|
<Modal
|
title="按钮·编辑"
|
visible={visible}
|
width={920}
|
maskClosable={false}
|
onCancel={this.editModalCancel}
|
footer={[
|
record && record.intertype === 'inner' ? <CreateFunc key="create" ref="btnCreatFunc" trigger={this.creatFunc}/> : null,
|
<Button key="cancel" onClick={this.editModalCancel}>取消</Button>,
|
<Button key="confirm" type="primary" onClick={this.handleSubmit}>确定</Button>
|
]}
|
destroyOnClose
|
>
|
<ActionForm
|
card={card}
|
formlist={this.state.formlist}
|
inputSubmit={this.handleSubmit}
|
setting={config.setting}
|
updRecord={(record) => this.setState({record: fromJS(record).toJS()})}
|
wrappedComponentRef={(inst) => this.actionFormRef = inst}
|
/>
|
</Modal>
|
{/* 按钮使用系统存储过程时,验证信息模态框 */}
|
<Modal
|
wrapClassName="mk-pop-modal"
|
visible={profVisible}
|
width={'90vw'}
|
maskClosable={false}
|
okText="提交"
|
onOk={this.verifySubmit}
|
onCancel={() => {
|
if (this.verifyRef.handleCancel) {
|
this.verifyRef.handleCancel().then(() => {
|
this.setState({ profVisible: false })
|
})
|
} else {
|
this.setState({ profVisible: false })
|
}
|
}}
|
destroyOnClose
|
>
|
{this.getVerify(card)}
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default ActionComponent
|