From 24842b40de5cd60700bf69dfd38a0332f5431e36 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 23 五月 2025 10:55:07 +0800 Subject: [PATCH] Merge branch 'master' into positec --- src/tabviews/custom/components/card/prop-card/index.jsx | 462 ++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 323 insertions(+), 139 deletions(-) diff --git a/src/tabviews/custom/components/card/prop-card/index.jsx b/src/tabviews/custom/components/card/prop-card/index.jsx index aac9321..2c4e2d2 100644 --- a/src/tabviews/custom/components/card/prop-card/index.jsx +++ b/src/tabviews/custom/components/card/prop-card/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Spin, notification, Col, Row, Modal } from 'antd' +import { Spin, Col, Row } from 'antd' import Api from '@/api' import UtilsDM from '@/utils/utils-datamanage.js' @@ -15,9 +15,7 @@ class PropCard extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -25,21 +23,19 @@ config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� activeKey: '', // 閫変腑鏁版嵁 - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: {}, // 鏁版嵁 BData: '', selected: 'false', } loaded = false + autoTimer = null UNSAFE_componentWillMount () { - const { data, initdata } = this.props - let _config = fromJS(this.props.config).toJS() + const { config } = this.props + let _config = fromJS(config).toJS() let _data = { $$empty: true } - let _sync = false - let BID = '' let BData = '' @@ -51,35 +47,55 @@ if (BData) { BID = BData.$BID || '' } - - if (_config.wrap.datatype === 'dynamic') { - _sync = _config.setting.sync === 'true' - if (_sync && data) { - _data = data[_config.dataName] || {$$empty: true} - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false - this.loaded = true - } else if (_sync && initdata) { - _data = initdata - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false - this.loaded = true + if (_config.wrap.datatype === 'dynamic') { + _config.setting.onload = _config.setting.sync === 'true' ? 'false' : _config.setting.onload || 'true' + + if (_config.setting.supModule && !BID) { + _config.setting.onload = 'false' } - } else if (_config.wrap.datatype === 'public' && window.GLOB.CacheData.get(_config.wrap.publicId)) { + + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] + + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS(), BID) + } + + _config.setting.sync = 'false' + + _data = _data[0] || {$$empty: true} + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) + } + } else if (_config.wrap.datatype === 'public' && window.GLOB.CacheData.has(_config.wrap.publicId)) { _data = window.GLOB.CacheData.get(_config.wrap.publicId) _data = fromJS(_data).toJS() this.loaded = true } else if (_config.wrap.datatype === 'static') { this.loaded = true + _config.subcards.forEach(card => { + card.elements.forEach(ele => { + if (ele.eleType === 'button') return + if (ele.datatype === 'dynamic' && ele.field) { + ele.field = ele.field.toLowerCase() + } + }) + }) } _data.$$BID = BID || '' _data.$$BData = BData || '' + + if (_config.wrap.datatype === 'static' && BData) { + Object.keys(BData).forEach(key => { + if (/\$/.test(key)) return + _data[key.toLowerCase()] = BData[key] + }) + } + if (_config.setting.primaryKey) { _data.$$uuid = _data[_config.setting.primaryKey] || '' } @@ -95,11 +111,19 @@ card.setting.click = '' } } + + if (card.style.clear === 'left') { + card.wStyle = {clear: 'left'} + } else if (card.style.clear === 'right') { + card.wStyle = {float: 'right'} + } + + delete card.style.clear }) let selected = _config.wrap.selected || 'false' - _config.wrap.selStyle = _config.wrap.selStyle || 'active' + _config.wrap.selStyle = _config.wrap.selStyle || 'none' _config.wrap.priKeyType = _config.wrap.priKeyType || 'static' _config.wrap.scale = _config.wrap.scale === 'true' ? 'scale' : '' @@ -111,37 +135,10 @@ this.setState({ selected, - sync: _sync, data: _data, BID: BID || '', BData: BData || '', - config: _config, - arr_field: _config.columns.map(col => col.field).join(','), - }, () => { - if (_config.wrap.datatype === 'dynamic' && _config.setting.sync !== 'true' && _config.setting.onload === 'true') { - setTimeout(() => { - this.loadData() - }, _config.setting.delay || 0) - } else if (_config.wrap.datatype === 'public') { - if (_data.$$loaded && selected !== 'false') { - setTimeout(() => { - this.checkTopLine() - }, 200) - } - } else if (!_sync && selected !== 'false') { - setTimeout(() => { - this.checkTopLine() - }, 200) - } - - if (_config.wrap.datatype === 'dynamic' && this.loaded) { - this.autoExec() - } - if (!_config.wrap.cardType && _data.$$uuid) { - setTimeout(() => { - this.transferLine() - }, 200) - } + config: _config }) } @@ -149,29 +146,27 @@ const { config } = this.state MKEmitter.addListener('reloadData', this.reloadData) + MKEmitter.addListener('refreshLineData', this.refreshLineData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.addListener('queryModuleParam', this.queryModuleParam) MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } + if (config.wrap.datatype === 'public') { MKEmitter.addListener('mkPublicData', this.mkPublicData) + } else if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) } - if (config.timer && config.wrap.datatype === 'dynamic') { + if (config.timer && config.wrap.datatype !== 'public') { this.timer = new TimerTask() - this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {this.loadData(true)}) + this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {this.loadData('timer')}) } - if (config.$cache && !this.loaded) { - Api.getLCacheConfig(config.uuid).then(res => { - if (!res || this.loaded) return - - let _data = res[0] - _data.$$uuid = _data[config.setting.primaryKey] || '' - - this.setState({data: _data}) - }) - } + this.initExec() } shouldComponentUpdate (nextProps, nextState) { @@ -184,47 +179,189 @@ } MKEmitter.removeListener('reloadData', this.reloadData) MKEmitter.removeListener('mkPublicData', this.mkPublicData) + 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() } - /** - * @description 鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config, BID, BData, selected } = this.state + initExec = () => { + const { config, selected, data, BID } = this.state - if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) { - let _data = { $$empty: true } - if (nextProps.data && nextProps.data[config.dataName]) { - _data = nextProps.data[config.dataName] - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} + if (config.wrap.datatype === 'dynamic') { + if (config.$cache) { + if (config.$time) { + if (!this.loaded) { + Api.getLCacheConfig(config.uuid, config.$time, BID).then(res => { + if (!res.valid && config.setting.onload === 'true') { + setTimeout(() => { + this.loadData('init') + }, config.setting.delay || 0) + } + + if (!res.data || this.loaded) return + + let _data = res.data[0] || {$$empty: true} + _data.$$uuid = _data[config.setting.primaryKey] || '' + + this.setState({data: _data}, () => { + if (selected !== 'false') { + this.checkTopLine() + } else if (config.wrap.empty === 'hidden') { + MKEmitter.emit('resetSelectLine', config.uuid, _data.$$uuid || '', _data) + } + }) + }) + } else { + if (config.wrap.goback === 'true' && data.$$empty) { + this.timer && this.timer.stop() + + MKEmitter.emit('closeTabView', config.$pageId) + } else { + if (selected !== 'false') { + this.checkTopLine() + } else { + this.transferLine() + } + this.autoExec() + } + } + } else { + if (!this.loaded) { + Api.getLCacheConfig(config.uuid, 0, BID).then(res => { + if (!res.data || this.loaded) return + + let _data = res.data[0] || {$$empty: true} + _data.$$uuid = _data[config.setting.primaryKey] || '' + + this.setState({data: _data}) + }) + } + + if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData('init') + }, config.setting.delay || 0) + } else if (this.loaded) { + if (config.wrap.goback === 'true' && data.$$empty) { + this.timer && this.timer.stop() + + MKEmitter.emit('closeTabView', config.$pageId) + } else { + if (selected !== 'false') { + this.checkTopLine() + } else { + this.transferLine() + } + this.autoExec() + } + } + } + } else if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData() + }, config.setting.delay || 0) + } else if (this.loaded) { + if (config.wrap.goback === 'true' && data.$$empty) { + this.timer && this.timer.stop() + + MKEmitter.emit('closeTabView', config.$pageId) + } else { + if (selected !== 'false') { + this.checkTopLine() + } else { + this.transferLine() + } + this.autoExec() } } + } else if (config.wrap.datatype === 'public') { + if (this.loaded) { + if (config.wrap.goback === 'true' && data.$$empty) { + this.timer && this.timer.stop() + + MKEmitter.emit('closeTabView', config.$pageId) + } else { + if (selected !== 'false') { + this.checkTopLine() + } else { + this.transferLine() + } + this.autoExec() + } + } + } else { + if (selected !== 'false') { + this.checkTopLine() + } - _data.$$BID = BID || '' - _data.$$BData = BData || '' - _data.$$uuid = _data[config.setting.primaryKey] || '' + if (config.$cache && config.$time && config.wrap.autoExec) { + Api.getLCacheConfig(config.uuid, config.$time, BID).then(res => { + if (res.valid) return + + this.autoExec() + + Api.writeCacheConfig(config.uuid, [], BID) + }) + } else { + this.autoExec() + } + } + } - this.loaded = true + transferSyncData = (syncId) => { + const { config } = this.state - this.setState({sync: false, data: _data}, () => { + if (config.$syncId !== syncId) return + + const { BID, BData, selected } = this.state + + let _data = window.GLOB.SyncData.get(config.dataName) || [] + + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS(), BID) + } + + _data = _data[0] || {$$empty: true} + + _data.$$BID = BID || '' + _data.$$BData = BData || '' + _data.$$uuid = _data[config.setting.primaryKey] || '' + + this.loaded = true + + this.setState({data: _data}, () => { + if (config.wrap.goback === 'true' && _data.$$empty) { + this.timer && this.timer.stop() + + MKEmitter.emit('closeTabView', config.$pageId) + } else { if (selected !== 'false') { this.checkTopLine() - } else if (!config.wrap.cardType && _data.$$uuid) { + } else { this.transferLine() } this.autoExec() - }) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } + } + }) + + window.GLOB.SyncData.delete(config.dataName) + + MKEmitter.removeListener('transferSyncData', this.transferSyncData) + } + + searchRefresh = (searchId) => { + const { config } = this.state + + if (config.$searchId !== searchId) return + + this.setState({}, () => { + this.loadData() + }) } mkPublicData = (publicId, data) => { @@ -235,28 +372,51 @@ _data.$$BID = BID || '' _data.$$BData = BData || '' - _data.$$uuid = _data[config.setting.primaryKey] || '' this.loaded = true this.setState({data: _data}, () => { - if (selected !== 'false') { - this.checkTopLine() + if (config.wrap.goback === 'true' && _data.$$empty) { + this.timer && this.timer.stop() + + MKEmitter.emit('closeTabView', config.$pageId) } else { - this.transferLine() + if (selected !== 'false') { + this.checkTopLine() + } else { + this.transferLine() + } + this.autoExec() } }) } } - autoExec = () => { + autoExec = (times) => { const { config, data } = this.state - if (!config.wrap.autoExec) return + if (!config.wrap.autoExec || (config.wrap.emptyExec === 'false' && data.$$empty)) return - setTimeout(() => { - MKEmitter.emit('triggerBtnId', config.wrap.autoExec, data.$$empty ? [] : [data]) - }, 200) + let btn = document.getElementById('button' + config.wrap.autoExec) + + this.autoTimer && clearTimeout(this.autoTimer) + + if (config.setting.supModule && config.wrap.datatype === 'static' && !data.$$BID) { + + } else if (btn) { + if (config.wrap.execDelay) { + setTimeout(() => { + MKEmitter.emit('triggerBtnId', config.wrap.autoExec, data.$$empty ? [] : [data]) + }, config.wrap.execDelay) + } else { + MKEmitter.emit('triggerBtnId', config.wrap.autoExec, data.$$empty ? [] : [data]) + } + } else if (!times || times < 20) { + times = times ? times + 1 : 1 + this.autoTimer = setTimeout(() => { + this.autoExec(times) + }, 1000) + } } checkTopLine = () => { @@ -280,7 +440,12 @@ transferLine = () => { const { config, data } = this.state - if (config.wrap.cardType) return + if (config.wrap.cardType) { + if (config.wrap.empty === 'hidden') { + MKEmitter.emit('resetSelectLine', config.uuid, data.$$uuid || '', data) + } + return + } MKEmitter.emit('resetSelectLine', config.uuid, data.$$uuid || '', data) } @@ -296,15 +461,24 @@ if (config.uuid !== menuId) return - if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 鍒锋柊婧愮粍浠舵椂锛岄檮甯﹀埛鏂颁笂绾ц涓庡綋鍓嶇粍浠� - MKEmitter.emit('reloadData', config.setting.supModule, BID) + if (['mainline', 'maingrid', 'popclose'].includes(position) && config.setting.supModule) { + MKEmitter.emit('reloadData', config.setting.supModule, position === 'maingrid' ? '' : BID) } else { - this.loadData() + this.loadData('', btn) } + } - 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() + _data[btn.field] = count + + this.setState({ + data: _data + }) } resetParentParam = (MenuID, id, data) => { @@ -314,7 +488,9 @@ if (id !== this.state.BID || id !== '') { this.setState({ BID: id, BData: data }, () => { - this.loadData() + if (config.wrap.datatype !== 'public') { + this.loadData() + } }) } } @@ -323,18 +499,18 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, callback) => { - const { mainSearch } = this.props const { config } = this.state if (config.uuid !== menuId) return - let searches = config.setting.useMSearch && mainSearch ? mainSearch : [] + let searches = [] + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + searches = window.GLOB.SearchBox.get(config.$searchId) || [] + } callback({ - arr_field: '', orderBy: '', - search: searches, - menuName: config.name + search: searches }) } @@ -346,9 +522,8 @@ this.loadData() } - async loadData (hastimer) { - const { mainSearch } = this.props - const { config, arr_field, BID, BData, selected } = this.state + async loadData (type, btn) { + const { config, BID, BData, selected } = this.state if (config.wrap.datatype === 'public') { MKEmitter.emit('reloadData', config.wrap.publicId) @@ -356,8 +531,20 @@ } if (config.wrap.datatype === 'static') { + let _data = {$$BID: BID || '', $$BData: BData, $$empty: true, $$time: new Date().getTime()} + if (BData) { + Object.keys(BData).forEach(key => { + if (/\$/.test(key)) return + _data[key.toLowerCase()] = BData[key] + }) + } + this.setState({ - data: {$$BID: BID || '', $$BData: BData, $$empty: true}, + data: _data, + }, () => { + if (!btn) { + this.autoExec() + } }) return } else if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -368,29 +555,31 @@ return } - let searches = config.setting.useMSearch && mainSearch ? mainSearch : [] + let searches = [] + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + searches = window.GLOB.SearchBox.get(config.$searchId) || [] + } - 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 } - if (!hastimer) { + if (type !== 'timer') { this.setState({ loading: true }) } let _orderBy = config.setting.order || '' - let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID) + let param = UtilsDM.getQueryDataParams(config.setting, searches, _orderBy, 1, 1, BID) let result = await Api.genericInterface(param) if (result.status) { let _data = {} this.loaded = true - if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + if (config.$cache && type === 'init') { + Api.writeCacheConfig(config.uuid, result.data || [], BID) } if (!result.data || !result.data[0]) { @@ -417,32 +606,27 @@ } else { this.transferLine() } - this.autoExec() + if (!btn) { + this.autoExec() + } } }) - if (config.timer && config.clearField) { + if (config.timer && config.clearField && result.data && result.data[0]) { let vals = (config.clearValue || '').split(',') - if (vals.includes(_data[config.clearField])) { + if (vals.includes(result.data[0][config.clearField])) { this.timer && this.timer.stop() } } + + UtilsDM.querySuccess(result) } else { this.setState({ loading: false }) this.timer && this.timer.stop() - if (result.ErrCode === 'N') { - Modal.error({ - title: result.message, - }) - } else { - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) - } + + UtilsDM.queryFail(result) } } @@ -487,7 +671,7 @@ } return ( - <Col className={className} key={index} span={item.setting.width || 6} offset={item.offset || 0}> + <Col className={className} key={index} style={item.wStyle} span={item.setting.width || 6} offset={item.offset || 0}> <CardItem card={item} cards={config} data={data} onClick={() => {this.changeCard(index, item)}}/> </Col> ) -- Gitblit v1.8.0