From 71e3da644eca32a5aa40503e903efb0640748093 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 21 七月 2023 17:00:59 +0800 Subject: [PATCH] 2023-07-21 --- src/tabviews/custom/components/code/sand-box/index.jsx | 108 src/tabviews/custom/components/editor/braft-editor/index.jsx | 96 src/tabviews/custom/components/tree/antd-tree/index.jsx | 118 src/tabviews/custom/components/tabs/antv-tabs/index.jsx | 4 src/templates/zshare/verifycard/customscript/index.jsx | 2 src/tabviews/zshare/actionList/excelInbutton/index.jsx | 10 src/tabviews/custom/popview/index.jsx | 234 +- src/templates/sharecomponent/actioncomponent/verifyexcelout/utils.jsx | 4 src/tabviews/basetable/index.jsx | 71 src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx | 2 src/views/billprint/index.jsx | 62 src/tabviews/subtabtable/index.jsx | 21 src/tabviews/commontable/index.jsx | 22 src/tabviews/zshare/actionList/normalbutton/index.jsx | 37 src/tabviews/custom/components/card/data-card/index.jsx | 266 +- src/tabviews/custom/components/card/prop-card/index.jsx | 150 + src/tabviews/custom/components/group/normal-group/index.jsx | 312 --- src/tabviews/custom/components/table/normal-table/index.jsx | 225 +- src/tabviews/custom/components/chart/antv-pie/index.jsx | 132 src/tabviews/custom/components/timeline/normal-timeline/index.jsx | 133 src/tabviews/custom/components/table/edit-table/normalTable/index.jsx | 10 src/tabviews/zshare/mutilform/index.jsx | 4 src/tabviews/custom/components/carousel/prop-card/index.jsx | 127 src/tabviews/custom/index.jsx | 262 +- src/tabviews/zshare/actionList/asyncButtonComponent.jsx | 2 src/tabviews/treepage/index.jsx | 6 src/tabviews/custom/components/chart/antv-scatter/index.jsx | 146 + src/tabviews/custom/components/chart/antv-bar-line/index.jsx | 146 + src/tabviews/custom/components/table/base-table/index.jsx | 86 src/tabviews/custom/components/chart/antv-dashboard/index.jsx | 140 + src/tabviews/zshare/topSearch/index.jsx | 19 src/tabviews/custom/components/card/double-data-card/index.jsx | 74 src/tabviews/custom/components/chart/antv-G6/index.jsx | 122 src/tabviews/zshare/actionList/exceloutbutton/index.jsx | 19 src/tabviews/custom/components/carousel/data-card/index.jsx | 143 + src/tabviews/custom/components/table/edit-table/index.jsx | 63 src/tabviews/custom/components/calendar/index.jsx | 39 src/templates/sharecomponent/actioncomponent/verifyprint/utils.jsx | 4 src/tabviews/custom/components/form/simple-form/index.jsx | 109 src/tabviews/subtable/index.jsx | 23 src/tabviews/custom/components/iframe/index.jsx | 92 src/tabviews/custom/components/chart/custom-chart/index.jsx | 146 + src/utils/utils.js | 36 src/templates/sharecomponent/actioncomponent/verifyexcelout/index.jsx | 2 src/index.js | 2 src/tabviews/custom/components/form/tab-form/index.jsx | 136 src/tabviews/custom/components/card/table-card/index.jsx | 165 + src/tabviews/custom/components/share/tabtransfer/index.jsx | 238 +- src/tabviews/zshare/actionList/printbutton/index.jsx | 7 src/tabviews/custom/components/form/step-form/index.jsx | 154 + src/tabviews/custom/components/card/balcony/index.jsx | 91 51 files changed, 2,327 insertions(+), 2,295 deletions(-) diff --git a/src/index.js b/src/index.js index 5a0bce2..e9c4830 100644 --- a/src/index.js +++ b/src/index.js @@ -298,6 +298,8 @@ window.GLOB.CacheVoucher = new Map() // 缂撳瓨鍑瘉淇℃伅 window.GLOB.UserCacheMap = new Map() // 缂撳瓨鐢ㄦ埛鑷畾涔夎缃� window.GLOB.CacheData = new Map() // 瀛樺偍閫変腑鏁版嵁 + window.GLOB.SearchBox = new Map() // 瀛樺偍鎼滅储鏉′欢 + window.GLOB.SyncData = new Map() // 瀛樺偍鍚屾鏌ヨ鏁版嵁 render(Route) }) diff --git a/src/tabviews/basetable/index.jsx b/src/tabviews/basetable/index.jsx index e62eb9e..630f728 100644 --- a/src/tabviews/basetable/index.jsx +++ b/src/tabviews/basetable/index.jsx @@ -37,9 +37,7 @@ viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 lostmsg: '', // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅 config: null, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷粍浠剁瓑 - mainSearch: null, // 涓绘悳绱� userConfig: null, // 鐢ㄦ埛鑷畾涔夎缃� - data: null, // 鍒楄〃鏁版嵁闆� loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� visible: false, // 鏍囩椤垫帶鍒� shortcuts: null, // 蹇嵎閿� @@ -175,20 +173,30 @@ } // 鑾峰彇涓绘悳绱㈡潯浠� - let mainSearch = [] config.components.forEach(component => { if (component.type === 'tabs') return - component.search = component.search.map(item => { - item.oriInitval = item.initval - if (['text', 'select', 'link'].includes(item.type) && param.$searchkey === item.field) { - item.initval = param.$searchval + if (param.$searchkey) { + component.search = component.search.map(item => { + if (['text', 'select', 'link'].includes(item.type) && param.$searchkey === item.field) { + item.initval = param.$searchval + } + + return item + }) + + component.$searches = Utils.initMainSearch(component.search) + } + + if (component.$searches.length) { + component.$main = true + + window.GLOB.SearchBox.set(MenuID, component.$searches) + + if (component.$s_req) { + window.GLOB.SearchBox.set(MenuID + 'required', true) } - - return item - }) - - mainSearch = Utils.initMainSearch(component.search) + } }) let BID = param.$BID || '' @@ -199,8 +207,7 @@ BID: BID, shortcuts: shortcuts.length > 0 ? shortcuts : null, config, - autoMatic, - mainSearch + autoMatic }, () => { setTimeout(() => { // 寤舵椂鍔犺浇鐘舵�� this.setState({ @@ -268,6 +275,7 @@ filterComponent = (components, roleId, permAction, skip, urlparam, pageId, MenuName) => { return components.filter(item => { item.$pageId = pageId + item.$searchId = pageId item.$menuname = (MenuName || '') + '-' + (item.name || '涓昏〃') @@ -298,9 +306,9 @@ } // 鎼滅储鏉′欢鍒濆鍖� - if (item.search && item.search.length > 0) { - item.search = Utils.initSearchVal(item.search) - } + Utils.initSearchVal(item) + + item.$searches = Utils.initMainSearch(item.search) if (item.setting.supModule) { let pid = item.setting.supModule.pop() @@ -512,6 +520,13 @@ } component.setting.useMSearch = component.setting.useMSearch === 'true' + if (component.setting.useMSearch) { + if (!window.GLOB.SearchBox.has(component.$searchId)) { + component.setting.useMSearch = false + } else if (window.GLOB.SearchBox.has(component.$searchId + 'required')) { + component.$s_req = true + } + } if (component.setting.interType !== 'system') { // 涓嶄娇鐢ㄧ郴缁熷嚱鏁版椂 component.setting.sync = 'false' @@ -540,10 +555,8 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'') - component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/') - _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'') - _customScript = _customScript.replace(/@\$/ig, '*/') + component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') + _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') @@ -624,6 +637,9 @@ } else { window.GLOB.CacheData.delete(item.uuid) } + if (item.type !== 'tabs' && item.$main) { + window.GLOB.SearchBox.delete(item.$searchId) + } }) } @@ -640,20 +656,13 @@ config: null, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷粍浠剁瓑 loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� shortcuts: null, - data: '' }, () => { this.loadconfig() }) } - resetSearch = (search) => { - this.setState({mainSearch: null}, () => { - this.setState({mainSearch: search}) - }) - } - getComponents = () => { - const { config, data, mainSearch } = this.state + const { config } = this.state if (!config || !config.components) return @@ -661,13 +670,13 @@ if (item.type === 'tabs') { return ( <Col span={item.width} key={item.uuid}> - <AntvTabs config={item} mainSearch={mainSearch} /> + <AntvTabs config={item}/> </Col> ) } else { return ( <Col span={item.width} key={item.uuid}> - <MkBaseTable config={item} data={data}/> + <MkBaseTable config={item}/> </Col> ) } diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx index 6ad0a67..4945a41 100644 --- a/src/tabviews/commontable/index.jsx +++ b/src/tabviews/commontable/index.jsx @@ -63,7 +63,6 @@ statFields: [], // 鍚堣瀛楁 statFValue: [], // 鍚堣鍊� absFields: [], // 缁濆鍊煎瓧娈� - hasReqFields: false, autoMatic: null, visible: false } @@ -209,19 +208,13 @@ chartId = config.charts[0] ? config.charts[0].uuid : '' } - config.search = Utils.initSearchVal(config.search) + Utils.initSearchVal(config) // 瀛楁閫忚鍙婂繀濉爣蹇� - let hasReqFields = false config.search = config.search.map(item => { if (['text', 'select', 'link'].includes(item.type) && param && param.$searchkey === item.field) { item.initval = param.$searchval } - - if (item.required) { - hasReqFields = true - } - return item }) @@ -263,10 +256,8 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*') - config.setting.dataresource = config.setting.dataresource.replace(/@\$/ig, '*/') - config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*') - config.setting.customScript = config.setting.customScript.replace(/@\$/ig, '*/') + config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/') + config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/') } else { config.setting.dataresource = config.setting.dataresource.replace(/@\$|\$@/ig, '') config.setting.customScript = config.setting.customScript.replace(/@\$|\$@/ig, '') @@ -471,8 +462,7 @@ columns: _columns, arr_field: _arrField.join(','), BID: param && param.$BID ? param.$BID : '', - search: Utils.initMainSearch(config.search), - hasReqFields + search: Utils.initMainSearch(config.search) }, () => { if (config.setting.onload !== 'false') { // 鍒濆鍖栧彲鍔犺浇 this.loadData() @@ -540,14 +530,14 @@ loadData = (id) => { const { MenuID } = this.props - const { setting, search, hasReqFields, ContainerId } = this.state + const { setting, search, config, ContainerId } = this.state this.setState({ selectedData: [] }) MKEmitter.emit('changeTableLine', ContainerId, MenuID, '', '') - if (hasReqFields) { + if (config.$s_req) { let requireFields = search.filter(item => item.required && item.value === '') if (requireFields.length > 0) { diff --git a/src/tabviews/custom/components/calendar/index.jsx b/src/tabviews/custom/components/calendar/index.jsx index 628bfeb..6363ec0 100644 --- a/src/tabviews/custom/components/calendar/index.jsx +++ b/src/tabviews/custom/components/calendar/index.jsx @@ -4,7 +4,6 @@ import { Spin, notification, Modal } from 'antd' 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' @@ -18,7 +17,6 @@ class NormalCalendar extends Component { static propTpyes = { config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 } state = { @@ -70,7 +68,7 @@ BData: BData, config: _config, arr_field: _config.columns.map(col => col.field).join(','), - search: Utils.initMainSearch(_config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 + search: _config.$searches }, () => { if (_config.setting.onload === 'true') { setTimeout(() => { @@ -86,6 +84,10 @@ MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } if (config.$cache && !this.loaded) { Api.getLCacheConfig(config.uuid).then(res => { @@ -117,21 +119,19 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { + searchRefresh = (searchId) => { const { config } = this.state - if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } + if (config.$searchId !== searchId) return + + this.setState({}, () => { + this.loadData() + }) } /** @@ -172,7 +172,6 @@ } async loadData () { - const { mainSearch } = this.props const { config, arr_field, BID, search, year } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -184,17 +183,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 } diff --git a/src/tabviews/custom/components/card/balcony/index.jsx b/src/tabviews/custom/components/card/balcony/index.jsx index 7f6990c..e65688f 100644 --- a/src/tabviews/custom/components/card/balcony/index.jsx +++ b/src/tabviews/custom/components/card/balcony/index.jsx @@ -14,8 +14,7 @@ class BalconyComponent extends Component { static propTpyes = { - data: PropTypes.array, - config: PropTypes.object, + config: PropTypes.object } state = { @@ -23,7 +22,6 @@ config: null, syncConfig: null, loading: false, - sync: false, data: {}, BData: null, syncData: [], @@ -34,12 +32,9 @@ loaded = false UNSAFE_componentWillMount () { - const { data, initdata } = this.props - let _config = fromJS(this.props.config).toJS() + const { config } = this.props - let _data = { $$empty: true } - let _sync = false - + let _config = fromJS(config).toJS() let BID = '' let BData = '' @@ -52,23 +47,22 @@ BID = BData.$BID || '' } + let _data = { $$empty: true } if (_config.wrap.datatype === 'dynamic') { - _sync = _config.setting.sync === 'true' + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] - if (_sync && data) { - _data = data[_config.dataName] || {$$empty: true} - if (_data && Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS()) } - _sync = false + + _config.setting.sync = 'false' + + _data = _data[0] || {$$empty: true} + this.loaded = true - } else if (_sync && initdata) { - _data = initdata - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false - this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } } else if (_config.wrap.datatype === 'public' && window.GLOB.CacheData.get(_config.wrap.publicId)) { _data = window.GLOB.CacheData.get(_config.wrap.publicId) @@ -121,13 +115,12 @@ 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 === 'dynamic' && _config.setting && _config.setting.sync !== 'true') { + if (_config.wrap.datatype === 'dynamic' && config.setting.sync !== 'true') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) @@ -139,11 +132,15 @@ 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('refreshLineData', this.refreshLineData) 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) @@ -158,7 +155,7 @@ Api.getLCacheConfig(config.uuid).then(res => { if (!res || this.loaded) return - let _data = res[0] + let _data = res[0] || {$$empty: true} _data.$$uuid = _data[config.setting.primaryKey] || '' this.setState({data: _data}) @@ -176,38 +173,42 @@ } 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('refreshLineData', this.refreshLineData) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) this.timer && this.timer.stop() } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config, BID, BData } = this.state + transferSyncData = (syncId) => { + const { config } = 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 (_data && Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - } + if (config.$syncId !== syncId) return - _data.$$BID = BID || '' - _data.$$BData = BData || '' - _data.$$uuid = _data[config.setting.primaryKey] || '' + const { BID, BData } = this.state - this.loaded = true + let _data = window.GLOB.SyncData.get(config.dataName) || [] - this.setState({sync: false, data: _data}) + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) } + + _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) => { @@ -359,7 +360,7 @@ this.loaded = true if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } if (!result.data || !result.data[0]) { diff --git a/src/tabviews/custom/components/card/data-card/index.jsx b/src/tabviews/custom/components/card/data-card/index.jsx index 8ab93fe..5b58e10 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 = '' @@ -119,49 +115,12 @@ }) _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 @@ -175,8 +134,6 @@ _config.wrap.layout = (_config.wrap.layout || 'grid') + '-layout float-' + (_config.wrap.cardFloat || 'left') _config.wrap.wrapClass = `${_config.wrap.selStyle} ${_config.wrap.cardType || ''} ${_config.wrap.scale}` - - this.loaded = _data !== null let pageOptions = ['10', '25', '50', '100', '500', '1000'] @@ -192,6 +149,36 @@ } } + let _data = null + 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()) + } + + _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) + } + this.setState({ pageSize: _config.setting.pageSize || 10, pageOptions, @@ -199,20 +186,21 @@ selected, precards, nextcards, - sync: _sync, data: _data, BID: BID || '', BData: BData || '', config: _config, card: _card, - search: Utils.initMainSearch(_config.search), + search: _config.$searches, arr_field: _config.columns.map(col => col.field).join(','), }, () => { - if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') { + if (config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) } + + this.loaded && this.prevCheck() }) } @@ -221,10 +209,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('refreshLineData', this.refreshLineData) 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() @@ -263,61 +259,70 @@ 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 () { this.setState = () => { return } MKEmitter.removeListener('reloadData', this.reloadData) MKEmitter.removeListener('mkCheckAll', this.mkCheckAll) - MKEmitter.removeListener('resetSelectLine', this.resetParentParam) - MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) + 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() + } + + 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() + }) } /** @@ -398,6 +403,20 @@ 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'}) + } } checkTopLine = (id) => { @@ -616,18 +635,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) }) } @@ -640,7 +659,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 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -657,12 +675,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) { @@ -673,17 +686,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 } @@ -705,16 +718,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) { @@ -810,16 +818,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) }) } diff --git a/src/tabviews/custom/components/card/double-data-card/index.jsx b/src/tabviews/custom/components/card/double-data-card/index.jsx index 08f6dd9..7589687 100644 --- a/src/tabviews/custom/components/card/double-data-card/index.jsx +++ b/src/tabviews/custom/components/card/double-data-card/index.jsx @@ -5,7 +5,6 @@ import { DownOutlined, UpOutlined, PlusSquareOutlined, MinusSquareOutlined } from '@ant-design/icons' import Api from '@/api' -import Utils from '@/utils/utils.js' import UtilsDM from '@/utils/utils-datamanage.js' import MKEmitter from '@/utils/events.js' import TimerTask from '@/utils/timer-task.js' @@ -20,7 +19,6 @@ class DoubleDataCard extends Component { static propTpyes = { config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 } state = { @@ -196,7 +194,7 @@ subconfig: subconfig, wrapStyle: wrapStyle, card: _card, - search: Utils.initMainSearch(_config.search), + search: _config.$searches, arr_field: _config.columns.map(col => col.field).join(','), }, () => { if (_config.setting.onload === 'true') { @@ -211,11 +209,15 @@ 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('refreshLineData', this.refreshLineData) MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + if (config.timer) { this.timer = new TimerTask() this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { @@ -276,27 +278,28 @@ return !is(fromJS(this.state), fromJS(nextState)) } - UNSAFE_componentWillReceiveProps (nextProps) { - const { config } = this.state - - if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({pageIndex: 1}, () => { - this.loadData() - }) - } - } - componentWillUnmount () { this.setState = () => { return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) + MKEmitter.removeListener('refreshLineData', this.refreshLineData) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) - MKEmitter.removeListener('refreshLineData', this.refreshLineData) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) this.timer && this.timer.stop() + } + + searchRefresh = (searchId) => { + const { config } = this.state + + if (config.$searchId !== searchId) return + + this.setState({pageIndex: 1}, () => { + this.loadData() + }) } /** @@ -501,18 +504,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()) + 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) }) } @@ -525,7 +528,6 @@ } async loadData (id, type) { - const { mainSearch } = this.props const { config, arr_field, pageIndex, pageSize, search, BID, BData, selected, card, orderBy } = this.state if (config.setting.supModule && !BID && config.wrap.supKey !== 'false') { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -556,17 +558,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 } @@ -588,7 +590,7 @@ 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')) { @@ -745,16 +747,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) }) } diff --git a/src/tabviews/custom/components/card/prop-card/index.jsx b/src/tabviews/custom/components/card/prop-card/index.jsx index 26f4ea6..fbec582 100644 --- a/src/tabviews/custom/components/card/prop-card/index.jsx +++ b/src/tabviews/custom/components/card/prop-card/index.jsx @@ -15,9 +15,7 @@ class PropCard extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -25,7 +23,6 @@ config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� activeKey: '', // 閫変腑鏁版嵁 - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: {}, // 鏁版嵁 BData: '', selected: 'false', @@ -35,9 +32,9 @@ 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 @@ -54,22 +51,20 @@ } if (_config.wrap.datatype === 'dynamic') { - _sync = _config.setting.sync === 'true' + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] - if (_sync && data) { - _data = data[_config.dataName] || {$$empty: true} - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS()) } - _sync = false + + _config.setting.sync = 'false' + + _data = _data[0] || {$$empty: true} + this.loaded = true - } else if (_sync && initdata) { - _data = initdata - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false - this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } } else if (_config.wrap.datatype === 'public' && window.GLOB.CacheData.get(_config.wrap.publicId)) { _data = window.GLOB.CacheData.get(_config.wrap.publicId) @@ -120,14 +115,13 @@ 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') { + if (_config.wrap.datatype === 'dynamic' && config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) @@ -166,10 +160,18 @@ 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('refreshLineData', this.refreshLineData) 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.wrap.datatype === 'public') { MKEmitter.addListener('mkPublicData', this.mkPublicData) @@ -184,7 +186,7 @@ Api.getLCacheConfig(config.uuid).then(res => { if (!res || this.loaded) return - let _data = res[0] + let _data = res[0] || {$$empty: true} _data.$$uuid = _data[config.setting.primaryKey] || '' this.setState({data: _data}) @@ -202,54 +204,65 @@ } MKEmitter.removeListener('reloadData', this.reloadData) MKEmitter.removeListener('mkPublicData', this.mkPublicData) - MKEmitter.removeListener('resetSelectLine', this.resetParentParam) - MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) + 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 + transferSyncData = (syncId) => { + const { config } = 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.$syncId !== syncId) return - _data.$$BID = BID || '' - _data.$$BData = BData || '' - _data.$$uuid = _data[config.setting.primaryKey] || '' + const { BID, BData, selected } = this.state - this.loaded = true + let _data = window.GLOB.SyncData.get(config.dataName) || [] - this.setState({sync: false, 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 (_data.$$uuid) { - this.transferLine() - } - this.autoExec() - } - }) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) } + + _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 (_data.$$uuid) { + this.transferLine() + } + this.autoExec() + } + }) + + 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) => { @@ -373,12 +386,14 @@ * @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: '', @@ -397,7 +412,6 @@ } async loadData (hastimer, btn) { - const { mainSearch } = this.props const { config, arr_field, BID, BData, selected } = this.state if (config.wrap.datatype === 'public') { @@ -422,10 +436,12 @@ 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 } @@ -444,7 +460,7 @@ this.loaded = true if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } if (!result.data || !result.data[0]) { diff --git a/src/tabviews/custom/components/card/table-card/index.jsx b/src/tabviews/custom/components/card/table-card/index.jsx index c23e2c7..ed2f53c 100644 --- a/src/tabviews/custom/components/card/table-card/index.jsx +++ b/src/tabviews/custom/components/card/table-card/index.jsx @@ -5,7 +5,6 @@ import { DownOutlined } from '@ant-design/icons' 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' @@ -17,9 +16,7 @@ class TableCard extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -29,7 +26,6 @@ search: null, // 鎼滅储鏉′欢 pageIndex: 1, // 椤电爜 total: 0, // 鎬绘暟 - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: null, // 鏁版嵁 BData: '' } @@ -41,12 +37,9 @@ * 1銆� initdata 涓烘墦鍗版椂浣跨敤鐨勬暟鎹泦 */ UNSAFE_componentWillMount () { - const { data, initdata } = this.props - let _config = fromJS(this.props.config).toJS() + const { config } = this.props - let _data = null - let _sync = _config.setting.sync === 'true' - + let _config = fromJS(config).toJS() let BID = '' let BData = '' @@ -57,25 +50,6 @@ } if (BData) { BID = BData.$BID || '' - } - - if (_config.setting.sync === 'true' && data) { - _data = data[_config.dataName] || [] - _sync = false - } else if (_config.setting.sync === 'true' && initdata) { - _data = initdata || [] - _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 @@ -92,18 +66,39 @@ _config.wrap.contentHeight = showHeader ? 'calc(100% - 45px)' : '100%' } - this.loaded = _data !== null + let _data = null + 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()) + } + + _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 + '' + return item + }) + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) + } this.setState({ - sync: _sync, BID: BID || '', BData: BData || '', data: _data, config: _config, - search: Utils.initMainSearch(_config.search), + search: _config.$searches, arr_field: _config.columns.map(col => col.field).join(','), }, () => { - if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') { + if (config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) @@ -115,10 +110,18 @@ 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('refreshLineData', this.refreshLineData) 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() @@ -156,43 +159,56 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) - MKEmitter.removeListener('resetSelectLine', this.resetParentParam) - MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) + 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 } = this.state + transferSyncData = (syncId) => { + const { config } = 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 (config.$syncId !== syncId) return - _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 - }) + const { BID, BData } = this.state - this.loaded = true + let _data = window.GLOB.SyncData.get(config.dataName) || [] - this.setState({sync: false, data: _data}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) + 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 + '' + + return item + }) + + 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({}, () => { + this.loadData() + }) } /** @@ -253,18 +269,18 @@ * @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()) + 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) }) } @@ -277,7 +293,6 @@ } async loadData (type) { - const { mainSearch } = this.props const { config, arr_field, pageIndex, search, BID, BData } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -291,17 +306,17 @@ } let searches = search ? fromJS(search).toJS() : [] - if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - let keys = searches.map(item => item.key) + 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)) { - 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 } @@ -323,7 +338,7 @@ this.loaded = true if (config.$cache && pageIndex === 1 && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } let data = [] diff --git a/src/tabviews/custom/components/carousel/data-card/index.jsx b/src/tabviews/custom/components/carousel/data-card/index.jsx index 50fdeb2..62fbc61 100644 --- a/src/tabviews/custom/components/carousel/data-card/index.jsx +++ b/src/tabviews/custom/components/carousel/data-card/index.jsx @@ -16,16 +16,13 @@ class DataCard extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { BID: '', // 涓婄骇ID config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 card: null, // 鍗$墖璁剧疆 data: null, // 鏁版嵁 BData: null, @@ -35,13 +32,10 @@ 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 _card = _config.subcards[0] - - let _data = null - let _sync = _config.setting.sync === 'true' - let BID = '' let BData = '' @@ -54,24 +48,28 @@ BID = BData.$BID || '' } - if (_config.setting.sync === 'true' && data) { - _data = data[_config.dataName] || [] - _sync = false - } else if (_config.setting.sync === 'true' && initdata) { - _data = initdata || [] - _sync = false - } + let _data = null + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] - if (_data) { - this.loaded = true + 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 + item.$Index = index + 1 + '' return item }) + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } if (_card.setting.click) { @@ -88,7 +86,6 @@ _config.wrap.speed = (_config.wrap.speed || 3) * 1000 this.setState({ - sync: _sync, data: _data, BID: BID || '', BData: BData || '', @@ -96,7 +93,7 @@ card: _card, arr_field: _config.columns.map(col => col.field).join(','), }, () => { - if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') { + if (config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) @@ -112,6 +109,14 @@ 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() @@ -140,45 +145,61 @@ return !is(fromJS(this.state), fromJS(nextState)) } - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config, BID, BData } = 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 - return item - }) - - this.loaded = true - - this.setState({sync: false, data: _data}, () => { - this.openModal() - }) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } - } - componentWillUnmount () { this.setState = () => { return } + MKEmitter.removeListener('searchRefresh', this.searchRefresh) 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() + } + + 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 + '' + + return item + }) + + this.loaded = true + + this.setState({data: _data}, () => { + this.openModal() + }) + + 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() + }) } openModal = (ErrCode) => { @@ -239,12 +260,14 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, callback) => { - const { mainSearch } = this.props const { arr_field, config } = this.state if (config.uuid !== menuId) return - let searches = config.setting.useMSearch && mainSearch ? fromJS(mainSearch).toJS() : [] + let searches = [] + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + searches = window.GLOB.SearchBox.get(config.$searchId) || [] + } callback({ arr_field: arr_field, @@ -255,7 +278,6 @@ } async loadData (type) { - const { mainSearch } = this.props const { config, arr_field, BID, BData } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -268,9 +290,12 @@ return } - let searches = config.setting.useMSearch && mainSearch ? fromJS(mainSearch).toJS() : [] - let requireFields = searches.filter(item => item.required && item.value === '') - if (requireFields.length > 0) { + let searches = [] + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + searches = window.GLOB.SearchBox.get(config.$searchId) || [] + } + + if (config.$s_req && searches.filter(item => item.required && item.value === '').length > 0) { return } @@ -287,7 +312,7 @@ if (result.status) { this.loaded = true if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } let data = result.data.map((item, index) => { diff --git a/src/tabviews/custom/components/carousel/prop-card/index.jsx b/src/tabviews/custom/components/carousel/prop-card/index.jsx index b5806a3..e732b7a 100644 --- a/src/tabviews/custom/components/carousel/prop-card/index.jsx +++ b/src/tabviews/custom/components/carousel/prop-card/index.jsx @@ -16,16 +16,13 @@ class PropCard extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { BID: '', // 涓婄骇ID config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: {$$empty: true}, BData: null, visible: false @@ -34,11 +31,10 @@ 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 _data = {$$empty: true} - let _sync = false let BID = '' let BData = '' @@ -53,22 +49,20 @@ } if (_config.wrap.datatype === 'dynamic') { - _sync = _config.setting.sync === 'true' + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] - if (_sync && data) { - _data = data[_config.dataName] || {$$empty: true} - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS()) } - _sync = false + + _config.setting.sync = 'false' + + _data = _data[0] || {$$empty: true} + this.loaded = true - } else if (_sync && initdata) { - _data = initdata - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false - this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } } else if (_config.wrap.datatype === 'static') { this.loaded = true @@ -93,14 +87,13 @@ _config.wrap.speed = (_config.wrap.speed || 3) * 1000 this.setState({ - 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 && _config.setting.sync !== 'true' && _config.setting.onload === 'true') { + if (_config.wrap.datatype === 'dynamic' && config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) @@ -118,6 +111,14 @@ 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 && config.wrap.datatype === 'dynamic') { this.timer = new TimerTask() this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { @@ -129,7 +130,7 @@ Api.getLCacheConfig(config.uuid).then(res => { if (!res || this.loaded) return - let _data = res[0] + let _data = res[0] || {$$empty: true} _data.$$uuid = _data[config.setting.primaryKey] || '' this.setState({data: _data}) @@ -146,44 +147,55 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) 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 } = this.state + transferSyncData = (syncId) => { + const { config } = 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.$syncId !== syncId) return - _data.$$uuid = _data[config.setting.primaryKey] || '' - _data.$$BID = BID || '' - _data.$$BData = BData || '' + const { BID, BData } = this.state - this.loaded = true + let _data = window.GLOB.SyncData.get(config.dataName) || [] - this.setState({sync: false, data: _data}, () => { - if (config.wrap.display === 'modal') { - this.openModal() - } - }) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) } + + _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.display === 'modal') { + this.openModal() + } + }) + + 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() + }) } openModal = (ErrCode) => { @@ -242,12 +254,14 @@ * @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: '', @@ -266,7 +280,6 @@ } async loadData (type) { - const { mainSearch } = this.props const { config, arr_field, BID, BData } = this.state if (config.wrap.datatype === 'static') { @@ -283,10 +296,12 @@ 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 } @@ -305,7 +320,7 @@ this.loaded = true if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } if (!result.data || !result.data[0]) { diff --git a/src/tabviews/custom/components/chart/antv-G6/index.jsx b/src/tabviews/custom/components/chart/antv-G6/index.jsx index 8d7f359..51977d6 100644 --- a/src/tabviews/custom/components/chart/antv-G6/index.jsx +++ b/src/tabviews/custom/components/chart/antv-G6/index.jsx @@ -797,9 +797,7 @@ class antvG6Chart extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -807,7 +805,6 @@ BID: '', BData: '', plot: null, - sync: false, arr_field : '', chartId: Utils.getuuid(), empty: true @@ -816,13 +813,12 @@ data = [] mkgraph = null selectedId = '' + loaded = false UNSAFE_componentWillMount () { - const { config, data, initdata } = this.props + const { config } = this.props + let _config = fromJS(config).toJS() - - let _sync = _config.setting.sync === 'true' - let BID = '' let BData = '' @@ -835,12 +831,18 @@ BID = BData.$BID || '' } - if (_sync && data) { - this.data = data[config.dataName] || [] - _sync = false - } else if (_sync && initdata) { - this.data = initdata || [] - _sync = false + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + this.data = window.GLOB.SyncData.get(_config.dataName) || [] + + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(this.data).toJS()) + } + + _config.setting.sync = 'false' + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } _config.plot.height = Utils.getHeight(_config.plot.height) @@ -855,8 +857,7 @@ BID: BID || '', BData: BData || '', arr_field: _config.columns.map(col => col.field).join(','), - plot: _config.plot, - sync: _sync + plot: _config.plot }, () => { if (config.setting.sync !== 'true' && config.setting.onload === 'true') { setTimeout(() => { @@ -997,44 +998,26 @@ } } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = 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 (!is(fromJS(this.data), fromJS(_data))) { - this.data = _data - this.handleData() - } - - this.setState({sync: false}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } - } - shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.state), fromJS(nextState)) } componentDidMount () { - const { config, sync } = this.state + const { config } = this.state MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) - if (config.$cache && (config.setting.sync !== 'true' || sync)) { + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } + + if (config.$cache && !this.loaded) { Api.getLCacheConfig(config.uuid).then(res => { - if (!res || this.data.length > 0) return + if (!res || this.loaded) return if (!is(fromJS(this.data), fromJS(res))) { this.data = res @@ -1052,7 +1035,42 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) + } + + transferSyncData = (syncId) => { + const { config } = this.state + + if (config.$syncId !== syncId) return + + let _data = window.GLOB.SyncData.get(config.dataName) || [] + + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) + } + + if (!is(fromJS(this.data), fromJS(_data))) { + this.data = _data + this.handleData() + } + + this.loaded = true + + 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() + }) } reloadData = (menuId) => { @@ -1075,7 +1093,6 @@ } async loadData () { - const { mainSearch } = this.props const { config, arr_field, BID } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -1083,13 +1100,16 @@ this.data = [] this.handleData() } + this.loaded = true 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 } @@ -1103,9 +1123,11 @@ let result = await Api.genericInterface(param) if (result.status) { if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } + this.loaded = true + this.setState({ loading: false }) diff --git a/src/tabviews/custom/components/chart/antv-bar-line/index.jsx b/src/tabviews/custom/components/chart/antv-bar-line/index.jsx index 4f83a14..184e810 100644 --- a/src/tabviews/custom/components/chart/antv-bar-line/index.jsx +++ b/src/tabviews/custom/components/chart/antv-bar-line/index.jsx @@ -22,9 +22,7 @@ class LineChart extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 } state = { @@ -34,7 +32,6 @@ loading: false, // 鏁版嵁鍔犺浇鐘舵�� chartId: Utils.getuuid(), // 鍥捐〃Id transfield: {}, // 瀛楁鍚嶇О缈昏瘧 - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 plot: null, // 鍥捐〃璁剧疆 search: null, // 鎼滅储鏉′欢 vFields: [], // 鏁板�煎瓧娈� @@ -43,12 +40,12 @@ } data = [] + loaded = false UNSAFE_componentWillMount () { - const { config, data, initdata } = this.props - let _config = fromJS(config).toJS() - let _sync = config.setting.sync === 'true' + const { config } = this.props + let _config = fromJS(config).toJS() let BID = '' let BData = '' @@ -59,14 +56,6 @@ } if (BData) { BID = BData.$BID || '' - } - - if (_sync && data) { - this.data = data[config.dataName] || [] - _sync = false - } else if (_sync && initdata) { - this.data = initdata || [] - _sync = false } let vFields = [] @@ -332,6 +321,20 @@ }) } + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + this.data = window.GLOB.SyncData.get(_config.dataName) || [] + + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(this.data).toJS()) + } + + _config.setting.sync = 'false' + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) + } + this.setState({ config: _config, BID: BID || '', @@ -339,8 +342,7 @@ vstFields: vstFields, arr_field: _config.columns.map(col => col.field).join(','), plot: _config.plot, - sync: _sync, - search: Utils.initMainSearch(config.search), + search: _config.$searches, transfield }, () => { if (config.setting.sync !== 'true' && config.setting.onload === 'true') { @@ -355,43 +357,26 @@ } } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = 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 (!is(fromJS(this.data), fromJS(_data))) { - this.data = _data - this.handleData() - } - - this.setState({sync: false}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } - } - shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.state), fromJS(nextState)) } componentDidMount () { - const { config, sync } = this.state + 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.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } + if (config.timer) { this.timer = new TimerTask() this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { @@ -399,14 +384,12 @@ }) } - if (config.$cache && (config.setting.sync !== 'true' || sync)) { + if (config.$cache && !this.loaded) { Api.getLCacheConfig(config.uuid).then(res => { - if (!res || this.data.length > 0) return + if (!res || this.loaded) return - if (!is(fromJS(this.data), fromJS(res))) { - this.data = res - this.handleData() - } + this.data = res + this.handleData() }) } } @@ -419,11 +402,46 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) 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() + } + + transferSyncData = (syncId) => { + const { config } = this.state + + if (config.$syncId !== syncId) return + + let _data = window.GLOB.SyncData.get(config.dataName) || [] + + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) + } + + if (!is(fromJS(this.data), fromJS(_data))) { + this.data = _data + this.handleData() + } + + this.loaded = true + + 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() + }) } /** @@ -467,18 +485,18 @@ * @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()) + 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) }) } @@ -494,7 +512,6 @@ * @description 鏁版嵁鍔犺浇 */ async loadData (hastimer) { - const { mainSearch } = this.props const { config, arr_field, BID, search } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -502,21 +519,22 @@ this.data = [] this.handleData() } + 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) + 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)) { - 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 } @@ -532,9 +550,11 @@ let result = await Api.genericInterface(param) if (result.status) { if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } + this.loaded = true + this.setState({ loading: false }) diff --git a/src/tabviews/custom/components/chart/antv-dashboard/index.jsx b/src/tabviews/custom/components/chart/antv-dashboard/index.jsx index 3d69559..c8cec13 100644 --- a/src/tabviews/custom/components/chart/antv-dashboard/index.jsx +++ b/src/tabviews/custom/components/chart/antv-dashboard/index.jsx @@ -53,9 +53,7 @@ class DashboardChart extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -63,19 +61,17 @@ config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� chartId: Utils.getuuid(), // 鍥捐〃Id - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 plot: null, // 鍥捐〃璁剧疆 chart: null } data = {} + loaded = false UNSAFE_componentWillMount () { - const { config, data, initdata } = this.props + const { config } = this.props + let _config = fromJS(config).toJS() - - let _sync = _config.setting.sync === 'true' - let BID = '' let BData = '' @@ -88,12 +84,18 @@ BID = BData.$BID || '' } - if (_sync && data) { - this.data = data[config.dataName] || [] - _sync = false - } else if (_sync && initdata) { - this.data = initdata || [] - _sync = false + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + this.data = window.GLOB.SyncData.get(_config.dataName) || [] + + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(this.data).toJS()) + } + + _config.setting.sync = 'false' + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } if (_config.subtype !== 'ratioboard') { @@ -115,8 +117,7 @@ config: _config, BID: BID || '', arr_field: _config.columns.map(col => col.field).join(','), - plot: _config.plot, - sync: _sync + plot: _config.plot }, () => { if (config.setting.sync !== 'true' && config.setting.onload === 'true') { setTimeout(() => { @@ -125,40 +126,8 @@ } }) - if (config.setting.sync === 'true' && !_sync) { + if (config.setting.sync === 'true' && this.loaded) { this.handleData() - } - } - - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = this.state - - if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) { - let _data = null - - if (nextProps.data && nextProps.data[config.dataName]) { - _data = nextProps.data[config.dataName] - if (config.subtype !== 'ratioboard') { - if (Array.isArray(_data)) { - _data = _data[0] || {} - } - _data.value = _data[config.plot.valueField] || 0 - } - } - - if (_data && !is(fromJS(this.data), fromJS(_data))) { - this.data = _data - this.handleData() - } - - this.setState({sync: false}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) } } @@ -167,11 +136,19 @@ } componentDidMount () { - const { config, sync } = this.state + const { config } = this.state MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) + 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() this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { @@ -179,15 +156,15 @@ }) } - if (config.$cache && (config.setting.sync !== 'true' || sync)) { + if (config.$cache && !this.loaded) { Api.getLCacheConfig(config.uuid).then(res => { - if (!res) return + if (!res || this.loaded) return let _data = null if (config.subtype === 'ratioboard') { _data = res } else { - _data = res[0] + _data = res[0] || {} _data.value = _data[config.plot.valueField] || 0 } @@ -207,9 +184,51 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) this.timer && this.timer.stop() + } + + transferSyncData = (syncId) => { + const { config } = this.state + + if (config.$syncId !== syncId) return + + let _data = window.GLOB.SyncData.get(config.dataName) || [] + + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) + } + + if (config.subtype !== 'ratioboard') { + if (Array.isArray(_data)) { + _data = _data[0] || {} + } + _data.value = _data[config.plot.valueField] || 0 + } + + if (!is(fromJS(this.data), fromJS(_data))) { + this.data = _data + this.handleData() + } + + this.loaded = true + + 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() + }) } reloadData = (menuId) => { @@ -243,7 +262,6 @@ } async loadData (hastimer) { - const { mainSearch } = this.props const { config, arr_field, BID } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -258,13 +276,17 @@ this.data = _data this.handleData() } + + this.loaded = true 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 } @@ -280,9 +302,11 @@ let result = await Api.genericInterface(param) if (result.status) { if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } + this.loaded = true + let _data = null if (config.subtype === 'ratioboard') { _data = result.data || [] diff --git a/src/tabviews/custom/components/chart/antv-pie/index.jsx b/src/tabviews/custom/components/chart/antv-pie/index.jsx index fcb3b7a..836e2e4 100644 --- a/src/tabviews/custom/components/chart/antv-pie/index.jsx +++ b/src/tabviews/custom/components/chart/antv-pie/index.jsx @@ -18,9 +18,7 @@ class PieChart extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -30,20 +28,18 @@ loading: false, // 鏁版嵁鍔犺浇鐘舵�� chartId: Utils.getuuid(), // 鍥捐〃Id title: '', // 缁勪欢鏍囬 - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 plot: null, // 鍥捐〃璁剧疆 search: null, // 鎼滅储鏉′欢 chart: null } data = [] + loaded = false UNSAFE_componentWillMount () { - const { config, data, initdata } = this.props + const { config } = this.props + let _config = fromJS(config).toJS() - - let _sync = config.setting.sync === 'true' - let BID = '' let BData = '' @@ -54,14 +50,6 @@ } if (BData) { BID = BData.$BID || '' - } - - if (_sync && data) { - this.data = data[config.dataName] || [] - _sync = false - } else if (_sync && initdata) { - this.data = initdata || [] - _sync = false } _config.plot.height = Utils.getHeight(_config.plot.height) @@ -81,14 +69,27 @@ _config.plot.$decimal = decimal + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + this.data = window.GLOB.SyncData.get(_config.dataName) || [] + + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(this.data).toJS()) + } + + _config.setting.sync = 'false' + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) + } + this.setState({ config: _config, BID: BID || '', arr_field: _config.columns.map(col => col.field).join(','), plot: _config.plot, - sync: _sync, title: config.plot.title, - search: Utils.initMainSearch(config.search) + search: _config.$searches }, () => { if (config.setting.sync !== 'true' && config.setting.onload === 'true') { setTimeout(() => { @@ -102,41 +103,24 @@ } } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = 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 (!is(fromJS(this.data), fromJS(_data))) { - this.data = _data - this.handleData() - } - - this.setState({sync: false}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } - } - shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.state), fromJS(nextState)) } componentDidMount () { - const { config, sync } = this.state + const { config } = this.state MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) + 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() this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { @@ -144,10 +128,10 @@ }) } - if (config.$cache && (config.setting.sync !== 'true' || sync)) { + if (config.$cache && !this.loaded) { Api.getLCacheConfig(config.uuid).then(res => { - if (!res || this.data.length > 0) return - + if (!res || this.loaded) return + if (!is(fromJS(this.data), fromJS(res))) { this.data = res this.handleData() @@ -164,9 +148,44 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) this.timer && this.timer.stop() + } + + transferSyncData = (syncId) => { + const { config } = this.state + + if (config.$syncId !== syncId) return + + let _data = window.GLOB.SyncData.get(config.dataName) || [] + + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) + } + + if (!is(fromJS(this.data), fromJS(_data))) { + this.data = _data + this.handleData() + } + + this.loaded = true + + 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() + }) } reloadData = (menuId) => { @@ -210,7 +229,6 @@ } async loadData (hastimer) { - const { mainSearch } = this.props const { config, arr_field, search, BID } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -218,21 +236,22 @@ this.data = [] this.handleData() } + this.loaded = true return } let searches = fromJS(search).toJS() - if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - let keys = searches.map(item => item.key) + 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)) { - 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 } @@ -248,8 +267,9 @@ let result = await Api.genericInterface(param) if (result.status) { if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } + this.loaded = true this.setState({ loading: false diff --git a/src/tabviews/custom/components/chart/antv-scatter/index.jsx b/src/tabviews/custom/components/chart/antv-scatter/index.jsx index 1c96f7a..bc44afb 100644 --- a/src/tabviews/custom/components/chart/antv-scatter/index.jsx +++ b/src/tabviews/custom/components/chart/antv-scatter/index.jsx @@ -20,9 +20,7 @@ class ScatterChart extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -31,19 +29,18 @@ empty: true, // 鍥捐〃鏁版嵁涓虹┖ loading: false, // 鏁版嵁鍔犺浇鐘舵�� chartId: Utils.getuuid(), // 鍥捐〃Id - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 plot: null, // 鍥捐〃璁剧疆 search: null, // 鎼滅储鏉′欢 chart: null } data = [] + loaded = false UNSAFE_componentWillMount () { - const { config, data, initdata } = this.props - let _config = fromJS(config).toJS() - let _sync = config.setting.sync === 'true' + const { config } = this.props + let _config = fromJS(config).toJS() let BID = '' let BData = '' @@ -56,14 +53,6 @@ BID = BData.$BID || '' } - if (_sync && data) { - this.data = data[config.dataName] || [] - _sync = false - } else if (_sync && initdata) { - this.data = initdata || [] - _sync = false - } - _config.plot.height = Utils.getHeight(_config.plot.height) _config.style.height = 'auto' _config.style.minHeight = _config.plot.height + 30 @@ -72,14 +61,27 @@ _config.style.minHeight = _config.style.minHeight + 45 } + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + this.data = window.GLOB.SyncData.get(_config.dataName) || [] + + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(this.data).toJS()) + } + + _config.setting.sync = 'false' + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) + } + this.setState({ config: _config, BID: BID || '', empty: this.data.length === 0, arr_field: _config.columns.map(col => col.field).join(','), plot: _config.plot, - sync: _sync, - search: Utils.initMainSearch(config.search), + search: _config.$searches }, () => { if (config.setting.sync !== 'true' && config.setting.onload === 'true') { setTimeout(() => { @@ -93,43 +95,26 @@ } } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = 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 (!is(fromJS(this.data), fromJS(_data))) { - this.data = _data - this.handleData() - } - - this.setState({sync: false, empty: _data.length === 0}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } - } - shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.state), fromJS(nextState)) } componentDidMount () { - const { config, sync } = this.state + 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.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } + if (config.timer) { this.timer = new TimerTask() this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { @@ -137,16 +122,16 @@ }) } - if (config.$cache && (config.setting.sync !== 'true' || sync)) { + if (config.$cache && !this.loaded) { Api.getLCacheConfig(config.uuid).then(res => { - if (!res || this.data.length > 0) return + if (!res || this.loaded) return if (!is(fromJS(this.data), fromJS(res))) { this.data = res this.handleData() } - this.setState({empty: false}) + this.setState({empty: res.length > 0}) }) } } @@ -159,11 +144,48 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) 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() + } + + transferSyncData = (syncId) => { + const { config } = this.state + + if (config.$syncId !== syncId) return + + let _data = window.GLOB.SyncData.get(config.dataName) || [] + + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) + } + + if (!is(fromJS(this.data), fromJS(_data))) { + this.data = _data + this.handleData() + } + + this.setState({empty: _data.length === 0}) + + this.loaded = true + + 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() + }) } /** @@ -207,18 +229,18 @@ * @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()) + 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) }) } @@ -234,7 +256,6 @@ * @description 鏁版嵁鍔犺浇 */ async loadData (hastimer) { - const { mainSearch } = this.props const { config, arr_field, BID, search } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -244,21 +265,23 @@ this.data = [] this.handleData() } + + 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) + 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)) { - 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 } @@ -274,8 +297,9 @@ let result = await Api.genericInterface(param) if (result.status) { if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } + this.loaded = true this.setState({ empty: !result.data || result.data.length === 0, diff --git a/src/tabviews/custom/components/chart/custom-chart/index.jsx b/src/tabviews/custom/components/chart/custom-chart/index.jsx index 2270240..fece466 100644 --- a/src/tabviews/custom/components/chart/custom-chart/index.jsx +++ b/src/tabviews/custom/components/chart/custom-chart/index.jsx @@ -16,9 +16,7 @@ class CustomChart extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -26,18 +24,17 @@ config: null, // 鍥捐〃閰嶇疆淇℃伅 empty: true, // 鍥捐〃鏁版嵁涓虹┖ loading: false, // 鏁版嵁鍔犺浇鐘舵�� - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 plot: null, // 鍥捐〃璁剧疆 search: null, // 鎼滅储鏉′欢 } data = [] + loaded = false UNSAFE_componentWillMount () { - const { config, data, initdata } = this.props - let _config = fromJS(config).toJS() - let _sync = config.setting.sync === 'true' + const { config } = this.props + let _config = fromJS(config).toJS() let BID = '' let BData = '' @@ -50,16 +47,22 @@ BID = BData.$BID || '' } - if (_sync && data) { - this.data = data[config.dataName] || [] - _sync = false - } else if (_sync && initdata) { - this.data = initdata || [] - _sync = false - } - _config.plot.height = Utils.getHeight(_config.plot.height) _config.style.height = 'auto' + + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + this.data = window.GLOB.SyncData.get(_config.dataName) || [] + + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(this.data).toJS()) + } + + _config.setting.sync = 'false' + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) + } this.setState({ config: _config, @@ -67,8 +70,7 @@ BID: BID || '', arr_field: _config.columns.map(col => col.field).join(','), plot: _config.plot, - sync: _sync, - search: Utils.initMainSearch(config.search) + search: _config.$searches }, () => { if (config.setting.sync !== 'true' && config.setting.onload === 'true') { setTimeout(() => { @@ -82,43 +84,26 @@ } } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = 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 (!is(fromJS(this.data), fromJS(_data))) { - this.data = _data - this.handleData() - } - - this.setState({sync: false, empty: _data.length === 0}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } - } - shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.state), fromJS(nextState)) } componentDidMount () { - const { config, sync } = this.state + 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.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } + if (config.timer) { this.timer = new TimerTask() this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { @@ -126,15 +111,15 @@ }) } - if (config.$cache && (config.setting.sync !== 'true' || sync)) { + if (config.$cache && !this.loaded) { Api.getLCacheConfig(config.uuid).then(res => { - if (!res || this.data.length > 0) return + if (!res || this.loaded) return if (!is(fromJS(this.data), fromJS(res))) { this.data = res this.handleData() } - this.setState({empty: false}) + this.setState({empty: res.length > 0}) }) } } @@ -147,11 +132,48 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) 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() + } + + transferSyncData = (syncId) => { + const { config } = this.state + + if (config.$syncId !== syncId) return + + let _data = window.GLOB.SyncData.get(config.dataName) || [] + + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) + } + + if (!is(fromJS(this.data), fromJS(_data))) { + this.data = _data + this.handleData() + } + + this.setState({empty: _data.length === 0}) + + this.loaded = true + + 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() + }) } /** @@ -195,18 +217,18 @@ * @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()) + 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) }) } @@ -222,7 +244,6 @@ * @description 鏁版嵁鍔犺浇 */ async loadData (hastimer) { - const { mainSearch } = this.props const { config, arr_field, BID, search } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -234,21 +255,23 @@ this.data = [] this.handleData() } + + 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) + 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)) { - 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 } @@ -264,8 +287,9 @@ let result = await Api.genericInterface(param) if (result.status) { if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } + this.loaded = true this.setState({ loading: false, diff --git a/src/tabviews/custom/components/code/sand-box/index.jsx b/src/tabviews/custom/components/code/sand-box/index.jsx index 6bdaf07..0a9b6a3 100644 --- a/src/tabviews/custom/components/code/sand-box/index.jsx +++ b/src/tabviews/custom/components/code/sand-box/index.jsx @@ -10,16 +10,13 @@ class SandBoxComponent extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { BID: '', // 涓婄骇ID config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: [], // 鏁版嵁 html: '', result: {} @@ -28,12 +25,10 @@ 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 _data = [] - let _sync = false - let BID = '' let BData = '' @@ -47,19 +42,20 @@ } if (_config.wrap.datatype !== 'static') { - _sync = _config.setting.sync === 'true' - - if (_sync && data) { - _data = data[_config.dataName] || [] - _sync = false + 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()) + } + + _config.setting.sync = 'false' + this.loaded = true - } else if (_sync && initdata) { - _data = initdata || {} - _sync = false - this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } } else { - _data = {} this.loaded = true } @@ -74,13 +70,12 @@ } this.setState({ - 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') { + if (_config.wrap.datatype !== 'static' && config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) @@ -93,6 +88,14 @@ const { config } = this.state MKEmitter.addListener('reloadData', this.reloadData) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } if (config.$cache && !this.loaded) { Api.getLCacheConfig(config.uuid).then(res => { @@ -114,34 +117,44 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = this.state + transferSyncData = (syncId) => { + const { config } = 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 (config.$syncId !== syncId) return - this.loaded = true + let _data = window.GLOB.SyncData.get(config.dataName) || [] - if (!is(fromJS(this.state.data), fromJS(_data))) { - setTimeout(() => { - this.renderView() - }, 10) - } - - this.setState({sync: false, data: _data}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) } + + if (!is(fromJS(this.state.data), fromJS(_data))) { + setTimeout(() => { + this.renderView() + }, 10) + } + + this.setState({data: _data}) + + this.loaded = true + + 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() + }) } reloadData = (menuId) => { @@ -153,7 +166,6 @@ } async loadData () { - const { mainSearch } = this.props const { config, arr_field, BID } = this.state if (config.wrap.datatype === 'static') { @@ -171,10 +183,12 @@ 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 } @@ -191,7 +205,7 @@ this.loaded = true if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } if (!is(fromJS(this.state.data), fromJS(_data))) { diff --git a/src/tabviews/custom/components/editor/braft-editor/index.jsx b/src/tabviews/custom/components/editor/braft-editor/index.jsx index 891bfa6..38f0382 100644 --- a/src/tabviews/custom/components/editor/braft-editor/index.jsx +++ b/src/tabviews/custom/components/editor/braft-editor/index.jsx @@ -14,25 +14,21 @@ class BraftEditorContent extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { BID: '', // 涓婄骇ID config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: {} // 鏁版嵁 } 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 = '' @@ -46,21 +42,14 @@ BID = BData.$BID || '' } - if (_config.setting && _config.wrap.datatype === 'dynamic') { - _sync = _config.setting.sync === 'true' + if (_config.wrap.datatype === 'dynamic') { + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] + _data = _data[0] || {$$empty: true} - if (_sync && data) { - _data = data[_config.dataName] || {$$empty: true} - if (_data && Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false - } else if (_sync && initdata) { - _data = initdata - if (_data && Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false + _config.setting.sync = 'false' + + window.GLOB.SyncData.delete(_config.dataName) } } @@ -69,13 +58,12 @@ } this.setState({ - sync: _sync, data: _data, BID: BID || '', config: _config, arr_field: _config.columns.map(col => col.field).join(','), }, () => { - if (_config.wrap.datatype === 'dynamic' && _config.setting && _config.setting.sync !== 'true' && _config.setting.onload === 'true') { + if (_config.wrap.datatype === 'dynamic' && config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) @@ -88,6 +76,14 @@ MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } if (config.wrap.datatype === 'public') { MKEmitter.addListener('mkPublicData', this.mkPublicData) @@ -104,30 +100,34 @@ } MKEmitter.removeListener('reloadData', this.reloadData) MKEmitter.removeListener('mkPublicData', this.mkPublicData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = this.state + transferSyncData = (syncId) => { + const { config } = 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 (_data && Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - } + if (config.$syncId !== syncId) return - this.setState({sync: false, data: _data}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } + let _data = window.GLOB.SyncData.get(config.dataName) || [] + _data = _data[0] || {$$empty: 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({}, () => { + this.loadData() + }) } mkPublicData = (publicId, data) => { @@ -160,7 +160,6 @@ } async loadData () { - const { mainSearch } = this.props const { config, arr_field, BID } = this.state if (config.wrap.datatype === 'public') { @@ -182,10 +181,12 @@ 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 } @@ -198,7 +199,8 @@ let result = await Api.genericInterface(param) if (result.status) { - let _data = result.data && result.data[0] ? result.data[0] : {$$empty: true} + let _data = result.data || [] + _data = _data[0] || {$$empty: true} this.setState({ data: _data, diff --git a/src/tabviews/custom/components/form/simple-form/index.jsx b/src/tabviews/custom/components/form/simple-form/index.jsx index 4d1bb99..a92f2cf 100644 --- a/src/tabviews/custom/components/form/simple-form/index.jsx +++ b/src/tabviews/custom/components/form/simple-form/index.jsx @@ -8,8 +8,6 @@ import asyncComponent from '@/utils/asyncComponent' import asyncSpinComponent from '@/utils/asyncSpinComponent' import MKEmitter from '@/utils/events.js' -import zhCN from '@/locales/zh-CN/main.js' -import enUS from '@/locales/en-US/main.js' import './index.scss' const MutilForm = asyncSpinComponent(() => import('@/tabviews/zshare/mutilform')) @@ -18,17 +16,13 @@ class SimpleForm extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { - dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, BID: '', config: null, loading: false, - sync: false, data: null, group: null, BData: '', @@ -36,40 +30,37 @@ } UNSAFE_componentWillMount () { - const { data } = this.props - let config = fromJS(this.props.config).toJS() + const { config } = this.props + let _config = fromJS(config).toJS() let _data = null - let _sync = false - let BID = '' let BData = '' - if (config.setting.supModule) { - BData = window.GLOB.CacheData.get(config.setting.supModule) + if (_config.setting.supModule) { + BData = window.GLOB.CacheData.get(_config.setting.supModule) } else { - BData = window.GLOB.CacheData.get(config.$pageId) + BData = window.GLOB.CacheData.get(_config.$pageId) } if (BData) { BID = BData.$BID || '' } - if (config.wrap.datatype !== 'static') { - _sync = config.setting.sync === 'true' + if (_config.wrap.datatype !== 'static') { + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] + _data = _data[0] || {$$empty: true} + _data.$$uuid = _data[_config.setting.primaryKey] || '' - if (_sync && data) { - _data = data[config.dataName] || {$$empty: true} - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false - _data.$$uuid = _data[config.setting.primaryKey] || '' + _config.setting.sync = 'false' + + window.GLOB.SyncData.delete(_config.dataName) } } else { _data = {$$empty: true} } - let _group = config.subcards[0] + let _group = _config.subcards[0] if (_group.subButton.enable === 'false' && (!_group.closeButton || _group.closeButton.enable !== 'true')) { _group.subButton.style.display = 'none' @@ -77,13 +68,12 @@ } this.setState({ - sync: _sync, data: _data, group: _group, BID: BID || '', BData: BData || '', - config: config, - arr_field: config.columns.map(col => col.field).join(','), + config: _config, + arr_field: _config.columns.map(col => col.field).join(','), }, () => { if (config.wrap.datatype !== 'static' && config.setting.sync !== 'true' && config.setting.onload === 'true') { setTimeout(() => { @@ -94,10 +84,20 @@ } componentDidMount () { + const { config } = this.state + MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('mkFormSubmit', this.mkFormSubmit) MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } } shouldComponentUpdate (nextProps, nextState) { @@ -110,33 +110,36 @@ } MKEmitter.removeListener('reloadData', this.reloadData) MKEmitter.removeListener('mkFormSubmit', this.mkFormSubmit) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = this.state + transferSyncData = (syncId) => { + const { config } = 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.$syncId !== syncId) return - _data.$$uuid = _data[config.setting.primaryKey] || '' + let _data = window.GLOB.SyncData.get(config.dataName) || [] + _data = _data[0] || {$$empty: true} + _data.$$uuid = _data[config.setting.primaryKey] || '' - this.setState({sync: false, data: _data}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } + 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({}, () => { + this.loadData() + }) } reloadData = (menuId, id) => { @@ -212,7 +215,6 @@ } async loadData () { - const { mainSearch } = this.props const { config, arr_field, BID } = this.state if (config.wrap.datatype === 'static') { @@ -230,10 +232,12 @@ 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 } @@ -309,7 +313,7 @@ } render() { - const { config, loading, BID, BData, data, group, dict } = this.state + const { config, loading, BID, BData, data, group } = this.state if (config.wrap.empty === 'hidden' && (!data || data.$$empty)) return null if (config.idCtrl && (!data || data.$$empty)) return null @@ -326,7 +330,6 @@ {data ? <MutilForm BID={BID} BData={BData} - dict={dict} data={data} action={group} unload={config.setting.supModule && !BID} diff --git a/src/tabviews/custom/components/form/step-form/index.jsx b/src/tabviews/custom/components/form/step-form/index.jsx index 3965ad6..7f3bb27 100644 --- a/src/tabviews/custom/components/form/step-form/index.jsx +++ b/src/tabviews/custom/components/form/step-form/index.jsx @@ -8,8 +8,6 @@ import asyncComponent from '@/utils/asyncComponent' import asyncSpinComponent from '@/utils/asyncSpinComponent' import MKEmitter from '@/utils/events.js' -import zhCN from '@/locales/zh-CN/main.js' -import enUS from '@/locales/en-US/main.js' import './index.scss' const MutilForm = asyncSpinComponent(() => import('@/tabviews/zshare/mutilform')) @@ -17,17 +15,13 @@ class StepForm extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { - dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, BID: '', config: null, loading: false, - sync: false, data: null, group: null, BData: '', @@ -35,53 +29,50 @@ } UNSAFE_componentWillMount () { - const { data } = this.props - let config = fromJS(this.props.config).toJS() + const { config } = this.props + let _config = fromJS(config).toJS() let _data = null - let _sync = false - let BID = '' let BData = '' - if (config.setting.supModule) { - BData = window.GLOB.CacheData.get(config.setting.supModule) + if (_config.setting.supModule) { + BData = window.GLOB.CacheData.get(_config.setting.supModule) } else { - BData = window.GLOB.CacheData.get(config.$pageId) + BData = window.GLOB.CacheData.get(_config.$pageId) } if (BData) { BID = BData.$BID || '' } - if (config.wrap.datatype !== 'static') { - _sync = config.setting.sync === 'true' + if (_config.wrap.datatype !== 'static') { + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] + _data = _data[0] || {$$empty: true} + _data.$$uuid = _data[_config.setting.primaryKey] || '' - if (_sync && data) { - _data = data[config.dataName] || {$$empty: true} - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false - _data.$$uuid = _data[config.setting.primaryKey] || '' + _config.setting.sync = 'false' + + window.GLOB.SyncData.delete(_config.dataName) } } else { _data = {$$empty: true} } - if (!config.wrap.groupLabel) { - if (config.subcards.length > 1) { - config.wrap.groupLabel = 'show' + if (!_config.wrap.groupLabel) { + if (_config.subcards.length > 1) { + _config.wrap.groupLabel = 'show' } else { - config.wrap.groupLabel = 'hidden' + _config.wrap.groupLabel = 'hidden' } } - config.subcards = config.subcards.map((group, i) => { + _config.subcards = _config.subcards.map((group, i) => { group.sort = i + 1 if (i === 0 && group.prevButton.actionType !== 'close') { group.prevButton.enable = 'false' } - if (i + 1 === config.subcards.length && group.nextButton.actionType !== 'close') { + if (i + 1 === _config.subcards.length && group.nextButton.actionType !== 'close') { group.nextButton.enable = 'false' } @@ -96,48 +87,57 @@ return group }) - let _group = config.subcards[0] + let _group = _config.subcards[0] - if (_data && config.wrap.statusControl && _data[config.wrap.statusControl] !== undefined) { - let _status = _data[config.wrap.statusControl] + '' + if (_data && _config.wrap.statusControl && _data[_config.wrap.statusControl] !== undefined) { + let _status = _data[_config.wrap.statusControl] + '' - let _groups = config.subcards.filter(item => item.setting.status === _status)[0] + let _groups = _config.subcards.filter(item => item.setting.status === _status)[0] _group = _groups || _group } - config.titleStyle = {} - config.sortStyle = {} + _config.titleStyle = {} + _config.sortStyle = {} - if (config.style.fontSize) { - let size = parseInt(config.style.fontSize) - config.titleStyle = {fontSize: size} + if (_config.style.fontSize) { + let size = parseInt(_config.style.fontSize) + _config.titleStyle = {fontSize: size} let s = size * 1.5 + 'px' - config.sortStyle = {width: s, height: s, lineHeight: s, borderRadius: s} + _config.sortStyle = {width: s, height: s, lineHeight: s, borderRadius: s} } this.setState({ - sync: _sync, data: _data, group: _group, step: _group.sort - 1, BID: BID || '', BData: BData || '', - config: config, - arr_field: config.columns.map(col => col.field).join(','), + 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') { + if (_config.wrap.datatype !== 'static' && config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() - }, config.setting.delay || 0) + }, _config.setting.delay || 0) } }) } componentDidMount () { + const { config } = this.state + MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('mkFormSubmit', this.mkFormSubmit) MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } } shouldComponentUpdate (nextProps, nextState) { @@ -150,40 +150,44 @@ } MKEmitter.removeListener('reloadData', this.reloadData) MKEmitter.removeListener('mkFormSubmit', this.mkFormSubmit) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config, group } = this.state + transferSyncData = (syncId) => { + const { config, group } = this.state - if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) { - let _data = {$$empty: true} - let _group = group - if (nextProps.data && nextProps.data[config.dataName]) { - _data = nextProps.data[config.dataName] - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - } + if (config.$syncId !== syncId) return - _data.$$uuid = _data[config.setting.primaryKey] || '' + let _data = window.GLOB.SyncData.get(config.dataName) || [] + _data = _data[0] || {$$empty: true} + _data.$$uuid = _data[config.setting.primaryKey] || '' - if (config.wrap.statusControl && _data[config.wrap.statusControl] !== undefined) { - let _status = _data[config.wrap.statusControl] + '' - let _groups = config.subcards.filter(item => item.setting.status === _status)[0] - _group = _groups || _group - } + let _group = group - this.setState({sync: false, data: _data, group: _group, step: _group.sort - 1,}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) + if (config.wrap.statusControl && _data[config.wrap.statusControl] !== undefined) { + let _status = _data[config.wrap.statusControl] + '' + let _groups = config.subcards.filter(item => item.setting.status === _status)[0] + _group = _groups || _group } + + this.setState({data: _data, group: _group, step: _group.sort - 1}) + + 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() + }) } reloadData = (menuId, id) => { @@ -271,7 +275,6 @@ } async loadData (type) { - const { mainSearch } = this.props const { config, arr_field, BID } = this.state if (config.wrap.datatype === 'static') { @@ -289,10 +292,12 @@ 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 } @@ -411,7 +416,7 @@ } render() { - const { config, loading, BID, BData, data, group, dict, step } = this.state + const { config, loading, BID, BData, data, group, step } = this.state if (config.wrap.empty === 'hidden' && (!data || data.$$empty)) return null if (config.idCtrl && (!data || data.$$empty)) return null @@ -437,7 +442,6 @@ {group && data ? <MutilForm BID={BID} BData={BData} - dict={dict} data={data} action={group} unload={config.setting.supModule && !BID} diff --git a/src/tabviews/custom/components/form/tab-form/index.jsx b/src/tabviews/custom/components/form/tab-form/index.jsx index 988b04c..92a5018 100644 --- a/src/tabviews/custom/components/form/tab-form/index.jsx +++ b/src/tabviews/custom/components/form/tab-form/index.jsx @@ -8,8 +8,6 @@ import asyncComponent from '@/utils/asyncComponent' import asyncSpinComponent from '@/utils/asyncSpinComponent' import MKEmitter from '@/utils/events.js' -import zhCN from '@/locales/zh-CN/main.js' -import enUS from '@/locales/en-US/main.js' import './index.scss' const MutilForm = asyncSpinComponent(() => import('@/tabviews/zshare/mutilform')) @@ -17,65 +15,58 @@ class TabForm extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { - dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, BID: '', // 涓婄骇ID config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: null, BData: '', group: null, } UNSAFE_componentWillMount () { - const { data } = this.props - let config = fromJS(this.props.config).toJS() + const { config } = this.props + let _config = fromJS(config).toJS() let _data = null - let _sync = false - let BID = '' let BData = '' - if (config.setting.supModule) { - BData = window.GLOB.CacheData.get(config.setting.supModule) + if (_config.setting.supModule) { + BData = window.GLOB.CacheData.get(_config.setting.supModule) } else { - BData = window.GLOB.CacheData.get(config.$pageId) + BData = window.GLOB.CacheData.get(_config.$pageId) } if (BData) { BID = BData.$BID || '' } - if (config.wrap.datatype !== 'static') { - _sync = config.setting.sync === 'true' + if (_config.wrap.datatype !== 'static') { + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] + _data = _data[0] || {$$empty: true} + _data.$$uuid = _data[_config.setting.primaryKey] || '' - if (_sync && data) { - _data = data[config.dataName] || {$$empty: true} - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false - _data.$$uuid = _data[config.setting.primaryKey] || '' + _config.setting.sync = 'false' + + window.GLOB.SyncData.delete(_config.dataName) } } else { _data = {$$empty: true} } - if (!config.wrap.groupLabel) { - if (config.subcards.length > 1) { - config.wrap.groupLabel = 'show' + if (!_config.wrap.groupLabel) { + if (_config.subcards.length > 1) { + _config.wrap.groupLabel = 'show' } else { - config.wrap.groupLabel = 'hidden' + _config.wrap.groupLabel = 'hidden' } } - config.subcards = config.subcards.map(group => { + _config.subcards = _config.subcards.map(group => { if (group.subButton.enable === 'false') { group.subButton.style.display = 'none' group.$button = 'no-button' @@ -84,34 +75,43 @@ return group }) - config.titleStyle = {} + _config.titleStyle = {} - if (config.style.fontSize) { - config.titleStyle = {fontSize: parseInt(config.style.fontSize)} + if (_config.style.fontSize) { + _config.titleStyle = {fontSize: parseInt(_config.style.fontSize)} } this.setState({ - sync: _sync, data: _data, - group: config.subcards[0], + group: _config.subcards[0], BID: BID || '', BData: BData || '', - config: config, - arr_field: config.columns.map(col => col.field).join(','), + 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') { + if (_config.wrap.datatype !== 'static' && config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() - }, config.setting.delay || 0) + }, _config.setting.delay || 0) } }) } componentDidMount () { + const { config } = this.state + MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('mkFormSubmit', this.mkFormSubmit) MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } } shouldComponentUpdate (nextProps, nextState) { @@ -124,36 +124,40 @@ } MKEmitter.removeListener('reloadData', this.reloadData) MKEmitter.removeListener('mkFormSubmit', this.mkFormSubmit) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config, group } = this.state + transferSyncData = (syncId) => { + const { config, group } = this.state - if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) { - let _data = {$$empty: true} - let _group = group - if (nextProps.data && nextProps.data[config.dataName]) { - _data = nextProps.data[config.dataName] - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - } + if (config.$syncId !== syncId) return - _data.$$uuid = _data[config.setting.primaryKey] || '' + let _data = window.GLOB.SyncData.get(config.dataName) || [] + _data = _data[0] || {$$empty: true} + _data.$$uuid = _data[config.setting.primaryKey] || '' - this.setState({sync: false, data: _data, group: null}, () => { - this.setState({group: _group}) - }) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } + let _group = group + + this.setState({data: _data, group: null}, () => { + this.setState({group: _group}) + }) + + 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() + }) } reloadData = (menuId, id) => { @@ -228,7 +232,6 @@ } async loadData () { - const { mainSearch } = this.props const { config, arr_field, BID } = this.state if (config.wrap.datatype === 'static') { @@ -246,10 +249,12 @@ 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 } @@ -327,7 +332,7 @@ } render() { - const { config, loading, BID, BData, data, group, dict } = this.state + const { config, loading, BID, BData, data, group } = this.state if (config.wrap.empty === 'hidden' && (!data || data.$$empty)) return null if (config.idCtrl && (!data || data.$$empty)) return null @@ -350,7 +355,6 @@ {group && data ? <MutilForm BID={BID} BData={BData} - dict={dict} data={data} action={group} unload={config.setting.supModule && !BID} diff --git a/src/tabviews/custom/components/group/normal-group/index.jsx b/src/tabviews/custom/components/group/normal-group/index.jsx index 52a33a1..5a87122 100644 --- a/src/tabviews/custom/components/group/normal-group/index.jsx +++ b/src/tabviews/custom/components/group/normal-group/index.jsx @@ -1,331 +1,33 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { is, fromJS } from 'immutable' -import { Col, notification, Row } from 'antd' -import Api from '@/api' import asyncComponent from '@/utils/asyncComponent' -import { - getStructuredParams, - getStructDefaultParam -} from '@/utils/utils-datamanage.js' -import Utils from '@/utils/utils.js' import './index.scss' -// 閫氱敤缁勪欢 -const AntvBarAndLine = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-bar-line')) -const AntvPie = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-pie')) -const AntvDashboard = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-dashboard')) -const AntvScatter = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-scatter')) -const DataCard = asyncComponent(() => import('@/tabviews/custom/components/card/data-card')) -const TableCard = asyncComponent(() => import('@/tabviews/custom/components/card/table-card')) -const NormalTable = asyncComponent(() => import('@/tabviews/custom/components/table/normal-table')) -const DoubleDataCard = asyncComponent(() => import('@/tabviews/custom/components/card/double-data-card')) -const EditTable = asyncComponent(() => import('@/tabviews/custom/components/table/edit-table')) -const PropCard = asyncComponent(() => import('@/tabviews/custom/components/card/prop-card')) -const BraftEditor = asyncComponent(() => import('@/tabviews/custom/components/editor/braft-editor')) -const SandBox = asyncComponent(() => import('@/tabviews/custom/components/code/sand-box')) -const SimpleForm = asyncComponent(() => import('@/tabviews/custom/components/form/simple-form')) -const NormalForm = asyncComponent(() => import('@/tabviews/custom/components/form/step-form')) -const TabForm = asyncComponent(() => import('@/tabviews/custom/components/form/tab-form')) -const NormalTree = asyncComponent(() => import('@/tabviews/custom/components/tree/antd-tree')) -const CarouselDataCard = asyncComponent(() => import('@/tabviews/custom/components/carousel/data-card')) -const CarouselPropCard = asyncComponent(() => import('@/tabviews/custom/components/carousel/prop-card')) -const Balcony = asyncComponent(() => import('@/tabviews/custom/components/card/balcony')) -const TimeLine = asyncComponent(() => import('@/tabviews/custom/components/timeline/normal-timeline')) -const CustomChart = asyncComponent(() => import('@/tabviews/custom/components/chart/custom-chart')) -const AntvG6 = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-G6')) -const AntvX6 = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-X6')) -const Calendar = asyncComponent(() => import('@/tabviews/custom/components/calendar')) +const TabTransfer = asyncComponent(() => import('@/tabviews/custom/components/share/tabtransfer')) -class TabTransfer extends Component { +class NormalGroup extends Component { static propTpyes = { config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 鍏ㄥ眬鎼滅储鏉′欢 } - state = { - mainSearch: [], - // printing: false, - data: null - } - - UNSAFE_componentWillMount () { - const { config, mainSearch } = this.props - - // 鑾峰彇涓绘悳绱㈡潯浠� - let _mainSearch = mainSearch ? fromJS(mainSearch).toJS() : [] - let params = [] - config.components.forEach(item => { - if (item.type === 'tabs') return - - if (!item.setting || item.setting.interType !== 'system') return - if (!item.format) return - - if ((!item.pageable || (item.pageable && !item.setting.laypage)) && item.setting.onload === 'true' && item.setting.sync === 'true') { - let searchlist = [] - if (item.search && item.search.length > 0) { - searchlist = Utils.initMainSearch(item.search) - } - if (item.setting.useMSearch) { - let keys = searchlist.map(item => item.key) - _mainSearch.forEach(item => { - if (!keys.includes(item.key)) { - searchlist.push(item) - } - }) - } - - if (searchlist.filter(cell => cell.required && cell.value === '').length > 0) { - item.setting.sync = 'false' - item.setting.onload = 'false' - } else { - params.push(getStructDefaultParam(item, searchlist, params.length === 0)) - } - } else { - item.setting.sync = 'false' - } - }) - - this.setState({mainSearch: _mainSearch}) - - if (params.length > 0) { - this.loadmaindata(params) - } - } - - UNSAFE_componentWillReceiveProps(nextProps) { - if (nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({mainSearch: null}, () => { - this.setState({mainSearch: fromJS(nextProps.mainSearch).toJS()}) - }) - } - } - - /** - * @description 涓昏〃鏁版嵁鍔犺浇 - */ - loadmaindata = (params) => { - const { config } = this.props - let BID = '' - let BData = window.GLOB.CacheData.get(config.$pageId) - - if (BData) { - BID = BData.$BID || '' - } - - let param = getStructuredParams(params, config, BID) - - Api.genericInterface(param).then(result => { - if (result.status) { - delete result.status - delete result.message - delete result.ErrMesg - delete result.ErrCode - - if (config.$cache) { - params.forEach((item) => { - let _data = result[item.name] || '' - if (_data && !Array.isArray(_data)) { - _data = [_data] - } - Api.writeCacheConfig(item.uuid, _data) - }) - } - - this.setState({ - data: result - }) - } else { - this.setState({ - data: '' - }) - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) - } - }) - } - - getComponents = () => { - const { config } = this.props - const { mainSearch, data } = this.state - - return config.components.map(item => { - let style = null - - if (item.style && item.style.clear === 'left') { - style = {clear: 'left'} - } else if (item.style && item.style.clear === 'right') { - style = {float: 'right'} - } - - if (item.type === 'card' && item.subtype === 'datacard') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <DataCard config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'card' && item.subtype === 'propcard') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <PropCard config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'table' && item.subtype === 'normaltable') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <NormalTable config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'card' && item.subtype === 'dualdatacard') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <DoubleDataCard config={item} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'bar' || item.type === 'line') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <AntvBarAndLine data={data} config={item} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'pie') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <AntvPie data={data} config={item} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'dashboard') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <AntvDashboard config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'form' && item.subtype === 'simpleform') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <SimpleForm config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'form' && item.subtype === 'stepform') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <NormalForm config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'form' && item.subtype === 'tabform') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <TabForm config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'scatter') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <AntvScatter config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'carousel' && item.subtype === 'datacard') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <CarouselDataCard config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'carousel' && item.subtype === 'propcard') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <CarouselPropCard config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'card' && item.subtype === 'tablecard') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <TableCard config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'table' && item.subtype === 'editable') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <EditTable config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'tree') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <NormalTree config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'calendar') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <Calendar config={item} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'editor') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <BraftEditor config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'code') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <SandBox config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'balcony') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <Balcony config={item} data={data}/> - </Col> - ) - } else if (item.type === 'timeline') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <TimeLine config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'chart') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <CustomChart config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'antvG6') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <AntvG6 config={item} data={data} mainSearch={mainSearch}/> - </Col> - ) - } else if (item.type === 'antvX6') { - return ( - <Col span={item.width} style={style} key={item.uuid}> - <AntvX6 config={item}/> - </Col> - ) - } else { - return null - } - }) - } + state = {} render() { const { config } = this.props - if (!config.components || config.components.length === 0) return (<div style={config.style}></div>) + if (config.components.length === 0) return (<div style={config.style}></div>) return ( <div className={'normal-group-wrap ' + (config.setting.layout || '')} id={'anchor' + config.uuid} style={config.style}> {config.setting && config.setting.title ? <div className="group-header" style={config.headerStyle}> <span className="title">{config.setting.title}</span> </div> : null} - <Row className="component-wrap">{this.getComponents()}</Row> + <TabTransfer config={config}/> + {/* <Row className="component-wrap">{this.getComponents()}</Row> */} </div> ) } } -export default TabTransfer \ No newline at end of file +export default NormalGroup \ No newline at end of file diff --git a/src/tabviews/custom/components/iframe/index.jsx b/src/tabviews/custom/components/iframe/index.jsx index bdd506d..02c9a4d 100644 --- a/src/tabviews/custom/components/iframe/index.jsx +++ b/src/tabviews/custom/components/iframe/index.jsx @@ -12,9 +12,7 @@ class NormalIframe extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -22,18 +20,15 @@ config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� activeKey: '', // 閫変腑鏁版嵁 - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: {}, // 鏁版嵁 linkUrl: '' } UNSAFE_componentWillMount () { - const { data } = 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 = '' let linkUrl = '' @@ -48,17 +43,16 @@ } if (_config.wrap.datatype === 'dynamic') { - _sync = _config.setting.sync === 'true' + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] + _data = _data[0] || {$$empty: true} + + linkUrl = _data[_config.wrap.linkField] || '' - if (_sync && data) { - _data = data[_config.dataName] || {$$empty: true} - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false + _config.setting.sync = 'false' + + window.GLOB.SyncData.delete(_config.dataName) } - - linkUrl = _data[_config.wrap.linkField] || '' } else { if (_config.wrap.linkType !== 'input') { linkUrl = _config.wrap.linkUrl || '' @@ -71,13 +65,12 @@ this.setState({ linkUrl: linkUrl, - sync: _sync, data: _data, BID: BID || '', config: _config, arr_field: _config.columns.map(col => col.field).join(','), }, () => { - if (_config.wrap.datatype === 'dynamic' && _config.setting.sync !== 'true' && _config.setting.onload === 'true') { + if (_config.wrap.datatype === 'dynamic' && config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) @@ -90,6 +83,14 @@ MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } if (config.wrap.linkType === 'input' && config.wrap.focus !== 'false') { setTimeout(() => { @@ -112,32 +113,36 @@ } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) } - /** - * @description 鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = this.state + transferSyncData = (syncId) => { + const { config } = 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.$syncId !== syncId) return - let linkUrl = _data[config.wrap.linkField] || '' + let _data = window.GLOB.SyncData.get(config.dataName) || [] + _data = _data[0] || {$$empty: true} + + let linkUrl = _data[config.wrap.linkField] || '' - this.setState({sync: false, data: _data, linkUrl}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } + this.setState({data: _data, linkUrl}) + + 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() + }) } resetParentParam = (MenuID, id, data) => { @@ -161,7 +166,6 @@ } async loadData () { - const { mainSearch } = this.props const { config, arr_field, BID } = this.state if (config.wrap.datatype === 'static') { @@ -176,10 +180,12 @@ 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 } diff --git a/src/tabviews/custom/components/share/tabtransfer/index.jsx b/src/tabviews/custom/components/share/tabtransfer/index.jsx index 2e26fb1..8ef2320 100644 --- a/src/tabviews/custom/components/share/tabtransfer/index.jsx +++ b/src/tabviews/custom/components/share/tabtransfer/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { is, fromJS } from 'immutable' -import { Row, Col, Empty, notification } from 'antd' +import { fromJS } from 'immutable' +import { Row, Col, Empty, notification, Modal } from 'antd' import Api from '@/api' import asyncComponent from '@/utils/asyncComponent' @@ -9,7 +9,7 @@ getStructuredParams, getStructDefaultParam } from '@/utils/utils-datamanage.js' -import Utils from '@/utils/utils.js' +import MKEmitter from '@/utils/events.js' import './index.scss' // 閫氱敤缁勪欢 @@ -45,89 +45,80 @@ class TabTransfer extends Component { static propTpyes = { config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 鍏ㄥ眬鎼滅储鏉′欢 - } - - state = { - mainSearch: [], - self: false, - data: null } UNSAFE_componentWillMount () { - const { config, mainSearch } = this.props + let _config = fromJS(this.props.config).toJS() - // 鑾峰彇涓绘悳绱㈡潯浠� - let _mainSearch = [] - let self = false - config.components.forEach(component => { - if (component.type === 'search') { - self = true - _mainSearch = Utils.initMainSearch(component.search) + if (_config.type !== 'group') { + let params = [] + + _config.components = this.formatSetting(_config.components, params) + + if (params.length > 0) { + this.loadmaindata(params) } - }) - - if (!self) { - _mainSearch = fromJS(mainSearch).toJS() + } else { + let delay = 110 + _config.components.forEach(item => { + if (!item.setting || item.setting.interType !== 'system') return + if (!item.format) return + + item.setting.delay = delay + delay += 20 + }) } - let params = [] - let delay = 20 - config.components.forEach(item => { - if (item.type === 'tabs' || item.type === 'group') return + this.setState({ + config: _config + }) + } - if (!item.setting || item.setting.interType !== 'system') return - if (!item.format) return + formatSetting = (components, params) => { + let delay = 110 + return components.map(item => { + if (item.type === 'tabs') return item + if (item.type === 'group') { + item.components = this.formatSetting(item.components, params) + return item + } - if ((!item.pageable || (item.pageable && !item.setting.laypage)) && item.setting.onload === 'true' && item.setting.sync === 'true') { - let searchlist = [] - if (item.search && item.search.length > 0) { - searchlist = Utils.initMainSearch(item.search) - } + if (!item.setting || item.setting.interType !== 'system') return item + if (!item.format) return item + + if (item.setting.sync === 'true') { + let searchlist = item.$searches || [] + if (item.setting.useMSearch) { - let keys = searchlist.map(item => item.key) - _mainSearch.forEach(item => { - if (!keys.includes(item.key)) { - searchlist.push(item) - } + let mainSearch = window.GLOB.SearchBox.get(item.$searchId) + let keys = item.$s_keys || [] + mainSearch.forEach(item => { + if (keys.includes(item.key.toLowerCase())) return + + searchlist.push(item) }) } - if (searchlist.filter(cell => cell.required && cell.value === '').length > 0) { + if (item.$s_req && searchlist.filter(item => item.required && item.value === '').length > 0) { item.setting.sync = 'false' item.setting.onload = 'false' } else { params.push(getStructDefaultParam(item, searchlist, params.length === 0)) } - } else { - item.setting.sync = 'false' - item.setting.delay = delay - delay += 20 } + + item.setting.delay = delay + delay += 20 + + return item }) - - this.setState({mainSearch: _mainSearch, self}) - - if (params.length > 0) { - this.loadmaindata(params) - } - } - - UNSAFE_componentWillReceiveProps(nextProps) { - const { self } = this.state - - if (!self && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({mainSearch: null}, () => { - this.setState({mainSearch: fromJS(nextProps.mainSearch).toJS()}) - }) - } } /** * @description 涓昏〃鏁版嵁鍔犺浇 */ loadmaindata = (params) => { - const { config } = this.props + const { config } = this.state let BID = '' let BData = window.GLOB.CacheData.get(config.$pageId) @@ -139,46 +130,49 @@ Api.genericInterface(param).then(result => { if (result.status) { - delete result.status - delete result.message - delete result.ErrMesg - delete result.ErrCode - - if (config.$cache) { - params.forEach((item) => { - let _data = result[item.name] || '' - if (_data && !Array.isArray(_data)) { - _data = [_data] - } - Api.writeCacheConfig(item.uuid, _data) - }) + 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 + }) + } } - this.setState({ - data: result + params.forEach((item) => { + let _data = result[item.name] || '' + if (_data && !Array.isArray(_data)) { + _data = [_data] + } + window.GLOB.SyncData.set(item.name, _data) }) + + MKEmitter.emit('transferSyncData', config.uuid) } else { - this.setState({ - data: '' - }) - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) + MKEmitter.emit('transferSyncData', config.uuid) + + if (!result.message) return + if (result.ErrCode === 'N') { + Modal.error({ + title: result.message, + }) + } else if (result.ErrCode !== '-2') { + notification.error({ + top: 92, + message: result.message, + duration: 10 + }) + } } }) } - resetSearch = (search) => { - this.setState({mainSearch: null}, () => { - this.setState({mainSearch: search}) - }) - } - getComponents = (components) => { - const { mainSearch, data } = this.state - return components.map(item => { let style = null @@ -191,49 +185,49 @@ if (item.type === 'card' && item.subtype === 'datacard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <DataCard config={item} data={data} mainSearch={mainSearch}/> + <DataCard config={item}/> </Col> ) } else if (item.type === 'card' && item.subtype === 'propcard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <PropCard config={item} data={data} mainSearch={mainSearch}/> + <PropCard config={item}/> </Col> ) } else if (item.type === 'table' && item.subtype === 'normaltable') { return ( <Col span={item.width} style={style} key={item.uuid}> - <NormalTable config={item} data={data} mainSearch={mainSearch}/> + <NormalTable config={item}/> </Col> ) } else if (item.type === 'card' && item.subtype === 'dualdatacard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <DoubleDataCard config={item} mainSearch={mainSearch}/> + <DoubleDataCard config={item}/> </Col> ) } else if (item.type === 'bar' || item.type === 'line') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvBarAndLine data={data} config={item} mainSearch={mainSearch}/> + <AntvBarAndLine config={item}/> </Col> ) } else if (item.type === 'pie') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvPie data={data} config={item} mainSearch={mainSearch}/> + <AntvPie config={item}/> </Col> ) } else if (item.type === 'dashboard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvDashboard config={item} data={data} mainSearch={mainSearch}/> + <AntvDashboard config={item}/> </Col> ) } else if (item.type === 'scatter') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvScatter config={item} data={data} mainSearch={mainSearch}/> + <AntvScatter config={item}/> </Col> ) } else if (item.type === 'search') { @@ -244,115 +238,115 @@ } return ( <Col span={item.width} style={style} key={item.uuid}> - <MainSearch config={item} BID={BID} refreshdata={this.resetSearch} /> + <MainSearch config={item} BID={BID}/> </Col> ) } else if (item.type === 'tabs') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvTabs config={item} mainSearch={mainSearch}/> + <AntvTabs config={item}/> </Col> ) } else if (item.type === 'carousel' && item.subtype === 'datacard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <CarouselDataCard config={item} data={data} mainSearch={mainSearch}/> + <CarouselDataCard config={item}/> </Col> ) } else if (item.type === 'carousel' && item.subtype === 'propcard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <CarouselPropCard config={item} data={data} mainSearch={mainSearch}/> + <CarouselPropCard config={item}/> </Col> ) } else if (item.type === 'card' && item.subtype === 'tablecard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <TableCard config={item} data={data} mainSearch={mainSearch}/> + <TableCard config={item}/> </Col> ) } else if (item.type === 'table' && item.subtype === 'basetable') { return ( <Col span={item.width} style={style} key={item.uuid}> - <MkBaseTable config={item} data={data} mainSearch={mainSearch}/> + <MkBaseTable config={item}/> </Col> ) } else if (item.type === 'table' && item.subtype === 'editable') { return ( <Col span={item.width} style={style} key={item.uuid}> - <EditTable config={item} mainSearch={mainSearch}/> + <EditTable config={item}/> </Col> ) } else if (item.type === 'group' && item.subtype === 'normalgroup') { return ( <Col span={item.width} style={style} key={item.uuid}> - <NormalGroup config={item} mainSearch={mainSearch}/> + <NormalGroup config={item}/> </Col> ) } else if (item.type === 'form' && item.subtype === 'simpleform') { return ( <Col span={item.width} style={style} key={item.uuid}> - <SimpleForm config={item} data={data} mainSearch={mainSearch}/> + <SimpleForm config={item}/> </Col> ) } else if (item.type === 'form' && item.subtype === 'stepform') { return ( <Col span={item.width} style={style} key={item.uuid}> - <StepForm config={item} data={data} mainSearch={mainSearch}/> + <StepForm config={item}/> </Col> ) } else if (item.type === 'form' && item.subtype === 'tabform') { return ( <Col span={item.width} style={style} key={item.uuid}> - <TabForm config={item} data={data} mainSearch={mainSearch}/> + <TabForm config={item}/> </Col> ) } else if (item.type === 'tree') { return ( <Col span={item.width} style={style} key={item.uuid}> - <NormalTree config={item} data={data} mainSearch={mainSearch}/> + <NormalTree config={item}/> </Col> ) } else if (item.type === 'calendar') { return ( <Col span={item.width} style={style} key={item.uuid}> - <Calendar config={item} mainSearch={mainSearch}/> + <Calendar config={item}/> </Col> ) } else if (item.type === 'editor') { return ( <Col span={item.width} style={style} key={item.uuid}> - <BraftEditor config={item} data={data} mainSearch={mainSearch}/> + <BraftEditor config={item}/> </Col> ) } else if (item.type === 'code') { return ( <Col span={item.width} style={style} key={item.uuid}> - <SandBox config={item} data={data} mainSearch={mainSearch}/> + <SandBox config={item}/> </Col> ) } else if (item.type === 'balcony') { return ( <Col span={item.width} style={style} key={item.uuid}> - <Balcony config={item} data={data}/> + <Balcony config={item}/> </Col> ) } else if (item.type === 'timeline') { return ( <Col span={item.width} style={style} key={item.uuid}> - <TimeLine config={item} data={data} mainSearch={mainSearch}/> + <TimeLine config={item}/> </Col> ) } else if (item.type === 'chart') { return ( <Col span={item.width} style={style} key={item.uuid}> - <CustomChart config={item} data={data} mainSearch={mainSearch}/> + <CustomChart config={item}/> </Col> ) } else if (item.type === 'antvG6') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvG6 config={item} data={data} mainSearch={mainSearch}/> + <AntvG6 config={item}/> </Col> ) } else if (item.type === 'antvX6') { @@ -368,10 +362,16 @@ } render() { - const { config } = this.props + const { config } = this.state if (!config || !config.components || config.components.length === 0) return (<Empty description={false} />) + if (config.type === 'group') { + return ( + <Row className="component-wrap">{this.getComponents(config.components)}</Row> + ) + } + return ( <Row className="component-wrap" id={'anchor' + config.uuid} gutter={8}>{this.getComponents(config.components)}</Row> ) diff --git a/src/tabviews/custom/components/table/base-table/index.jsx b/src/tabviews/custom/components/table/base-table/index.jsx index 6b910ec..9d3b50f 100644 --- a/src/tabviews/custom/components/table/base-table/index.jsx +++ b/src/tabviews/custom/components/table/base-table/index.jsx @@ -4,7 +4,6 @@ import { notification, Modal } 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' @@ -17,9 +16,7 @@ class MkBaseTable extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 } state = { @@ -86,7 +83,7 @@ actions: _config.action, columns: _config.cols, arr_field: _config.columns.map(col => col.field).join(','), - search: Utils.initMainSearch(_config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 + search: _config.$searches }, () => { if (_config.setting.onload === 'true') { setTimeout(() => { @@ -103,7 +100,6 @@ * @param { String } repage 琛ㄦ牸鏄惁閲嶇疆椤电爜 */ async loadmaindata (reset, repage, id) { - const { mainSearch } = this.props const { setting, config, arr_field, search, orderBy, BID, pageIndex, pageSize, BData } = this.state if (setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -122,17 +118,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 } @@ -261,16 +257,16 @@ * @description 鑾峰彇鍗曡鏁版嵁 */ async loadmainLinedata (id) { - const { mainSearch } = this.props const { setting, config, arr_field, search, orderBy, BID, pageIndex, pageSize, BData } = 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) }) } @@ -344,7 +340,6 @@ * @description 鑾峰彇鍚堣瀛楁鍊� */ getStatFieldsValue = () => { - const { mainSearch } = this.props const { setting, config, search, BID, orderBy } = this.state if (setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -357,16 +352,17 @@ if (config.statFields.length === 0 || setting.interType !== 'system' || !setting.dataresource) return 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 } @@ -411,6 +407,8 @@ * 鍚湁鍒濆涓嶅姞杞界殑椤甸潰锛屼慨鏀硅缃� */ refreshbysearch = (searches) => { + const { config} = this.state + this.setState({ pageIndex: 1, search: searches @@ -418,6 +416,11 @@ this.loadmaindata(true, 'true') this.getStatFieldsValue() }) + + if (config.$main) { + window.GLOB.SearchBox.set(config.$searchId, searches) + MKEmitter.emit('searchRefresh', config.$searchId) + } } /** @@ -470,18 +473,18 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, callback) => { - const { mainSearch } = this.props const { arr_field, config, orderBy, search, setting} = 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()) + 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) }) } @@ -545,14 +548,14 @@ } } - UNSAFE_componentWillReceiveProps(nextProps) { + searchRefresh = (searchId) => { const { config } = this.state - if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({pageIndex: 1}, () => { - this.reloadtable() - }) - } + if (config.$searchId !== searchId) return + + this.setState({pageIndex: 1}, () => { + this.reloadtable() + }) } shouldComponentUpdate (nextProps, nextState) { @@ -560,10 +563,16 @@ } componentDidMount () { + 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.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } } /** @@ -574,6 +583,7 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) diff --git a/src/tabviews/custom/components/table/edit-table/index.jsx b/src/tabviews/custom/components/table/edit-table/index.jsx index cbbbbed..6450750 100644 --- a/src/tabviews/custom/components/table/edit-table/index.jsx +++ b/src/tabviews/custom/components/table/edit-table/index.jsx @@ -19,7 +19,6 @@ class EditableTable extends Component { static propTpyes = { config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 } state = { @@ -175,7 +174,7 @@ actions: _config.action, columns: _columns, arr_field: _config.columns.map(col => col.field).join(','), - search: Utils.initMainSearch(_config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 + search: _config.$searches }, () => { if (_config.setting.onload === 'true') { setTimeout(() => { @@ -191,7 +190,6 @@ * @param { String } repage 琛ㄦ牸鏄惁閲嶇疆椤电爜 */ async loadmaindata (reset, repage) { - const { mainSearch } = this.props const { setting, config, arr_field, search, orderBy, BID, pageIndex, pageSize, BData } = this.state if (setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -205,17 +203,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 } @@ -300,16 +298,16 @@ * @description 鑾峰彇鍗曡鏁版嵁 */ async loadmainLinedata (id) { - const { mainSearch } = this.props const { setting, config, arr_field, search, orderBy, BID, pageIndex, pageSize, BData } = 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) }) } @@ -437,18 +435,18 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, callback) => { - const { mainSearch } = this.props const { arr_field, config, orderBy, search, setting} = 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()) + 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) }) } @@ -537,14 +535,14 @@ }) } - UNSAFE_componentWillReceiveProps(nextProps) { + searchRefresh = (searchId) => { const { config } = this.state - if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({pageIndex: 1}, () => { - this.reloadtable() - }) - } + if (config.$searchId !== searchId) return + + this.setState({pageIndex: 1}, () => { + this.reloadtable() + }) } shouldComponentUpdate (nextProps, nextState) { @@ -552,11 +550,17 @@ } componentDidMount () { + const { config } = this.state + MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.addListener('queryModuleParam', this.queryModuleParam) MKEmitter.addListener('refreshLineData', this.refreshLineData) MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } } /** @@ -567,9 +571,10 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) + MKEmitter.removeListener('refreshLineData', this.refreshLineData) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) - MKEmitter.removeListener('refreshLineData', this.refreshLineData) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) } diff --git a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx index f8bfcf3..4df974a 100644 --- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx +++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx @@ -1675,13 +1675,11 @@ param.func = 'sPC_TableData_InUpDe' if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - result.sql = result.sql.replace(/\$@/ig, '/*') - result.sql = result.sql.replace(/@\$/ig, '*/') - result.bottom = result.bottom.replace(/\$@/ig, '/*') - result.bottom = result.bottom.replace(/@\$/ig, '*/') + result.sql = result.sql.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') + result.bottom = result.bottom.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - result.sql = result.sql.replace(/@\$|\$@/ig, '') - result.bottom = result.bottom.replace(/@\$|\$@/ig, '') + result.sql = result.sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') + result.bottom = result.bottom.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } param.excel_in_type = 'true' diff --git a/src/tabviews/custom/components/table/normal-table/index.jsx b/src/tabviews/custom/components/table/normal-table/index.jsx index c9a2e15..59e8a1f 100644 --- a/src/tabviews/custom/components/table/normal-table/index.jsx +++ b/src/tabviews/custom/components/table/normal-table/index.jsx @@ -4,7 +4,6 @@ import { notification, Collapse, Modal } 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' @@ -21,9 +20,7 @@ class NormalTable extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -52,11 +49,10 @@ * 1銆� initdata 涓烘墦鍗版椂浣跨敤鐨勬暟鎹泦 */ UNSAFE_componentWillMount () { - const { data, initdata } = this.props - let _config = fromJS(this.props.config).toJS() - let _data = null - let _sync = _config.setting.sync === 'true' + const { config } = this.props + let _config = fromJS(config).toJS() + let _data = null let BID = '' let BData = '' @@ -85,16 +81,15 @@ setting.orisel = true } - if (_sync && data) { - _data = data[_config.dataName] || [] - _sync = false - } else if (_sync && initdata) { - _data = initdata || [] - _sync = false - } + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] - if (_data) { - this.loaded = true + 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] || '' @@ -120,7 +115,7 @@ return item }) - if (setting.selected !== 'false' && _data && _data.length > 0) { + if (setting.selected !== 'false' && _data.length > 0) { setTimeout(() => { MKEmitter.emit('mkCheckTopLine', _config.uuid, '', setting.selected) }, 200) @@ -128,8 +123,12 @@ setting.selected = 'false' } } - } + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) + } + if (_config.wrap.collapse === 'true') { _config.wrap.title = _config.wrap.title || ' ' } @@ -141,16 +140,15 @@ BID: BID || '', BData: BData || '', title: _config.wrap.title, - sync: _sync, data: _data, config: _config, setting: setting, actions: _config.action, columns: _config.cols, arr_field: _config.columns.map(col => col.field).join(','), - search: Utils.initMainSearch(_config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 + search: _config.$searches }, () => { - if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') { + if (config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadmaindata() this.getStatFieldsValue() @@ -161,13 +159,68 @@ }) } + transferSyncData = (syncId) => { + const { config } = this.state + + if (config.$syncId !== syncId) return + + const { setting, 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.$$key = '' + item.key + item.$$uuid + item.$$BID = BID || '' + item.$$BData = BData || '' + item.$Index = index + 1 + '' + + if (config.absFields) { + config.absFields.forEach(f => { + if (!isNaN(item[f])) { + item[f] = Math.abs(item[f]) + } + }) + } + + if (setting.controlField) { + if (setting.controlVal.includes(item[setting.controlField] + '')) { + item.$disabled = true + } + } + + return item + }) + + if (setting.selected !== 'false' && _data.length > 0) { + setTimeout(() => { + MKEmitter.emit('mkCheckTopLine', config.uuid, '', setting.selected) + }, 200) + if (setting.selected === 'init') { + this.setState({setting: {...setting, selected: 'false'}}) + } + } + + this.loaded = true + + this.setState({data: _data}) + + window.GLOB.SyncData.delete(config.dataName) + + MKEmitter.removeListener('transferSyncData', this.transferSyncData) + } + /** * @description 涓昏〃鏁版嵁鍔犺浇 * @param { Boolean } reset 琛ㄦ牸鏄惁閲嶇疆 * @param { String } repage 琛ㄦ牸鏄惁閲嶇疆椤电爜 */ async loadmaindata (reset, repage, id, type) { - const { mainSearch } = this.props const { setting, config, arr_field, search, orderBy, BID, pageIndex, pageSize, BData } = this.state if (setting.supModule && !BID && setting.supKey !== 'false') { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -188,17 +241,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 } @@ -333,16 +386,16 @@ * @description 鑾峰彇鍗曡鏁版嵁 */ async loadmainLinedata (id) { - const { mainSearch } = this.props const { setting, config, arr_field, search, orderBy, BID, pageIndex, pageSize, BData } = 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) }) } @@ -423,7 +476,6 @@ * @description 鑾峰彇鍚堣瀛楁鍊� */ getStatFieldsValue = () => { - const { mainSearch } = this.props const { setting, config, search, BID, orderBy } = this.state if (setting.supModule && !BID && setting.supKey !== 'false') { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -436,16 +488,17 @@ if (config.statFields.length === 0 || setting.interType !== 'system' || !setting.dataresource) return 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 } @@ -541,18 +594,18 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, callback) => { - const { mainSearch } = this.props const { arr_field, config, orderBy, search, setting} = 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()) + 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) }) } @@ -641,56 +694,14 @@ }) } - UNSAFE_componentWillReceiveProps(nextProps) { - const { sync, config, setting, BID, BData } = this.state + searchRefresh = (searchId) => { + const { config } = 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.$$key = '' + item.key + item.$$uuid - item.$$BID = BID || '' - item.$$BData = BData || '' - item.$Index = index + 1 + '' - - if (config.absFields) { - config.absFields.forEach(f => { - if (!isNaN(item[f])) { - item[f] = Math.abs(item[f]) - } - }) - } - - if (setting.controlField) { - if (setting.controlVal.includes(item[setting.controlField] + '')) { - item.$disabled = true - } - } - - return item - }) - - if (setting.selected !== 'false' && _data && _data.length > 0) { - setTimeout(() => { - MKEmitter.emit('mkCheckTopLine', config.uuid, '', setting.selected) - }, 200) - if (setting.selected === 'init') { - this.setState({setting: {...setting, 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.reloadtable() - }) - } + if (config.$searchId !== searchId) return + + this.setState({pageIndex: 1}, () => { + this.reloadtable() + }) } shouldComponentUpdate (nextProps, nextState) { @@ -701,10 +712,18 @@ const { config, setting } = this.state MKEmitter.addListener('reloadData', this.reloadData) + MKEmitter.addListener('refreshLineData', this.refreshLineData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.addListener('queryModuleParam', this.queryModuleParam) - MKEmitter.addListener('refreshLineData', this.refreshLineData) 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() @@ -756,9 +775,11 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) - MKEmitter.removeListener('resetSelectLine', this.resetParentParam) - MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) + 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() diff --git a/src/tabviews/custom/components/tabs/antv-tabs/index.jsx b/src/tabviews/custom/components/tabs/antv-tabs/index.jsx index 63eb3e2..5fce84e 100644 --- a/src/tabviews/custom/components/tabs/antv-tabs/index.jsx +++ b/src/tabviews/custom/components/tabs/antv-tabs/index.jsx @@ -14,7 +14,6 @@ class antvTabs extends Component { static propTpyes = { config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 } state = { @@ -142,7 +141,6 @@ } render() { - const { mainSearch } = this.props const { tabs } = this.state if (!tabs.subtabs.length) return null @@ -152,7 +150,7 @@ <Tabs defaultActiveKey="1" tabBarStyle={{background: tabs.setting.backgroundColor || 'transparent'}} tabPosition={tabs.setting.position} type={tabs.setting.tabStyle}> {tabs.subtabs.map(tab => ( <TabPane tab={<span id={'tab' + tab.uuid}>{tab.icon ? <MkIcon type={tab.icon} /> : null}{tab.label}</span>} style={{backgroundColor: tab.backgroundColor || 'transparent'}} key={tab.uuid}> - <TabTransfer config={tab} mainSearch={mainSearch}/> + <TabTransfer config={tab}/> </TabPane> ))} </Tabs> diff --git a/src/tabviews/custom/components/timeline/normal-timeline/index.jsx b/src/tabviews/custom/components/timeline/normal-timeline/index.jsx index 2690fad..0d92eb1 100644 --- a/src/tabviews/custom/components/timeline/normal-timeline/index.jsx +++ b/src/tabviews/custom/components/timeline/normal-timeline/index.jsx @@ -16,16 +16,13 @@ class NormalTimeline extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { BID: '', // 涓婄骇ID config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: null, // 鏁版嵁 BData: '', card: null, @@ -36,16 +33,13 @@ /** * @description 鍒濆鍖栧鐞� - * 1銆� initdata 涓烘墦鍗版椂浣跨敤鐨勬暟鎹泦 */ 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 = null let card = null - let _sync = _config.setting.sync === 'true' - let BID = '' let BData = '' @@ -58,16 +52,15 @@ BID = BData.$BID || '' } - if (_config.setting.sync === 'true' && data) { - _data = data[_config.dataName] || [] - _sync = false - } else if (_config.setting.sync === 'true' && initdata) { - _data = initdata || [] - _sync = false - } + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] - if (_data) { - this.loaded = true + 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] || '' @@ -76,6 +69,10 @@ item.$Index = index + 1 + '' return item }) + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } _config.search = [] @@ -94,14 +91,13 @@ this.setState({ card, - sync: _sync, BID: BID || '', BData: BData || '', data: _data, config: _config, arr_field: _config.columns.map(col => col.field).join(','), }, () => { - if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') { + if (config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) @@ -113,10 +109,18 @@ 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('refreshLineData', this.refreshLineData) 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() @@ -149,43 +153,55 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) + MKEmitter.removeListener('refreshLineData', this.refreshLineData) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) - MKEmitter.removeListener('refreshLineData', this.refreshLineData) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) this.timer && this.timer.stop() } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config, BID, BData } = this.state + transferSyncData = (syncId) => { + const { config } = 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 (config.$syncId !== syncId) return - _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 - }) + const { BID, BData } = this.state - this.loaded = true + let _data = window.GLOB.SyncData.get(config.dataName) || [] - this.setState({sync: false, data: _data}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) + 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 + '' + return item + }) + + 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({}, () => { + this.loadData() + }) } /** @@ -246,19 +262,13 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, callback) => { - const { mainSearch } = this.props const { arr_field, config } = this.state if (config.uuid !== menuId) return let searches = [] - 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) - } - }) + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + searches = window.GLOB.SearchBox.get(config.$searchId) || [] } callback({ @@ -270,7 +280,6 @@ } async loadData (hastimer) { - const { mainSearch } = this.props const { config, arr_field, BID, BData } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -288,17 +297,11 @@ } let searches = [] - if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - let keys = searches.map(item => item.key) - mainSearch.forEach(item => { - if (!keys.includes(item.key)) { - searches.push(item) - } - }) + 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 } @@ -315,7 +318,7 @@ if (result.status) { this.loaded = true if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } let data = result.data.map((item, index) => { diff --git a/src/tabviews/custom/components/tree/antd-tree/index.jsx b/src/tabviews/custom/components/tree/antd-tree/index.jsx index e924dd2..9c9b744 100644 --- a/src/tabviews/custom/components/tree/antd-tree/index.jsx +++ b/src/tabviews/custom/components/tree/antd-tree/index.jsx @@ -18,16 +18,13 @@ class NormalTree extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { BID: '', // 涓昏〃ID config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: null, // 鏁版嵁 searchkey: null, // 杩囨护鏉′欢 treedata: null, // 鍒楄〃鏁版嵁闆� @@ -40,11 +37,10 @@ loaded = false UNSAFE_componentWillMount () { - const { config, data, initdata } = this.props + const { config } = this.props + let _config = fromJS(config).toJS() let _data = null - let _sync = config.setting.sync === 'true' - let BID = '' let BData = '' @@ -57,17 +53,21 @@ BID = BData.$BID || '' } - if (_sync && data) { - _data = data[config.dataName] || [] - _sync = false - } else if (_sync && initdata) { - _data = initdata || [] - _sync = false + 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()) + } + + _config.setting.sync = 'false' + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } _config.wrap.contentHeight = config.wrap.title || config.wrap.searchable === 'true' ? 'calc(100% - 45px)' : '100%' - - this.loaded = _data !== null this.setState({ selected: _config.wrap.selected === 'true', @@ -75,7 +75,6 @@ data: _data, BID: BID || '', arr_field: _config.columns.map(col => col.field).join(','), - sync: _sync }, () => { if (config.setting.sync !== 'true' && config.setting.onload === 'true') { setTimeout(() => { @@ -85,30 +84,6 @@ this.handleData() } }) - } - - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = 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] || [] - } - - this.loaded = true - - this.setState({sync: false, data: _data}, () => { - this.handleData() - }) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) - } } shouldComponentUpdate (nextProps, nextState) { @@ -123,6 +98,14 @@ 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() this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { @@ -149,11 +132,45 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) 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() + } + + transferSyncData = (syncId) => { + const { config } = this.state + + if (config.$syncId !== syncId) return + + let _data = window.GLOB.SyncData.get(config.dataName) || [] + + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) + } + + this.loaded = true + + this.setState({data: _data}, () => { + this.handleData() + }) + + 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() + }) } reloadData = (menuId) => { @@ -179,19 +196,13 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, callback) => { - const { mainSearch } = this.props const { arr_field, config } = this.state if (config.uuid !== menuId) return let searches = [] - 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) - } - }) + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + searches = window.GLOB.SearchBox.get(config.$searchId) || [] } callback({ @@ -224,7 +235,6 @@ * @description 鏁版嵁鍔犺浇 */ async loadData (hastimer) { - const { mainSearch } = this.props const { config, arr_field, BID } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -237,10 +247,12 @@ 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 } @@ -257,7 +269,7 @@ if (result.status) { this.loaded = true if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } this.setState({ diff --git a/src/tabviews/custom/index.jsx b/src/tabviews/custom/index.jsx index f0d2148..633b8c8 100644 --- a/src/tabviews/custom/index.jsx +++ b/src/tabviews/custom/index.jsx @@ -66,9 +66,7 @@ viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 lostmsg: '', // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅 config: null, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷粍浠剁瓑 - mainSearch: null, // 涓绘悳绱� userConfig: null, // 鐢ㄦ埛鑷畾涔夎缃� - data: null, // 鍒楄〃鏁版嵁闆� loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� visible: false, // 鏍囩椤垫帶鍒� shortcuts: null, // 蹇嵎閿� @@ -210,24 +208,7 @@ let initInters = [] config.interfaces = this.formatInterSetting(config.interfaces, regs, MenuID, initInters) - config.components = this.filterComponent(config.components, roleId, window.GLOB.mkActions, balMap, skip, param, MenuID, config.interfaces, popview, config.$cache, config.MenuName) - - // 鑾峰彇涓绘悳绱㈡潯浠� - let mainSearch = [] - config.components.forEach(component => { - if (component.type !== 'search') return - - component.search = component.search.map(item => { - item.oriInitval = item.initval - if (['text', 'select', 'link'].includes(item.type) && param.$searchkey === item.field) { - item.initval = param.$searchval - } - - return item - }) - - mainSearch = Utils.initMainSearch(component.search) - }) + config.components = this.filterComponent(config.components, roleId, window.GLOB.mkActions, balMap, skip, param, MenuID, config.interfaces, popview, config.$cache, config.MenuName, MenuID, MenuID) let params = [] let BID = param.$BID || '' @@ -239,7 +220,30 @@ inherit.cacheTime = config.cacheTime } - config.components = this.formatSetting(config.components, params, mainSearch, inherit, regs, balMap) + // 瀛楁閫忚 + config.components.forEach(component => { + if (component.type !== 'search') return + + if (param.$searchkey) { + component.search = component.search.map(item => { + if (['text', 'select', 'link'].includes(item.type) && param.$searchkey === item.field) { + item.initval = param.$searchval + } + + return item + }) + + component.$searches = Utils.initMainSearch(component.search) + } + + window.GLOB.SearchBox.set(MenuID, component.$searches) + + if (component.$s_req) { + window.GLOB.SearchBox.set(MenuID + 'required', true) + } + }) + + config.components = this.formatSetting(config.components, params, inherit, regs, balMap) if ([...balMap.keys()].length > 0) { config.components = this.filterBalcony(config.components, balMap) @@ -257,8 +261,7 @@ BID: BID, loadinginter: this.stepInter !== null, shortcuts: shortcuts.length > 0 ? shortcuts : null, - config, - mainSearch + config }, () => { if (config.normalcss) { let node = document.getElementById(config.uuid) @@ -339,10 +342,12 @@ } } - filterComponent = (components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName) => { + filterComponent = (components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName, searchId, syncId) => { return components.filter(item => { item.$pageId = pageId item.$cache = cache + item.$searchId = searchId + item.$syncId = syncId if (item.style && item.style.boxShadow) { delete item.style.hShadow @@ -435,7 +440,18 @@ item.subtabs = item.subtabs.map(tab => { tab.$pageId = pageId - tab.components = this.filterComponent(tab.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName) + let _searchId = searchId + + tab.components.forEach(cell => { + if (cell.type !== 'search') return + _searchId = cell.uuid + window.GLOB.SearchBox.set(cell.uuid, cell.$searches) + if (cell.$s_req) { + window.GLOB.SearchBox.set(cell.uuid + 'required', true) + } + }) + + tab.components = this.filterComponent(tab.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName, _searchId, tab.uuid) return tab }) @@ -448,7 +464,7 @@ return false } - item.components = this.filterComponent(item.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName) + item.components = this.filterComponent(item.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName, searchId, syncId) return true } else if (['pie', 'bar', 'line', 'dashboard', 'scatter', 'chart', 'antvG6', 'antvX6'].includes(item.type)) { @@ -481,8 +497,12 @@ } // 鎼滅储鏉′欢鍒濆鍖� - if (item.search && item.search.length > 0) { - item.search = Utils.initSearchVal(item.search) + if (item.type === 'search' && item.search.length === 0) { + return false + } else if (item.search) { + Utils.initSearchVal(item) + + item.$searches = Utils.initMainSearch(item.search) } if (item.wrap && item.wrap.supType === 'multi') { // 鏁版嵁鍗″涓婄骇缁勪欢 @@ -889,28 +909,30 @@ } // 鏍煎紡鍖栭粯璁よ缃� - formatSetting = (components, params, mainSearch, inherit, regs, balMap) => { + formatSetting = (components, params, inherit, regs, balMap) => { let delay = 20 return components.map(component => { if (component.type === 'tabs') { component.subtabs = component.subtabs.map(tab => { - tab.components = this.formatSetting(tab.components, null, null, inherit, regs, balMap) + tab.components = this.formatSetting(tab.components, null, inherit, regs, balMap) tab = {...tab, ...inherit} return tab }) return component } else if (component.type === 'group') { - component.components = this.formatSetting(component.components, null, null, inherit, regs, balMap) + component.components = this.formatSetting(component.components, params, inherit, regs, balMap) component = {...component, ...inherit} return component } else if (component.wrap && component.wrap.datatype === 'public') { component.setting.useMSearch = false + component.setting.sync = 'false' return component } else if (component.wrap && component.wrap.datatype === 'static') { component.format = '' component.setting = component.setting || {} component.setting.useMSearch = false + component.setting.sync = 'false' return component } else if (!component.setting || !component.format) { @@ -918,6 +940,13 @@ } component.setting.useMSearch = component.setting.useMSearch === 'true' + if (component.setting.useMSearch) { + if (!window.GLOB.SearchBox.has(component.$searchId)) { + component.setting.useMSearch = false + } else if (window.GLOB.SearchBox.has(component.$searchId + 'required')) { + component.$s_req = true + } + } if (component.wrap && component.wrap.goback === 'true') { component.setting.sync = 'false' @@ -950,10 +979,8 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'') - component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/') - _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'') - _customScript = _customScript.replace(/@\$/ig, '*/') + component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') + _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') @@ -966,35 +993,39 @@ component.setting.customScript = _customScript // 鏁寸悊鍚庤嚜瀹氫箟鑴氭湰 + if (component.setting.sync === 'true') { + // pageable 鏄惁鍒嗛〉锛岀粍浠跺睘鎬э紝涓嶅垎椤电殑缁勪欢鎵嶅彲浠ョ粺涓�鏌ヨ + if ((!component.pageable || (component.pageable && !component.setting.laypage)) && component.setting.onload === 'true') { + + } else { + component.setting.sync = 'false' + } + } + // dataName 绯荤粺鐢熸垚鐨勬暟鎹簮鍚嶇О if (component.setting.sync === 'true') { component.dataName = 'mk' + component.uuid.slice(-18) - } - - // floor 缁勪欢鐨勫眰绾� - // pageable 鏄惁鍒嗛〉锛岀粍浠跺睘鎬э紝涓嶅垎椤电殑缁勪欢鎵嶅彲浠ョ粺涓�鏌ヨ - if (params && (!component.pageable || (component.pageable && !component.setting.laypage)) && component.setting.onload === 'true' && component.setting.sync === 'true') { - let searchlist = [] - if (component.search && component.search.length > 0) { - searchlist = Utils.initMainSearch(component.search) - } - if (component.setting.useMSearch) { - let keys = searchlist.map(item => item.key) - mainSearch.forEach(item => { - if (!keys.includes(item.key)) { + + if (params) { + let searchlist = component.$searches || [] + + if (component.setting.useMSearch) { + let mainSearch = window.GLOB.SearchBox.get(component.$searchId) + let keys = component.$s_keys || [] + mainSearch.forEach(item => { + if (keys.includes(item.key.toLowerCase())) return + searchlist.push(item) - } - }) + }) + } + + if (component.$s_req && searchlist.filter(item => item.required && item.value === '').length > 0) { + component.setting.sync = 'false' + component.setting.onload = 'false' + } else { + params.push(getStructDefaultParam(component, searchlist, params.length === 0)) + } } - - if (searchlist.filter(item => item.required && item.value === '').length > 0) { - component.setting.sync = 'false' - component.setting.onload = 'false' - } else { - params.push(getStructDefaultParam(component, searchlist, params.length === 0)) - } - } else if (params) { - component.setting.sync = 'false' } component.setting.delay = delay @@ -1068,10 +1099,8 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - inter.setting.dataresource = inter.setting.dataresource.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'') - inter.setting.dataresource = inter.setting.dataresource.replace(/@\$/ig, '*/') - _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'') - _customScript = _customScript.replace(/@\$/ig, '*/') + inter.setting.dataresource = inter.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') + _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { inter.setting.dataresource = inter.setting.dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') @@ -1098,6 +1127,10 @@ this.setState({loading: true, loadingview: false}) Api.genericInterface(param).then(result => { + this.setState({ + loading: false + }) + if (result.status) { if (result.message) { if (result.ErrCode === 'Y') { @@ -1113,31 +1146,18 @@ } } - delete result.status - delete result.message - delete result.ErrMesg - delete result.ErrCode - - if (config.$cache) { - params.forEach((item) => { - let _data = result[item.name] || '' - if (_data && !Array.isArray(_data)) { - _data = [_data] - } - Api.writeCacheConfig(item.uuid, _data) - }) - } - - this.setState({ - data: result, - loading: false + params.forEach((item) => { + let _data = result[item.name] || '' + if (_data && !Array.isArray(_data)) { + _data = [_data] + } + window.GLOB.SyncData.set(item.name, _data) }) + + MKEmitter.emit('transferSyncData', config.MenuID) } else { - this.setState({ - data: '', - loading: false - }) - + MKEmitter.emit('transferSyncData', config.MenuID) + if (!result.message) return if (result.ErrCode === 'N') { Modal.error({ @@ -1243,8 +1263,13 @@ }) } else if (item.type === 'group') { this.deleteCache(item.components) + } else if (item.type === 'search') { + window.GLOB.SearchBox.delete(item.$searchId) } else { window.GLOB.CacheData.delete(item.uuid) + } + if (item.dataName) { + window.GLOB.SyncData.delete(item.dataName) } }) } @@ -1267,21 +1292,14 @@ viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 config: null, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷粍浠剁瓑 loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� - shortcuts: null, - data: '' + shortcuts: null }, () => { this.loadconfig() }) } - resetSearch = (search) => { - this.setState({mainSearch: null}, () => { - this.setState({mainSearch: search}) - }) - } - getComponents = () => { - const { config, BID, data, mainSearch, loadinginter } = this.state + const { config, BID, loadinginter } = this.state if (!config || !config.components || loadinginter) return @@ -1297,157 +1315,157 @@ if (item.type === 'card' && item.subtype === 'datacard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <DataCard config={item} data={data} mainSearch={mainSearch}/> + <DataCard config={item}/> </Col> ) } else if (item.type === 'card' && item.subtype === 'propcard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <PropCard config={item} data={data} mainSearch={mainSearch}/> + <PropCard config={item}/> </Col> ) } else if (item.type === 'card' && item.subtype === 'dualdatacard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <DoubleDataCard config={item} mainSearch={mainSearch}/> + <DoubleDataCard config={item}/> </Col> ) } else if (item.type === 'table' && item.subtype === 'normaltable') { return ( <Col span={item.width} style={style} key={item.uuid}> - <NormalTable config={item} data={data} mainSearch={mainSearch}/> + <NormalTable config={item}/> </Col> ) } else if (item.type === 'bar' || item.type === 'line') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvBarAndLine config={item} data={data} mainSearch={mainSearch}/> + <AntvBarAndLine config={item}/> </Col> ) } else if (item.type === 'pie') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvPie config={item} data={data} mainSearch={mainSearch}/> + <AntvPie config={item}/> </Col> ) } else if (item.type === 'scatter') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvScatter config={item} data={data} mainSearch={mainSearch}/> + <AntvScatter config={item}/> </Col> ) } else if (item.type === 'dashboard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvDashboard config={item} data={data} mainSearch={mainSearch}/> + <AntvDashboard config={item}/> </Col> ) } else if (item.type === 'form' && item.subtype === 'simpleform') { return ( <Col span={item.width} style={style} key={item.uuid}> - <SimpleForm config={item} data={data} mainSearch={mainSearch}/> + <SimpleForm config={item}/> </Col> ) } else if (item.type === 'form' && item.subtype === 'stepform') { return ( <Col span={item.width} style={style} key={item.uuid}> - <StepForm config={item} data={data} mainSearch={mainSearch}/> + <StepForm config={item}/> </Col> ) } else if (item.type === 'form' && item.subtype === 'tabform') { return ( <Col span={item.width} style={style} key={item.uuid}> - <TabForm config={item} data={data} mainSearch={mainSearch}/> + <TabForm config={item}/> </Col> ) } else if (item.type === 'search') { return ( <Col span={item.width} style={style} key={item.uuid}> - <MainSearch config={item} BID={BID} refreshdata={this.resetSearch} /> + <MainSearch config={item} BID={BID}/> </Col> ) } else if (item.type === 'tabs') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvTabs config={item} mainSearch={mainSearch} /> + <AntvTabs config={item}/> </Col> ) } else if (item.type === 'balcony') { return ( <Col span={item.width} style={style} key={item.uuid}> - <Balcony config={item} data={data}/> + <Balcony config={item}/> </Col> ) } else if (item.type === 'timeline') { return ( <Col span={item.width} style={style} key={item.uuid}> - <TimeLine config={item} data={data} mainSearch={mainSearch}/> + <TimeLine config={item}/> </Col> ) } else if (item.type === 'carousel' && item.subtype === 'datacard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <CarouselDataCard config={item} data={data} mainSearch={mainSearch}/> + <CarouselDataCard config={item}/> </Col> ) } else if (item.type === 'carousel' && item.subtype === 'propcard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <CarouselPropCard config={item} data={data} mainSearch={mainSearch}/> + <CarouselPropCard config={item}/> </Col> ) } else if (item.type === 'card' && item.subtype === 'tablecard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <TableCard config={item} data={data} mainSearch={mainSearch}/> + <TableCard config={item}/> </Col> ) } else if (item.type === 'table' && item.subtype === 'editable') { return ( <Col span={item.width} style={style} key={item.uuid}> - <EditTable config={item} mainSearch={mainSearch}/> + <EditTable config={item}/> </Col> ) } else if (item.type === 'group' && item.subtype === 'normalgroup') { return ( <Col span={item.width} style={style} key={item.uuid}> - <NormalGroup config={item} mainSearch={mainSearch}/> + <NormalGroup config={item}/> </Col> ) } else if (item.type === 'editor') { return ( <Col span={item.width} style={style} key={item.uuid}> - <BraftEditor config={item} data={data} mainSearch={mainSearch}/> + <BraftEditor config={item}/> </Col> ) } else if (item.type === 'tree') { return ( <Col span={item.width} style={style} key={item.uuid}> - <NormalTree config={item} data={data} mainSearch={mainSearch}/> + <NormalTree config={item}/> </Col> ) } else if (item.type === 'calendar') { return ( <Col span={item.width} style={style} key={item.uuid}> - <Calendar config={item} mainSearch={mainSearch}/> + <Calendar config={item}/> </Col> ) } else if (item.type === 'code') { return ( <Col span={item.width} style={style} key={item.uuid}> - <SandBox config={item} data={data} mainSearch={mainSearch}/> + <SandBox config={item}/> </Col> ) } else if (item.type === 'chart') { return ( <Col span={item.width} style={style} key={item.uuid}> - <CustomChart config={item} data={data} mainSearch={mainSearch}/> + <CustomChart config={item}/> </Col> ) } else if (item.type === 'antvG6') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvG6 config={item} data={data} mainSearch={mainSearch}/> + <AntvG6 config={item}/> </Col> ) } else if (item.type === 'antvX6') { @@ -1471,7 +1489,7 @@ } else if (item.type === 'iframe') { return ( <Col span={item.width} style={style} key={item.uuid}> - <Iframe config={item} data={data} mainSearch={mainSearch}/> + <Iframe config={item}/> </Col> ) } else { diff --git a/src/tabviews/custom/popview/index.jsx b/src/tabviews/custom/popview/index.jsx index 4c74eee..04c65bb 100644 --- a/src/tabviews/custom/popview/index.jsx +++ b/src/tabviews/custom/popview/index.jsx @@ -8,6 +8,7 @@ import enUS from '@/locales/en-US/main.js' import Utils from '@/utils/utils.js' import { getStructuredParams, getStructDefaultParam } from '@/utils/utils-datamanage.js' +import MKEmitter from '@/utils/events.js' import asyncComponent from '@/utils/asyncComponent' import NotFount from '@/components/404' import './index.scss' @@ -56,8 +57,6 @@ viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 lostmsg: '', // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅 config: null, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷粍浠剁瓑 - mainSearch: null, // 涓绘悳绱� - data: null, // 鍒楄〃鏁版嵁闆� loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� } @@ -134,23 +133,29 @@ config.$cache = config.cacheLocal === 'true' - config.components = this.filterComponent(config.components, roleId, balMap, param, Tab, config.$cache) + config.components = this.filterComponent(config.components, roleId, balMap, param, Tab, config.$cache, Tab.uuid, Tab.uuid) // 鑾峰彇涓绘悳绱㈡潯浠� - let mainSearch = [] config.components.forEach(component => { if (component.type !== 'search') return - component.search = component.search.map(item => { - item.oriInitval = item.initval - if (['text', 'select', 'link'].includes(item.type) && param.$searchkey === item.field) { - item.initval = param.$searchval - } + if (param.$searchkey) { + component.search = component.search.map(item => { + if (['text', 'select', 'link'].includes(item.type) && param.$searchkey === item.field) { + item.initval = param.$searchval + } - return item - }) + return item + }) - mainSearch = Utils.initMainSearch(component.search) + component.$searches = Utils.initMainSearch(component.search) + } + + window.GLOB.SearchBox.set(Tab.uuid, component.$searches) + + if (component.$s_req) { + window.GLOB.SearchBox.set(Tab.uuid + 'required', true) + } }) let params = [] @@ -163,7 +168,7 @@ inherit.cacheTime = config.cacheTime } - config.components = this.formatSetting(config.components, params, mainSearch, inherit, regs, balMap) + config.components = this.formatSetting(config.components, params, inherit, regs, balMap) if ([...balMap.keys()].length > 0) { config.components = this.filterBalcony(config.components, balMap) @@ -171,8 +176,7 @@ this.setState({ BID: BID, - config, - mainSearch + config }, () => { if (params.length > 0) { this.loadmaindata(params) @@ -180,10 +184,12 @@ }) } - filterComponent = (components, roleId, balMap, urlparam, Tab, cache) => { + filterComponent = (components, roleId, balMap, urlparam, Tab, cache, searchId, syncId) => { return components.filter(item => { item.$pageId = Tab.uuid item.$cache = cache + item.$searchId = searchId + item.$syncId = syncId if (item.style && item.style.boxShadow) { delete item.style.hShadow @@ -276,7 +282,18 @@ item.subtabs = item.subtabs.map(tab => { tab.$pageId = Tab.uuid - tab.components = this.filterComponent(tab.components, roleId, balMap, urlparam, Tab, cache) + let _searchId = searchId + + tab.components.forEach(cell => { + if (cell.type !== 'search') return + _searchId = cell.uuid + window.GLOB.SearchBox.set(cell.uuid, cell.$searches) + if (cell.$s_req) { + window.GLOB.SearchBox.set(cell.uuid + 'required', true) + } + }) + + tab.components = this.filterComponent(tab.components, roleId, balMap, urlparam, Tab, cache, _searchId, tab.uuid) return tab }) @@ -289,7 +306,7 @@ return false } - item.components = this.filterComponent(item.components, roleId, balMap, urlparam, Tab, cache) + item.components = this.filterComponent(item.components, roleId, balMap, urlparam, Tab, cache, searchId, syncId) return true } else if (['pie', 'bar', 'line', 'dashboard', 'scatter', 'chart'].includes(item.type)) { @@ -309,8 +326,12 @@ } // 鎼滅储鏉′欢鍒濆鍖� - if (item.search && item.search.length > 0) { - item.search = Utils.initSearchVal(item.search) + if (item.type === 'search' && item.search.length === 0) { + return false + } else if (item.search) { + Utils.initSearchVal(item) + + item.$searches = Utils.initMainSearch(item.search) } if (item.wrap && item.wrap.supType === 'multi') { // 鏁版嵁鍗″涓婄骇缁勪欢 @@ -682,7 +703,7 @@ } // 鏍煎紡鍖栭粯璁よ缃� - formatSetting = (components, params, mainSearch, inherit, regs, balMap) => { + formatSetting = (components, params, inherit, regs, balMap) => { let delay = 20 return components.map(component => { if (component.type === 'tabs') { @@ -693,17 +714,19 @@ }) return component } else if (component.type === 'group') { - component.components = this.formatSetting(component.components, null, null, inherit, regs, balMap) + component.components = this.formatSetting(component.components, params, inherit, regs, balMap) component = {...component, ...inherit} return component } else if (component.wrap && component.wrap.datatype === 'public') { component.setting.useMSearch = false + component.setting.sync = 'false' return component } else if (component.wrap && component.wrap.datatype === 'static') { component.format = '' component.setting = component.setting || {} component.setting.useMSearch = false + component.setting.sync = 'false' return component } else if (!component.setting || !component.format) { @@ -711,6 +734,13 @@ } component.setting.useMSearch = component.setting.useMSearch === 'true' + if (component.setting.useMSearch) { + if (!window.GLOB.SearchBox.has(component.$searchId)) { + component.setting.useMSearch = false + } else if (window.GLOB.SearchBox.has(component.$searchId + 'required')) { + component.$s_req = true + } + } if (component.setting.interType !== 'system') { // 涓嶄娇鐢ㄧ郴缁熷嚱鏁版椂 component.setting.sync = 'false' @@ -739,10 +769,8 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'') - component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/') - _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'') - _customScript = _customScript.replace(/@\$/ig, '*/') + component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') + _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') @@ -755,35 +783,39 @@ component.setting.customScript = _customScript // 鏁寸悊鍚庤嚜瀹氫箟鑴氭湰 + if (component.setting.sync === 'true') { + // pageable 鏄惁鍒嗛〉锛岀粍浠跺睘鎬э紝涓嶅垎椤电殑缁勪欢鎵嶅彲浠ョ粺涓�鏌ヨ + if ((!component.pageable || (component.pageable && !component.setting.laypage)) && component.setting.onload === 'true') { + + } else { + component.setting.sync = 'false' + } + } + // dataName 绯荤粺鐢熸垚鐨勬暟鎹簮鍚嶇О if (component.setting.sync === 'true') { component.dataName = 'mk' + component.uuid.slice(-18) - } - // floor 缁勪欢鐨勫眰绾� - // pageable 鏄惁鍒嗛〉锛岀粍浠跺睘鎬э紝涓嶅垎椤电殑缁勪欢鎵嶅彲浠ョ粺涓�鏌ヨ - if (params && (!component.pageable || (component.pageable && !component.setting.laypage)) && component.setting.onload === 'true' && component.setting.sync === 'true') { - let searchlist = [] - if (component.search && component.search.length > 0) { - searchlist = Utils.initMainSearch(component.search) - } - if (component.setting.useMSearch) { - let keys = searchlist.map(item => item.key) - mainSearch.forEach(item => { - if (!keys.includes(item.key)) { + if (params) { + let searchlist = component.$searches || [] + + if (component.setting.useMSearch) { + let mainSearch = window.GLOB.SearchBox.get(component.$searchId) + let keys = component.$s_keys || [] + mainSearch.forEach(item => { + if (keys.includes(item.key.toLowerCase())) return + searchlist.push(item) - } - }) + }) + } + + if (component.$s_req && searchlist.filter(item => item.required && item.value === '').length > 0) { + component.setting.sync = 'false' + component.setting.onload = 'false' + } else { + params.push(getStructDefaultParam(component, searchlist, params.length === 0)) + } } - - if (searchlist.filter(item => item.required && item.value === '').length > 0) { - component.setting.sync = 'false' - component.setting.onload = 'false' - } else { - params.push(getStructDefaultParam(component, searchlist, params.length === 0)) - } - } else if (params) { - component.setting.sync = 'false' } component.setting.delay = delay @@ -802,12 +834,17 @@ * @description 涓昏〃鏁版嵁鍔犺浇 */ loadmaindata = (params) => { + const { Tab } = this.props const { config } = this.state let param = getStructuredParams(params, config, this.state.BID || '') this.setState({loading: true}) Api.genericInterface(param).then(result => { + this.setState({ + loading: false + }) + if (result.status) { if (result.message) { if (result.ErrCode === 'Y') { @@ -823,30 +860,17 @@ } } - delete result.status - delete result.message - delete result.ErrMesg - delete result.ErrCode - - if (config.$cache) { - params.forEach((item) => { - let _data = result[item.name] || '' - if (_data && !Array.isArray(_data)) { - _data = [_data] - } - Api.writeCacheConfig(item.uuid, _data) - }) - } - - this.setState({ - data: result, - loading: false + params.forEach((item) => { + let _data = result[item.name] || '' + if (_data && !Array.isArray(_data)) { + _data = [_data] + } + window.GLOB.SyncData.set(item.name, _data) }) + + MKEmitter.emit('transferSyncData', Tab.uuid) } else { - this.setState({ - data: '', - loading: false - }) + MKEmitter.emit('transferSyncData', Tab.uuid) if (!result.message) return if (result.ErrCode === 'N') { @@ -895,20 +919,20 @@ }) } else if (item.type === 'group') { this.deleteCache(item.components) + } else if (item.type === 'search') { + window.GLOB.SearchBox.delete(item.$searchId) } else { window.GLOB.CacheData.delete(item.uuid) + } + + if (item.dataName) { + window.GLOB.SyncData.delete(item.dataName) } }) } - resetSearch = (search) => { - this.setState({mainSearch: null}, () => { - this.setState({mainSearch: search}) - }) - } - getComponents = () => { - const { config, BID, data, mainSearch } = this.state + const { config, BID } = this.state if (!config) return @@ -924,19 +948,19 @@ if (item.type === 'card' && item.subtype === 'datacard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <DataCard config={item} data={data} mainSearch={mainSearch}/> + <DataCard config={item}/> </Col> ) } else if (item.type === 'card' && item.subtype === 'propcard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <PropCard config={item} data={data} mainSearch={mainSearch}/> + <PropCard config={item}/> </Col> ) } else if (item.type === 'card' && item.subtype === 'dualdatacard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <DoubleDataCard config={item} mainSearch={mainSearch}/> + <DoubleDataCard config={item}/> </Col> ) } else if (item.type === 'table' && item.subtype === 'basetable') { @@ -948,133 +972,133 @@ } else if (item.type === 'bar' || item.type === 'line') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvBarAndLine config={item} data={data} mainSearch={mainSearch}/> + <AntvBarAndLine config={item}/> </Col> ) } else if (item.type === 'pie') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvPie config={item} data={data} mainSearch={mainSearch}/> + <AntvPie config={item}/> </Col> ) } else if (item.type === 'scatter') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvScatter config={item} data={data} mainSearch={mainSearch}/> + <AntvScatter config={item}/> </Col> ) } else if (item.type === 'dashboard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvDashboard config={item} data={data} mainSearch={mainSearch}/> + <AntvDashboard config={item}/> </Col> ) } else if (item.type === 'form' && item.subtype === 'simpleform') { return ( <Col span={item.width} style={style} key={item.uuid}> - <SimpleForm config={item} data={data} mainSearch={mainSearch}/> + <SimpleForm config={item}/> </Col> ) } else if (item.type === 'form' && item.subtype === 'stepform') { return ( <Col span={item.width} style={style} key={item.uuid}> - <StepForm config={item} data={data} mainSearch={mainSearch}/> + <StepForm config={item}/> </Col> ) } else if (item.type === 'form' && item.subtype === 'tabform') { return ( <Col span={item.width} style={style} key={item.uuid}> - <TabForm config={item} data={data} mainSearch={mainSearch}/> + <TabForm config={item}/> </Col> ) } else if (item.type === 'search') { return ( <Col span={item.width} style={style} key={item.uuid}> - <MainSearch config={item} BID={BID} refreshdata={this.resetSearch} /> + <MainSearch config={item} BID={BID} /> </Col> ) } else if (item.type === 'tabs') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvTabs config={item} mainSearch={mainSearch} /> + <AntvTabs config={item}/> </Col> ) } else if (item.type === 'balcony') { return ( <Col span={item.width} style={style} key={item.uuid}> - <Balcony config={item} data={data}/> + <Balcony config={item}/> </Col> ) } else if (item.type === 'timeline') { return ( <Col span={item.width} style={style} key={item.uuid}> - <TimeLine config={item} data={data} mainSearch={mainSearch}/> + <TimeLine config={item}/> </Col> ) } else if (item.type === 'carousel' && item.subtype === 'datacard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <CarouselDataCard config={item} data={data} mainSearch={mainSearch}/> + <CarouselDataCard config={item}/> </Col> ) } else if (item.type === 'carousel' && item.subtype === 'propcard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <CarouselPropCard config={item} data={data} mainSearch={mainSearch}/> + <CarouselPropCard config={item}/> </Col> ) } else if (item.type === 'card' && item.subtype === 'tablecard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <TableCard config={item} data={data} mainSearch={mainSearch}/> + <TableCard config={item}/> </Col> ) } else if (item.type === 'table' && item.subtype === 'normaltable') { return ( <Col span={item.width} style={style} key={item.uuid}> - <NormalTable config={item} data={data} mainSearch={mainSearch}/> + <NormalTable config={item}/> </Col> ) } else if (item.type === 'table' && item.subtype === 'editable') { return ( <Col span={item.width} style={style} key={item.uuid}> - <EditTable config={item} mainSearch={mainSearch}/> + <EditTable config={item}/> </Col> ) } else if (item.type === 'group' && item.subtype === 'normalgroup') { return ( <Col span={item.width} style={style} key={item.uuid}> - <NormalGroup config={item} mainSearch={mainSearch}/> + <NormalGroup config={item}/> </Col> ) } else if (item.type === 'editor') { return ( <Col span={item.width} style={style} key={item.uuid}> - <BraftEditor config={item} data={data} mainSearch={mainSearch}/> + <BraftEditor config={item}/> </Col> ) } else if (item.type === 'tree') { return ( <Col span={item.width} style={style} key={item.uuid}> - <NormalTree config={item} data={data} mainSearch={mainSearch}/> + <NormalTree config={item}/> </Col> ) } else if (item.type === 'calendar') { return ( <Col span={item.width} style={style} key={item.uuid}> - <Calendar config={item} mainSearch={mainSearch}/> + <Calendar config={item}/> </Col> ) } else if (item.type === 'code') { return ( <Col span={item.width} style={style} key={item.uuid}> - <SandBox config={item} data={data} mainSearch={mainSearch}/> + <SandBox config={item}/> </Col> ) } else if (item.type === 'chart') { return ( <Col span={item.width} style={style} key={item.uuid}> - <CustomChart config={item} data={data} mainSearch={mainSearch}/> + <CustomChart config={item}/> </Col> ) } else if (item.type === 'module' && item.subtype === 'voucher') { @@ -1086,13 +1110,13 @@ } else if (item.type === 'iframe') { return ( <Col span={item.width} style={style} key={item.uuid}> - <Iframe config={item} data={data} mainSearch={mainSearch}/> + <Iframe config={item}/> </Col> ) } else if (item.type === 'antvG6') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvG6 config={item} data={data} mainSearch={mainSearch}/> + <AntvG6 config={item}/> </Col> ) } else if (item.type === 'antvX6') { diff --git a/src/tabviews/subtable/index.jsx b/src/tabviews/subtable/index.jsx index 73c7713..0da04de 100644 --- a/src/tabviews/subtable/index.jsx +++ b/src/tabviews/subtable/index.jsx @@ -57,7 +57,6 @@ statFields: [], // 鍚堣瀛楁 statFValue: [], // 鍚堣鍊� absFields: [], // 缁濆鍊煎瓧娈� - hasReqFields: false, BID: '', BData: '' } @@ -133,14 +132,7 @@ // 鏉冮檺杩囨护 config.action = config.action.filter(item => item.hidden !== 'true') - config.search = Utils.initSearchVal(config.search) - - let hasReqFields = false - config.search.forEach(field => { - if (field.required) { - hasReqFields = true - } - }) + Utils.initSearchVal(config) // 瀛楁鏉冮檺榛戝悕鍗� let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID @@ -304,10 +296,8 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*') - config.setting.dataresource = config.setting.dataresource.replace(/@\$/ig, '*/') - config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*') - config.setting.customScript = config.setting.customScript.replace(/@\$/ig, '*/') + config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/') + config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/') } else { config.setting.dataresource = config.setting.dataresource.replace(/@\$|\$@/ig, '') config.setting.customScript = config.setting.customScript.replace(/@\$|\$@/ig, '') @@ -374,8 +364,7 @@ actions: _actions, columns: _columns, arr_field: _arrField.join(','), - search: Utils.initMainSearch(config.search), - hasReqFields + search: Utils.initMainSearch(config.search) }, () => { if (config.setting.onload !== 'false' && (!Tab.supMenu || this.props.BID || Tab.isTreeNode)) { // 鍒濆鍖栧彲鍔犺浇 this.loadData() @@ -398,14 +387,14 @@ loadData = (id) => { const { mainSearch } = this.props - const { setting, BID, search, hasReqFields } = this.state + const { setting, BID, search, config } = this.state let searches = fromJS(search).toJS() if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 searches = [...mainSearch, ...searches] } - if (hasReqFields) { + if (config.$s_req) { let requireFields = searches.filter(item => item.required && item.value === '') if (requireFields.length > 0) { this.setState({ diff --git a/src/tabviews/subtabtable/index.jsx b/src/tabviews/subtabtable/index.jsx index b491e57..dfaae0f 100644 --- a/src/tabviews/subtabtable/index.jsx +++ b/src/tabviews/subtabtable/index.jsx @@ -50,7 +50,6 @@ statFields: [], // 鍚堣瀛楁 statFValue: [], // 鍚堣鍊� absFields: [], // 缁濆鍊煎瓧娈� - hasReqFields: false } /** @@ -126,14 +125,7 @@ // 鏉冮檺杩囨护 config.action = config.action.filter(item => item.hidden !== 'true') - config.search = Utils.initSearchVal(config.search) - - let hasReqFields = false - config.search.forEach(field => { - if (field.required) { - hasReqFields = true - } - }) + Utils.initSearchVal(config) // 瀛楁鏉冮檺榛戝悕鍗� let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID @@ -259,10 +251,8 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*') - config.setting.dataresource = config.setting.dataresource.replace(/@\$/ig, '*/') - config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*') - config.setting.customScript = config.setting.customScript.replace(/@\$/ig, '*/') + config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/') + config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/') } else { config.setting.dataresource = config.setting.dataresource.replace(/@\$|\$@/ig, '') config.setting.customScript = config.setting.customScript.replace(/@\$|\$@/ig, '') @@ -327,7 +317,6 @@ columns: _columns, arr_field: _arrField.join(','), search: Utils.initMainSearch(config.search), // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 - hasReqFields }, () => { if (config.setting.onload !== 'false') { // 鍒濆鍖栧彲鍔犺浇 this.loadData() @@ -347,11 +336,11 @@ } loadData = (id) => { - const { setting, search, hasReqFields } = this.state + const { setting, search, config } = this.state let searches = fromJS(search).toJS() - if (hasReqFields) { + if (config.$s_req) { let requireFields = searches.filter(item => item.required && item.value === '') if (requireFields.length > 0) { this.setState({ diff --git a/src/tabviews/treepage/index.jsx b/src/tabviews/treepage/index.jsx index 29bc25e..cbe188e 100644 --- a/src/tabviews/treepage/index.jsx +++ b/src/tabviews/treepage/index.jsx @@ -171,10 +171,8 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*') - config.setting.dataresource = config.setting.dataresource.replace(/@\$/ig, '*/') - config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*') - config.setting.customScript = config.setting.customScript.replace(/@\$/ig, '*/') + config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/') + config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/') } else { config.setting.dataresource = config.setting.dataresource.replace(/@\$|\$@/ig, '') config.setting.customScript = config.setting.customScript.replace(/@\$|\$@/ig, '') diff --git a/src/tabviews/zshare/actionList/asyncButtonComponent.jsx b/src/tabviews/zshare/actionList/asyncButtonComponent.jsx index 008bedb..1265253 100644 --- a/src/tabviews/zshare/actionList/asyncButtonComponent.jsx +++ b/src/tabviews/zshare/actionList/asyncButtonComponent.jsx @@ -41,7 +41,7 @@ return C ? <C {...this.props} /> : - <Button className={'mk-btn mk-' + btn.class} style={style} icon={btn.icon} disabled={true} >{btn.label}</Button> + <Button className={'mk-btn mk-' + btn.class} style={style} disabled={true} >{btn.label}</Button> } } } \ No newline at end of file diff --git a/src/tabviews/zshare/actionList/excelInbutton/index.jsx b/src/tabviews/zshare/actionList/excelInbutton/index.jsx index b819615..8227172 100644 --- a/src/tabviews/zshare/actionList/excelInbutton/index.jsx +++ b/src/tabviews/zshare/actionList/excelInbutton/index.jsx @@ -339,13 +339,11 @@ param.func = 'sPC_TableData_InUpDe' if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - result.sql = result.sql.replace(/\$@/ig, '/*') - result.sql = result.sql.replace(/@\$/ig, '*/') - result.bottom = result.bottom.replace(/\$@/ig, '/*') - result.bottom = result.bottom.replace(/@\$/ig, '*/') + result.sql = result.sql.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') + result.bottom = result.bottom.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - result.sql = result.sql.replace(/@\$|\$@/ig, '') - result.bottom = result.bottom.replace(/@\$|\$@/ig, '') + result.sql = result.sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') + result.bottom = result.bottom.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } param.excel_in_type = 'true' diff --git a/src/tabviews/zshare/actionList/exceloutbutton/index.jsx b/src/tabviews/zshare/actionList/exceloutbutton/index.jsx index de6b554..c24ba02 100644 --- a/src/tabviews/zshare/actionList/exceloutbutton/index.jsx +++ b/src/tabviews/zshare/actionList/exceloutbutton/index.jsx @@ -612,7 +612,7 @@ } if (col.round) { val = Math.round(val * col.round) / col.round - val = +val.toFixed(col.decimal) + // val = val.toFixed(col.decimal) } } @@ -701,7 +701,7 @@ } if (col.round) { val = Math.round(val * col.round) / col.round - val = +val.toFixed(col.decimal) + // val = val.toFixed(col.decimal) } } @@ -826,10 +826,9 @@ let script = btn.verify.script if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - script = script.replace(/\$@/ig, '/*') - script = script.replace(/@\$/ig, '*/') + script = script.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - script = script.replace(/@\$|\$@/ig, '') + script = script.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } let allSearch = Utils.getAllSearchOptions(search) @@ -945,13 +944,11 @@ }) if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - _dataresource = _dataresource.replace(/\$@/ig, '/*') - _dataresource = _dataresource.replace(/@\$/ig, '*/') - customScript = customScript.replace(/\$@/ig, '/*') - customScript = customScript.replace(/@\$/ig, '*/') + _dataresource = _dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') + customScript = customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - _dataresource = _dataresource.replace(/@\$|\$@/ig, '') - customScript = customScript.replace(/@\$|\$@/ig, '') + _dataresource = _dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') + customScript = customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } } diff --git a/src/tabviews/zshare/actionList/normalbutton/index.jsx b/src/tabviews/zshare/actionList/normalbutton/index.jsx index 3d474fb..fad39e6 100644 --- a/src/tabviews/zshare/actionList/normalbutton/index.jsx +++ b/src/tabviews/zshare/actionList/normalbutton/index.jsx @@ -464,10 +464,9 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - param.LText = param.LText.replace(/\$@/ig, '/*') - param.LText = param.LText.replace(/@\$/ig, '*/') + param.LText = param.LText.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - param.LText = param.LText.replace(/@\$|\$@/ig, '') + param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } param.exec_type = 'y' // 鍚庡彴瑙g爜 @@ -507,10 +506,9 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - param.LText = param.LText.replace(/\$@/ig, '/*') - param.LText = param.LText.replace(/@\$/ig, '*/') + param.LText = param.LText.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - param.LText = param.LText.replace(/@\$|\$@/ig, '') + param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } param.exec_type = 'y' // 鍚庡彴瑙g爜 @@ -540,10 +538,9 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - param.LText = param.LText.replace(/\$@/ig, '/*') - param.LText = param.LText.replace(/@\$/ig, '*/') + param.LText = param.LText.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - param.LText = param.LText.replace(/@\$|\$@/ig, '') + param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } param.exec_type = 'y' // 鍚庡彴瑙g爜 @@ -613,10 +610,9 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - param.LText = param.LText.replace(/\$@/ig, '/*') - param.LText = param.LText.replace(/@\$/ig, '*/') + param.LText = param.LText.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - param.LText = param.LText.replace(/@\$|\$@/ig, '') + param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } param.exec_type = 'y' // 鍚庡彴瑙g爜 @@ -660,10 +656,9 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - param.LText = param.LText.replace(/\$@/ig, '/*') - param.LText = param.LText.replace(/@\$/ig, '*/') + param.LText = param.LText.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - param.LText = param.LText.replace(/@\$|\$@/ig, '') + param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } param.exec_type = 'y' // 鍚庡彴瑙g爜 @@ -693,10 +688,9 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - param.LText = param.LText.replace(/\$@/ig, '/*') - param.LText = param.LText.replace(/@\$/ig, '*/') + param.LText = param.LText.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - param.LText = param.LText.replace(/@\$|\$@/ig, '') + param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } param.exec_type = 'y' // 鍚庡彴瑙g爜 @@ -1624,10 +1618,9 @@ param.LText = sql if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - param.LText = param.LText.replace(/\$@/ig, '/*') - param.LText = param.LText.replace(/@\$/ig, '*/') + param.LText = param.LText.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - param.LText = param.LText.replace(/@\$|\$@/ig, '') + param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } param.LText = param.LText.replace(/\$check@|@check\$/ig, '') @@ -2914,7 +2907,6 @@ > <MutilForm BID={BID} - dict={this.state.dict} action={btnconfig} inputSubmit={this.handleOk} data={this.state.selines[0]} @@ -2955,7 +2947,6 @@ > <MutilForm BID={BID} - dict={this.state.dict} action={btnconfig} inputSubmit={this.handleOk} data={this.state.selines[0]} diff --git a/src/tabviews/zshare/actionList/printbutton/index.jsx b/src/tabviews/zshare/actionList/printbutton/index.jsx index 850c3d3..53e51e0 100644 --- a/src/tabviews/zshare/actionList/printbutton/index.jsx +++ b/src/tabviews/zshare/actionList/printbutton/index.jsx @@ -1003,10 +1003,8 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - _dataresource = _dataresource.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'') - _dataresource = _dataresource.replace(/@\$/ig, '*/') - _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'') - _customScript = _customScript.replace(/@\$/ig, '*/') + _dataresource = _dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') + _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { _dataresource = _dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') @@ -2272,7 +2270,6 @@ > <MutilForm BID={BID} - dict={this.state.dict} action={btnconfig} inputSubmit={this.handleOk} data={this.state.selines[0]} diff --git a/src/tabviews/zshare/mutilform/index.jsx b/src/tabviews/zshare/mutilform/index.jsx index e04d23a..337129f 100644 --- a/src/tabviews/zshare/mutilform/index.jsx +++ b/src/tabviews/zshare/mutilform/index.jsx @@ -31,7 +31,7 @@ const MkVercode = asyncComponent(() => import('./mkVercode')) const MKEditor = asyncComponent(() => import('@/components/editor')) -class MainSearch extends Component { +class MutilFormComponent extends Component { static propTpyes = { action: PropTypes.object, // 鎸夐挳淇℃伅銆佽〃鍗曞垪琛� data: PropTypes.any, // 琛ㄦ牸鏁版嵁 @@ -1228,4 +1228,4 @@ } } -export default Form.create()(MainSearch) \ No newline at end of file +export default Form.create()(MutilFormComponent) \ No newline at end of file diff --git a/src/tabviews/zshare/topSearch/index.jsx b/src/tabviews/zshare/topSearch/index.jsx index a92e5cb..77ce4ca 100644 --- a/src/tabviews/zshare/topSearch/index.jsx +++ b/src/tabviews/zshare/topSearch/index.jsx @@ -11,6 +11,7 @@ import asyncComponent from '@/utils/asyncComponent' import asyncSpinComponent from '@/utils/asyncSpinComponent' import Utils from '@/utils/utils.js' +import MKEmitter from '@/utils/events.js' import MKInput from './mkInput' import './index.scss' @@ -25,8 +26,7 @@ class MainSearch extends Component { static propTpyes = { BID: PropTypes.any, // 鐖剁骇Id锛岀敤浜庢煡璇笅鎷夐�夋嫨椤� - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅(鑷畾涔夐〉闈�) - refreshdata: PropTypes.func // 鍒锋柊鏁版嵁 + config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 } state = { @@ -51,8 +51,6 @@ let advanceValues = [] let linkFields = {} let record = {} - let hasReqFields = false - let forbid = false // header涓笉璁剧疆楂樼骇鎼滅储 let _setting = {showAdv: false, show: false, style: null} @@ -112,10 +110,6 @@ if (fieldMap.has(item.field)) { item.field = item.field + '@tail@' - } - - if (item.required) { - hasReqFields = true } if (item.advanced && !forbid) { @@ -221,7 +215,7 @@ this.setState({ setting: _setting, - hasReqFields, + hasReqFields: config.$s_req, advanceValues, searchlist: _list }, () => { @@ -691,7 +685,12 @@ this.sign = '' }, 2000) - this.props.refreshdata(searches) + if (this.props.refreshdata) { + this.props.refreshdata(searches) + } else { + window.GLOB.SearchBox.set(this.props.config.$searchId, searches) + MKEmitter.emit('searchRefresh', this.props.config.$searchId) + } }) }) } diff --git a/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx b/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx index 837dd40..c3e8a56 100644 --- a/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx +++ b/src/templates/sharecomponent/actioncomponent/verifyexcelin/customscript/index.jsx @@ -215,7 +215,7 @@ } param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') - param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/\$check@|@check\$/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|typename)@/ig, `'${param.timestamp}'`) + param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/\$check@|@check\$/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'${param.timestamp}'`) param.LText = param.LText.replace(/\n/g, ' ') // 澶栬仈鏁版嵁搴撴浛鎹� diff --git a/src/templates/sharecomponent/actioncomponent/verifyexcelout/index.jsx b/src/templates/sharecomponent/actioncomponent/verifyexcelout/index.jsx index 86d94de..8e04fc0 100644 --- a/src/templates/sharecomponent/actioncomponent/verifyexcelout/index.jsx +++ b/src/templates/sharecomponent/actioncomponent/verifyexcelout/index.jsx @@ -731,7 +731,7 @@ } param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') - param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id)@/ig, `'${param.timestamp}'`) + param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam)@/ig, `'${param.timestamp}'`) param.LText = param.LText.replace(/\n/g, ' ') param.LText = Utils.formatOptions(param.LText) diff --git a/src/templates/sharecomponent/actioncomponent/verifyexcelout/utils.jsx b/src/templates/sharecomponent/actioncomponent/verifyexcelout/utils.jsx index 6e71f40..bd4d39b 100644 --- a/src/templates/sharecomponent/actioncomponent/verifyexcelout/utils.jsx +++ b/src/templates/sharecomponent/actioncomponent/verifyexcelout/utils.jsx @@ -45,8 +45,8 @@ _dataresource = '' } - _dataresource = _dataresource.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|typename)@/ig, `'${timestamp}'`) - _customScript = _customScript.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|typename)@/ig, `'${timestamp}'`) + _dataresource = _dataresource.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'${timestamp}'`) + _customScript = _customScript.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'${timestamp}'`) _dataresource = _dataresource.replace(/@\$|\$@/ig, '') _customScript = _customScript.replace(/@\$|\$@/ig, '') diff --git a/src/templates/sharecomponent/actioncomponent/verifyprint/utils.jsx b/src/templates/sharecomponent/actioncomponent/verifyprint/utils.jsx index 19c1db3..3d26d40 100644 --- a/src/templates/sharecomponent/actioncomponent/verifyprint/utils.jsx +++ b/src/templates/sharecomponent/actioncomponent/verifyprint/utils.jsx @@ -23,8 +23,8 @@ _dataresource = '' } - _dataresource = _dataresource.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|typename)@/ig, `'${timestamp}'`) - _customScript = _customScript.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|typename)@/ig, `'${timestamp}'`) + _dataresource = _dataresource.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'${timestamp}'`) + _customScript = _customScript.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'${timestamp}'`) _dataresource = _dataresource.replace(/@\$|\$@/ig, '') _customScript = _customScript.replace(/@\$|\$@/ig, '') diff --git a/src/templates/zshare/verifycard/customscript/index.jsx b/src/templates/zshare/verifycard/customscript/index.jsx index fd2f022..8e7181a 100644 --- a/src/templates/zshare/verifycard/customscript/index.jsx +++ b/src/templates/zshare/verifycard/customscript/index.jsx @@ -195,7 +195,7 @@ } param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') - param.LText = param.LText.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|typename)@/ig, `'${param.timestamp}'`) + param.LText = param.LText.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'${param.timestamp}'`) console.info(`/* sql 楠岃瘉 */\n${param.LText.replace(/\n\s{6,20}/ig, '\n')}`) diff --git a/src/utils/utils.js b/src/utils/utils.js index c62e490..bd37d3d 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -292,12 +292,17 @@ * @description 鍒濆鍖栨悳绱㈡潯浠跺垵濮嬪�� * @param {Array} searches 鎼滅储鏉′欢 */ - static initSearchVal (searches) { - if (!searches) return [] + static initSearchVal (config) { + if (!config.search) { + config.search = [] + return + } let roleId = sessionStorage.getItem('role_id') || '' + let required = false + let keys = [] - return searches.map(item => { + config.search = config.search.map(item => { item.hidden = item.Hide === 'true' item.required = !item.hidden && item.required === 'true' item.advanced = item.advanced === 'true' @@ -413,8 +418,28 @@ } } + if (item.required) { + required = true + } + + if (item.type === 'text' || item.type === 'select') { + if (/,/.test(item.field)) { + item.field.split(',').forEach(field => { + keys.push(field.toLowerCase()) + }) + } else { + keys.push(item.field.toLowerCase()) + } + } else if (item.type === 'group') { + keys.push(item.field.toLowerCase()) + keys.push(item.datefield.toLowerCase()) + } + return item }) + + config.$s_keys = keys + config.$s_req = required } /** @@ -835,10 +860,9 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - sql = sql.replace(/\$@/ig, '/*') - sql = sql.replace(/@\$/ig, '*/') + sql = sql.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - sql = sql.replace(/@\$|\$@/ig, '') + sql = sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } // 澶栬仈鏁版嵁搴撴浛鎹� diff --git a/src/views/billprint/index.jsx b/src/views/billprint/index.jsx index 3e8f53f..a52fd05 100644 --- a/src/views/billprint/index.jsx +++ b/src/views/billprint/index.jsx @@ -315,7 +315,10 @@ config.components = config.components.map(component => { if (component.action) component.action = [] - if (component.search) component.search = [] + if (component.search) { + component.search = [] + component.$searches = [] + } component.data = [] // 鍒濆鍖栨暟鎹负绌� if (component.subtype === 'tablecard') { // 鍏煎 @@ -429,13 +432,11 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*') - component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/') - _customScript = _customScript.replace(/\$@/ig, '/*') - _customScript = _customScript.replace(/@\$/ig, '*/') + component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') + _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'') } else { - component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '') - _customScript = _customScript.replace(/@\$|\$@/ig, '') + component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') + _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'') } regs.forEach(cell => { @@ -533,11 +534,6 @@ setTimeout(() => { this.getMenuParam() }, 50) - // Api.getAppVersion(tempId).then(() => { - // this.getMenuParam() - // }, () => { - // this.getMenuParam() - // }) }) } @@ -684,6 +680,13 @@ this.setState({loadingview: false, pages}) } + let setData = (item) => { + if (item.setting && item.setting.sync === 'true' && item.data) { + item.dataName = Utils.getuuid() + window.GLOB.SyncData.set(item.dataName, item.data) + } + } + while (!over) { let page = [] let count = 0 @@ -698,6 +701,7 @@ } if (item.wrap && item.wrap.printType === 'headerOrfooter') { // 椤电湁椤佃剼 + setData(item) page.push(item) } else if (_pageover) { return @@ -711,10 +715,12 @@ } if (count <= limit) { _item.added = true + setData(item) page.push(item) } } else if (!item.added) { _item.added = true + setData(item) page.push(item) } } else { @@ -732,11 +738,13 @@ } + setData(item) page.push(item) } _item.added = true } else if (!item.added) { _item.added = true + setData(item) page.push(item) } } else if (!item.added && item.wrap && item.wrap.printHeight) { @@ -751,10 +759,12 @@ } if (count <= limit) { _item.added = true + setData(item) page.push(item) } } else if (!item.added) { _item.added = true + setData(item) page.push(item) } @@ -883,85 +893,85 @@ if (item.type === 'bar' || item.type === 'line') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvBarAndLine config={item} initdata={item.data} mainSearch={[]} /> + <AntvBarAndLine config={item}/> </Col> ) } else if (item.type === 'pie') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvPie config={item} initdata={item.data} mainSearch={[]} /> + <AntvPie config={item} /> </Col> ) } else if (item.type === 'scatter') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvScatter config={item} initdata={item.data} mainSearch={[]}/> + <AntvScatter config={item}/> </Col> ) } else if (item.type === 'dashboard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvDashboard config={item} initdata={item.data} mainSearch={[]}/> + <AntvDashboard config={item}/> </Col> ) } else if (item.type === 'card' && item.subtype === 'datacard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <DataCard config={item} initdata={item.data} mainSearch={[]} /> + <DataCard config={item} /> </Col> ) } else if (item.type === 'card' && item.subtype === 'propcard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <PropCard config={item} initdata={item.data} mainSearch={[]} /> + <PropCard config={item} /> </Col> ) } else if (item.type === 'card' && item.subtype === 'dualdatacard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <DoubleDataCard config={item} mainSearch={[]}/> + <DoubleDataCard config={item}/> </Col> ) } else if (item.type === 'card' && item.subtype === 'tablecard') { return ( <Col span={item.width} style={style} key={item.uuid}> - <TableCard config={item} initdata={item.data} mainSearch={[]}/> + <TableCard config={item}/> </Col> ) } else if (item.type === 'table' && item.subtype === 'normaltable') { return ( <Col span={item.width} style={style} key={item.uuid}> - <NormalTable config={item} initdata={item.data} mainSearch={[]}/> + <NormalTable config={item}/> </Col> ) } else if (item.type === 'code') { return ( <Col span={item.width} style={style} key={item.uuid}> - <SandBox config={item} initdata={item.data} mainSearch={[]}/> + <SandBox config={item}/> </Col> ) } else if (item.type === 'balcony') { return ( <Col span={item.width} style={style} key={item.uuid}> - <Balcony config={item} initdata={item.data}/> + <Balcony config={item}/> </Col> ) } else if (item.type === 'timeline') { return ( <Col span={item.width} style={style} key={item.uuid}> - <TimeLine config={item} initdata={item.data} mainSearch={[]}/> + <TimeLine config={item}/> </Col> ) } else if (item.type === 'editor') { return ( <Col span={item.width} style={style} key={item.uuid}> - <BraftEditor config={item} initdata={item.data} mainSearch={[]}/> + <BraftEditor config={item}/> </Col> ) } else if (item.type === 'antvG6') { return ( <Col span={item.width} style={style} key={item.uuid}> - <AntvG6 config={item} initdata={item.data} mainSearch={[]}/> + <AntvG6 config={item}/> </Col> ) } else if (item.type === 'antvX6') { -- Gitblit v1.8.0