import { apiInterceptors, deletePrompt, getPromptList } from '@/client/api'; import useUser from '@/hooks/use-user'; import ConstructLayout from '@/new-components/layout/Construct'; import { IPrompt, PromptListResponse } from '@/types/prompt'; import { PlusOutlined } from '@ant-design/icons'; import { useRequest } from 'ahooks'; import type { SegmentedProps } from 'antd'; import { App, Button, Popconfirm, Segmented, Space, Table, Typography } from 'antd'; import type { ColumnsType } from 'antd/es/table'; import { TFunction } from 'i18next'; import { useRouter } from 'next/router'; import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import styles from './styles.module.css'; const LangMap = { zh: '中文', en: 'English' }; const DeleteBtn: React.FC<{ record: IPrompt; refresh: () => void }> = ({ record, refresh }) => { const userInfo = useUser(); const { t } = useTranslation(); const { message } = App.useApp(); // 删除prompt const { run: deletePromptRun, loading: deleteLoading } = useRequest( async record => { await deletePrompt({ ...record, }); }, { manual: true, onSuccess: async () => { message.success('删除成功'); await refresh(); }, }, ); if (userInfo?.user_id !== record?.user_id) { return null; } return ( await deletePromptRun(record)}> {t('Delete')} ); }; const Prompt = () => { const router = useRouter(); const { t } = useTranslation(); const [promptType, setPromptType] = useState('common'); const [promptList, setPromptList] = useState(); const { run: getPrompts, loading, refresh, } = useRequest( async (page = 1, page_size = 6) => { const [_, data] = await apiInterceptors( getPromptList({ page, page_size, }), ); return data; }, { manual: true, onSuccess: data => { setPromptList(data!); }, }, ); const handleEditBtn = (prompt: IPrompt) => { localStorage.setItem('edit_prompt_data', JSON.stringify(prompt)); router.push('/construct/prompt/edit'); }; const handleAddBtn = () => { router.push('/construct/prompt/add'); }; const getColumns = (t: TFunction, handleEdit: (prompt: IPrompt) => void): ColumnsType => [ { title: t('Prompt_Info_Name'), dataIndex: 'prompt_name', key: 'prompt_name', width: '10%', }, { title: t('Prompt_Info_Scene'), dataIndex: 'chat_scene', key: 'chat_scene', width: '10%', }, { title: t('language'), dataIndex: 'prompt_language', key: 'prompt_language', render: lang => (lang ? LangMap[lang as keyof typeof LangMap] : '-'), width: '10%', }, { title: t('Prompt_Info_Content'), dataIndex: 'content', key: 'content', render: content => {content}, }, { title: t('Operation'), dataIndex: 'operate', key: 'operate', render: (_, record) => ( { handleEdit(record); }} type='primary' > {t('Edit')} ), }, ]; useEffect(() => { getPrompts(); }, [promptType]); const items: SegmentedProps['options'] = [ { value: 'common', label: t('Public') + ' Prompts', }, // { // value: 'private', // label: t('Private') + ' Prompts', // }, ]; return ( { setPromptType(type as string); }} value={promptType} /> {/* } placeholder={t('please_enter_the_keywords')} allowClear className="w-[230px] h-[40px] border-1 border-white backdrop-filter backdrop-blur-lg bg-white bg-opacity-30 dark:border-[#6f7f95] dark:bg-[#6f7f95] dark:bg-opacity-60" /> */} {/* {promptType === 'common' && ( } disabled> {t('Add')} Prompts {t('template')} )} */} } > {t('Add')} Prompts record.prompt_name} pagination={{ pageSize: 6, total: promptList?.total_count, onChange: async (page, page_size) => { await getPrompts(page, page_size); }, }} /> ); }; export default Prompt;