SentTab.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import { Badge, Space, Tabs, Typography } from "antd";
  2. import {
  3. TranslationOutlined,
  4. CloseOutlined,
  5. BlockOutlined,
  6. } from "@ant-design/icons";
  7. import SentTabButton from "./SentTabButton";
  8. import SentCanRead from "./SentCanRead";
  9. import SentSim from "./SentSim";
  10. import { useIntl } from "react-intl";
  11. import TocPath, { ITocPathNode } from "../../corpus/TocPath";
  12. import { IWbw } from "../Wbw/WbwWord";
  13. import RelaGraphic from "../Wbw/RelaGraphic";
  14. import SentMenu from "./SentMenu";
  15. import { IChapter } from "../../corpus/BookViewer";
  16. import store from "../../../store";
  17. import { change } from "../../../reducers/para-change";
  18. import { useEffect, useState } from "react";
  19. const { Text } = Typography;
  20. interface IWidget {
  21. id: string;
  22. book: number;
  23. para: number;
  24. wordStart: number;
  25. wordEnd: number;
  26. channelsId?: string[];
  27. path?: ITocPathNode[];
  28. layout?: "row" | "column";
  29. tranNum?: number;
  30. nissayaNum?: number;
  31. commNum?: number;
  32. originNum: number;
  33. simNum?: number;
  34. wbwData?: IWbw[];
  35. magicDictLoading?: boolean;
  36. compact?: boolean;
  37. onMagicDict?: Function;
  38. onCompact?: Function;
  39. }
  40. const SentTabWidget = ({
  41. id,
  42. book,
  43. para,
  44. wordStart,
  45. wordEnd,
  46. channelsId,
  47. path,
  48. tranNum,
  49. nissayaNum,
  50. commNum,
  51. originNum,
  52. simNum = 0,
  53. wbwData,
  54. magicDictLoading = false,
  55. compact = false,
  56. onMagicDict,
  57. onCompact,
  58. }: IWidget) => {
  59. const intl = useIntl();
  60. const [isCompact, setIsCompact] = useState(compact);
  61. useEffect(() => setIsCompact(compact), [compact]);
  62. const mPath = path
  63. ? [
  64. ...path,
  65. { book: book, paragraph: para, title: para.toString(), level: 100 },
  66. ]
  67. : [];
  68. if (typeof id === "undefined") {
  69. return <></>;
  70. }
  71. const sentId = id.split("_");
  72. const sId = sentId[0].split("-");
  73. return (
  74. <>
  75. <Tabs
  76. style={isCompact ? { position: "absolute", marginTop: -32 } : undefined}
  77. tabBarStyle={{ marginBottom: 0 }}
  78. size="small"
  79. tabBarGutter={0}
  80. tabBarExtraContent={
  81. <Space>
  82. <TocPath
  83. link="none"
  84. data={mPath}
  85. trigger={path ? path.length > 0 ? path[0].title : <></> : <></>}
  86. onChange={(para: IChapter) => {
  87. //点击章节目录
  88. const type = para.level
  89. ? para.level < 8
  90. ? "chapter"
  91. : "para"
  92. : "para";
  93. store.dispatch(
  94. change({ book: para.book, para: para.para, type: type })
  95. );
  96. }}
  97. />
  98. <Text copyable={{ text: `{{${sentId[0]}}}` }}>{sentId[0]}</Text>
  99. <SentMenu
  100. book={book}
  101. para={para}
  102. loading={magicDictLoading}
  103. onMagicDict={(type: string) => {
  104. if (typeof onMagicDict !== "undefined") {
  105. onMagicDict(type);
  106. }
  107. }}
  108. onMenuClick={(key: string) => {
  109. switch (key) {
  110. case "compact" || "normal":
  111. if (typeof onCompact !== "undefined") {
  112. setIsCompact(true);
  113. onCompact(true);
  114. }
  115. break;
  116. case "normal":
  117. if (typeof onCompact !== "undefined") {
  118. setIsCompact(false);
  119. onCompact(false);
  120. }
  121. break;
  122. default:
  123. break;
  124. }
  125. }}
  126. />
  127. </Space>
  128. }
  129. items={[
  130. {
  131. label: (
  132. <Badge size="small" count={0}>
  133. <CloseOutlined />
  134. </Badge>
  135. ),
  136. key: "close",
  137. children: <></>,
  138. },
  139. {
  140. label: (
  141. <SentTabButton
  142. icon={<TranslationOutlined />}
  143. type="translation"
  144. sentId={id}
  145. count={tranNum}
  146. title={intl.formatMessage({
  147. id: "channel.type.translation.label",
  148. })}
  149. />
  150. ),
  151. key: "translation",
  152. children: (
  153. <SentCanRead
  154. book={parseInt(sId[0])}
  155. para={parseInt(sId[1])}
  156. wordStart={parseInt(sId[2])}
  157. wordEnd={parseInt(sId[3])}
  158. type="translation"
  159. />
  160. ),
  161. },
  162. {
  163. label: (
  164. <SentTabButton
  165. icon={<CloseOutlined />}
  166. type="nissaya"
  167. sentId={id}
  168. count={nissayaNum}
  169. title={intl.formatMessage({
  170. id: "channel.type.nissaya.label",
  171. })}
  172. />
  173. ),
  174. key: "nissaya",
  175. children: (
  176. <SentCanRead
  177. book={parseInt(sId[0])}
  178. para={parseInt(sId[1])}
  179. wordStart={parseInt(sId[2])}
  180. wordEnd={parseInt(sId[3])}
  181. type="nissaya"
  182. />
  183. ),
  184. },
  185. {
  186. label: (
  187. <SentTabButton
  188. icon={<TranslationOutlined />}
  189. type="commentary"
  190. sentId={id}
  191. count={commNum}
  192. title={intl.formatMessage({
  193. id: "channel.type.commentary.label",
  194. })}
  195. />
  196. ),
  197. key: "commentary",
  198. children: (
  199. <SentCanRead
  200. book={parseInt(sId[0])}
  201. para={parseInt(sId[1])}
  202. wordStart={parseInt(sId[2])}
  203. wordEnd={parseInt(sId[3])}
  204. type="commentary"
  205. channelsId={channelsId}
  206. />
  207. ),
  208. },
  209. /*{
  210. label: (
  211. <SentTabButton
  212. icon={<BlockOutlined />}
  213. type="original"
  214. sentId={id}
  215. count={originNum}
  216. title={intl.formatMessage({
  217. id: "channel.type.original.label",
  218. })}
  219. />
  220. ),
  221. key: "original",
  222. children: (
  223. <SentCanRead
  224. book={parseInt(sId[0])}
  225. para={parseInt(sId[1])}
  226. wordStart={parseInt(sId[2])}
  227. wordEnd={parseInt(sId[3])}
  228. type="original"
  229. />
  230. ),
  231. },*/
  232. {
  233. label: (
  234. <SentTabButton
  235. icon={<BlockOutlined />}
  236. type="original"
  237. sentId={id}
  238. count={simNum}
  239. title={intl.formatMessage({
  240. id: "buttons.sim",
  241. })}
  242. />
  243. ),
  244. key: "sim",
  245. children: (
  246. <SentSim
  247. book={parseInt(sId[0])}
  248. para={parseInt(sId[1])}
  249. wordStart={parseInt(sId[2])}
  250. wordEnd={parseInt(sId[3])}
  251. limit={5}
  252. />
  253. ),
  254. },
  255. {
  256. label: "关系图",
  257. key: "relation-graphic",
  258. children: <RelaGraphic wbwData={wbwData} />,
  259. },
  260. ]}
  261. />
  262. </>
  263. );
  264. };
  265. export default SentTabWidget;