291 lines
7.6 KiB
TypeScript
291 lines
7.6 KiB
TypeScript
|
|
import React, { useState } from 'react';
|
|||
|
|
import {
|
|||
|
|
Card, Table, Button, Typography, Space, Modal, Form,
|
|||
|
|
Input, Popconfirm, Select, Switch, Divider, Upload, message,
|
|||
|
|
Row, Col, Tag
|
|||
|
|
} from 'antd';
|
|||
|
|
import {
|
|||
|
|
PlusOutlined, EditOutlined, DeleteOutlined,
|
|||
|
|
BgColorsOutlined, UserOutlined, SettingOutlined
|
|||
|
|
} from '@ant-design/icons';
|
|||
|
|
|
|||
|
|
const { Title } = Typography;
|
|||
|
|
const { Option } = Select;
|
|||
|
|
|
|||
|
|
// 模拟场站数据
|
|||
|
|
const stationData = [
|
|||
|
|
{
|
|||
|
|
id: 1,
|
|||
|
|
name: '上海浦东光伏场站',
|
|||
|
|
code: 'PD001',
|
|||
|
|
address: '上海市浦东新区光伏大道',
|
|||
|
|
status: 0,
|
|||
|
|
contact: '张三',
|
|||
|
|
phone: '13800138000',
|
|||
|
|
maintainCompany: '上海新能源运维公司',
|
|||
|
|
areaCount: 3,
|
|||
|
|
hasMap: true,
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
id: 2,
|
|||
|
|
name: '苏州昆山储能电站',
|
|||
|
|
code: 'KS001',
|
|||
|
|
address: '苏州市昆山市能源路',
|
|||
|
|
status: 1,
|
|||
|
|
contact: '李四',
|
|||
|
|
phone: '13900139000',
|
|||
|
|
maintainCompany: '苏州智慧运维有限公司',
|
|||
|
|
areaCount: 2,
|
|||
|
|
hasMap: false,
|
|||
|
|
},
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
// 场站分区模拟
|
|||
|
|
const areaData = [
|
|||
|
|
{ id: 1, stationId: 1, name: 'A区', type: '清扫区', status: 0 },
|
|||
|
|
{ id: 2, stationId: 1, name: 'B区', type: '巡检区', status: 0 },
|
|||
|
|
{ id: 3, stationId: 1, name: 'C区', type: '禁飞区', status: 1 },
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
export default function StationManage() {
|
|||
|
|
const [stationList, setStationList] = useState(stationData);
|
|||
|
|
const [currentStation, setCurrentStation] = useState(null);
|
|||
|
|
|
|||
|
|
// 主弹窗
|
|||
|
|
const [modalVisible, setModalVisible] = useState(false);
|
|||
|
|
const [form] = Form.useForm();
|
|||
|
|
const [editRecord, setEditRecord] = useState(null);
|
|||
|
|
|
|||
|
|
// 分区弹窗
|
|||
|
|
const [areaVisible, setAreaVisible] = useState(false);
|
|||
|
|
// 边界绘制弹窗
|
|||
|
|
const [mapVisible, setMapVisible] = useState(false);
|
|||
|
|
|
|||
|
|
// 打开新增
|
|||
|
|
const handleAdd = () => {
|
|||
|
|
form.resetFields();
|
|||
|
|
setEditRecord(null);
|
|||
|
|
setModalVisible(true);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 打开编辑
|
|||
|
|
const handleEdit = (record) => {
|
|||
|
|
form.setFieldsValue(record);
|
|||
|
|
setEditRecord(record);
|
|||
|
|
setModalVisible(true);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 删除场站
|
|||
|
|
const handleDelete = (id) => {
|
|||
|
|
setStationList(stationList.filter(s => s.id !== id));
|
|||
|
|
message.success('删除成功');
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 保存场站
|
|||
|
|
const handleSave = () => {
|
|||
|
|
form.validateFields().then(values => {
|
|||
|
|
const data = { ...values, id: editRecord?.id || Date.now() };
|
|||
|
|
if (editRecord) {
|
|||
|
|
setStationList(stationList.map(s => s.id === editRecord.id ? data : s));
|
|||
|
|
message.success('编辑成功');
|
|||
|
|
} else {
|
|||
|
|
setStationList([...stationList, data]);
|
|||
|
|
message.success('新增场站成功');
|
|||
|
|
}
|
|||
|
|
setModalVisible(false);
|
|||
|
|
});
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 打开分区
|
|||
|
|
const handleOpenArea = (record) => {
|
|||
|
|
setCurrentStation(record);
|
|||
|
|
setAreaVisible(true);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 打开地图边界
|
|||
|
|
const handleOpenMap = (record) => {
|
|||
|
|
setCurrentStation(record);
|
|||
|
|
setMapVisible(true);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
const columns = [
|
|||
|
|
{ title: '场站名称', dataIndex: 'name' },
|
|||
|
|
{ title: '场站编号', dataIndex: 'code' },
|
|||
|
|
{ title: '地址', dataIndex: 'address' },
|
|||
|
|
{
|
|||
|
|
title: '状态',
|
|||
|
|
dataIndex: 'status',
|
|||
|
|
render: (s) => s === 0 ?
|
|||
|
|
<Tag color="green">启用</Tag> :
|
|||
|
|
<Tag color="red">停用</Tag>
|
|||
|
|
},
|
|||
|
|
{ title: '负责人', dataIndex: 'contact' },
|
|||
|
|
{ title: '运维单位', dataIndex: 'maintainCompany' },
|
|||
|
|
{
|
|||
|
|
title: '分区数量',
|
|||
|
|
dataIndex: 'areaCount',
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
title: '地图数据',
|
|||
|
|
render: (_, r) => r.hasMap ?
|
|||
|
|
<Tag color="blue">已维护</Tag> :
|
|||
|
|
<Tag>未维护</Tag>
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
title: '操作',
|
|||
|
|
width: 400,
|
|||
|
|
render: (_, record) => (
|
|||
|
|
<Space wrap size="small">
|
|||
|
|
<Button type="link" icon={<EditOutlined />} onClick={() => handleEdit(record)}>编辑</Button>
|
|||
|
|
|
|||
|
|
<Button type="link" icon={<BgColorsOutlined />} onClick={() => handleOpenArea(record)}>分区设置</Button>
|
|||
|
|
|
|||
|
|
<Button type="link" onClick={() => handleOpenMap(record)}>边界绘制</Button>
|
|||
|
|
|
|||
|
|
<Popconfirm title="确定删除?" onConfirm={() => handleDelete(record.id)}>
|
|||
|
|
<Button type="link" danger>删除</Button>
|
|||
|
|
</Popconfirm>
|
|||
|
|
</Space>
|
|||
|
|
)
|
|||
|
|
}
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
return (
|
|||
|
|
<div className="space-y-4">
|
|||
|
|
<div className="flex justify-between items-center">
|
|||
|
|
<Title level={5}>场站管理</Title>
|
|||
|
|
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>
|
|||
|
|
新增场站
|
|||
|
|
</Button>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<Card>
|
|||
|
|
<Table
|
|||
|
|
rowKey="id"
|
|||
|
|
columns={columns}
|
|||
|
|
dataSource={stationList}
|
|||
|
|
pagination={{ pageSize: 10 }}
|
|||
|
|
/>
|
|||
|
|
</Card>
|
|||
|
|
|
|||
|
|
{/* ====================== 1. 新增/编辑场站 ====================== */}
|
|||
|
|
<Modal
|
|||
|
|
title={editRecord ? '编辑场站' : '新增场站'}
|
|||
|
|
open={modalVisible}
|
|||
|
|
onCancel={() => setModalVisible(false)}
|
|||
|
|
onOk={handleSave}
|
|||
|
|
width={700}
|
|||
|
|
destroyOnClose
|
|||
|
|
>
|
|||
|
|
<Form form={form} layout="vertical">
|
|||
|
|
<Row gutter={16}>
|
|||
|
|
<Col span={12}>
|
|||
|
|
<Form.Item name="name" label="场站名称" rules={[{ required: true }]}>
|
|||
|
|
<Input placeholder="请输入场站名称" />
|
|||
|
|
</Form.Item>
|
|||
|
|
</Col>
|
|||
|
|
<Col span={12}>
|
|||
|
|
<Form.Item name="code" label="场站编号" rules={[{ required: true }]}>
|
|||
|
|
<Input placeholder="唯一编号" />
|
|||
|
|
</Form.Item>
|
|||
|
|
</Col>
|
|||
|
|
</Row>
|
|||
|
|
|
|||
|
|
<Form.Item name="address" label="场站地址">
|
|||
|
|
<Input placeholder="详细地址" />
|
|||
|
|
</Form.Item>
|
|||
|
|
|
|||
|
|
<Divider orientation="left">联系人与运维单位</Divider>
|
|||
|
|
|
|||
|
|
<Row gutter={16}>
|
|||
|
|
<Col span={12}>
|
|||
|
|
<Form.Item name="contact" label="场站联系人">
|
|||
|
|
<Input />
|
|||
|
|
</Form.Item>
|
|||
|
|
</Col>
|
|||
|
|
<Col span={12}>
|
|||
|
|
<Form.Item name="phone" label="联系电话">
|
|||
|
|
<Input />
|
|||
|
|
</Form.Item>
|
|||
|
|
</Col>
|
|||
|
|
</Row>
|
|||
|
|
|
|||
|
|
<Form.Item name="maintainCompany" label="运维单位">
|
|||
|
|
<Input placeholder="负责运维的公司" />
|
|||
|
|
</Form.Item>
|
|||
|
|
|
|||
|
|
<Divider />
|
|||
|
|
|
|||
|
|
<Form.Item name="status" label="是否启用" valuePropName="checked">
|
|||
|
|
<Switch checkedChildren="启用" unCheckedChildren="停用" />
|
|||
|
|
</Form.Item>
|
|||
|
|
</Form>
|
|||
|
|
</Modal>
|
|||
|
|
|
|||
|
|
{/* ====================== 2. 场站分区设置 ====================== */}
|
|||
|
|
<Modal
|
|||
|
|
title={`【${currentStation?.name}】分区设置`}
|
|||
|
|
open={areaVisible}
|
|||
|
|
width={600}
|
|||
|
|
onCancel={() => setAreaVisible(false)}
|
|||
|
|
footer={null}
|
|||
|
|
>
|
|||
|
|
<div className="mb-2">
|
|||
|
|
<Button size="small" type="primary">新增分区</Button>
|
|||
|
|
</div>
|
|||
|
|
<Table
|
|||
|
|
size="small"
|
|||
|
|
rowKey="id"
|
|||
|
|
pagination={false}
|
|||
|
|
columns={[
|
|||
|
|
{ title: '分区名称', dataIndex: 'name' },
|
|||
|
|
{ title: '类型', dataIndex: 'type' },
|
|||
|
|
{
|
|||
|
|
title: '状态', render: (_, r) => r.status === 0 ? '正常' : '禁用'
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
title: '操作', render: () => (
|
|||
|
|
<Space size="small">
|
|||
|
|
<Button size="small" type="link">编辑</Button>
|
|||
|
|
<Button size="small" type="link" danger>删除</Button>
|
|||
|
|
</Space>
|
|||
|
|
)
|
|||
|
|
}
|
|||
|
|
]}
|
|||
|
|
dataSource={areaData.filter(a => a.stationId === currentStation?.id)}
|
|||
|
|
/>
|
|||
|
|
</Modal>
|
|||
|
|
|
|||
|
|
{/* ====================== 3. 场站边界绘制 & 地图维护 ====================== */}
|
|||
|
|
<Modal
|
|||
|
|
title={`【${currentStation?.name}】边界绘制 & 地图维护`}
|
|||
|
|
open={mapVisible}
|
|||
|
|
width={800}
|
|||
|
|
onCancel={() => setMapVisible(false)}
|
|||
|
|
footer={null}
|
|||
|
|
>
|
|||
|
|
<div style={{
|
|||
|
|
height: 400,
|
|||
|
|
background: '#f5f5f5',
|
|||
|
|
borderRadius: 8,
|
|||
|
|
display: 'flex',
|
|||
|
|
alignItems: 'center',
|
|||
|
|
justifyContent: 'center',
|
|||
|
|
flexDirection: 'column',
|
|||
|
|
gap: 16
|
|||
|
|
}}>
|
|||
|
|
{/*<MapOutlined style={{ fontSize: 48, color: '#1677ff' }} />*/}
|
|||
|
|
<div>地图组件 / 百度地图 / 高德地图 区域绘制</div>
|
|||
|
|
<div style={{ color: '#888' }}>支持:边界点绘制、电子围栏、导入KML、保存GeoJSON</div>
|
|||
|
|
|
|||
|
|
<Space>
|
|||
|
|
<Button type="primary">开始绘制</Button>
|
|||
|
|
<Button>清除边界</Button>
|
|||
|
|
<Button>保存地图数据</Button>
|
|||
|
|
</Space>
|
|||
|
|
</div>
|
|||
|
|
</Modal>
|
|||
|
|
</div>
|
|||
|
|
);
|
|||
|
|
}
|