CopyToStep.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 Widget = ({
  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. multiSelect={false}
  61. onSelect={(e: IChannel[]) => {
  62. console.log("channel", e);
  63. if (e.length > 0) {
  64. setDestChannel(e[0]);
  65. setCopyPercent(100);
  66. next();
  67. }
  68. }}
  69. />
  70. </div>
  71. ),
  72. },
  73. {
  74. title: "文本比对",
  75. key: "diff",
  76. content: (
  77. <ChannelSentDiff
  78. srcChannel={channel}
  79. destChannel={destChannel}
  80. sentences={sentList}
  81. goPrev={() => {
  82. prev();
  83. }}
  84. onSubmit={() => {
  85. next();
  86. }}
  87. />
  88. ),
  89. },
  90. {
  91. title: "完成",
  92. key: "finish",
  93. content: (
  94. <div style={contentStyle}>
  95. <CopyToResult
  96. onClose={() => {
  97. if (typeof onClose !== "undefined") {
  98. onClose();
  99. }
  100. }}
  101. onInit={() => {
  102. setCurrent(0);
  103. }}
  104. />
  105. </div>
  106. ),
  107. },
  108. ];
  109. const items = steps.map((item) => ({ key: item.key, title: item.title }));
  110. return (
  111. <div>
  112. <Steps current={current} items={items} percent={copyPercent} />
  113. {steps[current].content}
  114. </div>
  115. );
  116. };
  117. export default Widget;