SentTabButton.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { useIntl } from "react-intl";
  2. import { Badge, Dropdown } from "antd";
  3. import type { MenuProps } from "antd";
  4. import {
  5. OneToOneOutlined,
  6. LinkOutlined,
  7. CalendarOutlined,
  8. } from "@ant-design/icons";
  9. import store from "../../../store";
  10. import {
  11. ISite,
  12. refresh as refreshLayout,
  13. } from "../../../reducers/open-article";
  14. const handleButtonClick = (e: React.MouseEvent<HTMLButtonElement>) => {
  15. console.log("click left button", e);
  16. };
  17. interface IWidget {
  18. icon?: JSX.Element;
  19. type: string;
  20. sentId: string;
  21. count?: number;
  22. title?: string;
  23. }
  24. const Widget = ({ icon, type, sentId, title, count = 0 }: IWidget) => {
  25. const intl = useIntl();
  26. const items: MenuProps["items"] = [
  27. {
  28. label: "在新标签页中打开",
  29. key: "openInWin",
  30. icon: <CalendarOutlined />,
  31. },
  32. {
  33. label: "复制链接",
  34. key: "copyLink",
  35. icon: <LinkOutlined />,
  36. },
  37. ];
  38. const handleMenuClick: MenuProps["onClick"] = (e) => {
  39. e.domEvent.stopPropagation();
  40. switch (e.key) {
  41. case "openInCol":
  42. const it: ISite = {
  43. title: intl.formatMessage({
  44. id: `channel.type.${type}.label`,
  45. }),
  46. url: "corpus_sent/" + type,
  47. id: sentId,
  48. };
  49. store.dispatch(refreshLayout(it));
  50. break;
  51. }
  52. };
  53. const menuProps = {
  54. items,
  55. onClick: handleMenuClick,
  56. };
  57. return (
  58. <Dropdown.Button
  59. size="small"
  60. type="text"
  61. menu={menuProps}
  62. onClick={handleButtonClick}
  63. >
  64. {title}
  65. <Badge size="small" color="geekblue" count={count}></Badge>
  66. </Dropdown.Button>
  67. );
  68. };
  69. export default Widget;