Commit 3ee09474 authored by Ylg's avatar Ylg

complete prompt word page

parent 5539db75
...@@ -31,16 +31,16 @@ const EditPromptModal = (props: IEditPromptModalProps) => { ...@@ -31,16 +31,16 @@ const EditPromptModal = (props: IEditPromptModalProps) => {
} }
}, [open]) }, [open])
const handleSavePrompt = () => { const handleSavePrompt = async () => {
if(modalType === 'create') { if(modalType === 'create') {
handleCreatePrompt({ await handleCreatePrompt({
type: currentSelectValue, type: currentSelectValue,
content: textAreaValue, content: textAreaValue,
}); });
} }
if(modalType === 'edit') { if(modalType === 'edit') {
handleEditPrompt({ await handleEditPrompt({
type: currentSelectValue, type: currentSelectValue,
content: textAreaValue, content: textAreaValue,
}) })
......
...@@ -19,10 +19,12 @@ const DeletePromptModal = (props: IDeletePromptModalProps) => { ...@@ -19,10 +19,12 @@ const DeletePromptModal = (props: IDeletePromptModalProps) => {
tip, tip,
content, content,
loading, loading,
handleDeletePrompt,
} = props; } = props;
const handleDeletePrompt = () => { const handleSavePrompt = async () => {
handleDeletePrompt(); await handleDeletePrompt();
setOpen(false);
} }
return ( return (
...@@ -30,7 +32,7 @@ const DeletePromptModal = (props: IDeletePromptModalProps) => { ...@@ -30,7 +32,7 @@ const DeletePromptModal = (props: IDeletePromptModalProps) => {
title={title} title={title}
okText='确认' okText='确认'
open={open} open={open}
onOk={handleDeletePrompt} onOk={handleSavePrompt}
onCancel={() => { onCancel={() => {
setOpen(false); setOpen(false);
}} }}
......
import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons'; import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
import type { ActionType } from '@ant-design/pro-components'; import { ActionType, PageContainer } from '@ant-design/pro-components';
import { PageContainer } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components'; import { ProTable } from '@ant-design/pro-components';
import { Button, Col, Divider, Form, Input, Modal, Radio, Row, Select, Switch, message } from 'antd'; import { Button, message } from 'antd';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { SetStateAction, useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import styles from './index.less'; import styles from './index.less';
import EditPromptModal from '@/components/EditAndAddPromptModal'; import EditPromptModal from '@/components/EditAndAddPromptModal';
import DeletePromptModal from '@/components/DeletePromptModal'; import DeletePromptModal from '@/components/DeletePromptModal';
...@@ -32,6 +31,9 @@ interface ILoading { ...@@ -32,6 +31,9 @@ interface ILoading {
} }
const PromptWord = () => { const PromptWord = () => {
const actionRef = useRef<ActionType>();
const [allLoading, setAllLoading] = useState<ILoading>({ const [allLoading, setAllLoading] = useState<ILoading>({
editModalLoading: false, editModalLoading: false,
createModalLoading: false, createModalLoading: false,
...@@ -47,16 +49,9 @@ const PromptWord = () => { ...@@ -47,16 +49,9 @@ const PromptWord = () => {
const [currentRow, setCurrentRaw] = useState({} as IPromptList); const [currentRow, setCurrentRaw] = useState({} as IPromptList);
const columns: any[] = [ const columns: any[] = [
{
title: '序号',
width: '10%',
key: 'sequenceNumber',
dataIndex: 'sequenceNumber',
search: false,
},
{ {
title: '类型', title: '类型',
width: '15%', width: '20%',
key: 'type', key: 'type',
dataIndex: 'type', dataIndex: 'type',
valueType: 'select', valueType: 'select',
...@@ -72,7 +67,7 @@ const PromptWord = () => { ...@@ -72,7 +67,7 @@ const PromptWord = () => {
}, },
{ {
title: '提示词语', title: '提示词语',
width: '45%', width: '40%',
key: 'promptWord', key: 'promptWord',
dataIndex: 'content', dataIndex: 'content',
ellipsis: true, ellipsis: true,
...@@ -81,7 +76,7 @@ const PromptWord = () => { ...@@ -81,7 +76,7 @@ const PromptWord = () => {
}, },
{ {
title: '创建时间', title: '创建时间',
width: '15%', width: '25%',
key: 'creationTime', key: 'creationTime',
dataIndex: 'creationTime', dataIndex: 'creationTime',
search: false, search: false,
...@@ -120,116 +115,57 @@ const PromptWord = () => { ...@@ -120,116 +115,57 @@ const PromptWord = () => {
}, },
]; ];
const fetchPromptList = async () => {
setAllLoading({
...allLoading,
listLoading: true,
})
try {
const response = await pagePromptWords({
filter: '',
type: '',
pageIndex: 0,
pageSize: 10
})
setAllLoading({
...allLoading,
listLoading: false,
})
const dataSource: IPromptList[] = response.items.map((item: IPromptList) => {
return {
...item,
}
})
setPromptList(dataSource);
} catch(error) {
setAllLoading({
...allLoading,
listLoading: false,
})
message.error('请求列表失败,请重试!')
}
};
const fetchTypes = async () => { const fetchTypes = async () => {
const data = await typePromptWords(); const data = await typePromptWords();
setTypes(data); setTypes(data);
}; };
useEffect(() => { useEffect(() => {
fetchPromptList();
fetchTypes(); fetchTypes();
}, []); }, []);
const handleEditPrompt = async (editValue: IFormValue) => { const handleEditPrompt = async (editValue: IFormValue) => {
setAllLoading({ setAllLoading({ ...allLoading, editModalLoading: true });
...allLoading,
editModalLoading: true,
})
try { try {
await updatePromptWords({ await updatePromptWords({
id: currentRow.id, id: currentRow.id,
content: editValue.content, content: editValue.content,
type: editValue.type type: editValue.type
}); });
setAllLoading({ setAllLoading({ ...allLoading, editModalLoading: false });
...allLoading, actionRef.current?.reload();
editModalLoading: false,
})
fetchPromptList();
} catch(error) { } catch(error) {
setAllLoading({ setAllLoading({ ...allLoading, editModalLoading: false });
...allLoading,
editModalLoading: false,
})
message.error('编辑提示用语失败,请重试!') message.error('编辑提示用语失败,请重试!')
} }
}; };
const handleCreatePrompt = async (createValue: IFormValue) => { const handleCreatePrompt = async (createValue: IFormValue) => {
setAllLoading({ setAllLoading({ ...allLoading, createModalLoading: true });
...allLoading,
createModalLoading: true,
})
try { try {
await createPromptWords({ await createPromptWords({
content: createValue.content, content: createValue.content,
type: createValue.type type: createValue.type
}) })
setAllLoading({ setAllLoading({ ...allLoading, createModalLoading: false });
...allLoading, actionRef.current?.reload();
createModalLoading: false,
})
fetchPromptList();
} catch(error) { } catch(error) {
setAllLoading({ setAllLoading({ ...allLoading, createModalLoading: false });
...allLoading,
createModalLoading: false,
})
message.error('新增提示用语失败,请重试!') message.error('新增提示用语失败,请重试!')
} }
}; };
const handleDeletePrompt = async () => { const handleDeletePrompt = async () => {
setAllLoading({ setAllLoading({ ...allLoading, deleteModalLoading: true });
...allLoading,
deleteModalLoading: true,
})
try { try {
await deletePromptWords({ await deletePromptWords({
id: currentRow.id id: currentRow.id
}); });
setAllLoading({ setAllLoading({ ...allLoading, deleteModalLoading: false });
...allLoading, actionRef.current?.reload();
deleteModalLoading: false,
})
fetchPromptList();
} catch(error) { } catch(error) {
setAllLoading({ setAllLoading({ ...allLoading, deleteModalLoading: false });
...allLoading,
deleteModalLoading: false,
})
message.error('删除提示用语失败,请重试!') message.error('删除提示用语失败,请重试!')
} }
}; };
...@@ -256,25 +192,38 @@ const PromptWord = () => { ...@@ -256,25 +192,38 @@ const PromptWord = () => {
loading={modalType === 'create' ? allLoading.createModalLoading : allLoading.editModalLoading} loading={modalType === 'create' ? allLoading.createModalLoading : allLoading.editModalLoading}
/> />
<ProTable <ProTable
dataSource={promptList} request={async (params = { pageSize: 10, current: 0 }) => {
setAllLoading({ ...allLoading, listLoading: true });
const promptListParams = {
filter: params?.promptWord || '',
type: params?.type || '',
pageIndex: params?.current as number - 1,
pageSize: params?.pageSize,
}
try {
const response = await pagePromptWords(promptListParams);
setAllLoading({ ...allLoading, listLoading: false });
return {
data: response.items,
total: response.totalCount,
success: !isEmpty(response),
}
} catch(error) {
setAllLoading({ ...allLoading, listLoading: false });
message.error('请求列表失败,请重试!');
return {
data: [],
total: 0,
success: false,
}
}
}}
actionRef={actionRef}
columns={columns} columns={columns}
cardBordered cardBordered
rowKey="id" rowKey="id"
pagination={{ pagination={{
pageSize: 5, pageSize: 10,
onChange: (page) => {
},
}}
search={{
labelWidth: 'auto',
className: styles.search,
optionRender: () => {
return [
<Button type='default' key='2'>重置</Button>,
<Button type='primary' key='3'>查询</Button>
]
}
}} }}
options={false} options={false}
dateFormatter="string" dateFormatter="string"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment