From 8a6ce370f1aa1c061b76fa3e9d2d4d1df53ca4c5 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 21 五月 2024 16:38:09 +0800 Subject: [PATCH] Merge branch 'master' into positec --- src/tabviews/custom/components/table/base-table/index.jsx | 275 ++++++++++++++++++++++++++++++++---------------------- 1 files changed, 163 insertions(+), 112 deletions(-) diff --git a/src/tabviews/custom/components/table/base-table/index.jsx b/src/tabviews/custom/components/table/base-table/index.jsx index 9d3b50f..bc2b635 100644 --- a/src/tabviews/custom/components/table/base-table/index.jsx +++ b/src/tabviews/custom/components/table/base-table/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { notification, Modal } from 'antd' +import { notification } from 'antd' import Api from '@/api' import UtilsDM from '@/utils/utils-datamanage.js' @@ -25,7 +25,6 @@ config: {}, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑 actions: null, // 鎸夐挳闆� columns: null, // 鏄剧ず鍒� - arr_field: '', // 鏌ヨ瀛楁闆� setting: null, // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑 data: [], // 鍒楄〃鏁版嵁闆� selectedData: [], // 宸查�夎〃鏍兼暟鎹� @@ -82,7 +81,6 @@ setting: setting, actions: _config.action, columns: _config.cols, - arr_field: _config.columns.map(col => col.field).join(','), search: _config.$searches }, () => { if (_config.setting.onload === 'true') { @@ -100,12 +98,13 @@ * @param { String } repage 琛ㄦ牸鏄惁閲嶇疆椤电爜 */ async loadmaindata (reset, repage, id) { - const { setting, config, arr_field, search, orderBy, BID, pageIndex, pageSize, BData } = this.state + const { setting, config, search, orderBy, BID, pageIndex, pageSize, BData } = this.state if (setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� this.setState({ data: [], selectedData: [], + loading: false, total: 0 }) @@ -114,6 +113,8 @@ if (setting.$hasSyncModule) { MKEmitter.emit('syncBalconyData', config.uuid, [], false) } + + this.requestId = '' return } @@ -137,10 +138,15 @@ }) let _orderBy = orderBy || setting.order - let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID) + let param = UtilsDM.getQueryDataParams(setting, searches, _orderBy, pageIndex, pageSize, BID) - let result = await Api.genericInterface(param) + this.requestId = config.uuid + new Date().getTime() + + let result = await Api.genericInterface(param, setting.js_script, '', this.requestId) + if (result.status) { + if (result.$requestId && this.requestId !== result.$requestId) return + if (repage === 'false' && result.data && result.data.length === 0 && result.total > 0 && pageIndex > 1) { let _pageIndex = Math.ceil(result.total / pageSize) @@ -179,32 +185,39 @@ start = pageSize * (pageIndex - 1) + 1 } - this.setState({ - data: result.data.map((item, index) => { - item.key = index - item.$$uuid = item[setting.primaryKey] || '' - item.$$key = '' + item.key + item.$$uuid - item.$$BID = BID || '' - item.$$BData = BData || '' - item.$Index = start + index + '' + let data = result.data.map((item, index) => { + item.key = index + item.$$uuid = item[setting.primaryKey] || '' + item.$$key = '' + item.key + item.$$uuid + item.$$BID = BID || '' + item.$$BData = BData || '' + item.$Index = start + index + '' - 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 + 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 - }), + } + + return item + }) + + let total = result.total || 0 + if (config.setting.custompage && data.length) { + total = data[data.length - 1].mk_total || 0 + } + + this.setState({ + data: data, selectedData: [], - total: result.total, + total: total, loading: false }) @@ -216,19 +229,7 @@ } } - 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 @@ -238,26 +239,20 @@ MKEmitter.emit('autoMaticError', config.MenuID) } - 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) } } /** * @description 鑾峰彇鍗曡鏁版嵁 */ - async loadmainLinedata (id) { - const { setting, config, arr_field, search, orderBy, BID, pageIndex, pageSize, BData } = this.state + async loadLinedata (id, position) { + const { setting, config, search, orderBy, BID, pageIndex, pageSize, BData } = this.state + + if (config.forbidLine) { + this.reloadtable() + return + } let searches = fromJS(search).toJS() if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 @@ -275,12 +270,18 @@ }) let _orderBy = orderBy || setting.order - let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, id) + let param = UtilsDM.getQueryDataParams(setting, searches, _orderBy, pageIndex, pageSize, BID, id) let result = await Api.genericInterface(param) if (result.status) { + if (position === 'line_grid' && (!result.data || !result.data[0])) { + this.loadmaindata(true, 'false') + return + } + let data = fromJS(this.state.data).toJS() let selectedData = fromJS(this.state.selectedData).toJS() + if (result.data && result.data[0]) { let _data = result.data[0] || {} _data.$$uuid = _data[setting.primaryKey] || '' @@ -295,44 +296,73 @@ }) } - try { - data = data.map(item => { - if (item.$$uuid === _data.$$uuid) { - _data.key = item.key - _data.$$key = '' + item.key + item.$$uuid - _data.$Index = item.$Index - return _data - } else { - return item - } - }) - selectedData = selectedData.map(item => { - if (_data.$$uuid === item.$$uuid) { - return _data - } + data = data.map(item => { + if (item.$$uuid === _data.$$uuid) { + _data.key = item.key + _data.$$key = '' + item.key + item.$$uuid + _data.$Index = item.$Index + return _data + } else { return item + } + }) + + if (!_data.$Index) { + this.setState({ + loading: false }) - } catch (e) { - console.warn('鏁版嵁鏌ヨ閿欒') + return } - MKEmitter.emit('resetSelectLine', config.uuid, _data.$$uuid || '', _data) - } + selectedData = selectedData.map(item => { + if (_data.$$uuid === item.$$uuid) { + return _data + } + return item + }) - this.setState({ - data, - selectedData, - loading: false - }) + if (selectedData.length && _data.$$uuid === selectedData[selectedData.length - 1].$$uuid) { + MKEmitter.emit('resetSelectLine', config.uuid, _data.$$uuid || '', _data) + } + + this.setState({ + data, + selectedData, + loading: false + }) + } else { + let index = data.findIndex(item => item.$$uuid === id) + + if (index === -1) { + this.setState({ + loading: false + }) + return + } + + data = data.filter(item => item.$$uuid !== id) + data = data.map((item, i) => { + item.key = i + item.$$key = '' + item.key + item.$$uuid + + return item + }) + + this.setState({ + data: data, + loading: false + }) + + setTimeout(() => { + MKEmitter.emit('resetTable', config.uuid, 'delete', index) + }, 20) + } } else { this.setState({ loading: false }) - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) + + UtilsDM.queryFail(result) } } @@ -342,6 +372,8 @@ getStatFieldsValue = () => { const { setting, config, search, BID, orderBy } = this.state + if (!config.statFields) return + if (setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� this.setState({ statFValue: [] @@ -473,7 +505,7 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, callback) => { - const { arr_field, config, orderBy, search, setting} = this.state + const { config, orderBy, search, setting } = this.state if (config.uuid !== menuId) return @@ -489,10 +521,8 @@ } callback({ - arr_field: arr_field, orderBy: orderBy || setting.order, - search: searches, - menuName: config.name + search: searches }) } @@ -504,7 +534,7 @@ if (!id) { this.reloadtable() } else { - this.loadmainLinedata(id) + this.loadLinedata(id) } } @@ -518,8 +548,10 @@ BID: id, BData: data }, () => { - this.loadmaindata(true, 'true') - this.getStatFieldsValue() + if (!setting.checkBid) { + this.loadmaindata(true, 'true') + this.getStatFieldsValue() + } }) } } @@ -535,14 +567,14 @@ if (config.uuid !== menuId) return - if (position === 'line') { + if (position === 'line' || position === 'line_grid') { if (lines && lines.length === 1) { - this.loadmainLinedata(lines[0].$$uuid) + this.loadLinedata(lines[0].$$uuid, position) } else { this.reloadtable(btn, id) } - } else if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 鍒锋柊婧愮粍浠舵椂锛岄檮甯﹀埛鏂颁笂绾ц涓庡綋鍓嶇粍浠� - MKEmitter.emit('reloadData', config.setting.supModule, BID) + } else if (['mainline', 'maingrid', 'popclose'].includes(position) && config.setting.supModule) { + MKEmitter.emit('reloadData', config.setting.supModule, position === 'maingrid' ? '' : BID) } else { this.reloadtable(btn, id) } @@ -556,6 +588,25 @@ this.setState({pageIndex: 1}, () => { this.reloadtable() }) + } + + autoExec = (times) => { + const { config } = this.state + + if (!config.wrap.autoExec) return + + let btn = document.getElementById('button' + config.wrap.autoExec) + + this.autoTimer && clearTimeout(this.autoTimer) + + if (btn) { + MKEmitter.emit('triggerBtnId', config.wrap.autoExec, []) + } else if (!times || times < 20) { + times = times ? times + 1 : 1 + this.autoTimer = setTimeout(() => { + this.autoExec(times) + }, 1000) + } } shouldComponentUpdate (nextProps, nextState) { @@ -573,6 +624,8 @@ if (config.setting.useMSearch) { MKEmitter.addListener('searchRefresh', this.searchRefresh) } + + this.autoExec() } /** @@ -605,22 +658,20 @@ columns={config.columns} selectedData={selectedData} /> : <div style={{height: '25px'}}></div>} - <div className="main-table-box"> - <MainTable - data={data} - setting={setting} - columns={columns} - MenuID={config.uuid} - fields={config.columns} - total={this.state.total} - autoMatic={config.autoMatic} - lineMarks={config.lineMarks} - loading={this.state.loading} - refreshdata={this.refreshbytable} - statFValue={this.state.statFValue} - chgSelectData={(selects) => this.setState({selectedData: selects})} - /> - </div> + <MainTable + data={data} + setting={setting} + columns={columns} + MenuID={config.uuid} + fields={config.columns} + total={this.state.total} + autoMatic={config.autoMatic} + lineMarks={config.lineMarks} + loading={this.state.loading} + refreshdata={this.refreshbytable} + statFValue={this.state.statFValue} + chgSelectData={(selects) => this.setState({selectedData: selects})} + /> </div> ) } -- Gitblit v1.8.0