From 3ca91a731665962918a026f521c556f4745ebf35 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 16 十一月 2020 19:20:19 +0800 Subject: [PATCH] 2020-11-16 --- src/tabviews/subtable/index.jsx | 146 +++++++++++++++++++++++++++++++++++------------- 1 files changed, 107 insertions(+), 39 deletions(-) diff --git a/src/tabviews/subtable/index.jsx b/src/tabviews/subtable/index.jsx index cb53311..f59e1da 100644 --- a/src/tabviews/subtable/index.jsx +++ b/src/tabviews/subtable/index.jsx @@ -36,8 +36,6 @@ mainSearch: PropTypes.any, // 涓昏〃鎼滅储鏉′欢 ContainerId: PropTypes.any, // 涓夌骇鑿滃崟Container(html) ID handleTableId: PropTypes.func, // 鎺у埗琛ㄦ牸鏁版嵁鍒囨崲鏃讹紝鏇存柊鍦ㄤ富琛ㄤ腑鐨刬d - handleMainTable: PropTypes.func, // 鍒锋柊涓昏〃 - refreshtabs: PropTypes.any, // 鏍囩鍒锋柊鎺у埗 userConfig: PropTypes.any, // 鐢ㄦ埛鑷畾涔夎缃� } @@ -81,8 +79,6 @@ this.getStatFieldsValue(nextProps.BID, 'refresh') } }) - } else if (this.state.config && nextProps.refreshtabs && nextProps.refreshtabs.includes(this.props.Tab.uuid)) { - this.reloadtable() } else if (!this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { if (this.state.setting) { this.setState({}, () => { @@ -464,6 +460,65 @@ } /** + * @description 鑾峰彇鍗曡鏁版嵁 + */ + async loadmainLinedata (id) { + const { mainSearch, BID } = this.props + const { setting, arr_field, search, orderBy, pageIndex, pageSize } = this.state + + let searches = fromJS(search).toJS() + if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 + searches = [...mainSearch, ...searches] + } + + this.setState({ + loading: true + }) + + let _orderBy = orderBy || setting.order + let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType, this.props.dataManager, id) + + if (param.func === 'sPC_Get_TableData') { + param.menuname = this.props.Tab.label || '' + } + + let result = await Api.genericInterface(param) + if (result.status) { + let data = fromJS(this.state.data).toJS() + if (result.data && result.data[0]) { + let _data = result.data[0] + + try { + data = data.map(item => { + if (item[setting.primaryKey] === _data[setting.primaryKey]) { + _data.key = item.key + return _data + } else { + return item + } + }) + } catch { + console.warn('鏁版嵁鏌ヨ閿欒') + } + } + + this.setState({ + data: data, + loading: false + }) + } else { + this.setState({ + loading: false + }) + notification.error({ + top: 92, + message: result.message, + duration: 10 + }) + } + } + + /** * @description 鑾峰彇鍚堣瀛楁鍊� */ getStatFieldsValue = (bid, type) => { @@ -573,49 +628,44 @@ /** * @description 琛ㄦ牸鍒锋柊 */ - reloadtable = () => { - MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 鍒楄〃閲嶇疆 - this.setState({ - pageIndex: 1 - }, () => { + reloadtable = (btn) => { + if (!btn || btn.resetPageIndex !== 'false') { + MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 鍒楄〃閲嶇疆 + this.setState({ + pageIndex: 1 + }, () => { + this.loadmaindata() + this.getStatFieldsValue() + }) + } else { + MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid, 'false') // 鍒楄〃閲嶇疆 this.loadmaindata() this.getStatFieldsValue() - }) - } - - /** - * @description 椤甸潰鍒锋柊锛岄噸鏂拌幏鍙栭厤缃� - */ - reloadview = () => { - this.setState({ loadingview: true, viewlost: false, lostmsg: '', config: null, searchlist: null, actions: null, - columns: null, arr_field: '', setting: null, data: null, total: 0, loading: false, pageIndex: 1, pageSize: 10, - orderBy: '', search: [] - }, () => { - this.loadconfig() - }) + } } /** * @description 鎸夐挳鎿嶄綔瀹屾垚鍚庯紙鎴愬姛鎴栧け璐ワ級锛岄〉闈㈠埛鏂帮紝閲嶇疆椤电爜鍙婇�夋嫨椤� */ - refreshbyaction = (position) => { - const { Tab } = this.props + refreshbyaction = (position, btn) => { + const { Tab, SupMenuID, BID } = this.props - if (position === 'grid') { - this.reloadtable() - } else if (position === 'view') { - this.reloadview() - } else if (position === 'maingrid') { - if (Tab.isTreeNode) { - this.reloadtable() + if (position === 'grid' || position === 'view') { + this.reloadtable(btn) + } else if (position === 'maingrid' || position === 'mainline') { + this.reloadtable(btn) + if (Tab.supMenu === 'mainTable') { + MKEmitter.emit('reloadData', SupMenuID, (BID || 'empty')) // 涓昏〃閲嶇疆 + } else if (Tab.supMenu) { + MKEmitter.emit('reloadData', Tab.supMenu, (BID || 'empty')) // 涓昏〃閲嶇疆 + } else if (!Tab.supMenu && Tab.level === 0) { + MKEmitter.emit('reloadData', SupMenuID, (BID || 'empty')) // 鏍戝舰缁撴瀯锛�0绾ф爣绛� } - this.props.handleMainTable('maingrid') } else if (position === 'equaltab') { - this.reloadtable() - this.props.handleMainTable('equaltab') - } else if (position === 'mainline') { - this.reloadtable() - this.props.handleMainTable('mainline') + this.reloadtable(btn) + if (Tab.equalTab && Tab.equalTab.length > 0) { + MKEmitter.emit('reloadData', Tab.equalTab.join(',')) // 鍚岀骇鏍囩閲嶇疆 + } } } @@ -671,13 +721,30 @@ this.setState({chartId: uuid}) } + reloadData = (menuId, id) => { + const { MenuID } = this.props + + if (menuId.indexOf(MenuID) === -1) return + if (id === 'empty') return + + if (!id) { + this.reloadtable() + } else { + this.loadmainLinedata(id) + } + } + UNSAFE_componentWillMount() { // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁 this.loadconfig() } - shouldComponentUpdate (nextProps, nextState) { // handleMainTable 鍑芥暟鍒ゆ柇鏃朵笉鐩哥瓑 - return !is(fromJS({...this.props, handleMainTable: '', handleTableId: ''}), fromJS({...nextProps, handleMainTable: '', handleTableId: ''})) || !is(fromJS(this.state), fromJS(nextState)) + shouldComponentUpdate (nextProps, nextState) { // handleTableId 鍑芥暟鍒ゆ柇鏃朵笉鐩哥瓑 + return !is(fromJS({...this.props, handleTableId: ''}), fromJS({...nextProps, handleTableId: ''})) || !is(fromJS(this.state), fromJS(nextState)) + } + + componentDidMount () { + MKEmitter.addListener('reloadData', this.reloadData) } /** @@ -687,6 +754,7 @@ this.setState = () => { return } + MKEmitter.removeListener('reloadData', this.reloadData) } render() { -- Gitblit v1.8.0