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); }} /> {"类别:"} ) => { 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); }} /> {"显示为:"}