| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import { Popover, Typography } from "antd";
- import { ArticleCtl, type TDisplayStyle } from "./Article"
- import { type IWidgetTermCtl, TermCtl } from "./Term"
- import { useEffect, useState } from "react";
- const { Text } = Typography;
- interface IWidgetQuoteLinkCtl {
- type: string;
- bookName?: string;
- volume?: number;
- page?: number;
- style: TDisplayStyle;
- book?: number;
- para?: number;
- term?: IWidgetTermCtl;
- title?: string;
- chapter?: string;
- found: boolean;
- }
- const QuoteLinkCtl = ({
- type,
- bookName,
- volume,
- page,
- style,
- book,
- para,
- term,
- title,
- chapter,
- found,
- }: IWidgetQuoteLinkCtl) => {
- const [tpl, setTpl] = useState<string>();
- let textShow = volume === 0 ? ` ${page}` : ` ${volume}.${page}`;
- if (type === "c") {
- textShow = ` ${chapter}`;
- }
- console.debug("found", found);
- useEffect(() => {
- if (type === "c") {
- setTpl(`{{ql|type=${type}|book=${book}|para=${para}}}`);
- }
- }, [book, para, type]);
- useEffect(() => {
- if (
- typeof type !== "undefined" &&
- typeof bookName !== "undefined" &&
- typeof volume !== "undefined" &&
- typeof page !== "undefined"
- ) {
- setTpl(
- `{{ql|type=${type}|bookname=${bookName}|volume=${volume}|page=${page}}}`
- );
- }
- }, [bookName, found, page, type, volume]);
- return (
- <>
- {found ? (
- <ArticleCtl
- book={book?.toString()}
- paragraphs={para?.toString()}
- title={
- title ? (
- title
- ) : (
- <>
- <TermCtl {...term} compact={true} /> {textShow}
- </>
- )
- }
- type={type === "c" ? "para" : "page"}
- focus={book && para ? `${book}-${para}` : undefined}
- id={
- type === "c"
- ? `${book}-${para}`
- : `${type}_${bookName}_${volume}_${page}`
- }
- style={style}
- modalExtra={
- <Text style={{ marginRight: 8 }} copyable={{ text: tpl }}>
- 复制模版
- </Text>
- }
- />
- ) : (
- <Popover
- placement="top"
- arrowPointAtCenter
- content={
- <>
- <TermCtl {...term} compact={true} />{" "}
- <Text copyable={{ text: tpl }}>{page}</Text>
- </>
- }
- trigger="hover"
- >
- <Text>
- {title ? (
- title
- ) : (
- <>
- <TermCtl {...term} compact={true} /> {textShow}
- </>
- )}
- </Text>
- </Popover>
- )}
- </>
- );
- };
- interface IWidget {
- props: string;
- }
- const Widget = ({ props }: IWidget) => {
- const prop = JSON.parse(atob(props)) as IWidgetQuoteLinkCtl;
- console.debug("QuoteLink", prop);
- return (
- <>
- <QuoteLinkCtl {...prop} />
- </>
- );
- };
- export default Widget;
|