DictContent.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import { Col, Divider, Row, Tabs } from "antd";
  2. import type { IAnchorData } from "./DictList";
  3. import type { IWidgetWordCardData } from "./WordCard";
  4. import type { ICaseListData } from "./CaseList";
  5. import WordCard from "./WordCard";
  6. import CaseList from "./CaseList";
  7. import DictList from "./DictList";
  8. import MyCreate from "./MyCreate";
  9. import { useIntl } from "react-intl";
  10. import DictGroupTitle from "./DictGroupTitle";
  11. import UserDictList from "./UserDictList";
  12. import { useAppSelector } from "../../hooks";
  13. import { currentUser } from "../../reducers/current-user";
  14. import { useState } from "react";
  15. export interface IDictWords {
  16. pass: string;
  17. words: IWidgetWordCardData[];
  18. }
  19. export interface IDictContentData {
  20. dictlist: IAnchorData[];
  21. words: IDictWords[];
  22. caselist: ICaseListData[];
  23. time?: number;
  24. count?: number;
  25. }
  26. export interface IApiDictContentData {
  27. ok: boolean;
  28. message: string;
  29. data: IDictContentData;
  30. }
  31. interface IMyDict {
  32. word?: string;
  33. }
  34. const MyDict = ({ word }: IMyDict) => {
  35. const user = useAppSelector(currentUser);
  36. const [myTab, setMyTab] = useState<string>("list");
  37. const [myRefresh, setMyRefresh] = useState(false);
  38. return (
  39. <div>
  40. <Tabs
  41. size="small"
  42. type="card"
  43. style={{ backgroundColor: "white" }}
  44. activeKey={myTab}
  45. onChange={(activeKey: string) => setMyTab(activeKey)}
  46. items={[
  47. {
  48. label: "列表",
  49. key: "list",
  50. children: (
  51. <UserDictList
  52. studioName={user?.realName}
  53. word={word}
  54. compact={true}
  55. refresh={myRefresh}
  56. onRefresh={(value: boolean) => setMyRefresh(value)}
  57. />
  58. ),
  59. },
  60. {
  61. label: "新建",
  62. key: "new",
  63. children: (
  64. <MyCreate
  65. word={word}
  66. onSave={() => {
  67. setMyRefresh(true);
  68. setMyTab("list");
  69. }}
  70. />
  71. ),
  72. },
  73. ]}
  74. />
  75. </div>
  76. );
  77. };
  78. interface IWidget {
  79. word?: string;
  80. data: IDictContentData;
  81. compact?: boolean;
  82. }
  83. const DictContentWidget = ({ word, data, compact }: IWidget) => {
  84. const intl = useIntl();
  85. return (
  86. <>
  87. <Row>
  88. <Col flex="200px">
  89. {compact ? <></> : <DictList data={data.dictlist} />}
  90. </Col>
  91. <Col flex="760px">
  92. <Tabs
  93. size="small"
  94. items={[
  95. {
  96. label: `查询结果`,
  97. key: "result",
  98. children: (
  99. <div>
  100. <div>
  101. {intl.formatMessage(
  102. {
  103. id: "message.result",
  104. },
  105. { count: data.count }
  106. )}
  107. {" ("}
  108. {intl.formatMessage(
  109. {
  110. id: "message.time",
  111. },
  112. { time: data.time?.toFixed(3) }
  113. )}
  114. {")"}
  115. </div>
  116. <div>
  117. {data.words.map((it, _id) => {
  118. return (
  119. <div>
  120. <DictGroupTitle
  121. title={
  122. <Divider orientation="left">
  123. {intl.formatMessage({
  124. id: `labels.dict.pass.${it.pass}`,
  125. })}
  126. </Divider>
  127. }
  128. path={[
  129. intl.formatMessage({
  130. id: `labels.dict.pass.${it.pass}`,
  131. }),
  132. ]}
  133. />
  134. <div>
  135. {it.words.map((word, index) => (
  136. <WordCard key={index} data={word} />
  137. ))}
  138. </div>
  139. </div>
  140. );
  141. })}
  142. </div>
  143. </div>
  144. ),
  145. },
  146. {
  147. label: `单词本`,
  148. key: "my",
  149. children: <MyDict word={word} />,
  150. },
  151. ]}
  152. />
  153. </Col>
  154. <Col flex="200px">
  155. <CaseList word={word} />
  156. </Col>
  157. </Row>
  158. </>
  159. );
  160. };
  161. export default DictContentWidget;