| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import { useEffect, useState } from "react";
- import { Modal, Space } from "antd";
- import TermEdit from "./TermEdit";
- import type { ITermDataResponse } from "../../api/Term";
- import { Link } from "react-router";
- interface IWidget {
- trigger?: React.ReactNode;
- open?: boolean;
- id?: string;
- word?: string;
- tags?: string[];
- studioName?: string;
- channelId?: string;
- parentChannelId?: string;
- parentStudioId?: string;
- community?: boolean;
- onUpdate?: Function;
- onClose?: Function;
- }
- const TermModalWidget = ({
- trigger,
- open = false,
- id,
- word,
- tags,
- studioName,
- channelId,
- parentChannelId,
- parentStudioId,
- community = false,
- onUpdate,
- onClose,
- }: IWidget) => {
- const [isModalOpen, setIsModalOpen] = useState(open);
- useEffect(() => {
- if (open) {
- showModal();
- } else {
- modalClose();
- }
- }, [open]);
- const modalClose = () => {
- setIsModalOpen(false);
- if (document.getElementsByTagName("body")[0].hasAttribute("style")) {
- document.getElementsByTagName("body")[0].removeAttribute("style");
- }
- };
- const showModal = () => {
- setIsModalOpen(true);
- };
- const handleOk = () => {
- modalClose();
- if (typeof onClose !== "undefined") {
- onClose();
- }
- };
- const handleCancel = () => {
- modalClose();
- if (typeof onClose !== "undefined") {
- onClose();
- }
- };
- return (
- <>
- <span onClick={showModal}>{trigger}</span>
- <Modal
- style={{ top: 20 }}
- width={760}
- title={
- <Space>
- {"术语"}
- <Link
- to={`/studio/${studioName}/term/list`}
- target="_blank"
- style={{ display: "none" }}
- >
- 在studio中打开
- </Link>
- </Space>
- }
- footer={false}
- destroyOnHidden={true}
- open={isModalOpen}
- onOk={handleOk}
- onCancel={handleCancel}
- >
- <TermEdit
- id={id}
- word={word}
- tags={tags}
- studioName={studioName}
- channelId={channelId}
- parentChannelId={parentChannelId}
- parentStudioId={parentStudioId}
- community={community}
- onUpdate={(value: ITermDataResponse) => {
- modalClose();
- if (typeof onUpdate !== "undefined") {
- onUpdate(value);
- }
- }}
- />
- </Modal>
- </>
- );
- };
- export default TermModalWidget;
|