From f3d4db769ba9b51b799d981511a710fd443d0e08 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 21 四月 2025 12:18:03 +0800 Subject: [PATCH] Merge branch 'master' into positec --- src/tabviews/custom/components/calendar/index.jsx | 175 ++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 96 insertions(+), 79 deletions(-) diff --git a/src/tabviews/custom/components/calendar/index.jsx b/src/tabviews/custom/components/calendar/index.jsx index 628bfeb..4c62b47 100644 --- a/src/tabviews/custom/components/calendar/index.jsx +++ b/src/tabviews/custom/components/calendar/index.jsx @@ -1,10 +1,9 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Spin, notification, Modal } from 'antd' +import { Spin } 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 = { @@ -47,6 +45,8 @@ BData = window.GLOB.CacheData.get(_config.$pageId) } + let BID = BData ? (BData.$BID || '') : '' + if (_config.setting.interType === 'system') { if (/@mk_year@/ig.test(_config.setting.dataresource) || /@mk_year@/ig.test(_config.setting.customScript)) { _config.setting.$re_year = true @@ -65,18 +65,15 @@ _config.action = [] } + if (_config.setting.supModule && !BID) { + _config.setting.onload = 'false' + } + this.setState({ - BID: BData ? (BData.$BID || '') : '', + BID: BID, BData: BData, config: _config, - arr_field: _config.columns.map(col => col.field).join(','), - search: Utils.initMainSearch(_config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 - }, () => { - if (_config.setting.onload === 'true') { - setTimeout(() => { - this.loadData() - }, _config.setting.delay || 0) - } + search: _config.$searches }) } @@ -87,25 +84,11 @@ MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) - if (config.$cache && !this.loaded) { - Api.getLCacheConfig(config.uuid).then(res => { - if (!res || this.loaded) return - - let data = [] - res.forEach((item, index) => { - item.key = index - item.$$uuid = item[config.setting.primaryKey] || '' - - let pass = this.resetLine(item) - - if (pass) { - data.push(item) - } - }) - - this.setState({data: data}) - }) + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) } + + this.initExec() } shouldComponentUpdate (nextProps, nextState) { @@ -117,21 +100,79 @@ 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) { + initExec = () => { + const { config, BID } = this.state + + if (config.$cache) { + if (config.$time) { + Api.getLCacheConfig(config.uuid, config.$time, BID).then(res => { + if (!res.valid && config.setting.onload === 'true') { + setTimeout(() => { + this.loadData('init') + }, config.setting.delay || 0) + } + + if (!res.data) return + + let _data = [] + res.data.forEach((item, index) => { + item.key = index + item.$$uuid = item[config.setting.primaryKey] || '' + + let pass = this.resetLine(item) + + if (pass) { + _data.push(item) + } + }) + + this.setState({data: _data}) + }) + } else { + Api.getLCacheConfig(config.uuid, 0, BID).then(res => { + if (!res.data || this.loaded) return + + let _data = [] + res.data.forEach((item, index) => { + item.key = index + item.$$uuid = item[config.setting.primaryKey] || '' + + let pass = this.resetLine(item) + + if (pass) { + _data.push(item) + } + }) + + this.setState({data: _data}) + }) + + if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData('init') + }, config.setting.delay || 0) + } + } + } else if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData() + }, config.setting.delay || 0) + } + } + + 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() + }) } /** @@ -145,8 +186,8 @@ if (config.uuid !== menuId) return - if (position === 'mainline' && config.setting.supModule && BID) { // 鍒锋柊婧愮粍浠舵椂锛岄檮甯﹀埛鏂颁笂绾ц涓庡綋鍓嶇粍浠� - MKEmitter.emit('reloadData', config.setting.supModule, BID) + if (['mainline', 'maingrid', 'popclose'].includes(position) && config.setting.supModule) { + MKEmitter.emit('reloadData', config.setting.supModule, position === 'maingrid' ? '' : BID) } else { this.loadData() } @@ -171,9 +212,8 @@ this.loadData() } - async loadData () { - const { mainSearch } = this.props - const { config, arr_field, BID, search, year } = this.state + async loadData (type) { + const { config, BID, search, year } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� this.setState({ @@ -184,17 +224,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 } @@ -203,13 +243,13 @@ }) let _orderBy = config.setting.order || '' - let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 99999, BID, '', year) + let param = UtilsDM.getQueryDataParams(config.setting, searches, _orderBy, 1, 99999, BID, '', year) let result = await Api.genericInterface(param) if (result.status) { this.loaded = true - if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + if (config.$cache && type === 'init') { + Api.writeCacheConfig(config.uuid, result.data || [], BID) } let data = [] @@ -230,36 +270,13 @@ loading: false }) - 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 - }) - } - } + UtilsDM.querySuccess(result) } else { this.setState({ loading: false }) - 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 - }) - } + UtilsDM.queryFail(result) } } -- Gitblit v1.8.0