| | |
| | | |
| | | 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' |
| | |
| | | } |
| | | |
| | | state = { |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | loading: false, |
| | | selines: null, |
| | | disabled: false, |
| | | hidden: false, |
| | | primaryId: '', |
| | | dict: window.GLOB.dict |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | |
| | | if (data.length > 0) { |
| | | data.forEach(item => { |
| | | let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' |
| | | if (btn.controlVals.includes(s)) { |
| | | if (btn.controlVals.includes(s) || item.$lock) { |
| | | disabled = true |
| | | } |
| | | }) |
| | |
| | | /** |
| | | * @description 触发按钮操作 |
| | | */ |
| | | actionTrigger = (triggerId, record, type) => { |
| | | const { setting, 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 && btn.uuid !== triggerId) return |
| | | if (type === 'linkbtn' && !btn.$toolbtn && LID !== lid) return |
| | | |
| | | let data = record || selectedData || [] |
| | | |
| | | if (setting.supModule && !BID) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '需要上级主键值!', |
| | | message: dict['sup_key_req'] || '需要上级主键值!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) { |
| | | return |
| | | } |
| | | |
| | | let data = record || selectedData || [] |
| | | |
| | | if (btn.Ot === 'requiredSgl' && data.length !== 1) { |
| | | } 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') { // 完成后不提示 |
| | | |
| | | } |
| | | |
| | |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', this.state.selines) |
| | | } |
| | | |
| | | btn.syncComponentId && MKEmitter.emit('reloadData', btn.syncComponentId) |
| | | |
| | | 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 (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({ |
| | |
| | | MKEmitter.emit('popclose') |
| | | } else if (btn.execError !== 'never') { |
| | | 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 (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.props.BID || ''), this.state.primaryId) |
| | | let result = getExcelInSql(btn, data, (BID || ''), this.state.primaryId) |
| | | |
| | | if (result.errors) { |
| | | notification.warning({ |
| | |
| | | excel_in: result.lines |
| | | } |
| | | |
| | | if (this.props.BID) { |
| | | param.BID = this.props.BID |
| | | if (BID) { |
| | | param.BID = BID |
| | | } |
| | | |
| | | 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, '*/') |
| | | } else { |
| | | result.sql = result.sql.replace(/@\$|\$@/ig, '') |
| | | result.bottom = result.bottom.replace(/@\$|\$@/ig, '') |
| | | } |
| | | |
| | | param.excel_in_type = 'true' |
| | | param.LText1 = Utils.formatOptions(result.insert) |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.LText2 = result.bottom |
| | | |
| | | 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.LText2) || /\$check@|@check\$/ig.test(param.LText)) { |
| | | if (/\$check@|@check\$/ig.test(param.LText)) { |
| | | unCheckParam = fromJS(param).toJS() |
| | | param.LText = param.LText.replace(/\$check@|@check\$/ig, '') |
| | | param.LText2 = param.LText2.replace(/\$check@|@check\$/ig, '') |
| | | } |
| | | |
| | | param.LText2 = Utils.formatOptions(param.LText2) |
| | | param.LText = Utils.formatOptions(param.LText) |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | if (window.GLOB.mkHS && param.timestamp) { // 云端验证 |
| | | 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) |
| | | } |
| | | |
| | | if (btn.database === 'sso' && window.GLOB.mainSystemApi) { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | |
| | | param.menuname = btn.logLabel |
| | |
| | | |
| | | if (unCheckParam) { |
| | | unCheckParam.LText = unCheckParam.LText.replace(/\$check@/ig, '/*').replace(/@check\$/ig, '*/') |
| | | unCheckParam.LText = Utils.formatOptions(unCheckParam.LText) |
| | | unCheckParam.LText2 = unCheckParam.LText2.replace(/\$check@/ig, '/*').replace(/@check\$/ig, '*/') |
| | | unCheckParam.LText2 = Utils.formatOptions(unCheckParam.LText2) |
| | | |
| | | unCheckParam.secretkey = Utils.encrypt(unCheckParam.LText, unCheckParam.timestamp) |
| | | |
| | | unCheckParam.LText = Utils.formatOptions(unCheckParam.LText, unCheckParam.exec_type) |
| | | unCheckParam.secretkey = Utils.encrypt('', unCheckParam.timestamp) |
| | | unCheckParam.menuname = btn.logLabel |
| | | |
| | | if (window.GLOB.probation) { |
| | |
| | | } else if (res.ErrCode === 'C') { |
| | | const _this = this |
| | | confirm({ |
| | | title: '继续执行?', |
| | | 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 => { |
| | |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | }, () => { |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } else { |
| | |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | }, () => { |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } |
| | | } 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 (btn.dataM === 'true') { |
| | | param.dataM = sessionStorage.getItem('dataM') === 'true' ? 'Y' : '' |
| | | } |
| | | |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | }, () => { |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } else if (btn.intertype === 'outer') { // 外部接口 |
| | |
| | | this.execError(res) |
| | | resolve(false) |
| | | } |
| | | }, () => { |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | this.execError({}) |
| | | }) |
| | | } else { |
| | |
| | | // 外部请求 |
| | | _outParam = fromJS(res).toJS() |
| | | |
| | | if (window.GLOB.mkHS) { |
| | | if (btn.sysInterface === 'true' && options.cloudServiceApi) { |
| | | param.rduri = options.cloudServiceApi |
| | | param.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | param.rduri = btn.proInterface |
| | | } else { |
| | | param.rduri = btn.interface |
| | | } |
| | | if (btn.sysInterface === 'true') { |
| | | if (window.GLOB.mainSystemApi) { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | } else { |
| | | 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 (btn.sysInterface === 'external') { |
| | | if (window.GLOB.systemType === 'production') { |
| | | param.$token = btn.exProInterface || '' |
| | | } 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 |
| | | } |
| | | 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 (window.GLOB.mkHS && res.func === 's_sDataDictb_excelIn') { // s_sDataDictb_excelIn 云端验证 |
| | | param.LText = Utils.formatOptions(result.sql) |
| | | 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) return |
| | | if (!response || response.ErrCode === 'LoginError') return |
| | | // 回调请求 |
| | | if (ver_token && response.ErrMesg === 'token_error') { |
| | | if (ver_token && response.ErrCode === 'token_error') { |
| | | response.ErrCode = 'E' |
| | | this.execError(response) |
| | | } else if (btn.callbackFunc ) { |
| | | // 存在回调函数时,调用 |
| | |
| | | } |
| | | } |
| | | }).then(res => { |
| | | if (!res) return |
| | | if (!res || res.ErrCode === 'LoginError') return |
| | | |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | |
| | | if (hidden) return null |
| | | |
| | | 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 = '' |
| | | if (btn.show === 'link') { |
| | | label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon} /> : ''}</span> |
| | | } else if (btn.show === 'icon') { |
| | | icon = btn.icon || 'upload' |
| | | } else if (!btn.$toolbtn) { |
| | | icon = btn.icon || '' |
| | | label = btn.label |
| | | className = 'mk-btn mk-' + btn.class |
| | | label = !loading ? <MkIcon type={btn.icon} /> : null |
| | | } else { |
| | | type = '' |
| | | icon = btn.icon || '' |
| | | label = btn.label |
| | | className = 'mk-btn mk-' + btn.class |
| | | label = <span>{!loading && btn.icon ? <MkIcon style={{marginRight: '8px'}} type={btn.icon} /> : ''}{btn.label}</span> |
| | | } |
| | | |
| | | return <> |
| | | <Button |
| | | type={type} |
| | | type="link" |
| | | id={'button' + btn.uuid} |
| | | title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | style={btn.style} |
| | | icon={icon} |
| | | className={className} |
| | | className={btn.hover || ''} |
| | | onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} |
| | | >{label}</Button> |
| | | <ExcelIn btn={btn} triggerExcelIn={() => this.setState({ loading: true })} returndata={this.getexceldata} ref="excelIn" /> |