CopyToStep.tsx 2.6 KB

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