import React from "react"; import "./index.css"; import { DtmplConfig, TmplBase } from "../../tmpl/interface"; import { Affix, Button } from "antd"; import { LocaleContext } from "../../locale/LocaleProvider"; interface RightBarProps { parentId: string; dtmplConfig: DtmplConfig; positionRight?: number; } interface RightBarState {} export default class RightBar extends React.PureComponent< RightBarProps, RightBarState > { static defaultProps = { positionRight: 15, }; static contextType = LocaleContext; context: React.ContextType; scrollToAnchor = (anchor: TmplBase) => { if (anchor) { let anchorElement = document.getElementById( this.props.parentId + anchor.id ); if (anchorElement) { anchorElement.scrollIntoView({ behavior: "smooth", block: "end" }); } } }; scroll = (e) => { e.preventDefault(); e.stopPropagation(); const list = document.getElementsByClassName("rightBar")[0]; if (list) { const ul = list.getElementsByTagName("ul")[0]; ul.style.marginTop = ""; } }; render() { const { dtmplConfig, positionRight } = this.props; const cardList: TmplBase[] = []; const { translate } = this.context; if (dtmplConfig) { dtmplConfig.groups.forEach((g) => { cardList.push({ title: g.title, id: g.id, }); }); } if ( dtmplConfig && dtmplConfig.premises && dtmplConfig.premises.length > 0 ) { cardList.push({ id: dtmplConfig.premises[0].id, title: translate("${默认字段}"), }); } // @ts-ignore return cardList && cardList.length > 3 ? (
    {cardList ? cardList.map((item, index) => (
  • this.scrollToAnchor(item)} key={index}> {item.title}
  • )) : ""}
) : ( "" ); } }