Commit 3ee09474 authored by Ylg's avatar Ylg

complete prompt word page

parent 5539db75
......@@ -31,16 +31,16 @@ const EditPromptModal = (props: IEditPromptModalProps) => {
}
}, [open])
const handleSavePrompt = () => {
const handleSavePrompt = async () => {
if(modalType === 'create') {
handleCreatePrompt({
await handleCreatePrompt({
type: currentSelectValue,
content: textAreaValue,
});
}
if(modalType === 'edit') {
handleEditPrompt({
await handleEditPrompt({
type: currentSelectValue,
content: textAreaValue,
})
......
......@@ -19,10 +19,12 @@ const DeletePromptModal = (props: IDeletePromptModalProps) => {
tip,
content,
loading,
handleDeletePrompt,
} = props;
const handleDeletePrompt = () => {
handleDeletePrompt();
const handleSavePrompt = async () => {
await handleDeletePrompt();
setOpen(false);
}
return (
......@@ -30,7 +32,7 @@ const DeletePromptModal = (props: IDeletePromptModalProps) => {
title={title}
okText='确认'
open={open}
onOk={handleDeletePrompt}
onOk={handleSavePrompt}
onCancel={() => {
setOpen(false);
}}
......
import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
import type { ActionType } from '@ant-design/pro-components';
import { PageContainer } from '@ant-design/pro-components';
import { ActionType, PageContainer } 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 { SetStateAction, useEffect, useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import styles from './index.less';
import EditPromptModal from '@/components/EditAndAddPromptModal';
import DeletePromptModal from '@/components/DeletePromptModal';
......@@ -32,6 +31,9 @@ interface ILoading {
}
const PromptWord = () => {
const actionRef = useRef<ActionType>();
const [allLoading, setAllLoading] = useState<ILoading>({
editModalLoading: false,
createModalLoading: false,
......@@ -47,16 +49,9 @@ const PromptWord = () => {
const [currentRow, setCurrentRaw] = useState({} as IPromptList);
const columns: any[] = [
{
title: '序号',
width: '10%',
key: 'sequenceNumber',
dataIndex: 'sequenceNumber',
search: false,
},
{
title: '类型',
width: '15%',
width: '20%',
key: 'type',
dataIndex: 'type',
valueType: 'select',
......@@ -72,7 +67,7 @@ const PromptWord = () => {
},
{
title: '提示词语',
width: '45%',
width: '40%',
key: 'promptWord',
dataIndex: 'content',
ellipsis: true,
......@@ -81,7 +76,7 @@ const PromptWord = () => {
},
{
title: '创建时间',
width: '15%',
width: '25%',
key: 'creationTime',
dataIndex: 'creationTime',
search: false,
......@@ -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 data = await typePromptWords();
setTypes(data);
};
useEffect(() => {
fetchPromptList();
fetchTypes();
}, []);
const handleEditPrompt = async (editValue: IFormValue) => {
setAllLoading({
...allLoading,
editModalLoading: true,
})
setAllLoading({ ...allLoading, editModalLoading: true });
try {
await updatePromptWords({
id: currentRow.id,
content: editValue.content,
type: editValue.type
});
setAllLoading({
...allLoading,
editModalLoading: false,
})
fetchPromptList();
setAllLoading({ ...allLoading, editModalLoading: false });
actionRef.current?.reload();
} catch(error) {
setAllLoading({
...allLoading,
editModalLoading: false,
})
setAllLoading({ ...allLoading, editModalLoading: false });
message.error('编辑提示用语失败,请重试!')
}
};
const handleCreatePrompt = async (createValue: IFormValue) => {
setAllLoading({
...allLoading,
createModalLoading: true,
})
setAllLoading({ ...allLoading, createModalLoading: true });
try {
await createPromptWords({
content: createValue.content,
type: createValue.type
})
setAllLoading({
...allLoading,
createModalLoading: false,
})
fetchPromptList();
setAllLoading({ ...allLoading, createModalLoading: false });
actionRef.current?.reload();
} catch(error) {
setAllLoading({
...allLoading,
createModalLoading: false,
})
setAllLoading({ ...allLoading, createModalLoading: false });
message.error('新增提示用语失败,请重试!')
}
};
const handleDeletePrompt = async () => {
setAllLoading({
...allLoading,
deleteModalLoading: true,
})
setAllLoading({ ...allLoading, deleteModalLoading: true });
try {
await deletePromptWords({
id: currentRow.id
});
setAllLoading({
...allLoading,
deleteModalLoading: false,
})
fetchPromptList();
setAllLoading({ ...allLoading, deleteModalLoading: false });
actionRef.current?.reload();
} catch(error) {
setAllLoading({
...allLoading,
deleteModalLoading: false,
})
setAllLoading({ ...allLoading, deleteModalLoading: false });
message.error('删除提示用语失败,请重试!')
}
};
......@@ -256,25 +192,38 @@ const PromptWord = () => {
loading={modalType === 'create' ? allLoading.createModalLoading : allLoading.editModalLoading}
/>
<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}
cardBordered
rowKey="id"
pagination={{
pageSize: 5,
onChange: (page) => {
},
}}
search={{
labelWidth: 'auto',
className: styles.search,
optionRender: () => {
return [
<Button type='default' key='2'>重置</Button>,
<Button type='primary' key='3'>查询</Button>
]
}
pageSize: 10,
}}
options={false}
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