Commit 462d055c authored by XieZhiXiong's avatar XieZhiXiong

chore: 完善代码

parent 88cef3d4
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* @LastEditTime: 2021-06-04 13:48:09 * @LastEditTime: 2021-06-04 13:48:09
* @Description: 内、外部流传记录 * @Description: 内、外部流传记录
*/ */
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState, useRef } from 'react';
import PolymericTable from '@/components/PolymericTable'; import PolymericTable from '@/components/PolymericTable';
import { EditableColumns } from '@/components/PolymericTable/interface'; import { EditableColumns } from '@/components/PolymericTable/interface';
import MellowCard, { MellowCardProps } from '@/components/MellowCard'; import MellowCard, { MellowCardProps } from '@/components/MellowCard';
...@@ -35,7 +35,7 @@ export interface FetchListParams { ...@@ -35,7 +35,7 @@ export interface FetchListParams {
pageSize: number, pageSize: number,
} }
interface IProps extends MellowCardProps { export interface IProps extends MellowCardProps {
/** /**
* 外部流转记录数据源,与 fetchOuterList 不能共存 * 外部流转记录数据源,与 fetchOuterList 不能共存
* 如果两个同时存在 outerDataSource 优先 * 如果两个同时存在 outerDataSource 优先
...@@ -66,12 +66,12 @@ interface IProps extends MellowCardProps { ...@@ -66,12 +66,12 @@ interface IProps extends MellowCardProps {
* 获取外部流转记录方法,与 outerDataSource 不能共存 * 获取外部流转记录方法,与 outerDataSource 不能共存
* 如果两个同时存在 outerDataSource 优先 * 如果两个同时存在 outerDataSource 优先
*/ */
fetchOuterList?: <T extends ListRes>(params: FetchListParams) => Promise<T>, fetchOuterList?: (params: FetchListParams) => Promise<ListRes>,
/** /**
* 获取内部流转记录方法,与 innerDataSource 不能共存 * 获取内部流转记录方法,与 innerDataSource 不能共存
* 如果两个同时存在 innerDataSource 优先 * 如果两个同时存在 innerDataSource 优先
*/ */
fetchInnerList?: <T extends ListRes>(params: FetchListParams) => Promise<T>, fetchInnerList?: (params: FetchListParams) => Promise<ListRes>,
} }
const FlowRecords: React.FC<IProps> = (props: IProps) => { const FlowRecords: React.FC<IProps> = (props: IProps) => {
...@@ -96,19 +96,21 @@ const FlowRecords: React.FC<IProps> = (props: IProps) => { ...@@ -96,19 +96,21 @@ const FlowRecords: React.FC<IProps> = (props: IProps) => {
const [innerLoading, setInnerLoading] = useState(false); const [innerLoading, setInnerLoading] = useState(false);
const [radioValue, setRadioValue] = useState<('inner' | 'outer')>('inner'); const [radioValue, setRadioValue] = useState<('inner' | 'outer')>('inner');
const mounted = useRef(false);
const getOuterList = (params: FetchListParams) => { const getOuterList = (params: FetchListParams) => {
if (outerDataSource) { if (outerDataSource) {
setOuterList({ data: outerDataSource, totalCount: outerDataSource.length }); setOuterList({ data: outerDataSource, totalCount: outerDataSource.length });
return; return;
} }
if (fetchOuterList) { if (fetchOuterList ) {
setOuterLoading(true); setOuterLoading(true);
fetchOuterList(params).then(res => { fetchOuterList(params).then(res => {
if (res) { if (res) {
setOuterList(res); mounted.current && setOuterList(res);
} }
}).finally(() => { }).finally(() => {
setOuterLoading(false); mounted.current && setOuterLoading(false);
}); });
} }
}; };
...@@ -122,15 +124,23 @@ const FlowRecords: React.FC<IProps> = (props: IProps) => { ...@@ -122,15 +124,23 @@ const FlowRecords: React.FC<IProps> = (props: IProps) => {
setInnerLoading(true); setInnerLoading(true);
fetchInnerList(params).then(res => { fetchInnerList(params).then(res => {
if (res) { if (res) {
setInnerList(res); mounted.current && setInnerList(res);
} }
}).finally(() => { }).finally(() => {
setInnerLoading(false); mounted.current && setInnerLoading(false);
}); });
} }
}; };
useEffect(() => { useEffect(() => {
mounted.current = true;
return () => {
mounted.current = false;
};
}, []);
useEffect(() => {
getOuterList({ getOuterList({
current: outerPage, current: outerPage,
pageSize: outerSize, pageSize: outerSize,
...@@ -199,7 +209,7 @@ const FlowRecords: React.FC<IProps> = (props: IProps) => { ...@@ -199,7 +209,7 @@ const FlowRecords: React.FC<IProps> = (props: IProps) => {
} }
: null : null
), ),
].filter(Boolean); ].filter(Boolean) as [];
return ( return (
<MellowCard <MellowCard
...@@ -224,7 +234,7 @@ const FlowRecords: React.FC<IProps> = (props: IProps) => { ...@@ -224,7 +234,7 @@ const FlowRecords: React.FC<IProps> = (props: IProps) => {
? { ? {
current: outerPage, current: outerPage,
pageSize: outerSize, pageSize: outerSize,
total: outerList.totalCount, total: outerList?.totalCount,
} }
: null : null
)} )}
...@@ -242,7 +252,7 @@ const FlowRecords: React.FC<IProps> = (props: IProps) => { ...@@ -242,7 +252,7 @@ const FlowRecords: React.FC<IProps> = (props: IProps) => {
? { ? {
current: innerPage, current: innerPage,
pageSize: innerSize, pageSize: innerSize,
total: innerList.totalCount, total: innerList?.totalCount,
} }
: null : null
)} )}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment