| | |
| | | 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, Drawer } from 'antd' |
| | | |
| | | import Api from '@/api' |
| | | import Utils, { getSysDefaultSql } from '@/utils/utils.js' |
| | |
| | | btnconfig: null, |
| | | loading: false, |
| | | loadingNumber: '', |
| | | disabled: false, |
| | | checkParam: null |
| | | } |
| | | |
| | | moduleParams = null |
| | | |
| | | 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) { |
| | |
| | | componentDidMount () { |
| | | const { position } = this.props |
| | | |
| | | if (position === 'toolbar') { |
| | | MKEmitter.addListener('triggerBtnId', this.actionTrigger) |
| | | } else if (position === 'form') { |
| | | MKEmitter.addListener('triggerBtnId', this.actionTrigger) |
| | | if (position === 'form') { |
| | | MKEmitter.addListener('triggerFormSubmit', this.actionSubmit) |
| | | } |
| | | MKEmitter.addListener('returnModuleParam', this.resetModuleParam) |
| | | } |
| | | |
| | | 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}) |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | MKEmitter.removeListener('triggerBtnId', this.actionTrigger) |
| | | MKEmitter.removeListener('triggerFormSubmit', this.actionSubmit) |
| | | MKEmitter.removeListener('returnModuleParam', this.resetModuleParam) |
| | | } |
| | | |
| | | actionSubmit = (res) => { |
| | |
| | | }) |
| | | |
| | | this.execSubmit(this.state.tabledata, () => {}, res.form) |
| | | } |
| | | |
| | | resetModuleParam = (menuId, btnId, param) => { |
| | | const { btn } = this.props |
| | | |
| | | if (btn.$menuId !== menuId || btn.uuid !== btnId || !param) return |
| | | |
| | | this.moduleParams = param |
| | | } |
| | | |
| | | /** |
| | |
| | | * @description 触发按钮操作 |
| | | */ |
| | | actionTrigger = (triggerId, record) => { |
| | | const { setting, Tab, BID, btn, selectedData } = this.props |
| | | const { Tab, BID, btn, selectedData, setting } = this.props |
| | | const { loading } = this.state |
| | | |
| | | if ((triggerId && btn.uuid !== triggerId) || loading) return |
| | | |
| | | if (Tab && Tab.supMenu && !BID) { |
| | | if (((Tab && Tab.supMenu) || setting.supModule) && !BID) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '需要上级主键值!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | if (btn.$syncModule && !triggerId) { |
| | | MKEmitter.emit('getSyncData', btn.$syncModule, btn.uuid) |
| | | return |
| | | } |
| | | |
| | |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.state.dict['main.action.confirm.selectSingleLine'], |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (btn.OpenType !== 'formSubmit' && !setting.primaryKey) { |
| | | // 需要选择行时,校验是否设置主键 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未设置主键!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | |
| | | let primaryId = '' |
| | | |
| | | if (btn.Ot === 'requiredSgl' || btn.Ot === 'requiredOnce') { |
| | | if ((btn.Ot === 'requiredSgl' || btn.Ot === 'requiredOnce') && setting.primaryKey) { |
| | | let ids = data.map(d => { return d[setting.primaryKey] || ''}) |
| | | ids = ids.filter(Boolean) |
| | | primaryId = ids.join(',') |
| | |
| | | param.ID = primaryId |
| | | |
| | | if (retmsg) { |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, '', param, data[0], columns, this.props.Tab, retmsg) // 数据源 |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, '', param, data[0], columns, this.props.Tab, retmsg, this.moduleParams, Utils.getAllSearchOptions) // 数据源 |
| | | param.LText = sql |
| | | param.$callbacksql = callbacksql |
| | | } else { |
| | | param.LText = getSysDefaultSql(btn, setting, '', param, data[0], columns, this.props.Tab) // 数据源 |
| | | param.LText = getSysDefaultSql(btn, setting, '', param, data[0], columns, this.props.Tab, false, this.moduleParams, Utils.getAllSearchOptions) // 数据源 |
| | | } |
| | | |
| | | if (sessionStorage.getItem('dataM') === 'true') { // 数据权限 |
| | |
| | | param.ID = primaryId || Utils.getguid() |
| | | |
| | | if (retmsg) { |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab, retmsg) // 数据源 |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab, retmsg, this.moduleParams, Utils.getAllSearchOptions) // 数据源 |
| | | param.LText = sql |
| | | param.$callbacksql = callbacksql |
| | | } else { |
| | | param.LText = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab) // 数据源 |
| | | param.LText = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab, false, this.moduleParams, Utils.getAllSearchOptions) // 数据源 |
| | | } |
| | | |
| | | if (sessionStorage.getItem('dataM') === 'true') { // 数据权限 |
| | |
| | | param.ID = primaryId |
| | | |
| | | if (retmsg) { |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab, retmsg) // 数据源 |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab, retmsg, this.moduleParams, Utils.getAllSearchOptions) // 数据源 |
| | | param.LText = sql |
| | | param.$callbacksql = callbacksql |
| | | } else { |
| | | param.LText = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab) // 数据源 |
| | | param.LText = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab, false, this.moduleParams, Utils.getAllSearchOptions) // 数据源 |
| | | } |
| | | |
| | | if (sessionStorage.getItem('dataM') === 'true') { // 数据权限 |
| | |
| | | param.ID = primaryId |
| | | |
| | | if (retmsg) { |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, '', param, cell, columns, this.props.Tab, retmsg) // 数据源 |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, '', param, cell, columns, this.props.Tab, retmsg, this.moduleParams, Utils.getAllSearchOptions) // 数据源 |
| | | param.LText = sql |
| | | param.$callbacksql = callbacksql |
| | | } else { |
| | | param.LText = getSysDefaultSql(btn, setting, '', param, cell, columns, this.props.Tab) // 数据源 |
| | | param.LText = getSysDefaultSql(btn, setting, '', param, cell, columns, this.props.Tab, false, this.moduleParams, Utils.getAllSearchOptions, Utils.getAllSearchOptions) // 数据源 |
| | | } |
| | | |
| | | if (sessionStorage.getItem('dataM') === 'true') { // 数据权限 |
| | |
| | | param.ID = Utils.getguid() |
| | | |
| | | if (retmsg) { |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab, retmsg) // 数据源 |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab, retmsg, this.moduleParams, Utils.getAllSearchOptions) // 数据源 |
| | | param.LText = sql |
| | | param.$callbacksql = callbacksql |
| | | } else { |
| | | param.LText = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab) // 数据源 |
| | | param.LText = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab, false, this.moduleParams, Utils.getAllSearchOptions) // 数据源 |
| | | } |
| | | |
| | | if (sessionStorage.getItem('dataM') === 'true') { // 数据权限 |
| | |
| | | param.ID = primaryId |
| | | |
| | | if (retmsg) { |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab, retmsg) // 数据源 |
| | | const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab, retmsg, this.moduleParams, Utils.getAllSearchOptions) // 数据源 |
| | | param.LText = sql |
| | | param.$callbacksql = callbacksql |
| | | } else { |
| | | param.LText = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab) // 数据源 |
| | | param.LText = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab, false, this.moduleParams, Utils.getAllSearchOptions) // 数据源 |
| | | } |
| | | |
| | | if (sessionStorage.getItem('dataM') === 'true') { // 数据权限 |
| | |
| | | |
| | | let primaryId = '' |
| | | |
| | | if (btn.Ot === 'requiredSgl' || btn.Ot === 'requiredOnce') { |
| | | if ((btn.Ot === 'requiredSgl' || btn.Ot === 'requiredOnce') && setting.primaryKey) { |
| | | let ids = data.map(d => { return d[setting.primaryKey] || ''}) |
| | | ids = ids.filter(Boolean) |
| | | primaryId = ids.join(',') |
| | | } |
| | | |
| | | param[setting.primaryKey] = primaryId // 设置主键参数 |
| | | if (setting.primaryKey) { |
| | | param[setting.primaryKey] = primaryId // 设置主键参数 |
| | | } |
| | | |
| | | if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') { // 表单 |
| | | formdata.forEach(_data => { |
| | |
| | | param[_data.key] = _data.value |
| | | }) |
| | | } |
| | | param[setting.primaryKey] = primaryId |
| | | if (setting.primaryKey) { |
| | | param[setting.primaryKey] = primaryId |
| | | } |
| | | |
| | | if (this.props.menuType === 'HS' && param.func === 's_sDataDictb_TBBack' && param.LTextOut) { // 函数 s_sDataDictb_TBBack 云端验证 |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | |
| | | * @description 按钮提交执行 |
| | | */ |
| | | execSubmit = (data, _resolve, formdata) => { |
| | | const { setting, btn } = this.props |
| | | this.moduleParams = null |
| | | |
| | | if ( |
| | | (btn.intertype === 'system' || (btn.intertype === 'custom' && btn.procMode === 'system')) && |
| | | btn.sqlType !== 'insert' && btn.Ot !== 'notRequired' && btn.verify && btn.verify.invalid === 'true' && |
| | | setting.dataresource |
| | | ) { |
| | | MKEmitter.emit('queryModuleParam', btn.$menuId, btn.uuid) |
| | | setTimeout(() => { |
| | | if (this.moduleParams) { |
| | | this.execRealSubmit(data, _resolve, formdata) |
| | | } else { |
| | | setTimeout(() => { |
| | | this.execRealSubmit(data, _resolve, formdata) |
| | | }, 100) |
| | | } |
| | | }, 50) |
| | | } else { |
| | | this.execRealSubmit(data, _resolve, formdata) |
| | | } |
| | | } |
| | | |
| | | execRealSubmit = (data, _resolve, formdata) => { |
| | | const { setting, btn } = this.props |
| | | if (btn.intertype === 'system' || btn.intertype === 'inner') { // 系统接口 |
| | | let params = [] |
| | |
| | | }) |
| | | |
| | | Api.directRequest(url, btn.method, param, btn.cross).then(res => { |
| | | if (typeof(res) !== 'object' || Array.isArray(res)) { |
| | | if (typeof(res) !== 'object') { |
| | | let error = '未知的返回结果!' |
| | | |
| | | if (typeof(res) === 'string') { |
| | |
| | | |
| | | this.customCallbackRequest(params, result, record, _resolve) |
| | | } else { |
| | | if (Array.isArray(res)) { |
| | | res = { data: res } |
| | | } |
| | | res.mk_api_key = mkey |
| | | this.customCallbackRequest(params, res, record, _resolve) |
| | | } |
| | |
| | | subObjs.push(val) |
| | | } |
| | | } else { |
| | | if (typeof(val) === 'string') { |
| | | val = val.replace(/'/ig, '"') |
| | | } |
| | | keys.push(key) |
| | | vals.push(`'${val}'`) |
| | | } |
| | |
| | | let _param = { |
| | | templatecode: verify.noteCode, // 模板编码 |
| | | TypeCharOne: verify.noteTemp, // N不同内容,Y相同内容 |
| | | ID: verify.noteId || '' // 模板Id,暂时未使用 |
| | | } |
| | | |
| | | _param.submitdate = res.submitdate |
| | |
| | | _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp) |
| | | |
| | | _param.rduri = 'http://sso.mk9h.cn/webapi/dostar' |
| | | _param.appkey = window.GLOB.appkey || '' |
| | | _param.rduri = 'http://sso.mk9h.cn/webapi/dostars' |
| | | |
| | | Api.dostarInterface(_param).then(result => { |
| | | _param.userid = 'bh0bapabtd45epsgra79segbch6c1ibk' |
| | | _param.LoginUID = 'bh0bapabtd45epsgra79segbch6c1ibk' |
| | | |
| | | Api.getLocalConfig(_param).then(result => { |
| | | if (!result.status) { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | _initval = '' |
| | | } |
| | | |
| | | let _type = item.type |
| | | |
| | | if (['date', 'datemonth', 'datetime'].includes(_type) && item.declareType === 'nvarchar(50)') { |
| | | _type = 'text' |
| | | } |
| | | |
| | | result.push({ |
| | | key: item.field, |
| | | readonly: item.readonly === 'true', |
| | | readin: _readin, |
| | | fieldlen: _fieldlen, |
| | | writein: item.writein !== 'false', |
| | | type: item.type, |
| | | type: _type, |
| | | value: _initval |
| | | }) |
| | | }) |
| | |
| | | |
| | | let title = btnconfig.setting.title |
| | | let width = btnconfig.setting.width + 'vw' |
| | | let clickouter = false |
| | | let container = document.body |
| | | let clickouter = btnconfig.setting.clickouter === 'close' |
| | | |
| | | if ( |
| | | (setting.tabType === 'main' && btnconfig.setting.container === 'tab' && this.props.ContainerId) || |
| | | (btnconfig.setting.container === 'tab' && btn.ContainerId) |
| | | ) { |
| | | width = btnconfig.setting.width + '%' |
| | | container = () => document.getElementById(this.props.ContainerId || btn.ContainerId) |
| | | if (btnconfig.setting.display === 'drawer') { |
| | | let height = '100vh' |
| | | if (btnconfig.setting.placement === 'top' || btnconfig.setting.placement === 'bottom') { |
| | | width = '100vw' |
| | | height = btnconfig.setting.width + 'vh' |
| | | } |
| | | return ( |
| | | <Drawer |
| | | title={title} |
| | | width={width} |
| | | height={height} |
| | | maskClosable={clickouter} |
| | | onClose={this.handleCancel} |
| | | visible={visible} |
| | | placement={btnconfig.setting.placement || 'right'} |
| | | bodyStyle={{ paddingBottom: 80 }} |
| | | destroyOnClose |
| | | > |
| | | <MutilForm |
| | | BID={BID} |
| | | dict={this.state.dict} |
| | | menuType={this.props.menuType} |
| | | action={btnconfig} |
| | | inputSubmit={this.handleOk} |
| | | data={this.state.tabledata[0]} |
| | | BData={this.props.BData} |
| | | wrappedComponentRef={(inst) => this.formRef = inst} |
| | | /> |
| | | <div style={{ position: 'absolute', zIndex: 1, right: 0, bottom: 0, width: '100%', borderTop: '1px solid #e9e9e9', padding: '10px 16px', background: '#fff', textAlign: 'right'}}> |
| | | <Button onClick={this.handleCancel} style={{ marginRight: 8 }}> |
| | | 取消 |
| | | </Button> |
| | | <Button onClick={this.handleOk} loading={this.state.confirmLoading} type="primary"> |
| | | 确定 |
| | | </Button> |
| | | </div> |
| | | </Drawer> |
| | | ) |
| | | } else { |
| | | let container = document.body |
| | | |
| | | if ( |
| | | (setting.tabType === 'main' && btnconfig.setting.container === 'tab' && this.props.ContainerId) || |
| | | (btnconfig.setting.container === 'tab' && btn.ContainerId) |
| | | ) { |
| | | width = btnconfig.setting.width + '%' |
| | | container = () => document.getElementById(this.props.ContainerId || btn.ContainerId) |
| | | } |
| | | return ( |
| | | <Modal |
| | | title={title} |
| | | maskClosable={clickouter} |
| | | getContainer={container} |
| | | wrapClassName='action-modal' |
| | | visible={visible} |
| | | width={width} |
| | | onOk={this.handleOk} |
| | | confirmLoading={this.state.confirmLoading} |
| | | onCancel={this.handleCancel} |
| | | destroyOnClose |
| | | > |
| | | <MutilForm |
| | | BID={BID} |
| | | dict={this.state.dict} |
| | | menuType={this.props.menuType} |
| | | action={btnconfig} |
| | | inputSubmit={this.handleOk} |
| | | data={this.state.tabledata[0]} |
| | | BData={this.props.BData} |
| | | wrappedComponentRef={(inst) => this.formRef = inst} |
| | | /> |
| | | </Modal> |
| | | ) |
| | | } |
| | | |
| | | if (btnconfig.setting.clickouter === 'close') { |
| | | clickouter = true |
| | | } |
| | | |
| | | return ( |
| | | <Modal |
| | | title={title} |
| | | maskClosable={clickouter} |
| | | getContainer={container} |
| | | wrapClassName='action-modal' |
| | | visible={visible} |
| | | width={width} |
| | | onOk={this.handleOk} |
| | | confirmLoading={this.state.confirmLoading} |
| | | onCancel={this.handleCancel} |
| | | destroyOnClose |
| | | > |
| | | <MutilForm |
| | | BID={BID} |
| | | dict={this.state.dict} |
| | | menuType={this.props.menuType} |
| | | action={btnconfig} |
| | | inputSubmit={this.handleOk} |
| | | data={this.state.tabledata[0]} |
| | | BData={this.props.BData} |
| | | wrappedComponentRef={(inst) => this.formRef = inst} |
| | | /> |
| | | </Modal> |
| | | ) |
| | | } |
| | | |
| | | render() { |
| | | const { btn, show, style } = this.props |
| | | const { loadingNumber, loading, visible } = this.state |
| | | const { loadingNumber, loading, disabled } = this.state |
| | | |
| | | if (show === 'actionList') { |
| | | return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> |
| | |
| | | style={style} |
| | | icon={btn.icon} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | className={'mk-btn mk-' + btn.class} |
| | | onClick={() => {this.actionTrigger()}} |
| | | >{(loadingNumber ? `(${loadingNumber})` : '') + btn.label}</Button> |
| | | {visible ? this.getModels() : null} |
| | | {this.getModels()} |
| | | </div> |
| | | } else if (show && show.indexOf('plus') > -1) { |
| | | return <div className="mk-btn-wrap"> |
| | |
| | | style={{fontSize: show.substring(4) + 'px'}} |
| | | onClick={() => {this.actionTrigger()}} |
| | | ></Button> |
| | | {visible ? this.getModels() : null} |
| | | {this.getModels()} |
| | | </div> |
| | | } else { // icon、text、 all 卡片 |
| | | return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> |
| | |
| | | type="link" |
| | | title={show === 'icon' ? btn.label : ''} |
| | | loading={loading} |
| | | style={btn.btnstyle || style} |
| | | disabled={disabled} |
| | | style={btn.style || style} |
| | | icon={show === 'text' ? '' : (btn.icon || '')} |
| | | onClick={() => {this.actionTrigger()}} |
| | | >{show === 'icon' && btn.icon ? '' : btn.label}</Button> |
| | | {visible ? this.getModels() : null} |
| | | {this.getModels()} |
| | | </div> |
| | | } |
| | | } |