CopyToStep.tsx 2.9 KB

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