From 5088d267c69e87673c85ba302dd9dc62c9da4951 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 16 二月 2020 18:54:49 +0800 Subject: [PATCH] 2020-02-16 --- src/tabviews/formtab/index.jsx | 195 +++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 164 insertions(+), 31 deletions(-) diff --git a/src/tabviews/formtab/index.jsx b/src/tabviews/formtab/index.jsx index 79c1cea..f64cfe6 100644 --- a/src/tabviews/formtab/index.jsx +++ b/src/tabviews/formtab/index.jsx @@ -14,7 +14,7 @@ import FormAction from './actionList' import SubTable from '@/tabviews/subtable' import NotFount from '@/components/404' -import {refreshTabView} from '@/store/action' +import {refreshTabView, modifyTabview} from '@/store/action' import './index.scss' const { TabPane } = Tabs @@ -23,8 +23,9 @@ static propTpyes = { // MenuNo: PropTypes.string, // 鑿滃崟鍙傛暟 // MenuName: PropTypes.string, // 鑿滃崟鍙傛暟 - MenuID: PropTypes.string, // 鑿滃崟Id - param: PropTypes.any // 涓昏〃浼犻�掑弬鏁� + MenuID: PropTypes.string, // 鑿滃崟Id + param: PropTypes.any, // 涓昏〃浼犻�掑弬鏁� + refresh: PropTypes.any // 鍒锋柊涓昏〃椤甸潰 } state = { @@ -45,7 +46,8 @@ pickup: false, // 涓昏〃鏁版嵁闅愯棌鏄剧ず鍒囨崲 isLinkMain: false, // 鏄惁瀛樺湪涓庝富琛ㄥ叧鑱旂殑瀛愯〃 popData: false, // 寮规椤甸潰锛屾墍閫夌殑琛ㄦ牸鏁版嵁 - visible: false // 寮规鏄剧ず闅愯棌鎺у埗 + visible: false, // 寮规鏄剧ず闅愯棌鎺у埗 + primaryId: null } /** @@ -90,18 +92,18 @@ let _arrField = [] // 瀛楁闆� - if (this.props.param && this.props.param.arr_field) { - _arrField = this.props.param.arr_field - } else { - config.groups.forEach(group => { - group.sublist.forEach(item => { - if (!item.field) return + // if (this.props.param && this.props.param.arr_field) { // 浣跨敤鏄剧ず鍒楀瓧娈垫煡璇� + // _arrField = this.props.param.arr_field + // } else { + config.groups.forEach(group => { + group.sublist.forEach(item => { + if (!item.field) return - _arrField.push(item.field) - }) + _arrField.push(item.field) }) - _arrField = _arrField.join(',') - } + }) + _arrField = _arrField.join(',') + // } // 鏉冮檺杩囨护 config.action = config.action.filter(item => permAction[item.uuid]) @@ -138,15 +140,16 @@ actions: config.action, isLinkMain: _isLinkMain, arr_field: _arrField, - data: config.setting.datatype === 'query' ? null : (this.props.param.data[0] || null), + primaryId: this.props.param.primaryId || '', + data: config.setting.datatype === 'query' ? null : this.props.param.data, BIDs: { mainTable: this.props.param.primaryId || '', - mainTabledata: config.setting.datatype === 'query' ? '' : (this.props.param.data[0] || '') + mainTabledata: config.setting.datatype === 'query' ? '' : this.props.param.data } }, () => { this.improveSelectOption(config.groups) - if (config.setting.datatype === 'query') { + if (config.setting.datatype === 'query' && this.props.param.primaryId) { this.loadmaindata() } }) @@ -279,15 +282,34 @@ */ async loadmaindata () { const { setting } = this.state - let param = this.getCustomParam() + + if (setting.datatype !== 'query') return + + let param = null + + if (setting.interType !== 'inner' || (setting.interType === 'inner' && setting.innerFunc)) { + param = this.getCustomParam() + } else { + param = this.getDefaultParam() + } + + if (!param) return // 鏈幏鍙栧弬鏁版椂锛屼笉鍙戣姹� let result = await Api.genericInterface(param) if (result.status) { + let _data = result.data[0] || '' + let _primaryId = '' + + if (_data) { + _primaryId = _data[setting.primaryKey] || '' + } + this.setState({ - data: result.data, + data: _data, + primaryId: _primaryId, BIDs: { - mainTable: (result.data[0] && result.data[0][setting.primaryKey]) || '', - mainTabledata: result.data[0] || '' + mainTable: _primaryId, + mainTabledata: _data } }) } else { @@ -300,10 +322,56 @@ } /** + * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁� + */ + getDefaultParam = () => { + const { arr_field, setting, primaryId } = this.state + + if (!arr_field) { + notification.warning({ + top: 92, + message: '鏈缃〃鍗曞瓧娈碉紒', + duration: 10 + }) + return null + } else if (!primaryId) { + notification.warning({ + top: 92, + message: '鏈幏鍙栧埌涓婚敭鍊硷紒', + duration: 10 + }) + return null + } + + + let param = { + func: 'sPC_Get_TableData', + obj_name: 'data', + arr_field: arr_field, + appkey: window.GLOB.appkey || '' + } + + let _dataresource = setting.dataresource + + if (/\s/.test(_dataresource)) { + _dataresource = '(' + _dataresource + ') tb' + } + + let LText = `select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() from ${_dataresource}) tmptable where ${setting.primaryKey}=${primaryId}` + + param.LText = Utils.formatOptions(LText) + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.secretkey = Utils.encrypt(param.LText, param.timestamp) + param.DateCount = '' + + return param + } + + /** * @description 鑾峰彇鐢ㄦ埛鑷畾涔夊瓨鍌ㄨ繃绋嬩紶鍙� */ getCustomParam = () => { - const { setting } = this.state + const { setting, primaryId } = this.state let param = {} @@ -323,21 +391,73 @@ } } + param[setting.primaryKey] = primaryId + return param } /** * @description 鎸夐挳鎿嶄綔瀹屾垚鍚庯紙鎴愬姛鎴栧け璐ワ級锛岄〉闈㈠埛鏂帮紝閲嶇疆椤电爜鍙婇�夋嫨椤� */ - refreshbyaction = (btn, type) => { - if (btn.execSuccess === 'grid' && type === 'success') { + refreshbyaction = (btn, type, primaryId) => { + if (type === 'success' && btn.afterExecSuccess === 'notclose') { + this.setState({ + primaryId: primaryId + }, () => { + if (btn.execSuccess === 'refresh') { + this.loadmaindata() + } + }) + } else if (type === 'success' && btn.afterExecSuccess === 'close') { + if (this.props.refresh) { + this.props.refresh(btn.execSuccess) + } else { + if (btn.execSuccess !== 'never') { + let PMenu = { + MenuID: this.props.param.parentId || '', + position: btn.execSuccess + } + this.props.refreshTabView(PMenu) + } - } else if (btn.execError === 'grid' && type === 'error') { + let tabs = this.props.tabviews.filter(tab => { + tab.selected = false + if (tab.MenuID === this.props.param.parentId) { + tab.selected = true + } - } else if (btn.execSuccess === 'view' && type === 'success') { + return tab.MenuID !== this.props.MenuID + }) - } else if (btn.execError === 'view' && type === 'error') { + this.props.modifyTabview(tabs) + } + } else if (type === 'error' && btn.afterExecError === 'notclose') { + if (btn.execSuccess === 'refresh') { + this.loadmaindata() + } + } else if (type === 'error' && btn.afterExecError === 'close') { + if (this.props.refresh) { + this.props.refresh(btn.execError) + } else { + if (btn.execError !== 'never') { + let PMenu = { + MenuID: this.props.param.parentId || '', + position: btn.execError + } + this.props.refreshTabView(PMenu) + } + let tabs = this.props.tabviews.filter(tab => { + tab.selected = false + if (tab.MenuID === this.props.param.parentId) { + tab.selected = true + } + + return tab.MenuID !== this.props.MenuID + }) + + this.props.modifyTabview(tabs) + } } } @@ -354,6 +474,10 @@ [type + 'data']: data } }) + } + + getFormData = () => { + return this.formGroupRef.handleConfirm() } UNSAFE_componentWillMount () { @@ -376,11 +500,16 @@ render() { const { setting, actions, loadingview, viewlost, isLinkMain, config, groups, data } = this.state + let hasform = false + + if (groups && (groups.length > 1 || groups[0].sublist.length > 0)) { + hasform = true + } return ( <div className={'formtab ' + (isLinkMain ? 'pick-control' : '')} id={this.state.ContainerId}> {loadingview && <Spin size="large" />} - {groups && (groups.length > 1 || groups[0].sublist.length > 0) ? + {hasform ? <FormGroup dict={this.state.dict} data={data} @@ -389,14 +518,16 @@ wrappedComponentRef={(inst) => this.formGroupRef = inst} /> : null } - {actions ? + {hasform ? <FormAction + logcolumns={[]} setting={setting} actions={actions} dict={this.state.dict} data={this.state.data} MenuID={this.props.MenuID} - logcolumns={[]} + primaryId={this.state.primaryId} + getFormData={this.getFormData} refreshdata={this.refreshbyaction} /> : null } @@ -440,6 +571,7 @@ const mapStateToProps = (state) => { return { + tabviews: state.tabviews, refreshTab: state.refreshTab, permAction: state.permAction } @@ -447,7 +579,8 @@ const mapDispatchToProps = (dispatch) => { return { - refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)) + refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)), + modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)) } } -- Gitblit v1.8.0