ListTab.js 2.4 KB
Newer Older
王绍森's avatar
王绍森 committed
1 2 3
import React, { Component, Fragment } from 'react';
import { Tabs } from 'antd';
import styles from '@/baseComponent/index.less';
4 5
import CreateC from '@/webPublic/FormInsertDiy/ExportComponent/ContextCreate';

王绍森's avatar
王绍森 committed
6 7 8 9 10
import Shell from '@/baseComponent/Shell';
import List from './List';

const TabPane = Tabs.TabPane;

11
class ListTab extends Component {
12 13 14 15 16 17 18 19 20 21 22 23 24
	constructor(props) {
		super(props);
		const { tabList, keepAliveData } = this.props;
		const tabKeys = Object.keys(tabList);
		let activeKey = this.props.locationState?.activeKey || tabKeys[0];
		if(keepAliveData && keepAliveData.activeKey){
		  activeKey = keepAliveData.activeKey;
    }
		this.state = {
			activeKey: activeKey,
			tabKeys: tabKeys,
		};
	}
王绍森's avatar
王绍森 committed
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39
	handleChangeTab = (activeKey) => {
		this.setState(
			{
				activeKey: '-111111',
			},
			() => {
				setTimeout(() => {
					this.setState({
						activeKey: activeKey,
					});
				}, 30);
			},
		);
	};
王绍森's avatar
王绍森 committed
40

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
	componentDidMount() {
		if (this.props.setRefInfo) {
			this.props.setRefInfo('ListTab', this);
		}
	}

	render() {
		const {
			tabList,
			pageSearch,
			pageButton,
			workId,
			dataBaseId,
			addFields,
			searchCondition,
		} = this.props;
		const { activeKey, tabKeys } = this.state;
		return (
			<Fragment>
				<Shell styleShell={{ marginTop: 0 }}>
					{/*<SearchDom />*/}
					<Tabs activeKey={activeKey} className={styles.ListTab} onChange={this.handleChangeTab}>
						{tabKeys.map((item) => {
							return <TabPane tab={tabList[item].name} key={item} />;
						})}
					</Tabs>
				</Shell>
				{tabKeys.map((item) => {
					if (activeKey === item && pageSearch[item]) {
						const search = pageSearch[item].search;
						if (search.mustHaveCondition && !search.condition.length) {
							// 如果配置了 mustHaveCondition 则 必须有搜索条件才渲染页面 保证 搜索条件正常传给后台
							return null;
						}
					}
					return activeKey === item ? (
						<List
							listConfig={tabList[item].listConfig}
							key={item}
							workId={workId}
							addFields={addFields}
							searchCondition={searchCondition}
							dataBaseId={dataBaseId}
							pageSearch={pageSearch[item]}
							pageButton={pageButton[item]}
							setRefInfo={this.props.setRefInfo}
              keepAliveData={this.props.keepAliveData}
						/>
					) : null;
				})}
			</Fragment>
		);
	}
王绍森's avatar
王绍森 committed
94 95
}

96 97 98
ListTab.contextType = CreateC;

ListTab.propTypes = {};
王绍森's avatar
王绍森 committed
99
ListTab.defaultProps = {};
100 101

export default ListTab;