From 2a3cc4e6cecfc6dab8b60adf93f7fde898ddc939 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 25 七月 2023 16:36:23 +0800 Subject: [PATCH] 2023-07-25 --- src/tabviews/custom/components/card/data-card/index.jsx | 449 +++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 282 insertions(+), 167 deletions(-) diff --git a/src/tabviews/custom/components/card/data-card/index.jsx b/src/tabviews/custom/components/card/data-card/index.jsx index 1fee1e4..08b1383 100644 --- a/src/tabviews/custom/components/card/data-card/index.jsx +++ b/src/tabviews/custom/components/card/data-card/index.jsx @@ -5,7 +5,6 @@ import { DownOutlined } from '@ant-design/icons' import Api from '@/api' -import Utils from '@/utils/utils.js' import UtilsDM from '@/utils/utils-datamanage.js' import preImg from '@/assets/img/prev.png' import nextImg from '@/assets/img/next.png' @@ -21,9 +20,7 @@ class DataCard extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -39,7 +36,6 @@ selectKeys: [], // 澶氶�夋椂閫変腑鍗$墖 selectedData: [], // 閫変腑鏁版嵁锛岀敤浜庡伐鍏锋爮鎸夐挳 loading: false, // 鏁版嵁鍔犺浇鐘舵�� - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 card: null, // 鍗$墖璁剧疆 data: null, // 鏁版嵁 total: null, @@ -53,9 +49,9 @@ loaded = false UNSAFE_componentWillMount () { - const { data, initdata } = this.props - let _config = fromJS(this.props.config).toJS() + const { config } = this.props + let _config = fromJS(config).toJS() let BID = '' let BData = '' @@ -80,6 +76,9 @@ } } + _config.$extend = false + _config.$empty = true + _config.subcards.forEach(item => { if (item.setting.click === 'button' && !item.setting.linkbtn) { item.elements.forEach(ele => { @@ -92,59 +91,36 @@ } } + if (item.style.clear === 'left') { + item.wStyle = {clear: 'left'} + } else if (item.style.clear === 'right') { + item.wStyle = {float: 'right'} + } + + delete item.style.clear + if (item.$cardType !== 'extendCard') { _card = item } else if (!_card) { + _config.$extend = true + if (item.setting.width !== 24) { + _config.$empty = false + } precards.push(item) } else { + _config.$extend = true + _config.$empty = false nextcards.push(item) } }) _config.subcards = null - - let _data = null - let _sync = _config.setting.sync === 'true' - - if (_sync && data) { - _data = data[_config.dataName] || [] - _sync = false - } else if (_sync && initdata) { - _data = initdata || [] - _sync = false - } let selected = 'false' if (_config.wrap.selected === 'always' || _config.wrap.selected === 'init' || _config.wrap.selected === 'sign') { selected = _config.wrap.selected } else { _config.wrap.selected = 'false' - } - - if (_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 - }) - - if (selected !== 'false') { - setTimeout(() => { - this.checkTopLine() - }, 200) - if (selected === 'init') { - selected = 'false' - } - } } let supComs = null @@ -159,15 +135,51 @@ _config.wrap.wrapClass = `${_config.wrap.selStyle} ${_config.wrap.cardType || ''} ${_config.wrap.scale}` - this.loaded = _data !== null - let pageOptions = ['10', '25', '50', '100', '500', '1000'] + + if (!_config.setting.laypage) { + _config.wrap.pagestyle = 'none' + } if (_config.wrap.pagestyle === 'page') { let size = (_config.setting.pageSize || 10) + '' if (!pageOptions.includes(size)) { pageOptions.push(size) pageOptions = pageOptions.sort((a, b) => a - b) + } + } + + let _data = null + if (_config.setting.sync === 'true') { + _config.setting.onload = 'false' + + if (window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] + + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS()) + } + + _config.setting.sync = 'false' + + _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 + }) + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } } @@ -178,20 +190,13 @@ selected, precards, nextcards, - sync: _sync, data: _data, BID: BID || '', BData: BData || '', config: _config, card: _card, - search: Utils.initMainSearch(_config.search), - arr_field: _config.columns.map(col => col.field).join(','), - }, () => { - if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') { - setTimeout(() => { - this.loadData() - }, _config.setting.delay || 0) - } + search: _config.$searches, + arr_field: _config.columns.map(col => col.field).join(',') }) } @@ -200,9 +205,18 @@ MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('mkCheckAll', this.mkCheckAll) + MKEmitter.addListener('refreshLineData', this.refreshLineData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.addListener('queryModuleParam', this.queryModuleParam) MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } if (config.timer) { this.timer = new TimerTask() @@ -215,73 +229,11 @@ }) } - if (config.$cache && !this.loaded) { - Api.getLCacheConfig(config.uuid).then(res => { - if (!res || this.loaded) return - let _data = res.map((item, index) => { - item.key = index - item.$$uuid = item[config.setting.primaryKey] || '' - item.$Index = index + 1 + '' - - if (config.wrap.controlField) { - if (config.wrap.controlVal.includes(item[config.wrap.controlField])) { - item.$disabled = true - } - } - - return item - }) - - this.setState({data: _data}) - }) - } + this.initExec() } shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.state), fromJS(nextState)) - } - - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config, BID, BData, selected } = this.state - - if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) { - let _data = [] - if (nextProps.data && nextProps.data[config.dataName]) { - _data = nextProps.data[config.dataName] || [] - _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 - }) - - if (selected !== 'false') { - setTimeout(() => { - this.checkTopLine() - }, 200) - if (selected === 'init') { - this.setState({selected: 'false'}) - } - } - } - - this.loaded = true - - this.setState({sync: false, data: _data}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({pageIndex: 1}, () => { - this.loadData() - }) - } } componentWillUnmount () { @@ -290,11 +242,134 @@ } MKEmitter.removeListener('reloadData', this.reloadData) MKEmitter.removeListener('mkCheckAll', this.mkCheckAll) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) + MKEmitter.removeListener('refreshLineData', this.refreshLineData) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) this.timer && this.timer.stop() + } + + initExec = () => { + const { config } = this.state + + this.loaded && this.prevCheck() + + if (config.$cache) { + if (config.$time && !config.setting.laypage) { + if (!this.loaded) { + Api.getLCacheConfig(config.uuid, config.$time).then(res => { + if (!res && config.setting.onload === 'true') { + setTimeout(() => { + this.loadData() + }, config.setting.delay || 0) + } + + if (!res || this.loaded) return + + let _data = res.map((item, index) => { + item.key = index + item.$$uuid = item[config.setting.primaryKey] || '' + item.$Index = index + 1 + '' + + if (config.wrap.controlField) { + if (config.wrap.controlVal.includes(item[config.wrap.controlField] + '')) { + item.$disabled = true + } + } + + return item + }) + + this.setState({data: _data}) + }) + } + } else { + if (!this.loaded) { + Api.getLCacheConfig(config.uuid, 0).then(res => { + if (!res || this.loaded) return + + let _data = res.map((item, index) => { + item.key = index + item.$$uuid = item[config.setting.primaryKey] || '' + item.$Index = index + 1 + '' + + if (config.wrap.controlField) { + if (config.wrap.controlVal.includes(item[config.wrap.controlField] + '')) { + item.$disabled = true + } + } + + return item + }) + + this.setState({data: _data}) + }) + } + + if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData() + }, config.setting.delay || 0) + } + } + } else if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData() + }, config.setting.delay || 0) + } + } + + transferSyncData = (syncId) => { + const { config } = this.state + + if (config.$syncId !== syncId) return + + const { BID, BData } = this.state + + let _data = window.GLOB.SyncData.get(config.dataName) || [] + + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) + } + + _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 + }) + + this.prevCheck() + + this.loaded = true + + this.setState({data: _data}) + + window.GLOB.SyncData.delete(config.dataName) + + MKEmitter.removeListener('transferSyncData', this.transferSyncData) + } + + searchRefresh = (searchId) => { + const { config } = this.state + + if (config.$searchId !== searchId) return + + this.setState({pageIndex: 1}, () => { + this.loadData() + }) } /** @@ -358,9 +433,36 @@ this.loadData(id) } } + } - if (position === 'popclose') { // 鎵ц鍚姩寮圭獥鐨勬寜閽墍閫夋嫨鐨勫埛鏂伴」 - btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId) + refreshLineData = (menuId, btn, uuid, count) => { + const { config, data } = this.state + + if (config.uuid !== menuId) return + + let _data = fromJS(data).toJS().map(item => { + if (item.$$uuid === uuid) { + item[btn.field] = count + } + return item + }) + + this.setState({ + data: _data + }) + } + + prevCheck = (id) => { + const { selected } = this.state + + if (selected === 'false' && !id) return + + setTimeout(() => { + this.checkTopLine(id) + }, 200) + + if (selected === 'init') { + this.setState({selected: 'false'}) } } @@ -488,6 +590,7 @@ checkAll = () => { const { config, data, selectedData } = this.state + if (config.wrap.cardType !== 'checkbox') return if (!data || data.length === 0) return if (selectedData.length === 0 || selectedData.length < data.length) { @@ -579,18 +682,18 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, callback) => { - const { mainSearch } = this.props const { arr_field, config, search, orderBy } = this.state if (config.uuid !== menuId) return - let searches = search ? fromJS(search).toJS() : [] - if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - let keys = searches.map(item => item.key.toLowerCase()) + let searches = fromJS(search).toJS() + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + let mainSearch = window.GLOB.SearchBox.get(config.$searchId) || [] + let keys = config.$s_keys || [] mainSearch.forEach(item => { - if (!keys.includes(item.key.toLowerCase())) { - searches.push(item) - } + if (keys.includes(item.key.toLowerCase())) return + + searches.push(item) }) } @@ -603,7 +706,6 @@ } async loadData (id, type) { - const { mainSearch } = this.props const { config, arr_field, pageIndex, pageSize, search, BID, BData, selected, orderBy } = this.state if (config.setting.supModule && !BID && config.wrap.supKey !== 'false') { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -620,12 +722,7 @@ }) if (selected !== 'false' || (id && config.wrap.selected !== 'false')) { - setTimeout(() => { - this.checkTopLine(id) - }, 200) - if (selected === 'init') { - this.setState({selected: 'false'}) - } + this.prevCheck(id) } else { MKEmitter.emit('resetSelectLine', config.uuid, '', '') if (config.setting.$hasSyncModule) { @@ -636,17 +733,17 @@ } let searches = fromJS(search).toJS() - if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - let keys = searches.map(item => item.key.toLowerCase()) + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + let mainSearch = window.GLOB.SearchBox.get(config.$searchId) || [] + let keys = config.$s_keys || [] mainSearch.forEach(item => { - if (!keys.includes(item.key.toLowerCase())) { - searches.push(item) - } + if (keys.includes(item.key.toLowerCase())) return + + searches.push(item) }) } - let requireFields = searches.filter(item => item.required && item.value === '') - if (requireFields.length > 0) { + if (config.$s_req && searches.filter(item => item.required && item.value === '').length > 0) { return } @@ -668,16 +765,11 @@ this.loaded = true if (config.$cache && pageIndex === 1 && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } if (selected !== 'false' || (id && config.wrap.selected !== 'false')) { - setTimeout(() => { - this.checkTopLine(id) - }, 200) - if (selected === 'init') { - this.setState({selected: 'false'}) - } + this.prevCheck(id) } else { MKEmitter.emit('resetSelectLine', config.uuid, '', '') if (config.setting.$hasSyncModule) { @@ -697,7 +789,7 @@ item.$Index = index + 1 + '' if (config.wrap.controlField) { - if (config.wrap.controlVal.includes(item[config.wrap.controlField])) { + if (config.wrap.controlVal.includes(item[config.wrap.controlField] + '')) { item.$disabled = true } } @@ -712,7 +804,7 @@ item.$Index = index + start + '' if (config.wrap.controlField) { - if (config.wrap.controlVal.includes(item[config.wrap.controlField])) { + if (config.wrap.controlVal.includes(item[config.wrap.controlField] + '')) { item.$disabled = true } } @@ -735,16 +827,31 @@ this.timer && this.timer.stop() } } + if (result.message) { + if (result.ErrCode === 'Y') { + Modal.success({ + title: result.message + }) + } else if (result.ErrCode === 'S') { + notification.success({ + top: 92, + message: result.message, + duration: 2 + }) + } + } } else { this.setState({ loading: false }) this.timer && this.timer.stop() + + if (!result.message) return if (result.ErrCode === 'N') { Modal.error({ title: result.message, }) - } else { + } else if (result.ErrCode !== '-2') { notification.error({ top: 92, message: result.message, @@ -758,16 +865,16 @@ * @description 鑾峰彇鍗曡鏁版嵁 */ async loadLinedata (id) { - const { mainSearch } = this.props const { config, arr_field, pageIndex, pageSize, search, BID, BData, orderBy } = this.state let searches = fromJS(search).toJS() - if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - let keys = searches.map(item => item.key.toLowerCase()) + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + let mainSearch = window.GLOB.SearchBox.get(config.$searchId) || [] + let keys = config.$s_keys || [] mainSearch.forEach(item => { - if (!keys.includes(item.key.toLowerCase())) { - searches.push(item) - } + if (keys.includes(item.key.toLowerCase())) return + + searches.push(item) }) } @@ -945,15 +1052,23 @@ let _total = 0 let switchable = false - if (config.wrap.pagestyle === 'switch' && config.pageable && config.setting.laypage && total > pageSize && data) { + if (config.wrap.pagestyle === 'switch' && total > pageSize && data) { _total = pageSize * pageIndex switchable = true } - let extendData = {$$BID: BID, $$BData: BData, $$selectedData: selectedData, $$type: 'extendCard'} + let extendData = null - if (data && data[0]) { - extendData = {...extendData, ...data[0]} + if (config.$extend) { + extendData = {$$BID: BID, $$BData: BData, $$selectedData: selectedData, $$type: 'extendCard'} + + if (data && data[0]) { + if (selectedData[0]) { + extendData = {...extendData, ...selectedData[0]} + } else { + extendData = {...extendData, ...data[0]} + } + } } let checkAll = '' @@ -986,7 +1101,7 @@ {switchable ? <div className={'prev-page ' + (pageIndex === 1 ? 'disabled' : '')} onClick={this.prevPage}><div><div><img src={preImg} alt=""/></div></div></div> : null} <Row className={'card-row-list ' + config.wrap.layout}> {precards.map((item, index) => ( - <Col key={'pre' + index} className="extend-card" span={item.setting.width || 6}> + <Col key={'pre' + index} className="extend-card" style={item.wStyle} span={item.setting.width || 6}> {item.setting.cardRole === 'header' ? <TableHeader card={item} data={extendData} refresh={this.refreshByHeader}> {item.setting.checkAll === 'show' ? <span onClick={this.checkAll} className={'circle-select' + checkAll}></span> : null} </TableHeader> : <CardItem card={item} cards={config} data={extendData}> @@ -1010,7 +1125,7 @@ } return ( - <Col className={className} key={index} span={card.setting.width}> + <Col className={className} key={index} style={card.wStyle} span={card.setting.width}> <CardItem card={card} cards={config} data={item} onClick={() => {this.changeCard(index, item)}}> <span className="circle-select"></span> </CardItem> @@ -1018,7 +1133,7 @@ ) })} {nextcards.map((item, index) => ( - <Col key={'next' + index} className="extend-card" span={item.setting.width || 6}> + <Col key={'next' + index} className="extend-card" style={item.wStyle} span={item.setting.width || 6}> {item.setting.cardRole === 'header' ? <TableHeader card={item} data={extendData} refresh={this.refreshByHeader}> {item.setting.checkAll === 'show' ? <span onClick={this.checkAll} className={'circle-select' + checkAll}></span> : null} </TableHeader> : <CardItem card={item} cards={config} data={extendData}> @@ -1028,10 +1143,10 @@ ))} </Row> {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 === 'page' && config.setting.laypage && data ? <Pagination size="small" total={total} showTotal={(t, range) => `${range[0]}-${range[1]} 鍏� ${total} 鏉} pageSize={pageSize} showSizeChanger={true} pageSizeOptions={this.state.pageOptions} onChange={this.changePageIndex} onShowSizeChange={this.pageSizeChange} current={pageIndex}/> : null} - {config.wrap.pagestyle === 'more' && config.setting.laypage && data && data.length > 0 ? <div className={'mk-more' + (pageSize * pageIndex >= total ? ' disabled' : '')} onClick={this.loadMore}>鏌ョ湅鏇村<DownOutlined/></div> : null} + {config.$empty && (!data || data.length === 0) ? <Empty description={false}/> : null} + {config.wrap.pagestyle === 'page' && data ? <Pagination size="small" total={total} showTotal={(t, range) => total > 0 ? `${range[0]}-${range[1]} 鍏� ${total} 鏉 : `鍏� ${total} 鏉} pageSize={pageSize} showSizeChanger={true} pageSizeOptions={this.state.pageOptions} onChange={this.changePageIndex} onShowSizeChange={this.pageSizeChange} current={pageIndex}/> : null} + {config.wrap.pagestyle === 'more' && data && data.length > 0 ? <div className={'mk-more' + (pageSize * pageIndex >= total ? ' disabled' : '')} onClick={this.loadMore}>鏌ョ湅鏇村<DownOutlined/></div> : null} </div> ) } -- Gitblit v1.8.0