| | |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, notification, Modal } from 'antd' |
| | | |
| | | 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, // 按钮显示样式控制 |
| | | BID: PropTypes.any, // BID |
| | | BData: PropTypes.any, // 主表数据 |
| | | btn: PropTypes.object, // 按钮 |
| | | selectedData: PropTypes.any, // 子表中选择数据 |
| | | setting: PropTypes.any, // 页面通用设置 |
| | | disabled: PropTypes.any, // 行按钮禁用 |
| | | lineBtn: PropTypes.any, // 是否为行级按钮 |
| | | name: PropTypes.any |
| | | } |
| | | |
| | | state = { |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | disabled: false, |
| | | hidden: false, |
| | | visible: 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] !== undefined ? 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] !== undefined ? 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' && !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) || item.$lock) { |
| | | 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, btn, selectedData, lineBtn } = this.props |
| | | actionTrigger = (triggerId, record, type, lid) => { |
| | | const { btn, selectedData, BID, LID } = this.props |
| | | const { disabled } = this.state |
| | | |
| | | if (disabled) return |
| | | if (triggerId && btn.uuid !== triggerId) return |
| | | |
| | | if (type === 'linkbtn' && lineBtn && !is(fromJS(selectedData || []), fromJS(record))) { |
| | | return |
| | | } |
| | | if (type === 'linkbtn' && !btn.$toolbtn && LID !== lid) return |
| | | |
| | | let data = record || selectedData || [] |
| | | |
| | | if (btn.Ot && btn.Ot !== 'notRequired' && data.length === 0) { |
| | | if (btn.Ot !== 'notRequired' && data.length === 0) { |
| | | // 需要选择行时,校验数据 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.state.dict['main.action.confirm.selectline'], |
| | | message: window.GLOB.dict['select_row'] || '请选择行!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | // 需要选择单行时,校验数据 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.state.dict['main.action.confirm.selectSingleLine'], |
| | | message: window.GLOB.dict['select_single_row'] || '请选择单行数据!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (btn.pageTemplate === 'custom' && window.GLOB.systemType === 'production' && !btn.proUrl) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: window.GLOB.dict['no_prod_link'] || '尚未设置正式系统链接地址!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | let Id = '' |
| | | let name = '' |
| | | let MenuNo = '' |
| | | let Remark = '' |
| | | let lang = '' |
| | | if (btn.Ot === 'requiredSgl' && data[0]) { |
| | | Id = setting.primaryKey ? (data[0][setting.primaryKey] || '') : '' |
| | | Id = data[0].$$uuid || '' |
| | | name = data[0].PrintTempName || '' |
| | | MenuNo = data[0].PrintTempNO || '' |
| | | Remark = data[0].Remark || '' |
| | | lang = data[0].lang_s || '' |
| | | } |
| | | |
| | | let _name = '新页面' |
| | | |
| | | if (btn.pageTemplate === 'billprint') { |
| | | _name = '单据打印' |
| | | if (btn.Ot === 'required' && data && data.length > 0) { |
| | | data.forEach((item, i) => { |
| | | let _id = setting.primaryKey ? (item[setting.primaryKey] || '') : '' |
| | | let url = '#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: _id, tempId: btn.printTemp, dataM: sessionStorage.getItem('dataM') }))) |
| | | window.open(url) |
| | | if (btn.preHandle === 'true' && btn.pre_func) { |
| | | MKEmitter.emit('queryModuleParam', btn.$menuId, (res) => { |
| | | let searches = {} |
| | | res.search && res.search.forEach(item => { |
| | | searches[item.key] = item.value |
| | | }) |
| | | |
| | | if (btn.Ot === 'requiredOnce') { |
| | | Id = data.map(item => item.$$uuid).filter(Boolean).join(',') |
| | | } |
| | | |
| | | if (btn.Ot === 'required') { |
| | | data.forEach(item => { |
| | | let _param = { id: item.$$uuid || '', tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM')} |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('btn', 'searches', 'data', 'param', 'systemType', btn.pre_func) |
| | | _param = func(btn, searches, [item], _param, window.GLOB.systemType) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | |
| | | if (!_param || _param.error) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: _param ? _param.error : '未获取到打印参数,自定义脚本错误!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify(_param)))) |
| | | }) |
| | | } else { |
| | | let _param = { id: Id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM')} |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('btn', 'searches', 'data', 'param', 'systemType', btn.pre_func) |
| | | _param = func(btn, searches, data, _param, window.GLOB.systemType) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | |
| | | if (!_param || _param.error) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: _param ? _param.error : '未获取到打印参数,自定义脚本错误!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify(_param)))) |
| | | } |
| | | }) |
| | | } else { |
| | | window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: Id, tempId: btn.printTemp, dataM: sessionStorage.getItem('dataM') })))) |
| | | if (btn.Ot === 'required') { |
| | | data.forEach(item => { |
| | | let _id = item.$$uuid || '' |
| | | let url = '#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: _id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM') }))) |
| | | window.open(url) |
| | | }) |
| | | } else if (btn.Ot === 'requiredOnce') { |
| | | Id = data.map(item => item.$$uuid).filter(Boolean).join(',') |
| | | |
| | | window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: Id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM') })))) |
| | | } else { |
| | | window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: Id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM') })))) |
| | | } |
| | | } |
| | | } else if (btn.pageTemplate === 'billprintTemp') { |
| | | let src = '#/menudesign/' + window.btoa(window.encodeURIComponent(JSON.stringify({ MenuType: 'billPrint', MenuId: Id, MenuNo: MenuNo, MenuName: name || '打印', Remark: Remark }))) |
| | | let src = '#/menudesign/' + window.btoa(window.encodeURIComponent(JSON.stringify({ MenuType: 'billPrint', MenuId: Id, MenuNo: MenuNo, MenuName: name || '打印', lang }))) |
| | | window.open(src) |
| | | } else if (btn.pageTemplate === 'print') { |
| | | let cloudmsg = '&cuid=' + (sessionStorage.getItem('CloudUserID') || '') + '&clid=' + (sessionStorage.getItem('CloudLoginUID') || '') + '&cun=' + (sessionStorage.getItem('CloudUserName') || '') |
| | | let msg = '&uid=' + sessionStorage.getItem('UserID') + '&lid=' + sessionStorage.getItem('LoginUID') + '&un=' + sessionStorage.getItem('User_Name') |
| | | let src = '#/print/' + window.btoa('ID=' + Id + msg + cloudmsg) |
| | | let src = '#/print/' + window.btoa(window.encodeURIComponent(JSON.stringify({ ID: Id, lang }))) |
| | | window.open(src) |
| | | } else if (btn.pageTemplate === 'pay') { |
| | | let _p = `ID=${Id}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID')}&logo=${window.GLOB.doclogo}&name=${sessionStorage.getItem('Full_Name')}&icp=${window.GLOB.ICP}©Right=${window.GLOB.copyRight}` |
| | |
| | | cancelText: '支付遇到问题', |
| | | onOk() { |
| | | // 支付后刷新界面 |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, 'grid', btn) |
| | | MKEmitter.emit('reloadMenuView', btn.$MenuID) |
| | | }, |
| | | onCancel() { |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, 'grid', btn) |
| | |
| | | window.open(url) |
| | | } else if (btn.pageTemplate === 'custom') { |
| | | let url = btn.url |
| | | let con = '?' |
| | | if (window.GLOB.systemType === 'production') { |
| | | url = btn.proUrl |
| | | } |
| | | |
| | | if (/\?/ig.test(url)) { |
| | | con = '&' |
| | | if (btn.Ot === 'notRequired' && BID) { |
| | | Id = BID |
| | | } |
| | | |
| | | if (btn.Ot === 'requiredSgl' && btn.joint !== 'false') { |
| | | if (/#\/iframe\//.test(url)) { |
| | | url = url.replace(/@loginuid@/ig, sessionStorage.getItem('LoginUID')) |
| | | url = url + '/' + Id |
| | | |
| | | let menu = { |
| | | MenuID: btn.uuid, |
| | | MenuName: btn.label, |
| | | type: 'iframe', |
| | | OpenType: 'newtab', |
| | | src: url |
| | | } |
| | | MKEmitter.emit('modifyTabs', menu) |
| | | |
| | | return |
| | | } |
| | | |
| | | if (btn.joint === 'true') { |
| | | let con = '?' |
| | | |
| | | if (/\?/ig.test(url)) { |
| | | con = '&' |
| | | } |
| | | url = url + `${con}id=${Id}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}` |
| | | } else if (btn.Ot === 'requiredSgl' && btn.joint === 'false') { |
| | | url = url + `${con}id=${Id}` |
| | | } else if (btn.joint !== 'false') { |
| | | url = url + `${con}appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}` |
| | | } else if (/@/.test(url)) { |
| | | url = url.replace(/@id@/ig, Id) |
| | | url = url.replace(/@appkey@/ig, window.GLOB.appkey) |
| | | url = url.replace(/@userid@/ig, sessionStorage.getItem('UserID')) |
| | | url = url.replace(/@LoginUID@/ig, sessionStorage.getItem('LoginUID')) |
| | | |
| | | if (btn.Ot === 'requiredSgl' && data[0]) { |
| | | Object.keys(data[0]).forEach(key => { |
| | | if (/^\$/.test(key)) return |
| | | let reg = new RegExp('@' + key + '@', 'ig') |
| | | url = url.replace(reg, data[0][key]) |
| | | }) |
| | | } |
| | | } |
| | | |
| | | window.open(url) |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { btn, show } = this.props |
| | | const { btn, name } = this.props |
| | | const { disabled, hidden } = this.state |
| | | |
| | | if (hidden) return null |
| | | |
| | | if (show === 'actionList') { |
| | | return ( |
| | | <Button |
| | | className={'mk-btn mk-' + btn.class} |
| | | icon={btn.icon} |
| | | disabled={disabled} |
| | | title={disabled ? (btn.reason || '') : ''} |
| | | 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={disabled ? (btn.reason || '') : (show === 'icon' ? btn.label : '')} |
| | | style={btn.style} |
| | | disabled={disabled} |
| | | icon={icon} |
| | | onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} |
| | | >{label}</Button> |
| | | ) |
| | | if (btn.show === 'link') { |
| | | label = <span>{name || btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon} /> : ''}</span> |
| | | } else if (btn.show === 'icon') { |
| | | label = <MkIcon type={btn.icon} /> |
| | | } else { |
| | | label = <span>{btn.icon ? <MkIcon style={{marginRight: '8px'}} type={btn.icon} /> : ''}{name || btn.label}</span> |
| | | } |
| | | |
| | | return ( |
| | | <Button |
| | | type="link" |
| | | id={'button' + btn.uuid} |
| | | title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')} |
| | | style={btn.style || null} |
| | | disabled={disabled} |
| | | className={btn.hover || ''} |
| | | onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} |
| | | >{label}</Button> |
| | | ) |
| | | } |
| | | } |
| | | |