CopyToStep.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { Steps } from "antd";
  2. import { useEffect, useState } from "react";
  3. import type { ArticleType } from "../article/Article";
  4. import type { IChannel } from "./Channel";
  5. import ChannelPickerTable from "./ChannelPickerTable";
  6. import ChannelSentDiff from "./ChannelSentDiff";
  7. import CopyToResult from "./CopyToResult";
  8. interface IWidget {
  9. initStep?: number;
  10. channel?: IChannel;
  11. type?: ArticleType;
  12. articleId?: string;
  13. sentencesId?: string[];
  14. important?: boolean;
  15. onClose?: () => void;
  16. }
  17. const CopyToStepWidget = ({
  18. initStep = 0,
  19. channel,
  20. sentencesId,
  21. important = false,
  22. onClose,
  23. }: IWidget) => {
  24. const [current, setCurrent] = useState(0);
  25. const [destChannel, setDestChannel] = useState<IChannel>();
  26. const [copyPercent, setCopyPercent] = useState<number>();
  27. const [total, setTotal] = useState<number>();
  28. useEffect(() => {
  29. setCurrent(initStep);
  30. }, [initStep]);
  31. const next = () => {
  32. setCurrent(current + 1);
  33. };
  34. const prev = () => {
  35. setCurrent(current - 1);
  36. };
  37. const contentStyle: React.CSSProperties = {
  38. borderRadius: 5,
  39. border: `1px dashed gray`,
  40. marginTop: 16,
  41. height: 400,
  42. overflowY: "scroll",
  43. };
  44. const steps = [
  45. {
  46. title: "选择目标版本",
  47. key: "channel",
  48. content: (
  49. <div style={contentStyle}>
  50. <ChannelPickerTable
  51. type="editable"
  52. disableChannelId={channel?.id}
  53. multiSelect={false}
  54. onSelect={(e: IChannel[]) => {
  55. console.log("channel", e);
  56. if (e.length > 0) {
  57. setDestChannel(e[0]);
  58. setCopyPercent(100);
  59. next();
  60. }
  61. }}
  62. />
  63. </div>
  64. ),
  65. },
  66. {
  67. title: "文本比对",
  68. key: "diff",
  69. content: (
  70. <ChannelSentDiff
  71. srcChannel={channel}
  72. destChannel={destChannel}
  73. sentences={sentencesId}
  74. important={important}
  75. goPrev={() => {
  76. prev();
  77. }}
  78. onSubmit={(total: number) => {
  79. setTotal(total);
  80. next();
  81. }}
  82. />
  83. ),
  84. },
  85. {
  86. title: "完成",
  87. key: "finish",
  88. content: (
  89. <div style={contentStyle}>
  90. <CopyToResult
  91. total={total}
  92. onClose={() => {
  93. if (typeof onClose !== "undefined") {
  94. onClose();
  95. }
  96. }}
  97. onInit={() => {
  98. setCurrent(0);
  99. }}
  100. />
  101. </div>
  102. ),
  103. },
  104. ];
  105. const items = steps.map((item) => ({ key: item.key, title: item.title }));
  106. return (
  107. <div>
  108. <Steps current={current} items={items} percent={copyPercent} />
  109. {steps[current].content}
  110. </div>
  111. );
  112. };
  113. export default CopyToStepWidget;