| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import moment from 'moment' |
| | | import {connect} from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, Modal, notification, message } from 'antd' |
| | | import md5 from 'md5' |
| | | |
| | | import ExcelIn from './excelin' |
| | | 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 MkIcon from '@/components/mk-icon' |
| | | // import './index.scss' |
| | | |
| | | const { confirm } = Modal |
| | | |
| | | class ExcelInButton extends Component { |
| | | static propTpyes = { |
| | | show: PropTypes.any, // 显示样式 |
| | | BID: PropTypes.string, // 主表ID |
| | | BData: PropTypes.any, // 主表数据 |
| | | selectedData: PropTypes.any, // 子表中选择数据 |
| | | Tab: PropTypes.any, // 如果当前元素为标签时,tab为标签信息 |
| | | btn: PropTypes.object, // 按钮 |
| | | setting: PropTypes.any, // 页面通用设置 |
| | | disabled: PropTypes.any, // 行按钮禁用 |
| | | lineId: PropTypes.any, // 行索引+主键值,用于行按钮双击 |
| | | } |
| | | |
| | | state = { |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | loading: false, |
| | | selines: null, |
| | | disabled: false, |
| | | hidden: false, |
| | | primaryId: '', |
| | | dict: window.GLOB.dict |
| | | } |
| | | |
| | | 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({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) || 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, Tab, BID, btn, selectedData } = this.props |
| | | const { loading, disabled } = this.state |
| | | actionTrigger = (triggerId, record, type, lid) => { |
| | | const { setting, BID, btn, selectedData, LID } = this.props |
| | | const { loading, disabled, dict } = 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 (((Tab && Tab.supMenu) || setting.supModule) && !BID) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '需要上级主键值!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (type === 'linkbtn' && selectedData && selectedData.length === 1) { |
| | | if (record[0].$Index !== selectedData[0].$Index) { |
| | | return |
| | | } |
| | | } |
| | | if (triggerId && btn.uuid !== triggerId) return |
| | | if (type === 'linkbtn' && !btn.$toolbtn && LID !== lid) return |
| | | |
| | | let data = record || selectedData || [] |
| | | |
| | | if (btn.Ot === 'requiredSgl' && data.length !== 1) { |
| | | |
| | | if (setting.supModule && !BID) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: dict['sup_key_req'] || '需要上级主键值!', |
| | | duration: 5 |
| | | }) |
| | | } else if (btn.Ot === 'requiredSgl' && data.length !== 1) { |
| | | // 需要选择单行时,校验数据 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.state.dict['main.action.confirm.selectSingleLine'], |
| | | message: dict['select_single_row'] || '请选择单行数据!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (!btn.verify || !btn.verify.sheet || !btn.verify.columns || btn.verify.columns.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: 'excel导入验证信息未设置!', |
| | | duration: 5 |
| | | } else { |
| | | let primaryId = '' // 导入时行Id |
| | | if (btn.Ot === 'requiredSgl' && setting.primaryKey) { |
| | | primaryId = data[0][setting.primaryKey] || '' |
| | | } |
| | | |
| | | this.setState({ |
| | | selines: data, |
| | | primaryId: primaryId |
| | | }, () => { |
| | | this.refs.excelIn.exceltrigger() |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let primaryId = '' // 导入时行Id |
| | | if (btn.Ot === 'requiredSgl' && setting.primaryKey) { |
| | | primaryId = data[0][setting.primaryKey] || '' |
| | | } |
| | | |
| | | this.setState({ |
| | | selines: data, |
| | | primaryId: primaryId |
| | | }, () => { |
| | | this.refs.excelIn.exceltrigger() |
| | | }) |
| | | |
| | | if (window.GLOB.systemType === 'production') { |
| | | MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '导入Excel'}) |
| | | |
| | | if (window.GLOB.systemType === 'production') { |
| | | MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '导入Excel'}) |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * 4、模态框执行成功后是否关闭 |
| | | * 5、通知主列表刷新 |
| | | */ |
| | | execSuccess = (res) => { |
| | | execSuccess = (res = {}) => { |
| | | const { btn } = this.props |
| | | const { dict } = this.state |
| | | |
| | | if (res && (res.ErrCode === 'S' || !res.ErrCode)) { // 执行成功 |
| | | if (res.ErrCode === 'S' || !res.ErrCode) { // 执行成功 |
| | | notification.success({ |
| | | top: 92, |
| | | message: res.ErrMesg || this.state.dict['main.action.confirm.success'], |
| | | message: res.message || dict['exc_success'] || '执行成功!', |
| | | duration: btn.verify && btn.verify.stime ? btn.verify.stime : 2 |
| | | }) |
| | | } else if (res && res.ErrCode === 'Y') { // 执行成功 |
| | | } else if (res.ErrCode === 'Y') { // 执行成功 |
| | | Modal.success({ |
| | | title: res.ErrMesg || this.state.dict['main.action.confirm.success'] |
| | | title: res.message || dict['exc_success'] || '执行成功!', |
| | | okText: dict['got_it'] || '知道了', |
| | | }) |
| | | } else if (res && res.ErrCode === '-1') { // 完成后不提示 |
| | | } else if (res.ErrCode === '-1') { // 完成后不提示 |
| | | |
| | | } |
| | | |
| | |
| | | loading: false |
| | | }) |
| | | |
| | | let tabId = '' |
| | | if (btn.refreshTab && btn.refreshTab.length > 0) { |
| | | tabId = btn.refreshTab[btn.refreshTab.length - 1] |
| | | } |
| | | |
| | | if (tabId && btn.$MenuID === tabId) { // 刷新当前菜单时,停止其他操作 |
| | | MKEmitter.emit('reloadMenuView', tabId) |
| | | return |
| | | } |
| | | |
| | | if (btn.execSuccess === 'closepoptab') { |
| | | MKEmitter.emit('popclose') |
| | | } else if (btn.execSuccess !== 'never') { |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', this.state.selines) |
| | | } |
| | | |
| | | if (btn.syncComponentId) { |
| | | if (btn.syncComponentId === 'multiComponent') { |
| | | btn.syncComponentIds.forEach((id, i) => { |
| | | setTimeout(() => { |
| | | if (/\$focus/.test(id)) { |
| | | MKEmitter.emit('reloadData', id.split('$')[0], id.split('$')[1]) |
| | | } else { |
| | | MKEmitter.emit('reloadData', id) |
| | | } |
| | | }, 20 * i) |
| | | }) |
| | | } else if (/\$focus/.test(btn.syncComponentId)) { |
| | | MKEmitter.emit('reloadData', btn.syncComponentId.split('$')[0], btn.syncComponentId.split('$')[1]) |
| | | } else { |
| | | MKEmitter.emit('reloadData', btn.syncComponentId) |
| | | } |
| | | } |
| | | |
| | | if (tabId) { |
| | | MKEmitter.emit('reloadMenuView', tabId) |
| | | } |
| | | |
| | | if (btn.switchTab && btn.switchTab.length > 0) { |
| | | let id = btn.switchTab[btn.switchTab.length - 1] |
| | | let node = document.getElementById('tab' + id) |
| | | node && node.click() |
| | | } |
| | | |
| | | if (btn.execSuccess === 'popclose' && btn.$tabId) { // 标签关闭刷新 |
| | | MKEmitter.emit('refreshPopButton', btn.$tabId) |
| | | } |
| | | } |
| | | |
| | |
| | | * 2、excel导出,失败后取消导出按钮加载中状态 |
| | | * 3、通知主列表刷新 |
| | | */ |
| | | execError = (res) => { |
| | | execError = (res = {}) => { |
| | | const { btn } = this.props |
| | | const { dict } = this.state |
| | | |
| | | if (!['LoginError', 'C', '-2', 'E', 'N', 'F', 'NM'].includes(res.ErrCode)) { |
| | | res.ErrCode = 'E' |
| | | } |
| | | |
| | | if (res.ErrCode === 'E') { |
| | | Modal.error({ |
| | | title: res.message || res.ErrMesg, |
| | | title: res.message || dict['exc_fail'] || '执行失败!', |
| | | okText: dict['got_it'] || '知道了' |
| | | }) |
| | | } else if (res.ErrCode === 'N') { |
| | | notification.error({ |
| | | top: 92, |
| | | message: res.message || res.ErrMesg, |
| | | message: res.message || dict['exc_fail'] || '执行失败!', |
| | | duration: btn.verify && btn.verify.ntime ? btn.verify.ntime : 10 |
| | | }) |
| | | } else if (res.ErrCode === 'F') { |
| | | notification.error({ |
| | | className: 'notification-custom-error', |
| | | top: 92, |
| | | message: res.message || res.ErrMesg, |
| | | message: res.message || dict['exc_fail'] || '执行失败!', |
| | | duration: btn.verify && btn.verify.ftime ? btn.verify.ftime : 10 |
| | | }) |
| | | } else if (res.ErrCode === 'NM') { |
| | | message.error(res.message || res.ErrMesg) |
| | | message.error(res.message || dict['exc_fail'] || '执行失败!') |
| | | } |
| | | |
| | | this.setState({ |
| | |
| | | if (btn.execError === 'closepoptab') { |
| | | MKEmitter.emit('popclose') |
| | | } else if (btn.execError !== 'never') { |
| | | let tabId = '' |
| | | if (btn.refreshTab && btn.refreshTab.length > 0) { |
| | | tabId = btn.refreshTab[btn.refreshTab.length - 1] |
| | | } |
| | | if (tabId && btn.$MenuID === tabId) { // 刷新当前菜单时,停止其他操作 |
| | | MKEmitter.emit('reloadMenuView', tabId, 'table') |
| | | return |
| | | } |
| | | |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines) |
| | | |
| | | if (btn.syncComponentId) { |
| | | if (btn.syncComponentId === 'multiComponent') { |
| | | btn.syncComponentIds.forEach((id, i) => { |
| | | setTimeout(() => { |
| | | if (/\$focus/.test(id)) { |
| | | MKEmitter.emit('reloadData', id.split('$')[0], id.split('$')[1]) |
| | | } else { |
| | | MKEmitter.emit('reloadData', id) |
| | | } |
| | | }, 20 * i) |
| | | }) |
| | | } else if (/\$focus/.test(btn.syncComponentId)) { |
| | | MKEmitter.emit('reloadData', btn.syncComponentId.split('$')[0], btn.syncComponentId.split('$')[1]) |
| | | } else { |
| | | MKEmitter.emit('reloadData', btn.syncComponentId) |
| | | } |
| | | } |
| | | |
| | | if (tabId) { |
| | | MKEmitter.emit('reloadMenuView', tabId) |
| | | } |
| | | } |
| | | |
| | | if (btn.execError === 'popclose' && btn.$tabId) { // 标签关闭刷新 |
| | | MKEmitter.emit('refreshPopButton', btn.$tabId) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description Excel 导入 |
| | | */ |
| | | getexceldata = (data, errors, sheetName, errDetail) => { |
| | | const { btn } = this.props |
| | | getexceldata = (data, error) => { |
| | | const { btn, BID } = this.props |
| | | |
| | | if (errors) { |
| | | if (errors === 'notexit') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '工作表《' + sheetName + '》不存在!', |
| | | duration: 5 |
| | | }) |
| | | } else if (errors === 'empty') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '工作表《' + sheetName + '》为空!', |
| | | duration: 5 |
| | | }) |
| | | } else if (errors === 'headerError') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: `工作表《${sheetName}》表头错误,${errDetail}`, |
| | | duration: 5 |
| | | }) |
| | | } |
| | | if (error) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: error, |
| | | duration: 5 |
| | | }) |
| | | |
| | | this.setState({ loading: false }) |
| | | return |
| | | } |
| | | |
| | | if (!data || data.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到工作表《' + sheetName + '》数据!', |
| | | duration: 5 |
| | | }) |
| | | this.setState({ loading: false }) |
| | | return |
| | | } else if (data.length * btn.verify.columns.length > 30000) { |
| | | |
| | | if (data.length * btn.verify.columns.length > 30000) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '当前导入数据量过大,如遇错误提示,请分批导入!', |
| | |
| | | }) |
| | | } |
| | | |
| | | let result = getExcelInSql(btn, data, this.state.dict, (this.props.BID || '')) |
| | | if (btn.intertype === 'system' && window.backend && window.GLOB.CacheData.has('sql_' + btn.uuid)) { |
| | | let ex = window.GLOB.CacheData.get('sql_' + btn.uuid) |
| | | let param = this.getExps(ex, data) |
| | | |
| | | if (result.errors) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: result.errors, |
| | | duration: 5 |
| | | }) |
| | | this.setState({ loading: false }) |
| | | return |
| | | } |
| | | if (param.errors) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: param.errors, |
| | | duration: 5 |
| | | }) |
| | | this.setState({ loading: false }) |
| | | return |
| | | } |
| | | |
| | | let param = { |
| | | ID: this.state.primaryId, |
| | | excel_in: result.lines |
| | | } |
| | | let unCheckParam = null |
| | | |
| | | if (this.props.BID) { |
| | | param.BID = this.props.BID |
| | | } |
| | | if (ex.reps.includes('mk_check_begin')) { |
| | | unCheckParam = fromJS(param).toJS() |
| | | |
| | | if (btn.intertype === 'system') { // 系统存储过程 |
| | | param.func = 'sPC_TableData_InUpDe' |
| | | |
| | | 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.data[0].exps.push({ |
| | | key: 'mk_check_begin', |
| | | value: '' |
| | | }, { |
| | | key: 'mk_check_end', |
| | | value: '' |
| | | }) |
| | | unCheckParam.data[0].exps.push({ |
| | | key: 'mk_check_begin', |
| | | value: 'Y' |
| | | }, { |
| | | key: 'mk_check_end', |
| | | value: 'Y' |
| | | }) |
| | | } |
| | | |
| | | if (unCheckParam) { |
| | | Api.genericInterface(param).then(res => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else if (res.ErrCode === 'C') { |
| | | const that = this |
| | | confirm({ |
| | | title: window.GLOB.dict['exec_sure'] || '请确认', |
| | | content: res.message, |
| | | okText: window.GLOB.dict['ok'] || '确定', |
| | | cancelText: window.GLOB.dict['cancel'] || '取消', |
| | | onOk() { |
| | | return new Promise(resolve => { |
| | | Api.genericInterface(unCheckParam).then(result => { |
| | | if (result.status) { |
| | | that.execSuccess(result) |
| | | } else { |
| | | that.execError(result) |
| | | } |
| | | resolve() |
| | | }) |
| | | }) |
| | | }, |
| | | onCancel() { |
| | | that.execError(res) |
| | | } |
| | | }) |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } else { |
| | | result.sql = result.sql.replace(/@\$|\$@/ig, '') |
| | | result.bottom = result.bottom.replace(/@\$|\$@/ig, '') |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } |
| | | |
| | | 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') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | if (this.props.menuType === 'HS' && param.timestamp) { // 云端验证 |
| | | param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) |
| | | } else { |
| | | let result = getExcelInSql(btn, data, (BID || ''), this.state.primaryId) |
| | | |
| | | if (result.errors) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: result.errors, |
| | | duration: 5 |
| | | }) |
| | | this.setState({ loading: false }) |
| | | return |
| | | } |
| | | |
| | | param.menuname = btn.logLabel |
| | | |
| | | if (window.GLOB.probation) { |
| | | param.s_debug_type = 'Y' |
| | | |
| | | let param = { |
| | | ID: this.state.primaryId, |
| | | excel_in: result.lines |
| | | } |
| | | |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else { |
| | | this.execError(res) |
| | | |
| | | if (BID) { |
| | | param.BID = BID |
| | | } |
| | | |
| | | if (btn.intertype === 'system') { // 系统存储过程 |
| | | param.func = 'sPC_TableData_InUpDe' |
| | | |
| | | delete param.excel_in |
| | | |
| | | // param.excel_in_type = 'true' |
| | | param.exec_type = window.GLOB.execType || 'y' |
| | | param.LText = result.sql |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | |
| | | let unCheckParam = null |
| | | |
| | | if (/\$check@|@check\$/ig.test(param.LText)) { |
| | | unCheckParam = fromJS(param).toJS() |
| | | param.LText = param.LText.replace(/\$check@|@check\$/ig, '') |
| | | } |
| | | }, () => { |
| | | this.execError({}) |
| | | }) |
| | | } else if (btn.intertype === 'inner' && btn.innerFunc) { // 自定义存储过程 |
| | | param.func = btn.innerFunc |
| | | |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else { |
| | | this.execError(res) |
| | | |
| | | param.LText = Utils.formatOptions(param.LText, param.exec_type) |
| | | param.secretkey = Utils.encrypt('', param.timestamp) |
| | | if (window.GLOB.mkHS) { // 云端验证 |
| | | param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) |
| | | } |
| | | }, () => { |
| | | this.execError({}) |
| | | }) |
| | | } else if (btn.intertype === 'outer') { // 外部接口 |
| | | let _outParam = null |
| | | |
| | | new Promise(resolve => { |
| | | // 内部请求 |
| | | if (btn.innerFunc) { |
| | | param.func = btn.innerFunc |
| | | // 存在内部函数时,数据预处理 |
| | | |
| | | if (btn.database === 'sso' && window.GLOB.mainSystemApi) { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | |
| | | param.menuname = btn.logLabel |
| | | |
| | | if (window.GLOB.probation) { |
| | | param.s_debug_type = 'Y' |
| | | } |
| | | |
| | | if (unCheckParam) { |
| | | unCheckParam.LText = unCheckParam.LText.replace(/\$check@/ig, '/*').replace(/@check\$/ig, '*/') |
| | | unCheckParam.LText = Utils.formatOptions(unCheckParam.LText, unCheckParam.exec_type) |
| | | unCheckParam.secretkey = Utils.encrypt('', unCheckParam.timestamp) |
| | | unCheckParam.menuname = btn.logLabel |
| | | |
| | | if (window.GLOB.probation) { |
| | | unCheckParam.s_debug_type = 'Y' |
| | | } |
| | | |
| | | Api.genericInterface(param).then(res => { |
| | | if (res.status) { |
| | | delete res.ErrCode |
| | | delete res.ErrMesg |
| | | delete res.message |
| | | delete res.status |
| | | |
| | | // 使用处理后的数据调用外部接口 |
| | | let keys = Object.keys(res) // 提交外部接口前,添加BID |
| | | if (this.props.BID && keys.filter(key => key.toLowerCase() === 'bid').length === 0) { |
| | | res.BID = this.props.BID |
| | | } |
| | | resolve(res) |
| | | this.execSuccess(res) |
| | | } else if (res.ErrCode === 'C') { |
| | | const that = this |
| | | confirm({ |
| | | title: window.GLOB.dict['exec_sure'] || '请确认', |
| | | content: res.message, |
| | | okText: window.GLOB.dict['ok'] || '确定', |
| | | cancelText: window.GLOB.dict['cancel'] || '取消', |
| | | onOk() { |
| | | return new Promise(resolve => { |
| | | Api.genericInterface(unCheckParam).then(result => { |
| | | if (result.status) { |
| | | that.execSuccess(result) |
| | | } else { |
| | | that.execError(result) |
| | | } |
| | | resolve() |
| | | }) |
| | | }) |
| | | }, |
| | | onCancel() { |
| | | that.execError(res) |
| | | } |
| | | }) |
| | | } else { |
| | | this.execError(res) |
| | | resolve(false) |
| | | } |
| | | }, () => { |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } else { |
| | | resolve(param) |
| | | } |
| | | }).then(res => { |
| | | if (!res) return |
| | | // 外部请求 |
| | | _outParam = fromJS(res).toJS() |
| | | |
| | | if (this.props.menuType === 'HS') { |
| | | if (btn.sysInterface === 'true' && options.cloudServiceApi) { |
| | | param.rduri = options.cloudServiceApi |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | param.rduri = btn.proInterface |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else { |
| | | param.rduri = btn.interface |
| | | this.execError(res) |
| | | } |
| | | } |
| | | } else { |
| | | if (btn.sysInterface === 'true' && window.GLOB.mainSystemApi) { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | param.rduri = btn.proInterface |
| | | } else { |
| | | param.rduri = btn.interface |
| | | } |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } |
| | | |
| | | if (btn.outerFunc) { |
| | | res.func = btn.outerFunc |
| | | } else if (btn.intertype === 'inner' && btn.innerFunc) { // 自定义存储过程 |
| | | param.func = btn.innerFunc |
| | | |
| | | if (btn.recordUser === 'true') { |
| | | param.username = sessionStorage.getItem('User_Name') || '' |
| | | param.fullname = sessionStorage.getItem('Full_Name') || '' |
| | | } |
| | | |
| | | 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) |
| | | if (btn.dataM === 'true') { |
| | | param.dataM = sessionStorage.getItem('dataM') === 'true' ? 'Y' : '' |
| | | } |
| | | |
| | | return Api.genericInterface(res) |
| | | }).then(response => { |
| | | if (!response) return |
| | | // 回调请求 |
| | | if (btn.callbackFunc) { |
| | | // 存在回调函数时,调用 |
| | | delete response.message |
| | | delete response.status |
| | | |
| | | response.func = btn.callbackFunc |
| | | |
| | | let _callbackparam = {..._outParam, ...response} |
| | | return Api.genericInterface(_callbackparam) |
| | | } else { |
| | | if (response.status) { |
| | | this.execSuccess(response) |
| | | |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } else if (btn.intertype === 'outer') { // 外部接口 |
| | | let _outParam = null |
| | | let ver_token = false |
| | | |
| | | new Promise(resolve => { |
| | | // 内部请求 |
| | | if (btn.innerFunc) { |
| | | param.func = btn.innerFunc |
| | | // 存在内部函数时,数据预处理 |
| | | Api.genericInterface(param).then(res => { |
| | | if (res.status) { |
| | | delete res.ErrCode |
| | | delete res.ErrMesg |
| | | delete res.message |
| | | delete res.status |
| | | |
| | | // 使用处理后的数据调用外部接口 |
| | | let keys = Object.keys(res) // 提交外部接口前,添加BID |
| | | if (this.props.BID && keys.filter(key => key.toLowerCase() === 'bid').length === 0) { |
| | | res.BID = this.props.BID |
| | | } |
| | | resolve(res) |
| | | } else { |
| | | this.execError(res) |
| | | resolve(false) |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } else { |
| | | resolve(param) |
| | | } |
| | | }).then(res => { |
| | | if (!res) return |
| | | // 外部请求 |
| | | _outParam = fromJS(res).toJS() |
| | | |
| | | if (btn.sysInterface === 'true') { |
| | | if (window.GLOB.mainSystemApi) { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | } else if (btn.sysInterface === 'external') { |
| | | if (window.GLOB.systemType === 'production') { |
| | | param.$token = btn.exProInterface || '' |
| | | } else { |
| | | param.$token = btn.exInterface || '' |
| | | } |
| | | ver_token = true |
| | | } else { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | param.rduri = btn.proInterface |
| | | } else { |
| | | param.rduri = btn.interface |
| | | } |
| | | let host = window.GLOB.baseurl.replace(/http(s):\/\//, '') |
| | | if (param.rduri.indexOf(host) === -1 && /\/dostars/.test(param.rduri)) { |
| | | param.$login = true |
| | | } |
| | | } |
| | | |
| | | if (btn.outerFunc) { |
| | | res.func = btn.outerFunc |
| | | } |
| | | |
| | | if (window.GLOB.mkHS && res.func === 's_sDataDictb_excelIn') { // s_sDataDictb_excelIn 云端验证 |
| | | let sql = `Declare @UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20),@mk_nation nvarchar(50),@mk_province nvarchar(50),@mk_city nvarchar(50),@mk_district nvarchar(50),@mk_address nvarchar(100),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@tbid Nvarchar(512)` |
| | | param.LText = Utils.formatOptions(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) |
| | | }).then(response => { |
| | | if (!response || response.ErrCode === 'LoginError') return |
| | | // 回调请求 |
| | | if (ver_token && response.ErrCode === 'token_error') { |
| | | response.ErrCode = 'E' |
| | | this.execError(response) |
| | | } else if (btn.callbackFunc ) { |
| | | // 存在回调函数时,调用 |
| | | delete response.message |
| | | delete response.status |
| | | |
| | | response.func = btn.callbackFunc |
| | | |
| | | let _callbackparam = {..._outParam, ...response} |
| | | return Api.genericInterface(_callbackparam) |
| | | } else { |
| | | if (response.status) { |
| | | this.execSuccess(response) |
| | | } else { |
| | | this.execError(response) |
| | | } |
| | | } |
| | | }).then(res => { |
| | | if (!res || res.ErrCode === 'LoginError') return |
| | | |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | |
| | | getExps = (ex, data) => { |
| | | const { BID, btn } = this.props |
| | | const { primaryId } = this.state |
| | | |
| | | let exps = [] |
| | | let values = { |
| | | time_id: Utils.getguid(), |
| | | roleid: sessionStorage.getItem('role_id') || '', |
| | | mk_departmentcode: sessionStorage.getItem('departmentcode') || '', |
| | | mk_organization: sessionStorage.getItem('organization') || '', |
| | | mk_user_type: sessionStorage.getItem('mk_user_type') || '', |
| | | mk_nation: sessionStorage.getItem('nation') || '', |
| | | mk_province: sessionStorage.getItem('province') || '', |
| | | mk_city: sessionStorage.getItem('city') || '', |
| | | mk_district: sessionStorage.getItem('district') || '', |
| | | mk_address: sessionStorage.getItem('address') || '', |
| | | id: primaryId || '', |
| | | bid: BID || '', |
| | | typename: 'admin', |
| | | datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | // mk_check_begin: '', |
| | | // mk_check_end: '' |
| | | } |
| | | |
| | | if (window.GLOB.externalDatabase !== null) { |
| | | values.db = window.GLOB.externalDatabase |
| | | } |
| | | |
| | | let keys = ['delete', 'drop', 'insert', 'truncate', 'update'] |
| | | let errors = [] |
| | | let _topline = btn.verify.range || 0 |
| | | let cols = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] |
| | | for (let i = 0; i < 26; i++) { |
| | | cols.push('A' + cols[i]) |
| | | } |
| | | |
| | | let lines = data.map((item, lindex) => { |
| | | let vals = [] |
| | | btn.verify.columns.forEach((col, cindex) => { |
| | | if (col.import === 'false') return |
| | | |
| | | let val = item[col.Column] !== undefined ? item[col.Column] : '' |
| | | let _colindex = cols[cindex] || (cindex + 1) |
| | | let _position = (_topline + lindex + 1) + '行 ' + _colindex + '列 ' |
| | | |
| | | if (col.import === 'init') { |
| | | if (/^Nvarchar/ig.test(col.type)) { |
| | | val = '' |
| | | } else if (/^Decimal/ig.test(col.type) || /^int/ig.test(col.type)) { |
| | | val = 0 |
| | | } else if (col.type === 'date') { |
| | | val = '1949-10-01' |
| | | } else if (col.type === 'datetime') { |
| | | val = '1949-10-01 00:00:00' |
| | | } |
| | | } else if (/^Nvarchar/ig.test(col.type)) { |
| | | val = val + '' |
| | | |
| | | if (/'/.test(val)) { |
| | | val = val.replace(/'/ig, '"') |
| | | } |
| | | |
| | | val = val.replace(/(^\s+$)|\t+|\v+/ig, '') |
| | | |
| | | if (!val && col.required === 'true') { // 必填校验 |
| | | errors.push(_position + '内容不可为空') |
| | | } else if (col.limit && val.length > col.limit) { // 长度校验 |
| | | errors.push(_position + '内容超长') |
| | | } else { // 关键字校验 |
| | | keys.forEach(key => { |
| | | let _patten = new RegExp('(^' + key + '\\s+)|(\\s+' + key + '\\s+)', 'ig') |
| | | if (_patten.test(val)) { |
| | | errors.push(_position + '含有关键字' + key) |
| | | } |
| | | }) |
| | | } |
| | | } else if (/^Decimal/ig.test(col.type) || /^int/ig.test(col.type)) { |
| | | if (col.required === 'false') { |
| | | if (!val || isNaN(val)) { |
| | | val = 0 |
| | | } |
| | | } else if (!val && val !== 0) { |
| | | errors.push(_position + '内容不可为空') |
| | | } else if (isNaN(val)) { // 检验是否为数值 |
| | | errors.push(_position + '内容应为数值') |
| | | } else if ((col.min || col.min === 0) && val < col.min) { // 最小值检验 |
| | | errors.push(_position + '小于最小值') |
| | | } else if ((col.max || col.max === 0) && val > col.max) { // 最大值检验 |
| | | errors.push(_position + '大于最大值') |
| | | } |
| | | } else if (col.type === 'date' || col.type === 'datetime') { |
| | | if (typeof(val) === 'number') { |
| | | if (val > 2958465 || val <= 0) { // 时间过大或小于等于0 |
| | | errors.push(_position + '时间为负值或太大') |
| | | } else { // 时间格式化 |
| | | if (val < 60) { // 1900-2-29,excel中存在,实际不存在 |
| | | val++ |
| | | } |
| | | if (col.type === 'datetime') { |
| | | val = val - 2 |
| | | let day = Math.floor(val) |
| | | let seconds = Math.round((val - day) * 24 * 60 * 60) |
| | | val = moment('19000101', 'YYYYMMDD').add(day, 'days').add(seconds, 'seconds').format('YYYY-MM-DD HH:mm:ss') |
| | | } else { |
| | | val = moment('19000101', 'YYYYMMDD').add(Math.floor(val - 2), 'days').format('YYYY-MM-DD') |
| | | } |
| | | } |
| | | } else if (typeof(val) === 'string') { |
| | | val = val.replace(/(^\s+$)|\t+|\v+/ig, '') |
| | | if (!val) { |
| | | if (col.required === 'true') { // 时间必填校验 |
| | | errors.push(_position + '内容不可为空') |
| | | } else if (col.type === 'date') { |
| | | val = '1949-10-01' |
| | | } else if (col.type === 'datetime') { |
| | | val = '1949-10-01 00:00:00' |
| | | } |
| | | } else if (!/^[1-9][0-9]{3}/.test(val)) { // 时间正则校验 |
| | | errors.push(_position + '时间格式错误') |
| | | } |
| | | } else { // 时间格式错误 |
| | | errors.push(_position + '时间格式错误') |
| | | } |
| | | } |
| | | }).then(res => { |
| | | if (!res) return |
| | | |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | vals.push(val) |
| | | }) |
| | | |
| | | let _lineIndex = '0000' + (lindex + 1) + '0' |
| | | _lineIndex = _lineIndex.substring(_lineIndex.length - 6) |
| | | |
| | | vals.push(Utils.getguid() + _lineIndex) |
| | | vals.push(BID) |
| | | |
| | | return vals |
| | | }) |
| | | |
| | | if (errors.length) return {errors: errors.join('; ')} |
| | | |
| | | ex.reps.forEach(n => { |
| | | let key = n.toLowerCase() |
| | | if (values.hasOwnProperty(key)) { |
| | | exps.push({ |
| | | key: n, |
| | | value: values[key] |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | exps.push({ |
| | | key: 'mk_excel_data', |
| | | value: lines |
| | | }) |
| | | |
| | | if (btn.$process && btn.verify.workFlow === 'true') { |
| | | let flow = window.GLOB.UserCacheMap.get(btn.$flowId) |
| | | let target = flow ? flow.cells.filter(cell => cell.mknode === 'start')[0] : '' |
| | | |
| | | let error = '' |
| | | let msg = '' |
| | | let status = 0 |
| | | let statusName = '' |
| | | let detailId = '' |
| | | |
| | | if (target) { |
| | | detailId = target.id |
| | | status = target.mkdata.status |
| | | statusName = target.mkdata.statusName |
| | | |
| | | let label = target.attrs && target.attrs.text && target.attrs.text.text ? target.attrs.text.text : '' |
| | | msg = {...target.mkdata, label: label, id: target.id, checkIds: [], checkUsers: []} |
| | | msg = window.btoa(window.encodeURIComponent(JSON.stringify(msg))) |
| | | } else { |
| | | status = 0 |
| | | statusName = '异常' |
| | | error = '工作流无开始节点' |
| | | } |
| | | |
| | | exps.push( |
| | | { key: 'works_flow_error', value: error }, |
| | | { key: 'works_flow_code', value: flow ? flow.flow_code : '' }, |
| | | { key: 'works_flow_name', value: flow ? flow.flow_name : '' }, |
| | | { key: 'works_flow_param', value: msg }, |
| | | { key: 'works_flow_detail_id', value: detailId }, |
| | | { key: 'status', value: status }, |
| | | { key: 'statusname', value: statusName }, |
| | | { key: 'work_group', value: sessionStorage.getItem('work_group') || '' }, |
| | | { key: 'work_grade', value: sessionStorage.getItem('work_grade') || 0 }, |
| | | // { key: 'start_type', value: '开始' }, |
| | | ) |
| | | } |
| | | |
| | | let md5_id = '' |
| | | if (window.GLOB.probation) { |
| | | md5_id = md5(ex.id + JSON.stringify(exps) + Math.floor(new Date().getTime() / 600000)) |
| | | md5_id = moment().format('YYYYMMDDHHmmss') + md5_id.slice(-18) |
| | | } |
| | | |
| | | return { |
| | | $backend: true, |
| | | $type: 's_TableData_InUpDe', |
| | | data: [{ |
| | | id: ex.id, |
| | | menuname: btn.logLabel || '', |
| | | exps: exps, |
| | | md5_id: md5_id |
| | | }] |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { btn, show } = this.props |
| | | const { btn } = this.props |
| | | const { loading, disabled, hidden } = this.state |
| | | |
| | | if (hidden) return null |
| | | |
| | | if (show === 'actionList') { |
| | | return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> |
| | | <Button |
| | | icon={btn.icon} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | className={'mk-btn mk-' + btn.class} |
| | | onClick={() => {this.actionTrigger()}} |
| | | >{btn.label}</Button> |
| | | <ExcelIn btn={btn} triggerExcelIn={() => this.setState({ loading: true })} returndata={this.getexceldata} ref="excelIn" /> |
| | | </div> |
| | | } 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 || '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.setState({ loading: true })} returndata={this.getexceldata} ref="excelIn" /> |
| | | </div> |
| | | 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" |
| | | id={'button' + btn.uuid} |
| | | 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> |
| | | <ExcelIn btn={btn} triggerExcelIn={() => this.setState({ loading: true })} returndata={this.getexceldata} ref="excelIn" /> |
| | | </> |
| | | } |
| | | } |
| | | |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | menuType: state.editLevel |
| | | } |
| | | } |
| | | |
| | | const mapDispatchToProps = () => { |
| | | return {} |
| | | } |
| | | |
| | | export default connect(mapStateToProps, mapDispatchToProps)(ExcelInButton) |
| | | export default ExcelInButton |