Files
shihezi-admin/src/pages/Area/Business/index.tsx

183 lines
5.1 KiB
TypeScript
Raw Normal View History

2025-10-29 17:34:55 +08:00
import React, { Fragment, useRef, useState } from 'react';
import { history, useAccess } from '@umijs/max';
import { Button, FormInstance, message, Modal } from 'antd';
2025-01-20 17:42:05 +08:00
import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components';
2025-10-29 17:34:55 +08:00
import { DeleteOutlined, FormOutlined, PlusOutlined } from '@ant-design/icons';
2025-01-20 17:42:05 +08:00
import {
2025-10-29 17:34:55 +08:00
addCmsLineSubWay,
deleteCmsLineSubWay,
getCmsLineList,
putCmsLineSubWay,
} from '@/services/area/subway';
import SubWayEdit from '@/pages/Area/Business/edit';
import {
addCmsSaveRegionalData,
deleteCmsRegionalData,
getCmsRegionalList,
updateRegionalData,
} from '@/services/area/business';
2024-12-05 16:32:02 +08:00
2025-10-29 17:34:55 +08:00
const handleRemoveOne = async (selectedRow: API.AreaRegional.RegionalRows) => {
2024-12-05 16:32:02 +08:00
const hide = message.loading('正在删除');
if (!selectedRow) return true;
try {
2025-10-29 17:34:55 +08:00
const resp = await deleteCmsRegionalData(selectedRow.regionalId);
2024-12-05 16:32:02 +08:00
hide();
if (resp.code === 200) {
message.success('删除成功,即将刷新');
} else {
message.error(resp.msg);
}
return true;
} catch (error) {
hide();
message.error('删除失败,请重试');
return false;
}
};
2025-01-20 17:42:05 +08:00
2024-11-26 16:43:31 +08:00
function ManagementList() {
const access = useAccess();
const formTableRef = useRef<FormInstance>();
const actionRef = useRef<ActionType>();
2025-10-29 17:34:55 +08:00
const [currentRow, setCurrentRow] = useState<API.AreaSubWay.Line>();
const [modalVisible, setModalVisible] = useState<boolean>(false);
2024-11-26 16:43:31 +08:00
2025-10-29 17:34:55 +08:00
const columns: ProColumns<API.AreaRegional.RegionalRows>[] = [
2024-11-26 16:43:31 +08:00
{
2025-10-29 17:34:55 +08:00
title: '区域名称',
dataIndex: 'regionalName',
2024-12-05 16:32:02 +08:00
align: 'center',
2025-10-29 17:34:55 +08:00
valueType: 'text',
render: (dom, record) => (
<Button
type="link"
onClick={() => history.push(`/area/updata-router/business/${record.regionalId}`)}
block
>
{dom}
</Button>
),
2024-11-26 16:43:31 +08:00
},
2024-12-05 16:32:02 +08:00
{
title: '操作',
2025-10-29 17:34:55 +08:00
hideInSearch: true,
2024-12-05 16:32:02 +08:00
align: 'center',
2025-01-20 17:42:05 +08:00
width: 300,
2024-12-05 16:32:02 +08:00
render: (_, record) => [
<Button
type="link"
size="small"
key="edit"
2025-10-29 17:34:55 +08:00
icon={<FormOutlined />}
2025-01-20 17:42:05 +08:00
hidden={!access.hasPerms('area:business:List.update')}
2024-12-05 16:32:02 +08:00
onClick={() => {
setModalVisible(true);
setCurrentRow(record);
}}
>
</Button>,
<Button
type="link"
size="small"
danger
key="batchRemove"
2025-10-29 17:34:55 +08:00
icon=<DeleteOutlined />
hidden={!access.hasPerms('area:subway:List')}
2024-12-05 16:32:02 +08:00
onClick={async () => {
Modal.confirm({
title: '删除',
content: '确定删除该项吗?',
okText: '确认',
cancelText: '取消',
onOk: async () => {
const success = await handleRemoveOne(record);
if (success) {
if (actionRef.current) {
actionRef.current.reload();
}
}
},
});
}}
>
2025-10-29 17:34:55 +08:00
</Button>,
],
},
];
2024-11-26 16:43:31 +08:00
return (
<Fragment>
<div style={{ width: '100%', float: 'right' }}>
2025-10-29 17:34:55 +08:00
<ProTable<API.AreaSubWay.Line>
2024-11-26 16:43:31 +08:00
// params 是需要自带的参数
// 这个参数优先级更高,会覆盖查询表单的参数
actionRef={actionRef}
formRef={formTableRef}
columns={columns}
2025-10-29 17:34:55 +08:00
headerTitle="信息"
rowKey="regionalId"
key="lineIdList"
request={(params) => {
return getCmsRegionalList(params as API.AreaRegional.RegionalParams).then((res) => {
console.log(params);
const result = {
2024-11-26 16:43:31 +08:00
data: res.rows,
total: res.total,
success: true,
2025-10-29 17:34:55 +08:00
};
return result;
});
}}
2024-11-26 16:43:31 +08:00
toolBarRender={() => [
<Button
type="primary"
key="add"
2025-01-20 17:42:05 +08:00
hidden={!access.hasPerms('manage:List:add')}
2024-11-26 16:43:31 +08:00
onClick={async () => {
setCurrentRow(undefined);
setModalVisible(true);
}}
>
<PlusOutlined />
</Button>,
]}
/>
</div>
2025-10-29 17:34:55 +08:00
<SubWayEdit
2024-12-05 16:32:02 +08:00
open={modalVisible}
onSubmit={async (values) => {
2025-10-29 17:34:55 +08:00
let resData;
if (values.regionalId) {
resData = await updateRegionalData(values);
2024-12-05 16:32:02 +08:00
} else {
2025-10-29 17:34:55 +08:00
resData = await addCmsSaveRegionalData(values);
2024-12-05 16:32:02 +08:00
}
if (resData.code === 200) {
setModalVisible(false);
setCurrentRow(undefined);
2025-10-29 17:34:55 +08:00
if (values.regionalId) {
message.success('修改成功');
2024-12-05 16:32:02 +08:00
} else {
2025-10-29 17:34:55 +08:00
message.success('新增成功');
2024-12-05 16:32:02 +08:00
}
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
onCancel={() => {
setModalVisible(false);
2025-10-29 17:34:55 +08:00
setCurrentRow(undefined);
2024-12-05 16:32:02 +08:00
}}
2025-10-29 17:34:55 +08:00
values={currentRow}
></SubWayEdit>
2024-11-26 16:43:31 +08:00
</Fragment>
2025-10-29 17:34:55 +08:00
);
2024-11-26 16:43:31 +08:00
}
2025-10-29 17:34:55 +08:00
export default ManagementList;