| | |
| | | import moment from 'moment' |
| | | import {connect} from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, Modal, notification, message, Drawer, Switch, Checkbox } from 'antd' |
| | | import { Button, Modal, notification, message, Drawer, Switch, Checkbox, Progress } from 'antd' |
| | | |
| | | import Api from '@/api' |
| | | import Utils, { getSysDefaultSql } from '@/utils/utils.js' |
| | |
| | | |
| | | class NormalButton extends Component { |
| | | static propTpyes = { |
| | | show: PropTypes.any, // 按钮显示样式控制 |
| | | position: PropTypes.any, // 按钮位置,工具栏为toolbar |
| | | BID: PropTypes.string, // 主表ID |
| | | BData: PropTypes.any, // 主表数据 |
| | | style: PropTypes.any, // 按钮样式 |
| | |
| | | setting: PropTypes.any, // 页面通用设置 |
| | | ContainerId: PropTypes.any, // tab页面ID,用于弹窗控制 |
| | | disabled: PropTypes.any, // 行按钮禁用 |
| | | lineId: PropTypes.any, // 行索引+主键值,用于行按钮双击 |
| | | } |
| | | |
| | | state = { |
| | |
| | | btnconfig: null, |
| | | loading: false, |
| | | loadingNumber: '', |
| | | loadingTotal: '', |
| | | disabled: false, |
| | | hidden: false, |
| | | checkParam: null, |
| | |
| | | |
| | | if (btn.controlField && selectedData && selectedData.length > 0) { // 表格中按钮隐藏控制 |
| | | selectedData.forEach(item => { |
| | | let s = item[btn.controlField] + '' |
| | | let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | disabled = true |
| | | } |
| | |
| | | } |
| | | |
| | | componentDidMount () { |
| | | const { position, btn } = this.props |
| | | const { btn } = this.props |
| | | |
| | | MKEmitter.addListener('triggerBtnId', this.actionTrigger) |
| | | if (position === 'form') { |
| | | if (btn.OpenType === 'formSubmit') { |
| | | MKEmitter.addListener('triggerFormSubmit', this.actionSubmit) |
| | | } |
| | | MKEmitter.addListener('returnModuleParam', this.resetModuleParam) |
| | |
| | | if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) { |
| | | if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 表格中按钮隐藏控制 |
| | | nextProps.selectedData.forEach(item => { |
| | | let s = item[btn.controlField] + '' |
| | | let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | disabled = true |
| | | } |
| | |
| | | const { loading, disabled } = this.state |
| | | |
| | | if (loading || disabled) return |
| | | if (triggerId) { |
| | | if (btn.uuid !== triggerId) return |
| | | if (this.props.lineId && record && record[0] && this.props.lineId !== record[0].$$key) { |
| | | return |
| | | } |
| | | } |
| | | if (triggerId && btn.uuid !== triggerId) return |
| | | |
| | | if (((Tab && Tab.supMenu) || setting.supModule) && !BID) { |
| | | notification.warning({ |
| | |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (type === 'linkbtn' && selectedData && selectedData.length === 1) { |
| | | if (record[0].$Index !== selectedData[0].$Index) { |
| | | return |
| | | } |
| | | } else if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) { |
| | | return |
| | | } |
| | | |
| | | this.setState({autoMatic: type === 'autoMatic'}) |
| | | |
| | | let _this = this |
| | | let data = record || selectedData || [] |
| | | |
| | | |
| | | if (btn.Ot !== 'notRequired' && data.length === 0) { |
| | | // 需要选择行时,校验数据 |
| | | notification.warning({ |
| | |
| | | _resolve() |
| | | }) |
| | | } else { // 超出20个请求时循环执行 |
| | | if (btn.progress === 'progressbar' && btn.$toolbtn) { |
| | | this.setState({ |
| | | loadingTotal: params.length |
| | | }) |
| | | } |
| | | this.innerLoopRequest(params, btn, _resolve) |
| | | } |
| | | } else if (btn.intertype === 'outer') { |
| | |
| | | }) |
| | | } |
| | | |
| | | if (_params.length > 1 && btn.progress === 'progressbar' && btn.$toolbtn) { |
| | | this.setState({ |
| | | loadingTotal: _params.length |
| | | }) |
| | | } |
| | | |
| | | // 循环调用外部接口(包括内部及回调函数) |
| | | this.outerLoopRequest(_params, btn, _resolve, _params.length > 20) |
| | | this.outerLoopRequest(_params, btn, _resolve) |
| | | } else if (btn.intertype === 'custom') { // 系统接口 |
| | | let params = [] |
| | | |
| | |
| | | params = this.getInnerParam(data, formdata) |
| | | } |
| | | |
| | | if (params.length > 1 && btn.progress === 'progressbar' && btn.$toolbtn) { |
| | | this.setState({ |
| | | loadingTotal: params.length |
| | | }) |
| | | } |
| | | |
| | | this.customLoopRequest(params, _resolve) |
| | | } |
| | | } |
| | |
| | | let param = params.shift() |
| | | |
| | | this.setState({ |
| | | loadingNumber: params.length || '' |
| | | loadingNumber: params.length |
| | | }) |
| | | |
| | | let record = { |
| | |
| | | let param = params.shift() |
| | | |
| | | this.setState({ |
| | | loadingNumber: params.length || '' |
| | | loadingNumber: params.length |
| | | }) |
| | | |
| | | let _param = null |
| | |
| | | /** |
| | | * @description 外部请求循环执行 |
| | | */ |
| | | outerLoopRequest = (params, btn, _resolve, widthNumber) => { |
| | | outerLoopRequest = (params, btn, _resolve) => { |
| | | if (!params && params.length === 0) return |
| | | |
| | | let param = params.shift() |
| | | let _outParam = null |
| | | |
| | | if (widthNumber) { |
| | | this.setState({ |
| | | loadingNumber: params.length || '' |
| | | }) |
| | | } |
| | | this.setState({ |
| | | loadingNumber: params.length |
| | | }) |
| | | |
| | | new Promise(resolve => { |
| | | // 内部请求 |
| | |
| | | this.execSuccess(response) |
| | | _resolve() |
| | | } else { |
| | | this.outerLoopRequest(params, btn, _resolve, widthNumber) |
| | | this.outerLoopRequest(params, btn, _resolve) |
| | | } |
| | | } else { |
| | | this.execError(response) |
| | |
| | | this.execSuccess(res) |
| | | _resolve() |
| | | } else { |
| | | this.outerLoopRequest(params, btn, _resolve, widthNumber) |
| | | this.outerLoopRequest(params, btn, _resolve) |
| | | } |
| | | } else { |
| | | this.execError(res) |
| | |
| | | } else if (res && res.ErrCode === '-1') { // 完成后不提示 |
| | | |
| | | } |
| | | |
| | | this.setState({ |
| | | loadingNumber: '', |
| | | loadingTotal: '', |
| | | }) |
| | | |
| | | if (autoMatic) { |
| | | this.setState({ |
| | |
| | | if (btn.output) { |
| | | id = res.mk_b_id || res[btn.output] || '' |
| | | } |
| | | if (res.mk_icon) { |
| | | sessionStorage.setItem('avatar', res.mk_icon) |
| | | } |
| | | let tabId = '' |
| | | if (btn.refreshTab && btn.refreshTab.length > 0) { |
| | | tabId = btn.refreshTab[btn.refreshTab.length - 1] |
| | |
| | | } else if (btn.execSuccess !== 'never') { |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, id, this.state.selines) |
| | | } |
| | | |
| | | btn.syncComponentId && MKEmitter.emit('reloadData', btn.syncComponentId) |
| | | |
| | | if (tabId) { |
| | | MKEmitter.emit('reloadMenuView', tabId, 'table') |
| | |
| | | let node = document.getElementById('tab' + id) |
| | | node && node.click() |
| | | } |
| | | if (btn.anchors && btn.anchors.length > 0) { |
| | | let id = btn.anchors[btn.anchors.length - 1] |
| | | let node = document.getElementById('anchor' + id) |
| | | node && node.scrollIntoView({behavior: 'smooth', block: 'center', inline: 'nearest'}) |
| | | } |
| | | |
| | | if (btn.openmenu && btn.openmenu.length > 0 && btn.MenuID) { |
| | | if (btn.MenuID && Array.isArray(btn.openmenu) && btn.openmenu.length > 0) { |
| | | let newtab = { |
| | | MenuID: btn.MenuID, |
| | | MenuName: btn.MenuName, |
| | |
| | | this.setState({ |
| | | loading: false, |
| | | loadingNumber: '', |
| | | loadingTotal: '', |
| | | visible: false |
| | | }) |
| | | MKEmitter.emit('autoExecOver', btn.uuid, 'error') |
| | |
| | | |
| | | this.setState({ |
| | | loading: false, |
| | | loadingNumber: '' |
| | | loadingNumber: '', |
| | | loadingTotal: '', |
| | | }) |
| | | |
| | | if (res.ErrCode === 'C') { |
| | |
| | | */ |
| | | improveAction = () => { |
| | | const { btn } = this.props |
| | | const { btnconfig, autoMatic } = this.state |
| | | const { btnconfig } = this.state |
| | | |
| | | if (btnconfig) { |
| | | if (!autoMatic && (btnconfig.setting.display === 'prompt' || btnconfig.setting.display === 'exec')) { // 如果表单以是否框展示 |
| | | if (btnconfig.setting.display === 'prompt' || btnconfig.setting.display === 'exec') { // 如果表单以是否框展示 |
| | | this.modelconfirm() |
| | | } else { |
| | | this.setState({ |
| | |
| | | this.setState({ |
| | | btnconfig: _LongParam |
| | | }, () => { |
| | | if (!autoMatic && (_LongParam.setting.display === 'prompt' || _LongParam.setting.display === 'exec')) { // 如果表单以是否框展示 |
| | | if (_LongParam.setting.display === 'prompt' || _LongParam.setting.display === 'exec') { // 如果表单以是否框展示 |
| | | this.modelconfirm() |
| | | } else { |
| | | this.setState({ |
| | |
| | | */ |
| | | handleOk = () => { |
| | | if (!this.formRef) return |
| | | |
| | | this.formRef.handleConfirm().then(res => { |
| | | this.setState({ confirmLoading: true }) |
| | | |
| | |
| | | |
| | | if (!btnconfig || !btnconfig.setting) return null |
| | | |
| | | let title = btnconfig.setting.title |
| | | let title = btn.label |
| | | let width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vw' |
| | | let clickouter = btnconfig.setting.clickouter === 'close' |
| | | |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { btn, show, style } = this.props |
| | | const { loadingNumber, loading, disabled, hidden, check } = this.state |
| | | const { btn } = this.props |
| | | const { loadingNumber, loadingTotal, loading, disabled, hidden, check } = this.state |
| | | |
| | | if (hidden) return null |
| | | |
| | | if (btn.OpenType === 'form') { |
| | | if (btn.formType === 'switch') { |
| | | return <Switch loading={loading} checked={check} disabled={disabled || loading} onChange={(val,e) => {e.stopPropagation();this.actionTrigger()}} style={style} size={btn.size} checkedChildren={btn.openText || ''} unCheckedChildren={btn.closeText || ''}/> |
| | | return <Switch loading={loading} checked={check} disabled={disabled || loading} title={disabled ? (btn.reason || '') : ''} onChange={(val,e) => {e.stopPropagation();this.actionTrigger()}} style={btn.style} className={btn.size === 'large' ? 'ant-switch-large' : ''} size={btn.size} checkedChildren={btn.openText || ''} unCheckedChildren={btn.closeText || ''}/> |
| | | } else { |
| | | return <Checkbox disabled={disabled || loading} checked={check} onChange={(e) => {e.stopPropagation();this.actionTrigger()}} style={style}></Checkbox> |
| | | return <Checkbox disabled={disabled || loading} title={disabled ? (btn.reason || '') : ''} checked={check} onChange={(e) => {e.stopPropagation();this.actionTrigger()}} style={btn.style}></Checkbox> |
| | | } |
| | | } else if (show === 'actionList') { |
| | | return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> |
| | | <Button |
| | | style={style} |
| | | icon={btn.icon} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | className={'mk-btn mk-' + btn.class} |
| | | onClick={() => {this.actionTrigger()}} |
| | | >{(loadingNumber ? `(${loadingNumber})` : '') + btn.label}</Button> |
| | | {this.getModels()} |
| | | </div> |
| | | } else if (show && show.indexOf('plus') > -1) { |
| | | return <div style={{display: 'inline-block'}}> |
| | | <Button |
| | | type="link" |
| | | loading={loading} |
| | | icon={btn.icon || 'plus'} |
| | | style={{fontSize: show.substring(4) + 'px'}} |
| | | onClick={() => {this.actionTrigger()}} |
| | | ></Button> |
| | | {this.getModels()} |
| | | </div> |
| | | } else { // icon、text、 all 卡片 |
| | | let label = '' |
| | | let icon = '' |
| | | |
| | | if (show === 'button') { |
| | | label = btn.label |
| | | icon = btn.icon || '' |
| | | } else if (show === 'link') { |
| | | label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> |
| | | icon = '' |
| | | } else if (show === 'icon') { |
| | | icon = btn.icon || '' |
| | | } else { |
| | | label = btn.label |
| | | } |
| | | |
| | | return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> |
| | | <Button |
| | | type="link" |
| | | title={show === 'icon' ? btn.label : ''} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | style={btn.style || style} |
| | | icon={icon} |
| | | onClick={() => {this.actionTrigger()}} |
| | | >{label}</Button> |
| | | {this.getModels()} |
| | | </div> |
| | | } |
| | | |
| | | let label = '' |
| | | let icon = '' |
| | | let type = 'link' |
| | | let className = '' |
| | | |
| | | if (btn.show === 'button') { |
| | | label = btn.label |
| | | icon = btn.icon || '' |
| | | } else if (btn.show === 'link') { |
| | | label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> |
| | | icon = '' |
| | | } else if (btn.show === 'icon') { |
| | | icon = btn.icon || '' |
| | | } else if (!btn.$toolbtn) { |
| | | icon = btn.icon || '' |
| | | label = btn.label |
| | | className = 'mk-btn mk-' + btn.class |
| | | } else { |
| | | type = '' |
| | | icon = btn.icon || '' |
| | | label = btn.label |
| | | className = 'mk-btn mk-' + btn.class |
| | | } |
| | | |
| | | if (loadingNumber && !loadingTotal && btn.$toolbtn && (!btn.show || btn.show === 'button')) { |
| | | label = (loadingNumber && !loadingTotal ? `(${loadingNumber})` : '') + btn.label |
| | | } |
| | | |
| | | return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> |
| | | <Button |
| | | type={type} |
| | | icon={icon} |
| | | title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | style={btn.style || null} |
| | | className={className} |
| | | onClick={() => {this.actionTrigger()}} |
| | | >{label}</Button> |
| | | {this.getModels()} |
| | | {loadingTotal ? <Progress className="mk-button-progress" percent={(loadingTotal - loadingNumber) / loadingTotal * 100} size="small" showInfo={false} /> : null} |
| | | </div> |
| | | } |
| | | } |
| | | |