From 97e18fa9b628357fa43013cfefc96eec078de25e Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 16 一月 2023 15:58:12 +0800 Subject: [PATCH] 2023-01-16 --- src/tabviews/custom/components/card/table-card/index.jsx | 406 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 329 insertions(+), 77 deletions(-) diff --git a/src/tabviews/custom/components/card/table-card/index.jsx b/src/tabviews/custom/components/card/table-card/index.jsx index 6459618..5629e18 100644 --- a/src/tabviews/custom/components/card/table-card/index.jsx +++ b/src/tabviews/custom/components/card/table-card/index.jsx @@ -1,37 +1,40 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Spin, notification, Col, Empty, Pagination } from 'antd' +import { Spin, notification, Row, Col, Empty, Pagination, Modal } from 'antd' +import { DownOutlined } from '@ant-design/icons' -import asyncComponent from '@/utils/asyncComponent' import Api from '@/api' +import Utils from '@/utils/utils.js' +import asyncComponent from '@/utils/asyncComponent' import UtilsDM from '@/utils/utils-datamanage.js' import MKEmitter from '@/utils/events.js' +import TimerTask from '@/utils/timer-task.js' import './index.scss' const CardCellComponent = asyncComponent(() => import('../cardcellList')) +const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader')) class TableCard extends Component { static propTpyes = { - BID: PropTypes.any, // 鐖剁骇Id data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 - menuType: PropTypes.any, // 鑿滃崟绫诲瀷 - dataManager: PropTypes.any, // 鏁版嵁鏉冮檺 } state = { + BID: '', // 涓婄骇ID config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� - preIndex: 0, // 寮�濮嬬储寮� + search: null, // 鎼滅储鏉′欢 pageIndex: 1, // 椤电爜 total: 0, // 鎬绘暟 sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: null, // 鏁版嵁 - title: '', // 鏍囬 - showHeader: false // 瀛樺湪鏍囬銆佹悳绱� + BData: '' } + + loaded = false /** * @description 鍒濆鍖栧鐞� @@ -45,6 +48,18 @@ let _data = null let _sync = _config.setting.sync === 'true' + 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 || '' + } + if (_config.setting.sync === 'true' && data) { _data = data[_config.dataName] || [] _sync = false @@ -53,46 +68,96 @@ _sync = 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 + '' + return item + }) + } + let showHeader = false if (_config.wrap.title || _config.search.length > 0) { showHeader = true } if (_config.setting.laypage) { - _config.wrap.contentHeight = _config.wrap.height - (showHeader ? 85 : 40) + _config.wrap.contentHeight = showHeader ? 'calc(100% - 85px)' : 'calc(100% - 40px)' } else { - _config.wrap.contentHeight = _config.wrap.height - (showHeader ? 45 : 0) + _config.wrap.contentHeight = showHeader ? 'calc(100% - 45px)' : '100%' } _config.columns.forEach(item => { + if (item.type !== 'number') return _cols.set(item.field, item) }) _config.subcards.forEach(card => { card.elements = card.elements.map(item => { - if (item.field && _cols.has(item.field)) { - item.col = _cols.get(item.field) + if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') { + item.decimal = _cols.get(item.field).decimal || 0 } return item }) }) + _config.wrap.pagestyle = _config.wrap.pagestyle || 'page' + + this.loaded = _data !== null + this.setState({ - showHeader: showHeader, - title: _config.wrap.title, sync: _sync, + BID: BID || '', + BData: BData || '', data: _data, config: _config, + search: Utils.initMainSearch(_config.search), arr_field: _config.columns.map(col => col.field).join(','), }, () => { if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') { - this.loadData() + setTimeout(() => { + this.loadData() + }, _config.setting.delay || 0) } }) } componentDidMount () { - MKEmitter.addListener('syncRefreshComponentId', this.reload) + const { config } = this.state + + MKEmitter.addListener('reloadData', this.reloadData) + MKEmitter.addListener('resetSelectLine', this.resetParentParam) + MKEmitter.addListener('queryModuleParam', this.queryModuleParam) + MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) + + if (config.timer) { + this.timer = new TimerTask() + this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { + this.setState({ + pageIndex: 1 + }, () => { + this.loadData('timer') + }) + }) + } + + 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 + '' + return item + }) + + this.setState({data: _data}) + }) + } } shouldComponentUpdate (nextProps, nextState) { @@ -103,14 +168,19 @@ this.setState = () => { return } - MKEmitter.removeListener('syncRefreshComponentId', this.reload) + MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) + MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) + + this.timer && this.timer.stop() } /** * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� */ UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = this.state + const { sync, config, BID, BData } = this.state if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) { let _data = [] @@ -118,34 +188,109 @@ _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 + '' + return item + }) + + this.loaded = true + this.setState({sync: false, data: _data}) - } else if (!is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - if (config.setting.syncRefresh === 'true') { - this.setState({}, () => { - this.loadData() - }) - } + } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { + this.setState({}, () => { + this.loadData() + }) } } - reload = (syncId) => { + /** + * @description 鎸夐挳鎵ц瀹屾垚鍚庨〉闈㈠埛鏂� + * @param {*} menuId // 鑿滃崟Id + * @param {*} position // 鍒锋柊浣嶇疆 + * @param {*} btn // 鎵ц鐨勬寜閽� + */ + refreshByButtonResult = (menuId, position, btn) => { + const { config, BID } = this.state + + if (config.uuid !== menuId) return + + if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 鍒锋柊婧愮粍浠舵椂锛岄檮甯﹀埛鏂颁笂绾ц涓庡綋鍓嶇粍浠� + MKEmitter.emit('reloadData', config.setting.supModule, BID) + } else { + this.loadData() + } + + if (position === 'popclose') { // 鎵ц鍚姩寮圭獥鐨勬寜閽墍閫夋嫨鐨勫埛鏂伴」 + btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId) + } + } + + resetParentParam = (MenuID, id, data) => { const { config } = this.state - if (syncId && syncId !== config.uuid) return + if (!config.setting.supModule || config.setting.supModule !== MenuID) return + if (id !== this.state.BID || id !== '') { + this.setState({ BID: id, BData: data, pageIndex: 1 }, () => { + this.loadData() + }) + } + } - this.setState({ - pageIndex: 1 - }, () => { - this.loadData() + reloadData = (menuId) => { + const { config } = this.state + + if (config.uuid !== menuId) return + + this.loadData() + } + + /** + * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� + */ + queryModuleParam = (menuId, callback) => { + const { mainSearch } = this.props + const { arr_field, config, search } = 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()) + mainSearch.forEach(item => { + if (!keys.includes(item.key.toLowerCase())) { + searches.push(item) + } + }) + } + + callback({ + arr_field: arr_field, + orderBy: config.setting.order || '', + search: searches, + menuName: config.name }) } - async loadData () { - const { mainSearch, BID, menuType, dataManager } = this.props - const { config, arr_field, pageIndex } = this.state + async loadData (type) { + const { mainSearch } = this.props + const { config, arr_field, pageIndex, search, BID, BData } = this.state - let searches = [] - if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 + if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� + this.setState({ + data: [], + total: 0 + }) + + this.loaded = true + return + } + + let searches = search ? fromJS(search).toJS() : [] + if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 let keys = searches.map(item => item.key) mainSearch.forEach(item => { if (!keys.includes(item.key)) { @@ -154,48 +299,76 @@ }) } - this.setState({ - loading: true - }) + let requireFields = searches.filter(item => item.required && item.value === '') + if (requireFields.length > 0) { + return + } + + if (type !== 'timer') { + this.setState({ + loading: true + }) + } let _orderBy = config.setting.order || '' - let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID, menuType, dataManager) + let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID) let result = await Api.genericInterface(param) if (result.status) { - let _preIndex = 0 + let start = 1 if (config.setting.laypage) { - _preIndex = config.setting.pageSize * (pageIndex - 1) + start = config.setting.pageSize * (pageIndex - 1) + 1 + } + + this.loaded = true + if (config.$cache && pageIndex === 1) { + Api.writeCacheConfig(config.uuid, result.data || '') + } + + 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 + '' + return item + }) + } else { + data = result.data.map((item, index) => { + item.key = index + item.$$uuid = item[config.setting.primaryKey] || '' + item.$$BID = BID || '' + item.$$BData = BData || '' + item.$Index = index + start + '' + return item + }) } this.setState({ - data: result.data, + data: data, total: result.total, - preIndex: _preIndex, loading: false }) } else { this.setState({ loading: false }) - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) - } - } - - updateStatus = (type, position, btn) => { - const { config } = this.state - - if (type === 'refresh' && position === 'grid') { - this.loadData() - if (btn && btn.syncComponent && btn.syncComponent[0]) { - let syncId = btn.syncComponent.slice(-1)[0] - if (config.uuid !== syncId) { - MKEmitter.emit('syncRefreshComponentId', syncId) - } + this.timer && this.timer.stop() + + if (result.ErrCode === 'N') { + Modal.error({ + title: result.message, + }) + } else { + notification.error({ + top: 92, + message: result.message, + duration: 10 + }) } } } @@ -208,8 +381,64 @@ }) } - getLines = (data, seq) => { - const { BID } = this.props + openView = (card, data) => { + if (card.setting.click === 'menu' && card.setting.menu) { + let menuId = card.setting.menu.slice(-1)[0] + let menu = window.GLOB.mkThdMenus.filter(m => m.MenuID === menuId)[0] + + if (!menu && card.setting.MenuName && card.setting.MenuID) { + menu = { + MenuID: card.setting.MenuID, + MenuName: card.setting.MenuName, + MenuNo: card.setting.MenuNo || '', + type: card.setting.tabType + } + } + + if (!menu) { + notification.warning({ + top: 92, + message: '鑿滃崟宸插垹闄ゆ垨娌℃湁璁块棶鏉冮檺锛�', + duration: 5 + }) + return + } + + let newtab = { + ...menu, + param: {} + } + + if (card.setting.joint === 'true') { + newtab.param.$BID = data.$$uuid || '' + + Object.keys(data).forEach(key => { + if (/^\$/.test(key)) return + newtab.param[key] = data[key] + }) + } + + MKEmitter.emit('modifyTabs', newtab, true) + } else if (card.setting.click === 'link') { + let src = card.setting.linkurl + + if (card.setting.joint === 'true') { + let con = '?' + + if (/\?/ig.test(src)) { + con = '&' + } + + src = src + `${con}id=${data.$$uuid || ''}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}` + } + + window.open(src) + } else if (card.setting.click === 'button' && card.setting.linkbtn) { + MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [data], 'linkbtn') + } + } + + getLines = (data) => { const { config } = this.state let line = [] @@ -239,8 +468,8 @@ line.push( <Col key={index} span={24}> - <div className="card-item-box" style={item.style}> - <CardCellComponent BID={BID} seq={seq} data={data} cards={config} cardCell={item} elements={item.elements} updateStatus={this.updateStatus}/> + <div className="card-item-box" style={item.style} onClick={() => {this.openView(item, data)}}> + <CardCellComponent data={data} cards={config} cardCell={item} elements={item.elements}/> </div> </Col> ) @@ -249,28 +478,51 @@ return line } - render() { - const { config, loading, data, title, showHeader, pageIndex, preIndex, total } = this.state + refreshSearch = (list) => { + this.setState({ + search: list, + pageIndex: 1 + }, () => { + this.loadData() + }) + } + loadMore = () => { + const { total, pageIndex, loading, config } = this.state + + if (loading || config.setting.pageSize * pageIndex >= total) { + return + } + + this.setState({ + pageIndex: pageIndex + 1 + }, () => { + this.loadData('plus') + }) + } + + render() { + const { config, loading, data, BID, pageIndex, total } = this.state + + if (config.wrap.empty === 'hidden' && (!data || data.length === 0)) return null + return ( - <div className="custom-table-card-box" style={{...config.style, height: config.wrap.height}}> + <div className="custom-table-card-box" id={'anchor' + config.uuid} style={{...config.style}}> {loading ? <div className="loading-mask"> - <div className="ant-spin-blur"></div> + {data ? <div className="ant-spin-blur"></div> : null} <Spin /> </div> : null } - {showHeader ? <div className="table-header" style={config.headerStyle}> - <span className="table-title">{title}</span> - {/* <searchLine /> */} - </div> : null} - {data && data.length > 0 ? <div className="card-row-list" style={{height: config.wrap.contentHeight}}> - {data.map((item, index) => this.getLines(item, preIndex + index + 1))} - </div> : null} + <NormalHeader config={config} BID={BID} refresh={this.refreshSearch} /> + {data && data.length > 0 ? <Row className="card-row-list" style={{height: config.wrap.contentHeight}}> + {data.map(item => this.getLines(item))} + </Row> : null} {data && data.length === 0 ? <div className="card-row-list" style={{height: config.wrap.contentHeight}}> <Empty description={false}/> </div> : null} - {config.setting.laypage ? <Pagination size="small" current={pageIndex} total={total} onChange={this.changePageIndex} /> : null} + {config.setting.laypage && config.wrap.pagestyle === 'page' ? <Pagination size="small" current={pageIndex} total={total} onChange={this.changePageIndex} /> : null} + {config.setting.laypage && config.wrap.pagestyle === 'more' && 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