| | |
| | | import moment from 'moment' |
| | | import {connect} from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, Modal, notification, message } from 'antd' |
| | | import { Button, Modal, notification, message, Icon } from 'antd' |
| | | |
| | | import ExcelIn from './excelin' |
| | | import Utils from '@/utils/utils.js' |
| | | import Utils, { getExcelInSql } from '@/utils/utils.js' |
| | | import options from '@/store/options.js' |
| | | 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 './index.scss' |
| | | |
| | | class ExcelInButton extends Component { |
| | | static propTpyes = { |
| | | show: PropTypes.any, // 显示样式 |
| | | position: PropTypes.any, // 按钮位置,工具栏为toolbar |
| | | BID: PropTypes.string, // 主表ID |
| | | BData: PropTypes.any, // 主表数据 |
| | | selectedData: PropTypes.any, // 子表中选择数据 |
| | | Tab: PropTypes.any, // 如果当前元素为标签时,tab为标签信息 |
| | | MenuID: PropTypes.string, // 菜单ID |
| | | btn: PropTypes.object, // 按钮 |
| | | columns: PropTypes.array, // 字段列 |
| | | setting: PropTypes.any, // 页面通用设置 |
| | | ContainerId: PropTypes.any, // tab页面ID,用于弹窗控制 |
| | | updateStatus: PropTypes.func, // 按钮状态更新 |
| | | triggerBtn: PropTypes.any, |
| | | } |
| | | |
| | | state = { |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | loading: false, |
| | | disabled: false, |
| | | primaryId: '', |
| | | } |
| | | |
| | | /** |
| | | * @description 外部触发按钮点击 |
| | | */ |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (nextProps.triggerBtn && !is(fromJS(this.props.triggerBtn), fromJS(nextProps.triggerBtn)) && nextProps.triggerBtn.button.uuid === this.props.btn.uuid) { |
| | | this.actionTrigger(nextProps.triggerBtn.data) |
| | | UNSAFE_componentWillMount () { |
| | | const { btn, selectedData } = this.props |
| | | let disabled = false |
| | | |
| | | 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({disabled}) |
| | | } |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | | return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | componentDidMount () { |
| | | const { position } = this.props |
| | | |
| | | if (position === 'toolbar') { |
| | | MKEmitter.addListener('triggerBtnId', this.actionTrigger) |
| | | } |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | const { btn, selectedData } = this.props |
| | | |
| | | if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) { |
| | | let disabled = false |
| | | |
| | | 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}) |
| | | } |
| | | } |
| | | |
| | | componentWillUnmount () { |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | MKEmitter.removeListener('triggerBtnId', this.actionTrigger) |
| | | } |
| | | |
| | | /** |
| | |
| | | this.setState({ |
| | | loading: true |
| | | }) |
| | | this.props.updateStatus('start') |
| | | } else if (type === 'over') { |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | this.props.updateStatus('over') |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 触发按钮操作 |
| | | */ |
| | | actionTrigger = (record) => { |
| | | actionTrigger = (triggerId, record) => { |
| | | const { setting, Tab, BID, btn, selectedData } = this.props |
| | | const { loading } = this.state |
| | | |
| | | if (Tab && Tab.supMenu && !BID) { |
| | | if ((triggerId && btn.uuid !== triggerId) || loading) return |
| | | |
| | | if (((Tab && Tab.supMenu) || setting.supModule) && !BID) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '需要上级主键值!', |
| | |
| | | return |
| | | } |
| | | |
| | | let data = [] |
| | | |
| | | if (record) { // 表格中触发按钮 |
| | | data = [record] |
| | | } else { |
| | | data = selectedData || [] |
| | | } |
| | | let data = record || selectedData || [] |
| | | |
| | | if (btn.Ot === 'requiredSgl' && data.length !== 1) { |
| | | // 需要选择单行时,校验数据 |
| | |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | if (btn.verify && btn.verify.sheet && btn.verify.columns && btn.verify.columns.length > 0) { |
| | | let primaryId = '' // 导入时行Id |
| | | if (btn.Ot === 'requiredSgl') { |
| | | primaryId = data[0][setting.primaryKey] || '' |
| | | } |
| | | |
| | | this.setState({ |
| | | primaryId: primaryId |
| | | }, () => { |
| | | this.refs.excelIn.exceltrigger() |
| | | }) |
| | | } else { |
| | | } else if (!btn.verify || !btn.verify.sheet || !btn.verify.columns || btn.verify.columns.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: 'excel导入验证信息未设置!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let primaryId = '' // 导入时行Id |
| | | if (btn.Ot === 'requiredSgl' && setting.primaryKey) { |
| | | primaryId = data[0][setting.primaryKey] || '' |
| | | } |
| | | |
| | | this.setState({ |
| | | primaryId: primaryId |
| | | }, () => { |
| | | this.refs.excelIn.exceltrigger() |
| | | }) |
| | | |
| | | if (window.GLOB.systemType === 'production') { |
| | | MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '导入Excel'}) |
| | | } |
| | | } |
| | | |
| | |
| | | loading: false |
| | | }) |
| | | |
| | | this.props.updateStatus('refresh', btn.execSuccess) |
| | | if (btn.execSuccess !== 'never') { |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn) |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | loading: false |
| | | }) |
| | | |
| | | this.props.updateStatus('refresh', btn.execError) |
| | | if (btn.execError !== 'never') { |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description Excel 导入 |
| | | */ |
| | | getexceldata = (data, errors) => { |
| | | getexceldata = (data, errors, sheetName, errDetail) => { |
| | | const { btn } = this.props |
| | | |
| | | if (errors) { |
| | | if (errors === 'notexit') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '工作表《' + btn.verify.sheet + '》不存在!', |
| | | message: '工作表《' + sheetName + '》不存在!', |
| | | duration: 5 |
| | | }) |
| | | } else if (errors === 'empty') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '工作表《' + btn.verify.sheet + '》为空!', |
| | | message: '工作表《' + sheetName + '》为空!', |
| | | duration: 5 |
| | | }) |
| | | } else if (errors === 'headerError') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '工作表《' + btn.verify.sheet + '》表头设置错误!', |
| | | message: `工作表《${sheetName}》表头错误,${errDetail}`, |
| | | duration: 5 |
| | | }) |
| | | } |
| | |
| | | if (!data || data.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到工作表《' + btn.verify.sheet + '》数据!', |
| | | message: '未获取到工作表《' + sheetName + '》数据!', |
| | | duration: 5 |
| | | }) |
| | | this.updateStatus('over') |
| | | return |
| | | } else if (data.length * btn.verify.columns.length > 30000) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '当前导入数据量过大,如遇错误提示,请分批导入!', |
| | | duration: 5 |
| | | }) |
| | | } |
| | | |
| | | let result = Utils.getExcelInSql(btn, data, this.state.dict) |
| | | let result = getExcelInSql(btn, data, this.state.dict, (this.props.BID || '')) |
| | | |
| | | if (result.errors) { |
| | | notification.warning({ |
| | |
| | | param.BID = this.props.BID |
| | | } |
| | | |
| | | if (btn.intertype === 'inner' && !btn.innerFunc) { // 系统存储过程 |
| | | if (btn.intertype === 'system') { // 系统存储过程 |
| | | param.func = 'sPC_TableData_InUpDe' |
| | | |
| | | if (this.props.dataManager) { // 数据权限 |
| | | if (sessionStorage.getItem('dataM') === 'true') { // 数据权限 |
| | | result.sql = result.sql.replace(/\$@/ig, '/*') |
| | | result.sql = result.sql.replace(/@\$/ig, '*/') |
| | | result.bottom = result.bottom.replace(/\$@/ig, '/*') |
| | |
| | | result.bottom = result.bottom.replace(/@\$|\$@/ig, '') |
| | | } |
| | | |
| | | param.LText_insert = Utils.formatOptions(result.insert) |
| | | param.LText_bottom = Utils.formatOptions(result.bottom) |
| | | param.excel_in_type = 'true' |
| | | param.LText1 = Utils.formatOptions(result.insert) |
| | | param.LText2 = Utils.formatOptions(result.bottom) |
| | | param.LText = Utils.formatOptions(result.sql) |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | if (this.props.menuType === 'HS' && param.timestamp) { // 云端验证 |
| | | param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true) |
| | | param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) |
| | | } |
| | | |
| | | param.menuname = btn.logLabel |
| | | |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | |
| | | }).then(res => { |
| | | if (!res) return |
| | | // 外部请求 |
| | | _outParam = JSON.parse(JSON.stringify(res)) |
| | | _outParam = fromJS(res).toJS() |
| | | |
| | | if (this.props.menuType === 'HS') { |
| | | if (btn.sysInterface === 'true' && options.cloudServiceApi) { |
| | | param.rduri = options.cloudServiceApi |
| | | } else if (btn.sysInterface !== 'true') { |
| | | param.rduri = btn.interface |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | param.rduri = btn.proInterface |
| | | } else { |
| | | param.rduri = btn.interface |
| | | } |
| | | } |
| | | } else { |
| | | if (btn.sysInterface === 'true' && window.GLOB.mainSystemApi) { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } else if (btn.sysInterface !== 'true') { |
| | | param.rduri = btn.interface |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | param.rduri = btn.proInterface |
| | | } else { |
| | | param.rduri = btn.interface |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (btn.outerFunc) { |
| | | res.func = btn.outerFunc |
| | | } |
| | | |
| | | if (this.props.menuType === 'HS' && res.func === 's_sDataDictb_excelIn') { // s_sDataDictb_excelIn 云端验证 |
| | | param.LText = Utils.formatOptions(result.sql) |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) |
| | | } |
| | | |
| | | return Api.genericInterface(res) |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { btn } = this.props |
| | | const { loading } = this.state |
| | | const { btn, show } = this.props |
| | | const { loading, disabled } = this.state |
| | | |
| | | return ( |
| | | <div className="mk-btn-wrap"> |
| | | if (show === 'actionList') { |
| | | return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> |
| | | <Button |
| | | className={'mk-btn mk-' + btn.class} |
| | | icon={btn.icon} |
| | | onClick={() => {this.actionTrigger()}} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | className={'mk-btn mk-' + btn.class} |
| | | onClick={() => {this.actionTrigger()}} |
| | | >{btn.label}</Button> |
| | | <ExcelIn MenuID={this.props.MenuID} btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" /> |
| | | <ExcelIn btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" /> |
| | | </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 ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> |
| | | icon = '' |
| | | } else if (show === 'icon') { |
| | | icon = btn.icon || 'upload' |
| | | // } else if (show === 'text') { |
| | | } 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} |
| | | icon={icon} |
| | | onClick={() => {this.actionTrigger()}} |
| | | >{label}</Button> |
| | | <ExcelIn btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" /> |
| | | </div> |
| | | } |
| | | } |
| | | } |
| | | |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | menuType: state.editLevel, |
| | | dataManager: state.dataManager |
| | | menuType: state.editLevel |
| | | } |
| | | } |
| | | |