feat[景区管理]:后台管理界面新增景区管理模块,以及部分代码优化等逻辑
This commit is contained in:
@@ -57,6 +57,10 @@
|
||||
{
|
||||
path: '/orders/orderFiles.html',
|
||||
component: './orders/OrderFile',
|
||||
},
|
||||
{
|
||||
path: '/orders/tourism.html',
|
||||
component: './orders/Tourism',
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
@@ -11,7 +11,7 @@ import React, { useRef, useState } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const handleDelete = async (deletefile: ORDERS.orderFile) => {
|
||||
const handleDelete = async (deletefile: ORDERS.OrderFile) => {
|
||||
const hide = message.loading('正在删除');
|
||||
try {
|
||||
const result = await deleteFile(deletefile.id);
|
||||
@@ -33,7 +33,7 @@ const handleDelete = async (deletefile: ORDERS.orderFile) => {
|
||||
const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({ });
|
||||
const columns: ProColumns<ORDERS.orderFile>[] = [
|
||||
const columns: ProColumns<ORDERS.OrderFile>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
@@ -94,7 +94,7 @@ const TableList: React.FC = () => {
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.orderFile>
|
||||
<ProTable<ORDERS.OrderFile>
|
||||
rowKey="id"
|
||||
headerTitle="任务列表"
|
||||
request={orderFiles}
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Form } from 'antd';
|
||||
|
||||
export type FormValueType = Partial<ORDERS.Tourism>;
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onVisibleChange: (flag: boolean) => void;
|
||||
onSubmit: (values: FormValueType) => Promise<void>;
|
||||
updateModalVisible: boolean;
|
||||
values?: ORDERS.Tourism;
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const [form] = Form.useForm();
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改景区"
|
||||
form={form}
|
||||
visible={props.updateModalVisible}
|
||||
onFinish={props.onSubmit}
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '名称不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismName"
|
||||
label="名称"
|
||||
placeholder="输入名称"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '地址不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismAddress"
|
||||
label="地址"
|
||||
placeholder="输入地址"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '手机号不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismPhone"
|
||||
label="手机号"
|
||||
placeholder="输入手机号"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateForm;
|
||||
@@ -0,0 +1 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
@@ -0,0 +1,259 @@
|
||||
import UpdateForm from '@/pages/orders/Tourism/components/UpdateForm';
|
||||
import { tourism, saveOrUpdateTourism, deleteTourism } from '@/services/orders/api';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
ModalForm,
|
||||
PageContainer,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, message, Popconfirm, Button, Space } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const handleAdd = async (fields: ORDERS.Tourism) => {
|
||||
const hide = message.loading('正在添加');
|
||||
try {
|
||||
const result = await saveOrUpdateTourism({ ...fields });
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('添加用户成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('添加用户失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = async (fields: ORDERS.Tourism) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const result = await saveOrUpdateTourism({ ...fields });
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('修改景区成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('修改景区失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
const handleDelete = async (tourism: ORDERS.Tourism) => {
|
||||
const hide = message.loading('正在删除');
|
||||
try {
|
||||
const result = await deleteTourism(tourism.id);
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('删除景区成功');
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('删除景区失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<ORDERS.Tourism>();
|
||||
const columns: ProColumns<ORDERS.Tourism>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
},
|
||||
{
|
||||
title: 'ID',
|
||||
dataIndex: 'id',
|
||||
},
|
||||
{
|
||||
title: '编号',
|
||||
dataIndex: 'tourismNo',
|
||||
},
|
||||
{
|
||||
title: '名称',
|
||||
dataIndex: 'tourismName',
|
||||
},
|
||||
{
|
||||
title: '地址',
|
||||
dataIndex: 'tourismAddress',
|
||||
},
|
||||
{
|
||||
title: '联系电话',
|
||||
dataIndex: 'tourismPhone',
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, entity) =>
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(entity);
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除景区[${entity.tourismName}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleDelete(entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '管理景区' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
span={6}
|
||||
className="query-filter"
|
||||
onFinish={async (values) => setParams(values)}
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.Tourism>
|
||||
rowKey="id"
|
||||
headerTitle="景区列表"
|
||||
request={tourism}
|
||||
actionRef={actionRef}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={params}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
handleModalVisible(true);
|
||||
}}
|
||||
>
|
||||
<PlusOutlined /> 添加
|
||||
</Button>
|
||||
</>,
|
||||
]}
|
||||
/>
|
||||
<ModalForm
|
||||
title="添加景区"
|
||||
// layout="horizontal"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={handleModalVisible}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (values) => {
|
||||
|
||||
const success = await handleAdd(values);
|
||||
if (success) {
|
||||
handleModalVisible(false);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '名称不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismName"
|
||||
label="名称"
|
||||
placeholder="输入名称"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '地址不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismAddress"
|
||||
label="地址"
|
||||
placeholder="输入地址"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '手机号不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismPhone"
|
||||
label="手机号"
|
||||
placeholder="输入手机号"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
<UpdateForm
|
||||
onSubmit={async (values) => {
|
||||
if (currentRow) {
|
||||
|
||||
const success = await handleEdit({ ...currentRow, ...values });
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
}}
|
||||
onVisibleChange={handleUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
/>
|
||||
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default TableList;
|
||||
@@ -21,9 +21,34 @@ export async function deleteFile(id: number) {
|
||||
|
||||
export async function orderFiles(params?: { [key: string]: string | number }) {
|
||||
const { current, pageSize, ...rest } = params ?? {};
|
||||
const result = await request<SYSTEM.Page<ORDERS.orderFile>>('/api-order/files', {
|
||||
const result = await request<SYSTEM.Page<ORDERS.OrderFile>>('/api-order/files', {
|
||||
method: 'GET',
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
});
|
||||
return { data: result.data, total: result.count };
|
||||
}
|
||||
|
||||
export async function tourism(params?: { [key: string]: string | number }) {
|
||||
const { current, pageSize, ...rest } = params ?? {};
|
||||
const result = await request<SYSTEM.Page<ORDERS.Tourism>>('/api-order/tourism', {
|
||||
method: 'GET',
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
});
|
||||
return { data: result.data, total: result.count };
|
||||
}
|
||||
|
||||
export async function saveOrUpdateTourism(data: ORDERS.Tourism): Promise<API.Result<ORDERS.Tourism>> {
|
||||
const result = await request<API.Result<ORDERS.Tourism>>('/api-order/tourism', {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deleteTourism(id: number) {
|
||||
const url = `/api-order/tourism/${id}`;
|
||||
const result = await request<API.Result<void>>(url, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
return result;
|
||||
}
|
||||
@@ -12,15 +12,28 @@ declare namespace ORDERS {
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
type orderFile = {
|
||||
type OrderFile = {
|
||||
id: number;
|
||||
userId: string;
|
||||
fileId: string;
|
||||
filePath: string;
|
||||
orderNo: string;
|
||||
file_type: string;
|
||||
fileType: string;
|
||||
createTime?: string;
|
||||
tenantId?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
type Tourism = {
|
||||
id: number;
|
||||
tourismName: string;
|
||||
tourismDesc: string;
|
||||
tourismNo: string;
|
||||
tourismAddress: string;
|
||||
tourismPhone: string;
|
||||
createTime?: string;
|
||||
status: number;
|
||||
tenantId?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user