import React from "react"; import { Button, Drawer, Skeleton, Timeline } from "antd"; import HcserviceV3 from "../../tmpl/hcservice-v3"; import "../dtmpl.css"; import { DtmplConfig } from "../../tmpl/interface"; import Units from "../../units"; import { LocaleContext } from "../../locale/LocaleProvider"; import ViewComparePanel, { ViewComparData } from "./view-compare-panel"; type SnapshotType = { code: number, time: string, userName: string }; export interface SnapshotTimelineProps { sourceId: string; serverKey?: string; code: string; showSnapshot?: () => void; onClose: () => void; open: boolean; dtmplConfig: DtmplConfig; } export interface SnapshotTimelineStat { list?: SnapshotType[]; loading?: boolean; pageNo?: number; currents?: SnapshotType[]; isEnd?: boolean; rightDrawerSize?: number | string; // 抽屉组件尺寸 leftDrawerSize?: number | string; // 抽屉组件尺寸 } class SnapshotTimeline extends React.PureComponent< SnapshotTimelineProps, SnapshotTimelineStat > { static defaultProps = {}; state = { list: undefined, loading: false, currents: [], pageNo: 1, isEnd: false, rightDrawerSize: 370, leftDrawerSize: "calc(100% - 380px)" }; static contextType = LocaleContext; context: React.ContextType; async componentDidMount() { } async componentDidUpdate(prevProps) { const { open } = this.props; const { list } = this.state; if (open && !list) { this.loadData(1); } } loadData = async (pageNo: number) => { const { sourceId, code, serverKey } = this.props; const { currents, list } = this.state; if (code) { this.setState({ loading: true, }); const list1 = await HcserviceV3.requestVersionList( serverKey, sourceId, code, pageNo ); if (currents.length == 0 && list1.length > 0) { this.onAdd(list1[0]); } this.setState({ list: list ? [...list, ...list1] : list1, loading: false, isEnd: list1.length < 100, pageNo: pageNo, }); } }; onAdd = (item: SnapshotType) => { const { showSnapshot } = this.props; const { currents } = this.state; if (!this.isCurrent(item, currents)) { this.setState({ currents: [...currents, item], }); } // showSnapshot(); }; onRemove = (item: SnapshotType) => { const { showSnapshot } = this.props; const { currents } = this.state; let list: SnapshotType[] = []; for (const c of currents) { if (c.code != item.code) { list.push(c); } } this.setState({ currents: [...list], }); // showSnapshot(); }; isCurrent = (item: SnapshotType, currents: SnapshotType[]) => { for (const c of currents) { if (c.code == item.code) { return true; } } return false; } detailHistory = () => { const { list, currents } = this.state; const { translate } = this.context; let detailHistory; if (list.length > 0) { detailHistory = list.map((item, index) => { const isCurrentItem = this.isCurrent(item, currents); const color = isCurrentItem ? "red" : "blue"; return ( {Units.formateDate(item.time)}
{`` + item.userName} {isCurrentItem ? ( ) : ( )}
); }); return detailHistory; } }; render() { const { open, onClose, dtmplConfig, sourceId, code, serverKey, } = this.props; const { list, currents, loading, pageNo, isEnd, rightDrawerSize, leftDrawerSize } = this.state; const { translate } = this.context; const leftDrawerMaxSize = document.documentElement.clientWidth - 380; let viewDatas: ViewComparData[] = []; currents.sort((a, b) => b.time - a.time); for (const c of currents) { viewDatas.push({ code, versionId: c.code, time: c.time, userName: c.userName }); } return ( <> this.setState({ rightDrawerSize: newSize })) }} size={rightDrawerSize} maxSize={370} styles={{ body: { minWidth: "300px" } }} > {loading ? : list && list.length > 0 ? ( <> {this.detailHistory()} {isEnd ? "" : } ) : ( translate("${暂无历史记录}") )} this.setState({ leftDrawerSize: newSize })) }} size={leftDrawerSize} maxSize={leftDrawerMaxSize} closable={true} mask={false} onClose={onClose} open={open} styles={{ body: { padding: "6px 24px 6px 24px", minWidth: "1000px" } }} > {/**/} ); } } export default SnapshotTimeline;