From fa381753ef2a2b25b1c0722549ac17e333da79be Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 06 九月 2022 22:50:54 +0800 Subject: [PATCH] 2022-09-06 --- src/tabviews/custom/components/card/data-card/index.jsx | 144 ++++++++++++++++++++++++++++++------------------ 1 files changed, 90 insertions(+), 54 deletions(-) diff --git a/src/tabviews/custom/components/card/data-card/index.jsx b/src/tabviews/custom/components/card/data-card/index.jsx index ff0e6b9..0d24ab6 100644 --- a/src/tabviews/custom/components/card/data-card/index.jsx +++ b/src/tabviews/custom/components/card/data-card/index.jsx @@ -2,6 +2,7 @@ import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' import { Spin, Empty, notification, message, Row, Col, Pagination } from 'antd' +import { DownOutlined } from '@ant-design/icons' import Api from '@/api' import Utils from '@/utils/utils.js' @@ -18,11 +19,9 @@ class DataCard extends Component { static propTpyes = { - BID: PropTypes.any, // 鐖剁骇Id data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 - menuType: PropTypes.any, // 鑿滃崟绫诲瀷 } state = { @@ -47,8 +46,20 @@ } UNSAFE_componentWillMount () { - const { data, initdata, BID, BData } = this.props + const { data, initdata } = this.props let _config = fromJS(this.props.config).toJS() + + let BID = '' + let BData = '' + + if (_config.setting.supModule) { + BData = window.GLOB.CacheData.get(_config.setting.supModule) + } else { + BData = window.GLOB.CacheData.get(_config.$pageId) + } + if (BData) { + BID = BData.$BID || '' + } let _card = null let precards = [] @@ -155,6 +166,7 @@ } _config.wrap.selStyle = _config.wrap.selStyle || 'active' + _config.wrap.pagestyle = _config.wrap.pagestyle || 'page' _config.wrap.scale = _config.wrap.scale === 'true' ? 'scale' : '' _config.wrap.layout = (_config.wrap.layout || 'grid') + '-layout float-' + (_config.wrap.cardFloat || 'left') @@ -258,13 +270,9 @@ if (config.uuid !== menuId) return if (supComs) { - btn.syncComponentId && MKEmitter.emit('reloadData', btn.syncComponentId) - if (position === 'mainline' || position === 'popclose') { // 涓昏〃鍒锋柊锛屽幓闄ゅ悓姝ュ埛鏂扮粍浠� let supNode = supNodes[supNodes.length - 1] supComs.forEach((item, i) => { - if (item === btn.syncComponentId) return - setTimeout(() => { if (supNode && supNode.key === item) { MKEmitter.emit('reloadData', item, supNode.value) @@ -273,7 +281,7 @@ } }, i * 10) }) - } else if (!btn.syncComponentId || !supComs.includes(btn.syncComponentId)) { + } else { if (position === 'line') { if (lines && lines.length === 1) { this.loadLinedata(lines[0].$$uuid) @@ -293,30 +301,22 @@ } else { let supModule = config.setting.supModule - btn.syncComponentId && MKEmitter.emit('reloadData', btn.syncComponentId) - - if (!btn.syncComponentId || btn.syncComponentId !== supModule) { - if (position === 'line') { - if (lines && lines.length === 1) { - this.loadLinedata(lines[0].$$uuid) - } else { - this.loadData(id) - } - } else if (position === 'mainline' || position === 'popclose') { // 鍒锋柊婧愮粍浠舵椂锛岄檮甯﹀埛鏂颁笂绾ц涓庡綋鍓嶇粍浠� - if (supModule && BID) { - MKEmitter.emit('reloadData', supModule, BID) - } else { - this.loadData(id) - } - } else if (!btn || btn.resetPageIndex !== 'false') { - this.setState({ - pageIndex: 1 - }, () => { - this.loadData(id) - }) + if (position === 'line') { + if (lines && lines.length === 1) { + this.loadLinedata(lines[0].$$uuid) } else { this.loadData(id) } + } else if ((position === 'mainline' || position === 'popclose') && supModule && BID) { // 鍒锋柊婧愮粍浠舵椂锛岄檮甯﹀埛鏂颁笂绾ц涓庡綋鍓嶇粍浠� + MKEmitter.emit('reloadData', supModule, BID) + } else if (!btn || btn.resetPageIndex !== 'false') { + this.setState({ + pageIndex: 1 + }, () => { + this.loadData(id) + }) + } else { + this.loadData(id) } } @@ -328,7 +328,15 @@ checkTopLine = (id) => { const { config, data } = this.state - if (!data || data.length === 0 || data[0].$disabled) { + let index = 0 + if (id && data) { + index = data.findIndex(item => item.$$uuid === id) + if (index === -1) { + index = 0 + } + } + + if (!data || data.length === 0 || data[index].$disabled) { this.setState({ activeKey: '', selectKeys: [], @@ -340,14 +348,6 @@ MKEmitter.emit('syncBalconyData', config.uuid, [], false) } return - } - - let index = 0 - if (id) { - index = data.findIndex(item => item.$$uuid === id) - if (index === -1) { - index = 0 - } } this.setState({ @@ -440,7 +440,7 @@ /** * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ - queryModuleParam = (menuId, btnId) => { + queryModuleParam = (menuId, callback) => { const { mainSearch } = this.props const { arr_field, config, search } = this.state @@ -456,7 +456,7 @@ }) } - MKEmitter.emit('returnModuleParam', config.uuid, btnId, { + callback({ arr_field: arr_field, orderBy: config.setting.order || '', search: searches, @@ -464,8 +464,8 @@ }) } - async loadData (id) { - const { mainSearch, menuType } = this.props + async loadData (id, type) { + const { mainSearch } = this.props const { config, arr_field, pageIndex, search, BID, BData, selected } = this.state if (config.setting.supModule && !BID && config.wrap.supKey !== 'false') { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -515,7 +515,7 @@ }) let _orderBy = config.setting.order || '' - let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID, menuType) + let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID) let result = await Api.genericInterface(param) if (result.status) { @@ -538,11 +538,26 @@ } } - this.setState({ - activeKey: '', - selectKeys: [], - selectedData: [], - data: result.data.map((item, index) => { + let data = [] + + if (type === 'plus') { + let _data = (this.state.data || []).concat(result.data || []) + data = _data.map((item, index) => { + item.key = index + item.$$uuid = item[config.setting.primaryKey] || '' + item.$$BID = BID || '' + item.$$BData = BData || '' + item.$Index = index + 1 + '' + + if (config.wrap.controlField) { + if (config.wrap.controlVal.includes(item[config.wrap.controlField])) { + item.$disabled = true + } + } + return item + }) + } else { + data = result.data.map((item, index) => { item.key = index item.$$uuid = item[config.setting.primaryKey] || '' item.$$BID = BID || '' @@ -554,9 +569,15 @@ item.$disabled = true } } - return item - }), + }) + } + + this.setState({ + activeKey: '', + selectKeys: [], + selectedData: [], + data: data, total: result.total, loading: false }) @@ -576,7 +597,7 @@ * @description 鑾峰彇鍗曡鏁版嵁 */ async loadLinedata (id) { - const { mainSearch, menuType } = this.props + const { mainSearch } = this.props const { config, arr_field, pageIndex, search, BID, BData } = this.state let searches = fromJS(search).toJS() @@ -594,7 +615,7 @@ }) let _orderBy = config.setting.order || '' - let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID, menuType, id) + let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID, id) let result = await Api.genericInterface(param) if (result.status) { @@ -636,6 +657,20 @@ duration: 10 }) } + } + + loadMore = () => { + const { total, pageIndex, loading, config } = this.state + + if (loading || config.setting.pageSize * pageIndex >= total) { + return + } + + this.setState({ + pageIndex: pageIndex + 1 + }, () => { + this.loadData('', 'plus') + }) } prevPage = () => { @@ -751,7 +786,7 @@ <Spin /> </div> : null } - <NormalHeader config={config} BID={BID} menuType={this.props.menuType} refresh={this.refreshSearch} /> + <NormalHeader config={config} BID={BID} refresh={this.refreshSearch} /> {config.action && config.action.length > 0 ? <MainAction BID={BID} @@ -795,7 +830,8 @@ {switchable ? <div className={'prev-page ' + (total <= _total ? 'disabled' : '')} onClick={this.nextPage}><div><div><img src={nextImg} alt=""/></div></div></div> : null} {precards.length === 0 && nextcards.length === 0 && (!data || data.length === 0) ? <Empty description={false}/> : null} </div> - {config.wrap.pagestyle !== 'switch' && config.setting.laypage && data ? <Pagination size="small" total={total} showTotal={t => `鍏� ${t} 鏉} pageSize={config.setting.pageSize} onChange={this.changePageIndex} current={pageIndex}/> : null} + {config.wrap.pagestyle === 'page' && config.setting.laypage && data ? <Pagination size="small" total={total} showTotal={t => `鍏� ${t} 鏉} pageSize={config.setting.pageSize} onChange={this.changePageIndex} current={pageIndex}/> : null} + {config.wrap.pagestyle === 'more' && config.setting.laypage && data && data.length > 0 ? <div className={'mk-more' + (config.setting.pageSize * pageIndex >= total ? ' disabled' : '')} onClick={this.loadMore}>鏌ョ湅鏇村<DownOutlined/></div> : null} </div> ) } -- Gitblit v1.8.0