import { useEffect, useState } from "react";
import {
Button,
Divider,
Input,
Modal,
Select,
Space,
Tabs,
Typography,
} from "antd";
import { FolderOpenOutlined } from "@ant-design/icons";
import { ArticleCtl, type TDisplayStyle } from "../Article";
import type { ArticleType } from "../../article/Article";
import { useIntl } from "react-intl";
import ArticleListModal from "../../article/ArticleListModal";
import { useAppSelector } from "../../../hooks";
import { currentUser } from "../../../reducers/current-user";
import ChannelTableModal from "../../channel/ChannelTableModal";
import type { IChannel } from "../../channel/Channel";
const { TextArea } = Input;
const { Paragraph } = Typography;
interface IWidget {
type?: ArticleType;
articleId?: string;
title?: string;
style?: TDisplayStyle;
channel?: string | null;
onSelect?: Function;
onCancel?: Function;
}
const ArticleTplWidget = ({
type,
articleId,
channel,
title,
style = "modal",
}: IWidget) => {
const intl = useIntl(); //i18n
const [currTitle, setCurrTitle] = useState(title);
const [currChannel, setCurrChannel] = useState(channel);
const [styleText, setStyleText] = useState(style);
const [typeText, setTypeText] = useState(type);
const [idText, setIdText] = useState(articleId);
const [tplText, setTplText] = useState("");
const user = useAppSelector(currentUser);
const ids = articleId?.split("_");
const id1 = ids ? ids[0] : undefined;
const channels = ids
? ids.length > 1
? ids?.slice(1)
: undefined
: undefined;
useEffect(() => {
setCurrTitle(title);
}, [title]);
useEffect(() => {
let tplText = `{{article|\n`;
tplText += `type=${typeText}|\n`;
tplText += `id=${idText}|\n`;
tplText += `title=${currTitle}|\n`;
tplText += currChannel ? `channel=${currChannel}|\n` : "";
tplText += `style=${styleText}`;
tplText += channels ? `channel=${channels}` : "";
tplText += "}}";
setTplText(tplText);
}, [currTitle, styleText, type, id1, channels, typeText, idText]);
return (
<>
{"标题:"}
) => {
setCurrTitle(event.target.value);
}}
/>
{"类别:"}
{"id:"}
) => {
setIdText(event.target.value);
}}
/>
{typeText === "article" ? (
} type="text" />}
multiple={false}
onSelect={(id: string, title: string) => {
setIdText(id);
setCurrTitle(title);
}}
/>
) : undefined}
{"channel:"}
) => {
setCurrChannel(event.target.value);
}}
/>
} type="text" />}
onSelect={(channel: IChannel) => {
setCurrChannel(channel.id);
}}
/>
{"显示为:"}
),
},
{
label: `Code`,
key: "code",
children: (
),
},
]}
/>
复制到剪贴板
>
);
};
interface IModalWidget {
open?: boolean;
type?: ArticleType;
articleId?: string;
channelsId?: string | null;
title?: string;
style?: TDisplayStyle;
trigger?: JSX.Element;
onClose?: () => void;
}
export const ArticleTplModal = ({
open = false,
type,
articleId,
channelsId,
title,
style = "modal",
trigger,
onClose,
}: IModalWidget) => {
const [isModalOpen, setIsModalOpen] = useState(open);
useEffect(() => setIsModalOpen(open), [open]);
const showModal = () => {
setIsModalOpen(true);
};
const handleOk = () => {
setIsModalOpen(false);
};
const handleCancel = () => {
if (onClose) {
onClose();
} else {
setIsModalOpen(false);
}
};
return (
<>
{trigger}
>
);
};
export default ArticleTplWidget;