2
0

ToolButtonSearch.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { SearchOutlined } from "@ant-design/icons";
  2. import ToolButton from "./ToolButton";
  3. import { Input, Tree, type TreeDataNode } from "antd";
  4. import { useSearchParams } from "react-router";
  5. import type { ArticleType } from "./Article";
  6. import { get } from "../../request";
  7. import type { IArticleFtsListResponse } from "../../api/Article";
  8. import type { Key } from "antd/lib/table/interface";
  9. import { useState } from "react";
  10. const { Search } = Input;
  11. interface IWidget {
  12. type?: ArticleType;
  13. articleId?: string;
  14. anthologyId?: string;
  15. channels?: string[];
  16. }
  17. const ToolButtonSearchWidget = ({
  18. type,
  19. articleId,
  20. anthologyId,
  21. channels,
  22. }: IWidget) => {
  23. const [_searchParams, _setSearchParams] = useSearchParams();
  24. const [treeNode, _setTreeNode] = useState<TreeDataNode[]>();
  25. const content = (
  26. <>
  27. <Search
  28. placeholder="搜索本章节"
  29. onSearch={(
  30. value: string,
  31. _event?:
  32. | React.ChangeEvent<HTMLInputElement>
  33. | React.MouseEvent<HTMLElement, MouseEvent>
  34. | React.KeyboardEvent<HTMLInputElement>
  35. | undefined
  36. ) => {
  37. if (type === "article") {
  38. let url = `/v2/article-fts?id=${articleId}&anthology=${anthologyId}&key=${value}`;
  39. url += "&channel=" + channels?.join(",");
  40. console.debug("api request", url);
  41. get<IArticleFtsListResponse>(url).then((json) => {
  42. console.debug("api response", json);
  43. if (json.ok) {
  44. }
  45. });
  46. }
  47. }}
  48. style={{ width: "100%" }}
  49. />
  50. <Tree onSelect={(_selectedKeys: Key[]) => {}} treeData={treeNode} />
  51. </>
  52. );
  53. return (
  54. <ToolButton title="搜索" icon={<SearchOutlined />} content={content} />
  55. );
  56. };
  57. export default ToolButtonSearchWidget;