CopyToStep.tsx 2.7 KB

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