import { useState, useEffect, useRef, Ref } from 'react'; import type { ColumnsType } from 'antd/es/table'; import type { FormInstance, MenuProps } from 'antd'; import { Menu, Table, Button, Tooltip, Modal } from 'antd'; import { PlusOutlined } from '@ant-design/icons'; import GroupsIcon from '@mui/icons-material/Groups'; import PersonIcon from '@mui/icons-material/Person'; import { useTranslation } from 'react-i18next'; import { addPrompt, apiInterceptors, getPromptList, postScenes, updatePrompt } from '@/client/api'; import { IPrompt } from '@/types/prompt'; import PromptForm from '@/components/prompt/prompt-form'; import { TFunction } from 'i18next'; const getItems = (t: TFunction) => [ { label: t('Public') + ' Prompts', key: 'common', icon: , }, { label: t('Private') + ' Prompts', key: 'private', icon: , }, ]; const getColumns = (t: TFunction, handleEdit: (prompt: IPrompt) => void): ColumnsType => [ { title: t('Prompt_Info_Name'), dataIndex: 'prompt_name', key: 'prompt_name', }, { title: t('Prompt_Info_Scene'), dataIndex: 'chat_scene', key: 'chat_scene', }, { title: t('Prompt_Info_Sub_Scene'), dataIndex: 'sub_chat_scene', key: 'sub_chat_scene', }, { title: t('Prompt_Info_Content'), dataIndex: 'content', key: 'content', render: (content) => ( {content} ), }, { title: t('Operation'), dataIndex: 'operate', key: 'operate', render: (_, record) => ( ), }, ]; type FormType = Ref> | undefined; const Prompt = () => { const { t } = useTranslation(); const [promptType, setPromptType] = useState('common'); const [promptList, setPromptList] = useState>(); const [loading, setLoading] = useState(false); const [prompt, setPrompt] = useState(); const [showModal, setShowModal] = useState(false); const [scenes, setScenes] = useState>>(); const formRef = useRef(); const getPrompts = async () => { setLoading(true); const body = { prompt_type: promptType, current: 1, pageSize: 1000, hideOnSinglePage: true, showQuickJumper: true, }; const [_, data] = await apiInterceptors(getPromptList(body)); setPromptList(data!); setLoading(false); }; const getScenes = async () => { const [, res] = await apiInterceptors(postScenes()); setScenes(res?.map((scene) => ({ value: scene.chat_scene, label: scene.scene_name }))); }; const onFinish = async (newPrompt: IPrompt) => { if (prompt) { await apiInterceptors(updatePrompt({ ...newPrompt, prompt_type: promptType })); } else { await apiInterceptors(addPrompt({ ...newPrompt, prompt_type: promptType })); } getPrompts(); handleClose(); }; const handleEditBtn = (prompt: IPrompt) => { setPrompt(prompt); setShowModal(true); }; const handleAddBtn = () => { setShowModal(true); setPrompt(undefined); }; const handleClose = () => { setShowModal(false); }; const handleMenuChange: MenuProps['onClick'] = (e) => { const type = e.key; setPromptType(type); }; useEffect(() => { getPrompts(); }, [promptType]); useEffect(() => { getScenes(); }, []); return (
{promptType === 'common' && ( )}
record.prompt_name} scroll={{ y: 600 }} /> { // @ts-ignore formRef.current?.submit(); }} > ); }; export default Prompt;