| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Spin, notification, Checkbox } from 'antd' |
| | | import { Spin, Checkbox } from 'antd' |
| | | |
| | | import Api from '@/api' |
| | | // import Utils from '@/utils/utils.js' |
| | | import UtilsDM from '@/utils/utils-datamanage.js' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import TimerTask from '@/utils/timer-task.js' |
| | | import './index.scss' |
| | | |
| | | const CardCellComponent = asyncComponent(() => import('../cardcellList')) |
| | | |
| | | class BalconyComponent extends Component { |
| | | static propTpyes = { |
| | | BID: PropTypes.any, |
| | | data: PropTypes.array, |
| | | config: PropTypes.object, |
| | | menuType: PropTypes.any, |
| | | config: PropTypes.object |
| | | } |
| | | |
| | | state = { |
| | |
| | | config: null, |
| | | syncConfig: null, |
| | | loading: false, |
| | | sync: false, |
| | | data: {}, |
| | | BData: null, |
| | | syncData: [], |
| | | show: true, |
| | | checked: false |
| | | } |
| | | |
| | | loaded = false |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { data, BID } = this.props |
| | | let _config = fromJS(this.props.config).toJS() |
| | | let _cols = new Map() |
| | | const { config } = this.props |
| | | |
| | | let _data = {} |
| | | let _sync = false |
| | | let _config = fromJS(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 || '' |
| | | } |
| | | |
| | | if (_config.setting && _config.wrap.datatype !== 'static') { |
| | | _sync = _config.setting.sync === 'true' |
| | | let _data = { $$empty: true } |
| | | if (_config.wrap.datatype === 'dynamic') { |
| | | _config.setting.onload = _config.setting.sync === 'true' ? 'false' : 'true' |
| | | |
| | | if (_sync && data) { |
| | | _data = data[_config.dataName] || {} |
| | | if (_data && Array.isArray(_data)) { |
| | | _data = _data[0] || {} |
| | | 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) |
| | | } |
| | | _sync = false |
| | | |
| | | _config.setting.sync = 'false' |
| | | |
| | | _data = _data[0] || {$$empty: true} |
| | | |
| | | this.loaded = true |
| | | |
| | | window.GLOB.SyncData.delete(_config.dataName) |
| | | } |
| | | } else if (_config.wrap.datatype === 'public') { |
| | | if (window.GLOB.CacheData.has(_config.wrap.publicId)) { |
| | | _data = window.GLOB.CacheData.get(_config.wrap.publicId) |
| | | _data = fromJS(_data).toJS() |
| | | } |
| | | } else { |
| | | _data = {} |
| | | _config.elements.forEach(item => { |
| | | if (item.eleType === 'button') return |
| | | if (item.datatype === 'dynamic' && item.field) { |
| | | item.field = item.field.toLowerCase() |
| | | } |
| | | }) |
| | | } |
| | | |
| | | if (_data) { |
| | | _data.$$BID = BID || '' |
| | | _data.$$BID = BID || '' |
| | | _data.$$BData = BData || '' |
| | | if (_config.setting.primaryKey) { |
| | | _data.$$uuid = _data[_config.setting.primaryKey] || '' |
| | | } |
| | | |
| | | _config.columns.forEach(item => { |
| | | _cols.set(item.field, item) |
| | | }) |
| | | if (_config.wrap.datatype === 'static' && BData) { |
| | | Object.keys(BData).forEach(key => { |
| | | if (/\$/.test(key)) return |
| | | _data[key.toLowerCase()] = BData[key] |
| | | }) |
| | | } |
| | | |
| | | if (_config.wrap.position === 'fixed') { |
| | | _config.style.position = 'fixed' |
| | | _config.style.zIndex = 2 |
| | | _config.style.left = _config.wrap.left || '' |
| | | _config.style.right = _config.wrap.right || '' |
| | | _config.style.top = _config.wrap.top || '' |
| | | _config.style.bottom = _config.wrap.bottom || '' |
| | | _config.style.transform = _config.wrap.transform || '' |
| | | _config.style.width = _config.wrap.realwidth || '' |
| | | if (!_config.style.position) { |
| | | if (_config.wrap.position === 'fixed' || _config.wrap.position === 'absolute') { |
| | | _config.style.position = _config.wrap.position |
| | | _config.style.zIndex = _config.wrap.position === 'fixed' ? 3 : 2 |
| | | _config.style.left = _config.wrap.left || '' |
| | | _config.style.right = _config.wrap.right || '' |
| | | _config.style.top = _config.wrap.top || '' |
| | | _config.style.bottom = _config.wrap.bottom || '' |
| | | _config.style.transform = _config.wrap.transform || '' |
| | | _config.style.width = _config.wrap.realwidth || '' |
| | | } else { |
| | | _config.style.zIndex = 1 |
| | | _config.style.left = _config.wrap.left || '' |
| | | _config.style.right = _config.wrap.right || '' |
| | | _config.style.top = _config.wrap.top || '' |
| | | _config.style.bottom = _config.wrap.bottom || '' |
| | | } |
| | | } |
| | | |
| | | let show = true |
| | |
| | | } |
| | | return item |
| | | }) |
| | | } else if (_config.wrap.linkType === 'sup') { |
| | | _config.wrap.supModule = _config.wrap.supModule.pop() |
| | | if (_config.wrap.supControl === 'hidden') { |
| | | show = false |
| | | } |
| | | } else if (_config.wrap.linkType === 'sup' && _config.wrap.supControl === 'hidden') { |
| | | show = false |
| | | } |
| | | |
| | | this.setState({ |
| | | show, |
| | | syncConfig, |
| | | sync: _sync, |
| | | data: _data, |
| | | BID: BID || '', |
| | | config: _config, |
| | | arr_field: _config.columns.map(col => col.field).join(','), |
| | | }, () => { |
| | | if (_config.wrap.datatype !== 'static' && _config.setting && _config.setting.sync !== 'true' && _config.setting.onload === 'true') { |
| | | this.loadData() |
| | | } |
| | | config: _config |
| | | }) |
| | | } |
| | | |
| | | componentDidMount () { |
| | | const { config } = this.state |
| | | |
| | | MKEmitter.addListener('reloadData', this.reloadData) |
| | | MKEmitter.addListener('refreshLineData', this.refreshLineData) |
| | | MKEmitter.addListener('syncBalconyData', this.syncBalconyData) |
| | | 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) |
| | | } |
| | | |
| | | if (config.wrap.datatype === 'dynamic') { |
| | | if (config.timer) { |
| | | this.timer = new TimerTask() |
| | | this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {this.loadData('timer')}) |
| | | } |
| | | |
| | | this.initExec() |
| | | } |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | |
| | | return |
| | | } |
| | | MKEmitter.removeListener('reloadData', this.reloadData) |
| | | MKEmitter.removeListener('mkPublicData', this.mkPublicData) |
| | | MKEmitter.removeListener('refreshLineData', this.refreshLineData) |
| | | MKEmitter.removeListener('syncBalconyData', this.syncBalconyData) |
| | | MKEmitter.removeListener('resetSelectLine', this.resetParentParam) |
| | | MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) |
| | | MKEmitter.removeListener('transferSyncData', this.transferSyncData) |
| | | MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) |
| | | |
| | | this.timer && this.timer.stop() |
| | | } |
| | | |
| | | /** |
| | | * @description 图表数据更新,刷新内容 |
| | | */ |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | const { sync, config, BID } = this.state |
| | | initExec = () => { |
| | | const { config, BID } = 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] |
| | | if (_data && Array.isArray(_data)) { |
| | | _data = _data[0] |
| | | 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}) |
| | | }) |
| | | } |
| | | } 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 (config.setting.onload === 'true') { |
| | | setTimeout(() => { |
| | | this.loadData() |
| | | }, config.setting.delay || 0) |
| | | } |
| | | } |
| | | |
| | | if (_data) { |
| | | _data.$$BID = BID || '' |
| | | } |
| | | transferSyncData = (syncId) => { |
| | | const { config } = this.state |
| | | |
| | | this.setState({sync: false, data: _data}) |
| | | 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(), 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}) |
| | | |
| | | window.GLOB.SyncData.delete(config.dataName) |
| | | |
| | | MKEmitter.removeListener('transferSyncData', this.transferSyncData) |
| | | } |
| | | |
| | | mkPublicData = (publicId, data) => { |
| | | const { config, BID, BData } = this.state |
| | | |
| | | if (config.wrap.datatype === 'public' && config.wrap.publicId === publicId) { |
| | | let _data = fromJS(data).toJS() |
| | | |
| | | _data.$$BID = BID || '' |
| | | _data.$$BData = BData || '' |
| | | |
| | | this.setState({data: _data}) |
| | | } |
| | | } |
| | | |
| | |
| | | * @param {*} position // 刷新位置 |
| | | * @param {*} btn // 执行的按钮 |
| | | */ |
| | | refreshByButtonResult = (menuId, position, btn) => { |
| | | refreshByButtonResult = (menuId, position, btn, id, lines) => { |
| | | const { config, BID, syncConfig } = this.state |
| | | |
| | | if (config.uuid !== menuId) return |
| | | |
| | | this.loadData() // 数据刷新 |
| | | |
| | | let supModule = config.wrap.supModule |
| | | |
| | | if (syncConfig) { |
| | | supModule = syncConfig.setting.supModule |
| | | MKEmitter.emit('refreshByButtonResult', syncConfig.uuid, position, btn, id, lines) |
| | | |
| | | MKEmitter.emit('refreshByButtonResult', syncConfig.uuid, position, btn) |
| | | this.loadData() |
| | | } else { |
| | | if (['mainline', 'maingrid', 'popclose'].includes(position) && config.wrap.supModule) { |
| | | MKEmitter.emit('reloadData', config.wrap.supModule, position === 'maingrid' ? '' : BID) |
| | | } else { |
| | | this.loadData() |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (btn.syncComponentId && btn.syncComponentId !== config.uuid && btn.syncComponentId !== supModule) { |
| | | MKEmitter.emit('reloadData', btn.syncComponentId) // 同级标签刷新 |
| | | } |
| | | refreshLineData = (menuId, btn, uuid, count) => { |
| | | const { config, data } = this.state |
| | | |
| | | if (position === 'mainline' && supModule) { // 主表行刷新 |
| | | MKEmitter.emit('reloadData', supModule, (BID || 'empty')) |
| | | } else if (position === 'popclose') { // 标签关闭刷新 |
| | | supModule && MKEmitter.emit('reloadData', supModule, (BID || 'empty')) |
| | | btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId) |
| | | } |
| | | if (config.uuid !== menuId) return |
| | | |
| | | let _data = fromJS(data).toJS() |
| | | _data[btn.field] = count |
| | | |
| | | this.setState({ |
| | | data: _data |
| | | }) |
| | | } |
| | | |
| | | syncBalconyData = (menuId, data, checked) => { |
| | |
| | | this.setState({syncData: data, checked}) |
| | | } |
| | | |
| | | resetParentParam = (MenuID, id) => { |
| | | resetParentParam = (MenuID, id, data) => { |
| | | const { config, syncConfig } = this.state |
| | | |
| | | if (syncConfig) { |
| | | if (!syncConfig.setting.supModule || syncConfig.setting.supModule !== MenuID) return |
| | | |
| | | if (id !== this.state.BID) { |
| | | this.setState({ BID: id }, () => { |
| | | if (id !== this.state.BID || id !== '') { |
| | | this.setState({ BID: id, BData: data }, () => { |
| | | this.loadData() |
| | | }) |
| | | } |
| | |
| | | this.setState({ show: id ? true : false }) |
| | | } |
| | | |
| | | if (id !== this.state.BID) { |
| | | this.setState({ BID: id }, () => { |
| | | if (id !== this.state.BID || id !== '') { |
| | | this.setState({ BID: id, BData: data }, () => { |
| | | this.loadData() |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 导出Excel时,获取页面搜索排序等参数 |
| | | */ |
| | | queryModuleParam = (menuId, callback) => { |
| | | const { config } = this.state |
| | | |
| | | if (config.uuid !== menuId) return |
| | | |
| | | callback({ |
| | | orderBy: '', |
| | | search: [], |
| | | }) |
| | | } |
| | | |
| | | reloadData = (menuId) => { |
| | |
| | | this.loadData() |
| | | } |
| | | |
| | | async loadData () { |
| | | const { menuType } = this.props |
| | | const { config, arr_field, BID } = this.state |
| | | async loadData (type) { |
| | | const { config, BID, BData } = this.state |
| | | |
| | | if (config.wrap.datatype === 'public') { |
| | | MKEmitter.emit('reloadData', config.wrap.publicId) |
| | | return |
| | | } |
| | | |
| | | 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 || ''}, |
| | | data: _data |
| | | }) |
| | | return |
| | | } else if (config.setting.supModule && !BID) { // BID 不存在时,不做查询 |
| | | this.setState({ |
| | | data: {$$BID: BID || ''}, |
| | | data: {$$BID: BID || '', $$BData: BData, $$empty: true}, |
| | | }) |
| | | this.loaded = true |
| | | return |
| | | } |
| | | |
| | | let searches = [] |
| | | |
| | | this.setState({ |
| | | loading: true |
| | | }) |
| | | 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, menuType) |
| | | let param = UtilsDM.getQueryDataParams(config.setting, searches, _orderBy, 1, 1, BID) |
| | | |
| | | let result = await Api.genericInterface(param) |
| | | if (result.status) { |
| | | let _data = result.data && result.data[0] ? result.data[0] : {} |
| | | let _data = {} |
| | | |
| | | this.loaded = true |
| | | if (config.$cache && type === 'init') { |
| | | Api.writeCacheConfig(config.uuid, result.data || [], BID) |
| | | } |
| | | |
| | | if (!result.data || !result.data[0]) { |
| | | _data.$$empty = true |
| | | } else { |
| | | _data = result.data[0] |
| | | } |
| | | |
| | | _data.$$BID = BID || '' |
| | | _data.$$BData = BData |
| | | _data.$$uuid = _data[config.setting.primaryKey] || '' |
| | | |
| | | this.setState({ |
| | | data: _data, |
| | | 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() |
| | | } |
| | | } |
| | | |
| | | UtilsDM.querySuccess(result) |
| | | } else { |
| | | this.setState({ |
| | | loading: false, |
| | | loading: false |
| | | }) |
| | | notification.error({ |
| | | top: 92, |
| | | message: result.message, |
| | | duration: 10 |
| | | }) |
| | | this.timer && this.timer.stop() |
| | | |
| | | UtilsDM.queryFail(result) |
| | | } |
| | | } |
| | | |
| | |
| | | MKEmitter.emit('mkCheckAll', syncConfig.uuid, e.target.checked) |
| | | } |
| | | |
| | | triggerButton = () => { |
| | | const { config, data } = this.state |
| | | |
| | | if (config.wrap.linkbtn) { |
| | | MKEmitter.emit('triggerBtnId', config.wrap.linkbtn, data.$$empty ? [] : [data]) |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { config, loading, data, show, syncConfig, syncData, checked } = this.state |
| | | |
| | | if (config.wrap.empty === 'hidden' && (!data || data.$$empty)) return null |
| | | |
| | | let style = {...config.style} |
| | | if (config.wrap.bgField) { |
| | | style.backgroundImage = `url('${data[config.wrap.bgField] || ''}')` |
| | | } |
| | | |
| | | return ( |
| | | <div className={'custom-balcony-box' + (!show ? ' hidden' : '')} style={config.style}> |
| | | <div className={'custom-balcony-box' + (!show ? ' hidden' : '')} id={'anchor' + config.uuid} style={style} onClick={this.triggerButton}> |
| | | {loading ? |
| | | <div className="loading-mask"> |
| | | <div className="loading-mask" onClick={(e) => e.stopPropagation()}> |
| | | <div className="ant-spin-blur"></div> |
| | | <Spin /> |
| | | </div> : null |
| | | } |
| | | {config.wrap.checkAll === 'show' ? <div className="check-all"><Checkbox checked={checked} onChange={this.checkAll}>全选</Checkbox></div> : null} |
| | | {config.wrap.checkAll === 'show' ? <div className="check-all" onClick={(e) => e.stopPropagation()}><Checkbox checked={checked} onChange={this.checkAll}>全选</Checkbox></div> : null} |
| | | <CardCellComponent data={data} syncData={syncData || []} cards={syncConfig || config} cardCell={config} elements={config.elements}/> |
| | | </div> |
| | | ) |