From 3c6862fdfc6af3ae176436d2e22f1b7f8bcc8479 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 07 六月 2023 17:55:07 +0800 Subject: [PATCH] 2023-06-07 --- src/tabviews/custom/components/table/base-table/index.jsx | 138 ++++++++++++++++++++++++++------------------- 1 files changed, 79 insertions(+), 59 deletions(-) diff --git a/src/tabviews/custom/components/table/base-table/index.jsx b/src/tabviews/custom/components/table/base-table/index.jsx index 58a66c5..9658a04 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 } from 'antd' +import { notification, Modal } from 'antd' import Api from '@/api' import Utils from '@/utils/utils.js' @@ -46,7 +46,6 @@ */ UNSAFE_componentWillMount () { let _config = fromJS(this.props.config).toJS() - let _cols = new Map() let BID = '' let BData = '' @@ -70,22 +69,11 @@ let setting = {..._config.setting, ..._config.wrap} - if (setting.selected !== 'always' && setting.selected !== 'init') { + if (setting.selected !== 'always' && setting.selected !== 'init' && setting.selected !== 'sign') { setting.selected = 'false' } else { setting.orisel = true } - - _config.columns.forEach(item => { - if (item.type !== 'number') return - _cols.set(item.field, item) - }) - - _config.cols.forEach(column => { - if (column.type === 'action') { - column.operations = column.elements - } - }) _config.style = _config.style || {} @@ -126,7 +114,7 @@ }) MKEmitter.emit('resetSelectLine', config.uuid, '', '') // 骞挎挱鏁版嵁鍒囨崲 - reset && MKEmitter.emit('resetTable', config.uuid, repage) // 鍒楄〃閲嶇疆 + reset && MKEmitter.emit('resetTable', config.uuid, 'true') // 鍒楄〃閲嶇疆 if (setting.$hasSyncModule) { MKEmitter.emit('syncBalconyData', config.uuid, [], false) } @@ -157,9 +145,26 @@ let result = await Api.genericInterface(param) if (result.status) { + if (repage === 'false' && result.data && result.data.length === 0 && result.total > 0 && pageIndex > 1) { + let _pageIndex = Math.ceil(result.total / pageSize) + + if (_pageIndex < pageIndex) { + MKEmitter.emit('resetTable', config.uuid, 'repage', _pageIndex) + this.setState({ + pageIndex: _pageIndex, + data: [], + selectedData: [], + total: result.total + }, () => { + this.loadmaindata() + }) + return + } + } + if ((setting.selected !== 'false' || (setting.orisel && id)) && result.data && result.data.length > 0) { setTimeout(() => { - MKEmitter.emit('mkCheckTopLine', config.uuid, id) + MKEmitter.emit('mkCheckTopLine', config.uuid, id, setting.selected) }, 200) if (setting.selected === 'init') { this.setState({setting: {...setting, selected: 'false'}}) @@ -195,7 +200,7 @@ }) } if (setting.controlField) { - if (setting.controlVal.includes(item[setting.controlField])) { + if (setting.controlVal.includes(item[setting.controlField] + '')) { item.$disabled = true } } @@ -206,15 +211,34 @@ total: result.total, loading: false }) + + if (config.autoMatic) { + if (result.data && result.data.length > 0) { + MKEmitter.emit('autoGetData', config.MenuID) + } else { + MKEmitter.emit('autoMaticOver', config.MenuID) + } + } } else { this.setState({ loading: false }) - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) + + if (config.autoMatic) { + MKEmitter.emit('autoMaticError', config.MenuID) + } + + if (result.ErrCode === 'N') { + Modal.error({ + title: result.message, + }) + } else { + notification.error({ + top: 92, + message: result.message, + duration: 10 + }) + } } } @@ -372,47 +396,42 @@ * 鍚湁鍒濆涓嶅姞杞界殑椤甸潰锛屼慨鏀硅缃� */ refreshbysearch = (searches) => { - const { setting } = this.state - - if (setting.onload === 'false') { - this.setState({ - pageIndex: 1, - search: searches, - setting: {...setting, onload: 'true'} - }, () => { - this.loadmaindata() - this.getStatFieldsValue() - }) - } else { - this.setState({ - pageIndex: 1, - search: searches - }, () => { - this.loadmaindata(true, 'true') - this.getStatFieldsValue() - }) - } + this.setState({ + pageIndex: 1, + search: searches + }, () => { + this.loadmaindata(true, 'true') + this.getStatFieldsValue() + }) } /** * @description 琛ㄦ牸鏉′欢鏀瑰彉鏃堕噸缃暟鎹紙鍒嗛〉鎴栨帓搴忥級 */ refreshbytable = (pagination, filters, sorter) => { - if (sorter.order) { - let _chg = { - ascend: 'asc', - descend: 'desc' + if (!sorter) { // 鏃犱汉鍊煎畧 + this.setState({ + pageIndex: pagination.pageIndex + }, () => { + this.loadmaindata() + }) + } else { + if (sorter.order) { + let _chg = { + ascend: 'asc', + descend: 'desc' + } + sorter.order = _chg[sorter.order] } - sorter.order = _chg[sorter.order] + + this.setState({ + pageIndex: pagination.current, + pageSize: pagination.pageSize, + orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : '' + }, () => { + this.loadmaindata() + }) } - - this.setState({ - pageIndex: pagination.current, - pageSize: pagination.pageSize, - orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : '' - }, () => { - this.loadmaindata() - }) } /** @@ -518,7 +537,7 @@ UNSAFE_componentWillReceiveProps(nextProps) { const { config } = this.state - if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { + if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { this.setState({pageIndex: 1}, () => { this.reloadtable() }) @@ -551,20 +570,20 @@ render() { const { BID, setting, actions, config, columns, selectedData, BData, data } = this.state - + return ( <div className="custom-base-table" style={config.style}> {config.search.length ? <MainSearch BID={BID} config={config} refreshdata={this.refreshbysearch}/> : null } - {actions.length ? <MainAction + {actions.length > 0 ? <MainAction BID={BID} setting={setting} actions={actions} BData={BData} columns={config.columns} selectedData={selectedData} - /> : <div style={{height: '15px'}}></div>} + /> : <div style={{height: '25px'}}></div>} <div className="main-table-box"> <MainTable data={data} @@ -573,6 +592,7 @@ MenuID={config.uuid} fields={config.columns} total={this.state.total} + autoMatic={config.autoMatic} lineMarks={config.lineMarks} loading={this.state.loading} refreshdata={this.refreshbytable} -- Gitblit v1.8.0