场站和组织增删改查
This commit is contained in:
@@ -1,149 +1,165 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Card, Table, Button, Typography, Space, Modal, Form,
|
||||
Input, Popconfirm, Select, Switch, Divider, Upload, message,
|
||||
Row, Col, Tag
|
||||
Card, Table, Button, Space, Modal, Form, Input, Popconfirm, Select,
|
||||
Switch, Divider, Row, Col, Tag, message
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined, EditOutlined, DeleteOutlined,
|
||||
BgColorsOutlined, UserOutlined, SettingOutlined
|
||||
PlusOutlined, EditOutlined, DeleteOutlined, BgColorsOutlined
|
||||
} from '@ant-design/icons';
|
||||
import {
|
||||
getStationList, saveSite, deleteSite,
|
||||
getStationRegions, saveRegion, deleteRegion
|
||||
} from '../api/stationManage';
|
||||
|
||||
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 [stationList, setStationList] = useState([]);
|
||||
const [currentStation, setCurrentStation] = useState(null);
|
||||
const [regionList, setRegionList] = useState([]);
|
||||
|
||||
// 主弹窗
|
||||
// 场站弹窗
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
const [editRecord, setEditRecord] = useState(null);
|
||||
|
||||
// 分区弹窗
|
||||
const [areaVisible, setAreaVisible] = useState(false);
|
||||
// 边界绘制弹窗
|
||||
const [regionForm] = Form.useForm();
|
||||
const [editRegion, setEditRegion] = useState(null);
|
||||
|
||||
// 地图弹窗
|
||||
const [mapVisible, setMapVisible] = useState(false);
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
|
||||
// 打开新增
|
||||
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('新增场站成功');
|
||||
// ====================== 获取场站列表 ======================
|
||||
const getStationData = () => {
|
||||
getStationList().then(res => {
|
||||
if (res.code === 200) {
|
||||
setStationList(res.rows || []);
|
||||
}
|
||||
setModalVisible(false);
|
||||
});
|
||||
};
|
||||
|
||||
// 打开分区
|
||||
const handleOpenArea = (record) => {
|
||||
setCurrentStation(record);
|
||||
setAreaVisible(true);
|
||||
useEffect(() => {
|
||||
getStationData();
|
||||
}, []);
|
||||
|
||||
// ====================== 新增 / 编辑 场站 ======================
|
||||
const handleAdd = () => {
|
||||
form.resetFields();
|
||||
setEditRecord(null);
|
||||
form.setFieldsValue({ status: 1 });
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
// 打开地图边界
|
||||
const handleEdit = (record) => {
|
||||
setEditRecord(record);
|
||||
form.setFieldsValue({ ...record, status: record.status === 1 });
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
form.validateFields().then(values => {
|
||||
const params = {
|
||||
...values,
|
||||
status: values.status ? 1 : 0
|
||||
};
|
||||
if (editRecord) {
|
||||
params.id = editRecord.id;
|
||||
}
|
||||
saveSite(params).then(res => {
|
||||
if (res.code === 200) {
|
||||
messageApi.success(editRecord ? '编辑成功' : '新增成功');
|
||||
getStationData();
|
||||
setModalVisible(false);
|
||||
} else {
|
||||
messageApi.error(res.msg || '保存失败');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// ====================== 删除场站 ======================
|
||||
const handleDelete = (id) => {
|
||||
deleteSite([id]).then(res => {
|
||||
if (res.code === 200) {
|
||||
messageApi.success('删除成功');
|
||||
getStationData();
|
||||
} else {
|
||||
messageApi.error(res.msg || '删除失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// ====================== 分区管理 ======================
|
||||
const handleOpenArea = async (record) => {
|
||||
setCurrentStation(record);
|
||||
setAreaVisible(true);
|
||||
setEditRegion(null);
|
||||
regionForm.resetFields();
|
||||
|
||||
const res = await getStationRegions({ id: record.id });
|
||||
if (res.code === 200) setRegionList(res.data || []);
|
||||
};
|
||||
|
||||
const handleSaveRegion = () => {
|
||||
regionForm.validateFields().then(values => {
|
||||
const params = {
|
||||
...values,
|
||||
siteId: currentStation.id,
|
||||
status: values.status ? 1 : 0
|
||||
};
|
||||
if (editRegion) params.id = editRegion.id;
|
||||
|
||||
saveRegion(params).then(res => {
|
||||
if (res.code === 200) {
|
||||
messageApi.success('保存成功');
|
||||
getStationRegions({ id: currentStation.id }).then(r => {
|
||||
setRegionList(r.data || []);
|
||||
});
|
||||
setEditRegion(null);
|
||||
regionForm.resetFields();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const handleDeleteRegion = (id) => {
|
||||
deleteRegion([id]).then(res => {
|
||||
if (res.code === 200) {
|
||||
messageApi.success('删除成功');
|
||||
setRegionList(regionList.filter(x => x.id !== id));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// ====================== 边界绘制 ======================
|
||||
const handleOpenMap = (record) => {
|
||||
setCurrentStation(record);
|
||||
setMapVisible(true);
|
||||
};
|
||||
|
||||
// ====================== 表格列 ======================
|
||||
const columns = [
|
||||
{ title: '场站名称', dataIndex: 'name' },
|
||||
{ title: '场站编号', dataIndex: 'code' },
|
||||
{ title: '场站名称', dataIndex: 'siteName' },
|
||||
{ title: '场站编号', dataIndex: 'siteCode' },
|
||||
{ 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>
|
||||
render: s => s === 1 ? <Tag color="green">启用</Tag> : <Tag color="red">停用</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>
|
||||
|
||||
<Button icon={<EditOutlined />} onClick={() => handleEdit(record)}>编辑</Button>
|
||||
<Button icon={<BgColorsOutlined />} onClick={() => handleOpenArea(record)}>分区设置</Button>
|
||||
<Button onClick={() => handleOpenMap(record)}>边界绘制</Button>
|
||||
<Popconfirm title="确定删除?" onConfirm={() => handleDelete(record.id)}>
|
||||
<Button type="link" danger>删除</Button>
|
||||
<Button danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
@@ -151,137 +167,157 @@ export default function StationManage() {
|
||||
];
|
||||
|
||||
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>
|
||||
<div style={{ padding: '20px' }}>
|
||||
{contextHolder}
|
||||
|
||||
{/* 统一卡片样式 */}
|
||||
<Card title="场站管理" style={{ borderRadius: 8 }}>
|
||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||
<div></div>
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>
|
||||
新增场站
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<Table
|
||||
rowKey="id"
|
||||
columns={columns}
|
||||
dataSource={stationList}
|
||||
pagination={{ pageSize: 10 }}
|
||||
pagination={true}
|
||||
bordered
|
||||
size="middle"
|
||||
/>
|
||||
</Card>
|
||||
|
||||
{/* ====================== 1. 新增/编辑场站 ====================== */}
|
||||
{/* ====================== 场站弹窗 ====================== */}
|
||||
<Modal
|
||||
title={editRecord ? '编辑场站' : '新增场站'}
|
||||
open={modalVisible}
|
||||
width={650}
|
||||
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 name="siteName" label="场站名称" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item name="code" label="场站编号" rules={[{ required: true }]}>
|
||||
<Input placeholder="唯一编号" />
|
||||
<Form.Item name="siteCode" label="场站编号" rules={[{ required: true }]}>
|
||||
<Input placeholder="唯一编码" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Form.Item name="address" label="场站地址">
|
||||
<Input placeholder="详细地址" />
|
||||
<Form.Item name="orgId" label="所属组织ID">
|
||||
<Input placeholder="选填" />
|
||||
</Form.Item>
|
||||
|
||||
<Divider orientation="left">联系人与运维单位</Divider>
|
||||
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item name="contact" label="场站联系人">
|
||||
<Input />
|
||||
<Form.Item name="longitude" label="经度">
|
||||
<Input placeholder="经度" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item name="phone" label="联系电话">
|
||||
<Input />
|
||||
<Form.Item name="latitude" label="纬度">
|
||||
<Input placeholder="纬度" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Form.Item name="maintainCompany" label="运维单位">
|
||||
<Input placeholder="负责运维的公司" />
|
||||
<Form.Item name="address" label="详细地址">
|
||||
<Input placeholder="地址" />
|
||||
</Form.Item>
|
||||
|
||||
<Divider />
|
||||
<Form.Item name="remark" label="备注">
|
||||
<Input.TextArea rows={3} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="status" label="是否启用" valuePropName="checked">
|
||||
<Form.Item name="status" label="状态" valuePropName="checked">
|
||||
<Switch checkedChildren="启用" unCheckedChildren="停用" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
{/* ====================== 2. 场站分区设置 ====================== */}
|
||||
{/* ====================== 分区弹窗 ====================== */}
|
||||
<Modal
|
||||
title={`【${currentStation?.name}】分区设置`}
|
||||
title={`【${currentStation?.siteName}】分区设置`}
|
||||
open={areaVisible}
|
||||
width={600}
|
||||
width={650}
|
||||
onCancel={() => setAreaVisible(false)}
|
||||
footer={null}
|
||||
>
|
||||
<div className="mb-2">
|
||||
<Button size="small" type="primary">新增分区</Button>
|
||||
</div>
|
||||
<Form form={regionForm} layout="vertical" style={{ marginBottom: 16 }}>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item name="regionName" label="分区名称" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item name="regionCode" label="分区编码" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item name="type" label="分区类型">
|
||||
<Select><Option value="清扫区">清扫区</Option><Option value="巡检区">巡检区</Option></Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item name="status" label="状态" valuePropName="checked">
|
||||
<Switch checkedChildren="启用" unCheckedChildren="停用" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<Form.Item name="remark" label="备注"><Input.TextArea rows={2} /></Form.Item>
|
||||
<Button type="primary" onClick={handleSaveRegion}>保存分区</Button>
|
||||
</Form>
|
||||
|
||||
<Table
|
||||
size="small"
|
||||
size="middle"
|
||||
rowKey="id"
|
||||
pagination={false}
|
||||
bordered
|
||||
columns={[
|
||||
{ title: '分区名称', dataIndex: 'name' },
|
||||
{ title: '分区名称', dataIndex: 'regionName' },
|
||||
{ title: '编码', dataIndex: 'regionCode' },
|
||||
{ title: '类型', dataIndex: 'type' },
|
||||
{
|
||||
title: '状态', render: (_, r) => r.status === 0 ? '正常' : '禁用'
|
||||
title: '状态', render: r => r.status === 1 ? '启用' : '停用'
|
||||
},
|
||||
{
|
||||
title: '操作', render: () => (
|
||||
<Space size="small">
|
||||
<Button size="small" type="link">编辑</Button>
|
||||
<Button size="small" type="link" danger>删除</Button>
|
||||
title: '操作', render: (_, r) => (
|
||||
<Space>
|
||||
<Button onClick={() => { setEditRegion(r); regionForm.setFieldsValue(r); }}>编辑</Button>
|
||||
<Button danger onClick={() => handleDeleteRegion(r.id)}>删除</Button>
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
]}
|
||||
dataSource={areaData.filter(a => a.stationId === currentStation?.id)}
|
||||
dataSource={regionList}
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
{/* ====================== 3. 场站边界绘制 & 地图维护 ====================== */}
|
||||
{/* ====================== 地图绘制 ====================== */}
|
||||
<Modal
|
||||
title={`【${currentStation?.name}】边界绘制 & 地图维护`}
|
||||
title={`【${currentStation?.siteName}】边界绘制`}
|
||||
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>
|
||||
<div style={{ height: 400, background: '#f5f5f5', borderRadius: 8, display: 'flex', alignItems: 'center', justifyContent: 'center', flexDirection: 'column' }}>
|
||||
地图区域绘制(可自行接入高德/百度地图)
|
||||
<Space style={{ marginTop: 20 }}>
|
||||
<Button type="primary">开始绘制</Button>
|
||||
<Button>清除边界</Button>
|
||||
<Button>保存地图数据</Button>
|
||||
<Button>保存边界</Button>
|
||||
</Space>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
Reference in New Issue
Block a user