| | |
| | | import { Button, notification, Modal } from 'antd' |
| | | |
| | | import Api from '@/api' |
| | | import zhCN from '@/locales/zh-CN/main.js' |
| | | import enUS from '@/locales/en-US/main.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import MkIcon from '@/components/mk-icon' |
| | | // import './index.scss' |
| | |
| | | |
| | | class NewPageButton extends Component { |
| | | static propTpyes = { |
| | | show: PropTypes.any, // 按钮显示样式控制 |
| | | MenuID: PropTypes.any, // 菜单ID |
| | | BData: PropTypes.any, // 主表数据 |
| | | BID: PropTypes.string, // 主表ID |
| | |
| | | } |
| | | |
| | | state = { |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | disabled: false, |
| | | hidden: false, |
| | | loading: false |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { btn, selectedData, BData } = this.props |
| | | let disabled = false |
| | | const { btn, selectedData, BData, disabled } = this.props |
| | | |
| | | if (btn.controlField && selectedData && selectedData.length > 0) { // 表格中按钮隐藏控制 |
| | | selectedData.forEach(item => { |
| | | let s = item[btn.controlField] + '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | disabled = true |
| | | } |
| | | }) |
| | | this.setState({hidden: disabled && btn.control === 'hidden'}) |
| | | } else if (btn.control === 'parent') { |
| | | if (!BData || !BData.hasOwnProperty(btn.controlField)) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | let s = BData[btn.controlField] + '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | this.setState({hidden: false}) |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (this.props.disabled || disabled) { |
| | | if (btn.controlField) { |
| | | this.setStatus(btn, selectedData || [], BData, disabled) |
| | | } else if (disabled) { |
| | | this.setState({disabled: true}) |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | const { btn, selectedData, BData } = this.props |
| | | const { btn } = this.props |
| | | |
| | | let disabled = false |
| | | 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] + '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | disabled = true |
| | | } |
| | | }) |
| | | } |
| | | this.setState({disabled, hidden: disabled && btn.control === 'hidden'}) |
| | | } else if (btn.control === 'parent' && !is(fromJS(nextProps.BData || {}), fromJS(BData || {}))) { |
| | | if (!nextProps.BData || !nextProps.BData.hasOwnProperty(btn.controlField)) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | let s = nextProps.BData[btn.controlField] + '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | this.setState({hidden: false}) |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (nextProps.disabled || disabled) { |
| | | this.setState({disabled: true}) |
| | | if (btn.controlField) { |
| | | this.setStatus(btn, nextProps.selectedData || [], nextProps.BData, nextProps.disabled) |
| | | } else { |
| | | this.setState({disabled: false}) |
| | | this.setState({disabled: nextProps.disabled === true}) |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | MKEmitter.removeListener('triggerBtnId', this.actionTrigger) |
| | | } |
| | | |
| | | setStatus = (btn, data, BData, disprop) => { |
| | | let disabled = false |
| | | let hidden = false |
| | | |
| | | if (btn.control !== 'parent') { |
| | | if (data.length > 0) { |
| | | data.forEach(item => { |
| | | let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' |
| | | if (btn.controlVals.includes(s)) { |
| | | disabled = true |
| | | } |
| | | }) |
| | | } else if (btn.controlVals.includes('')) { |
| | | disabled = true |
| | | } |
| | | } else { |
| | | if (!BData || !BData.hasOwnProperty(btn.controlField)) { |
| | | hidden = true |
| | | } else { |
| | | let s = BData[btn.controlField] + '' |
| | | if (btn.controlVals.includes(s)) { |
| | | hidden = true |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (disabled && btn.control === 'hidden') { |
| | | hidden = true |
| | | } |
| | | |
| | | if (disprop) { |
| | | disabled = true |
| | | } |
| | | |
| | | this.setState({hidden, disabled}) |
| | | } |
| | | |
| | | /** |
| | | * @description 触发按钮操作 |
| | | */ |
| | | actionTrigger = (triggerId, record, type) => { |
| | | const { setting, selectedData, btn, MenuID } = this.props |
| | | actionTrigger = (triggerId, record, type, lid) => { |
| | | const { setting, selectedData, btn, MenuID, LID } = this.props |
| | | const { loading, disabled } = this.state |
| | | |
| | | if ((triggerId && btn.uuid !== triggerId) || loading || disabled) return |
| | | if (loading || disabled) return |
| | | if (triggerId && btn.uuid !== triggerId) return |
| | | if (type === 'linkbtn' && !btn.$toolbtn && LID !== lid) return |
| | | |
| | | if (btn.funcType === 'closetab') { |
| | | MKEmitter.emit('closeTabView', MenuID || btn.$MenuID) |
| | |
| | | MKEmitter.emit('reloadMenuView', btn.refreshTab[btn.refreshTab.length - 1], 'table') |
| | | } |
| | | return |
| | | } else if (type === 'linkbtn' && selectedData && selectedData.length === 1) { |
| | | if (record[0].$Index !== selectedData[0].$Index) { |
| | | return |
| | | } |
| | | } |
| | | |
| | | let data = record || selectedData || [] |
| | |
| | | // 需要选择单行时,校验数据 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.state.dict['main.action.confirm.selectSingleLine'], |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (!setting.primaryKey) { |
| | | // 需要选择行时,校验是否设置主键 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未设置主键!', |
| | | message: window.GLOB.dict['select_single_row'] || '请选择单行数据!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | let _this = this |
| | | |
| | | let param = { |
| | | func: 'webapi_ChangeUser' |
| | | func: 'webapi_ChangeUser', |
| | | login_city: sessionStorage.getItem('city') || '', |
| | | login_id_address: sessionStorage.getItem('ipAddress') || '', |
| | | domain_name: window.btoa(window.encodeURIComponent(window.GLOB.host)), |
| | | } |
| | | |
| | | if (this.props.BID) { |
| | |
| | | param[setting.primaryKey] = primaryId |
| | | |
| | | confirm({ |
| | | title: this.state.dict['main.action.confirm.tip'], |
| | | title: window.GLOB.dict['exec_sure'] || '确定要执行吗?', |
| | | okText: window.GLOB.dict['ok'] || '确定', |
| | | cancelText: window.GLOB.dict['cancel'] || '取消', |
| | | onOk() { |
| | | return new Promise(resolve => { |
| | | Api.genericInterface(param).then(res => { |
| | |
| | | sessionStorage.setItem('Full_Name', res.FullName) |
| | | sessionStorage.setItem('avatar', res.icon || '') |
| | | sessionStorage.setItem('dataM', res.dataM ? 'true' : '') |
| | | sessionStorage.setItem('localDataM', res.dataM ? 'true' : '') |
| | | sessionStorage.setItem('debug', res.debug || '') |
| | | sessionStorage.setItem('role_id', res.role_id || '') |
| | | sessionStorage.setItem('departmentcode', res.departmentcode || '') |
| | | sessionStorage.setItem('organization', res.organization || '') |
| | | sessionStorage.setItem('localRole_id', res.role_id || '') |
| | | sessionStorage.setItem('mk_user_type', res.mk_user_type || '') |
| | | |
| | | if (res.paas_externalDatabase) { |
| | | sessionStorage.setItem('externalDatabase', res.paas_externalDatabase) |
| | | window.GLOB.externalDatabase = `[${res.paas_externalDatabase}]..` |
| | | } else { |
| | | sessionStorage.removeItem('externalDatabase') |
| | | } |
| | | |
| | | sessionStorage.removeItem('CloudAvatar') |
| | | sessionStorage.removeItem('cloudDataM') |
| | |
| | | } else { |
| | | notification.error({ |
| | | top: 92, |
| | | message: res.message || res.ErrMesg, |
| | | message: res.message || '执行失败!', |
| | | duration: btn.verify && btn.verify.ntime ? btn.verify.ntime : 10 |
| | | }) |
| | | _this.setState({loading: false}) |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { btn, show } = this.props |
| | | const { btn } = this.props |
| | | const { loading, disabled, hidden } = this.state |
| | | |
| | | if (hidden) return null |
| | | |
| | | if (show === 'actionList') { |
| | | return ( |
| | | <Button |
| | | icon={btn.icon} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | className={'mk-btn mk-' + btn.class} |
| | | onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} |
| | | >{btn.label}</Button> |
| | | ) |
| | | } else { // icon、text、 all 卡片 |
| | | let label = '' |
| | | let icon = '' |
| | | let label = '' |
| | | |
| | | 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 if (show === 'text') { |
| | | } else { |
| | | label = btn.label |
| | | } |
| | | |
| | | return ( |
| | | <Button |
| | | type="link" |
| | | title={show === 'icon' ? btn.label : ''} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | style={btn.style} |
| | | icon={icon} |
| | | onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} |
| | | >{label}</Button> |
| | | ) |
| | | if (btn.show === 'link') { |
| | | label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon} /> : ''}</span> |
| | | } else if (btn.show === 'icon') { |
| | | label = !loading ? <MkIcon type={btn.icon} /> : null |
| | | } else { |
| | | label = <span>{!loading && btn.icon ? <MkIcon style={{marginRight: '8px'}} type={btn.icon} /> : ''}{btn.label}</span> |
| | | } |
| | | |
| | | return ( |
| | | <Button |
| | | type="link" |
| | | title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | style={btn.style} |
| | | className={btn.hover || ''} |
| | | onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} |
| | | >{label}</Button> |
| | | ) |
| | | } |
| | | } |
| | | |