From 20185ab64a165df51515d9fa1c9b12a7a8c55f59 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 07 四月 2023 23:11:04 +0800 Subject: [PATCH] 2023-04-07 --- src/tabviews/custom/components/card/data-card/index.jsx | 202 +++++++++++++++++++++++++++++++++++++------------- 1 files changed, 150 insertions(+), 52 deletions(-) diff --git a/src/tabviews/custom/components/card/data-card/index.jsx b/src/tabviews/custom/components/card/data-card/index.jsx index 7a4dd46..1fee1e4 100644 --- a/src/tabviews/custom/components/card/data-card/index.jsx +++ b/src/tabviews/custom/components/card/data-card/index.jsx @@ -15,6 +15,7 @@ import './index.scss' const CardItem = asyncComponent(() => import('../cardItem')) +const TableHeader = asyncComponent(() => import('../tableHeader')) const MainAction = asyncComponent(() => import('@/tabviews/zshare/actionList')) const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader')) @@ -31,6 +32,9 @@ config: null, // 鍥捐〃閰嶇疆淇℃伅 search: null, // 鎼滅储鏉′欢 pageIndex: 1, // 椤电爜 + pageSize: 10, + orderBy: '', + pageOptions: [], activeKey: '', // 閫変腑鍗� selectKeys: [], // 澶氶�夋椂閫変腑鍗$墖 selectedData: [], // 閫変腑鏁版嵁锛岀敤浜庡伐鍏锋爮鎸夐挳 @@ -99,8 +103,6 @@ _config.subcards = null - let _cols = new Map() - let _data = null let _sync = _config.setting.sync === 'true' @@ -145,24 +147,6 @@ } } - _config.columns.forEach(item => { - if (item.type !== 'number') return - _cols.set(item.field, item) - }) - - _card.elements = _card.elements.map(item => { - if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') { - item.decimal = _cols.get(item.field).decimal || 0 - } - return item - }) - _card.backElements = _card.backElements.map(item => { - if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') { - item.decimal = _cols.get(item.field).decimal || 0 - } - return item - }) - let supComs = null if (_config.wrap.supType === 'multi') { supComs = _config.supNodes.map(item => item.componentId) @@ -177,7 +161,19 @@ this.loaded = _data !== null + let pageOptions = ['10', '25', '50', '100', '500', '1000'] + + 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) + } + } + this.setState({ + pageSize: _config.setting.pageSize || 10, + pageOptions, supComs, selected, precards, @@ -452,15 +448,29 @@ if (config.uuid !== menuId) return if (checked) { + let index = '' + let keys = [] + let items = [] + let last = '' + + data.forEach((item, i) => { + if (item.$disabled) return + + items.push(item) + keys.push(i) + index = i + last = item + }) + this.setState({ - activeKey: '', - selectKeys: data.map((item, index) => index), - selectedData: data + activeKey: index, + selectKeys: keys, + selectedData: items }) - MKEmitter.emit('resetSelectLine', config.uuid, '', '') - MKEmitter.emit('syncBalconyData', config.uuid, data, data.length > 0) - if (data.length === 0) { + MKEmitter.emit('resetSelectLine', config.uuid, last ? last.$$uuid : '', last) + MKEmitter.emit('syncBalconyData', config.uuid, items, data.length > 0 && data.length === keys.length) + if (items.length === 0) { message.warning('鏈幏鍙栧埌鏁版嵁锛�') } } else { @@ -472,6 +482,50 @@ MKEmitter.emit('resetSelectLine', config.uuid, '', '') MKEmitter.emit('syncBalconyData', config.uuid, [], false) + } + } + + checkAll = () => { + const { config, data, selectedData } = this.state + + if (!data || data.length === 0) return + + if (selectedData.length === 0 || selectedData.length < data.length) { + let index = '' + let keys = [] + let items = [] + let last = '' + + data.forEach((item, i) => { + if (item.$disabled) return + + items.push(item) + keys.push(i) + index = i + last = item + }) + + this.setState({ + activeKey: index, + selectKeys: keys, + selectedData: items + }) + + MKEmitter.emit('resetSelectLine', config.uuid, last ? last.$$uuid : '', last) + if (config.setting.$hasSyncModule) { + MKEmitter.emit('syncBalconyData', config.uuid, items, data.length === keys.length) + } + } else { + this.setState({ + activeKey: '', + selectKeys: [], + selectedData: [] + }) + + MKEmitter.emit('resetSelectLine', config.uuid, '', '') + if (config.setting.$hasSyncModule) { + MKEmitter.emit('syncBalconyData', config.uuid, [], false) + } } } @@ -526,7 +580,7 @@ */ queryModuleParam = (menuId, callback) => { const { mainSearch } = this.props - const { arr_field, config, search } = this.state + const { arr_field, config, search, orderBy } = this.state if (config.uuid !== menuId) return @@ -542,7 +596,7 @@ callback({ arr_field: arr_field, - orderBy: config.setting.order || '', + orderBy: orderBy ||config.setting.order || '', search: searches, menuName: config.name }) @@ -550,7 +604,7 @@ async loadData (id, type) { const { mainSearch } = this.props - const { config, arr_field, pageIndex, search, BID, BData, selected } = this.state + const { config, arr_field, pageIndex, pageSize, search, BID, BData, selected, orderBy } = this.state if (config.setting.supModule && !BID && config.wrap.supKey !== 'false') { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� this.loaded = true @@ -602,18 +656,18 @@ }) } - let _orderBy = config.setting.order || '' - let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID) + let _orderBy = orderBy || config.setting.order || '' + let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID) let result = await Api.genericInterface(param) if (result.status) { let start = 1 if (config.setting.laypage) { - start = config.setting.pageSize * (pageIndex - 1) + 1 + start = pageSize * (pageIndex - 1) + 1 } this.loaded = true - if (config.$cache && pageIndex === 1) { + if (config.$cache && pageIndex === 1 && config.setting.onload !== 'false') { Api.writeCacheConfig(config.uuid, result.data || '') } @@ -674,6 +728,13 @@ total: result.total, loading: false }) + + if (config.timer && config.clearField && result.data && result.data[0]) { + let vals = (config.clearValue || '').split(',') + if (vals.includes(result.data[0][config.clearField])) { + this.timer && this.timer.stop() + } + } } else { this.setState({ loading: false @@ -698,7 +759,7 @@ */ async loadLinedata (id) { const { mainSearch } = this.props - const { config, arr_field, pageIndex, search, BID, BData } = this.state + 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) { // 涓昏〃鎼滅储鏉′欢 @@ -714,8 +775,8 @@ loading: true }) - let _orderBy = config.setting.order || '' - let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID, id) + let _orderBy = orderBy || config.setting.order || '' + let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, id) let result = await Api.genericInterface(param) if (result.status) { @@ -760,9 +821,9 @@ } loadMore = () => { - const { total, pageIndex, loading, config } = this.state + const { total, pageIndex, pageSize, loading } = this.state - if (loading || config.setting.pageSize * pageIndex >= total) { + if (loading || pageSize * pageIndex >= total) { return } @@ -786,8 +847,8 @@ } nextPage = () => { - const { config, pageIndex, total } = this.state - let _total = config.setting.pageSize * pageIndex + const { pageIndex, pageSize, total } = this.state + let _total = pageSize * pageIndex if (_total >= total) return @@ -810,6 +871,15 @@ this.setState({ search: list, pageIndex: 1 + }, () => { + this.loadData() + }) + } + + pageSizeChange = (current, size) => { + this.setState({ + pageIndex: current, + pageSize: size }, () => { this.loadData() }) @@ -860,15 +930,23 @@ } } + refreshByHeader = (sorter) => { + this.setState({ + orderBy: sorter || '' + }, () => { + this.loadData() + }) + } + render() { - const { config, precards, nextcards, loading, data, pageIndex, total, card, activeKey, BID, BData, selectedData, selectKeys } = this.state + const { config, precards, nextcards, loading, data, pageIndex, pageSize, total, card, activeKey, BID, BData, selectedData, selectKeys } = this.state if (config.wrap.empty === 'hidden' && (!data || data.length === 0)) return null let _total = 0 let switchable = false - if (config.wrap.pagestyle === 'switch' && config.pageable && config.setting.laypage && total > config.setting.pageSize && data) { - _total = config.setting.pageSize * pageIndex + if (config.wrap.pagestyle === 'switch' && config.pageable && config.setting.laypage && total > pageSize && data) { + _total = pageSize * pageIndex switchable = true } @@ -876,6 +954,13 @@ if (data && data[0]) { extendData = {...extendData, ...data[0]} + } + + let checkAll = '' + if (config.wrap.selStyle && config.wrap.selStyle.indexOf('check') > -1) { + if (selectedData.length > 0) { + checkAll = selectedData.length < data.length ? ' half' : ' whole' + } } return ( @@ -902,11 +987,20 @@ <Row className={'card-row-list ' + config.wrap.layout}> {precards.map((item, index) => ( <Col key={'pre' + index} className="extend-card" span={item.setting.width || 6}> - <CardItem card={item} cards={config} data={extendData}/> + {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}> + {item.setting.checkAll === 'show' ? <span onClick={this.checkAll} className={'circle-select' + checkAll}></span> : null} + </CardItem>} </Col> ))} {data && data.map((item, index) => { - let className = card.setting.click ? 'mk-card pointer ' : 'mk-card ' + let className = 'mk-card ' + if (config.wrap.parity === 'true') { + if (index % 2 === 1) { + className += 'mk-parity-bg ' + } + } if (item.$disabled) { className = 'mk-disabled' } else if (activeKey === index) { @@ -916,27 +1010,31 @@ } return ( - <Col className={className} key={index} span={card.setting.width} onClick={() => {this.changeCard(index, item)}}> - <CardItem card={card} cards={config} data={item}/> + <Col className={className} key={index} span={card.setting.width}> + <CardItem card={card} cards={config} data={item} onClick={() => {this.changeCard(index, item)}}> + <span className="circle-select"></span> + </CardItem> </Col> ) })} {nextcards.map((item, index) => ( <Col key={'next' + index} className="extend-card" span={item.setting.width || 6}> - <CardItem card={item} cards={config} data={extendData}/> + {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}> + {item.setting.checkAll === 'show' ? <span onClick={this.checkAll} className={'circle-select' + checkAll}></span> : null} + </CardItem>} </Col> ))} </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 => `鍏� ${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} + {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} </div> ) } } - - export default DataCard \ No newline at end of file -- Gitblit v1.8.0