场站和组织增删改查
This commit is contained in:
36
src/api/organization/index.tsx
Normal file
36
src/api/organization/index.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import request from '../request';
|
||||
|
||||
//获取组织列表
|
||||
export function getOrgList() {
|
||||
return request({
|
||||
url: '/system/org/list',
|
||||
method: 'get',
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//获取组织列表
|
||||
export function addOrg(data) {
|
||||
return request({
|
||||
url: '/system/org/save',
|
||||
method: 'post',
|
||||
data
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export function deleteOrg(params) {
|
||||
return request({
|
||||
url: '/system/org/delete',
|
||||
method: 'get',
|
||||
params
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
63
src/api/stationManage/index.ts
Normal file
63
src/api/stationManage/index.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import request from '../request';
|
||||
|
||||
//获取组织列表
|
||||
export function getStationList() {
|
||||
return request({
|
||||
url: '/system/site/list',
|
||||
method: 'get',
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
export function saveSite(data) {
|
||||
return request({
|
||||
url: '/system/site/save',
|
||||
method: 'post',
|
||||
data
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function deleteSite(data) {
|
||||
return request({
|
||||
url: '/system/site/delete',
|
||||
method: 'post',
|
||||
data
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function getStationRegions(params) {
|
||||
return request({
|
||||
url: '/system/region/selectBySiteId',
|
||||
method: 'get',
|
||||
params
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//新增分区
|
||||
export function saveRegion(data) {
|
||||
return request({
|
||||
url: '/system/region/save',
|
||||
method: 'post',
|
||||
data
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//删除分区
|
||||
export function deleteRegion(data) {
|
||||
return request({
|
||||
url: '/system/region/delete',
|
||||
method: 'post',
|
||||
data
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -189,14 +189,14 @@ export default function MenuList() {
|
||||
return (
|
||||
<div style={{ padding: '20px' }}>
|
||||
{contextHolder}
|
||||
<Card title="菜单权限管理" style={{ borderRadius: 8 }}>
|
||||
<Card title="菜单管理" style={{ borderRadius: 8 }}>
|
||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||
<Space>
|
||||
{/*<Space>
|
||||
<Select placeholder="选择角色" style={{ width: 180 }} value={selectedRole} onChange={setSelectedRole}>
|
||||
{roleList.map(r => <Option key={r.key} value={r.key}>{r.name}</Option>)}
|
||||
</Select>
|
||||
<Button type="primary" icon={<SettingOutlined />} onClick={handlePermOpen}>配置权限</Button>
|
||||
</Space>
|
||||
</Space>*/}
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={() => {
|
||||
setEditMenu(null);
|
||||
menuForm.resetFields();
|
||||
@@ -208,7 +208,7 @@ export default function MenuList() {
|
||||
columns={columns}
|
||||
dataSource={menuTreeData}
|
||||
rowKey="menuId"
|
||||
pagination={false}
|
||||
pagination={true}
|
||||
bordered
|
||||
size="middle"
|
||||
indentSize={24}
|
||||
|
||||
@@ -1,106 +1,128 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Card, Table, Button, Typography, Space, Modal, Form, Tree, message,
|
||||
Input, Popconfirm, Select, TreeSelect
|
||||
Card, Table, Button, Typography, Space, Modal, Form, message,
|
||||
Input, Popconfirm, Select, InputNumber
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined, EditOutlined, DeleteOutlined, BuildOutlined
|
||||
PlusOutlined, EditOutlined, DeleteOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { addOrg, deleteOrg, getOrgList } from '../api/organization';
|
||||
|
||||
|
||||
|
||||
const { Title } = Typography;
|
||||
const { Option } = Select;
|
||||
|
||||
// 模拟组织数据
|
||||
const orgData = [
|
||||
{
|
||||
id: 1,
|
||||
name: '华东区域总部',
|
||||
code: 'EAST_REGION',
|
||||
parentId: 0,
|
||||
status: '0',
|
||||
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: '华北区域总部',
|
||||
code: 'NORTH_REGION',
|
||||
parentId: 0,
|
||||
status: '0',
|
||||
},
|
||||
];
|
||||
|
||||
// 转平数组用于表格
|
||||
const flatten = (list) => {
|
||||
let arr = [];
|
||||
const loop = (data) => {
|
||||
data.forEach(item => {
|
||||
arr.push(item);
|
||||
if (item.children) loop(item.children);
|
||||
});
|
||||
};
|
||||
loop(list);
|
||||
return arr;
|
||||
};
|
||||
const AntdCard = Card as any;
|
||||
|
||||
export default function Organization() {
|
||||
const [orgList, setOrgList] = useState(flatten(orgData));
|
||||
const [treeData] = useState(orgData);
|
||||
|
||||
const [orgList, setOrgList] = useState([]);
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
const [editRecord, setEditRecord] = useState(null);
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
|
||||
// 获取组织列表
|
||||
const getOrgData = () => {
|
||||
getOrgList().then(res => {
|
||||
if (res.code === 200) {
|
||||
setOrgList(res.rows || []);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getOrgData();
|
||||
}, []);
|
||||
|
||||
// 打开新增
|
||||
const handleAdd = () => {
|
||||
form.resetFields();
|
||||
setEditRecord(null);
|
||||
form.setFieldsValue({
|
||||
status: 0,
|
||||
});
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
// 打开编辑
|
||||
const handleEdit = (record) => {
|
||||
form.setFieldsValue(record);
|
||||
setEditRecord(record);
|
||||
form.setFieldsValue({ ...record });
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
// 删除
|
||||
const handleDelete = (id) => {
|
||||
setOrgList(orgList.filter(i => i.id !== id));
|
||||
message.success('删除成功');
|
||||
|
||||
|
||||
deleteOrg({ id }).then(res => {
|
||||
console.log(id, "删除")
|
||||
if (res.code == 200) {
|
||||
messageApi.success('删除成功');
|
||||
getOrgData();
|
||||
} else {
|
||||
messageApi.error(res.msg || '删除失败');
|
||||
}
|
||||
}).catch(() => {
|
||||
messageApi.error('删除失败');
|
||||
});
|
||||
};
|
||||
|
||||
// 保存
|
||||
const handleSave = () => {
|
||||
form.validateFields().then(values => {
|
||||
if (editRecord) {
|
||||
setOrgList(orgList.map(i => i.id === editRecord.id ? { ...i, ...values } : i));
|
||||
message.success('编辑成功');
|
||||
// 编辑
|
||||
const params = {
|
||||
...values,
|
||||
id: editRecord.id
|
||||
};
|
||||
addOrg(params).then(res => {
|
||||
if (res.code === 200) {
|
||||
messageApi.success('编辑成功');
|
||||
getOrgData();
|
||||
setModalVisible(false);
|
||||
} else {
|
||||
messageApi.error(res.msg || '编辑失败');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setOrgList([...orgList, { ...values, id: Date.now() }]);
|
||||
message.success('新增成功');
|
||||
// 新增
|
||||
addOrg(values).then(res => {
|
||||
if (res.code === 200) {
|
||||
messageApi.success('新增成功');
|
||||
getOrgData();
|
||||
setModalVisible(false);
|
||||
} else {
|
||||
messageApi.error(res.msg || '新增失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
setModalVisible(false);
|
||||
});
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{ title: '组织名称', dataIndex: 'name' },
|
||||
{ title: '组织编码', dataIndex: 'code' },
|
||||
{ title: '组织名称', dataIndex: 'orgName' },
|
||||
{ title: '组织编码', dataIndex: 'orgCode' },
|
||||
{ title: '负责人', dataIndex: 'manager' },
|
||||
{ title: '联系电话', dataIndex: 'phone' },
|
||||
{ title: '邮箱', dataIndex: 'email' },
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
render: s => s === '0' ?
|
||||
<Button type="text" size="small">正常</Button> :
|
||||
<Button type="text" danger size="small">禁用</Button>
|
||||
render: (s) => (
|
||||
<span className={s == 1 ? 'text-green-600' : 'text-red-600'}>
|
||||
{s == 1 ? '正常' : '禁用'}
|
||||
</span>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
render: (_, r) => (
|
||||
<Space>
|
||||
<Button type="link" icon={<EditOutlined />} onClick={() => handleEdit(r)}>编辑</Button>
|
||||
<Popconfirm title="确定删除?" onConfirm={() => handleDelete(r.id)}>
|
||||
<Button type="link" danger>删除</Button>
|
||||
<Button type="text" icon={<EditOutlined />} onClick={() => handleEdit(r)}>编辑</Button>
|
||||
<Popconfirm title="确定删除该组织?" onConfirm={() => handleDelete(r.id)}>
|
||||
<Button type="text" danger icon={<DeleteOutlined />}>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
@@ -108,42 +130,71 @@ export default function Organization() {
|
||||
];
|
||||
|
||||
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>
|
||||
{/* 统一卡片容器 */}
|
||||
<AntdCard title="组织管理" style={{ borderRadius: 8 }}>
|
||||
{/* 顶部按钮 */}
|
||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>
|
||||
新增组织
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 表格 */}
|
||||
<Table
|
||||
rowKey="id"
|
||||
columns={columns}
|
||||
dataSource={orgList}
|
||||
pagination={false}
|
||||
bordered
|
||||
size="middle"
|
||||
/>
|
||||
</Card>
|
||||
</AntdCard>
|
||||
|
||||
{/* 新增/编辑弹窗 */}
|
||||
<Modal
|
||||
title={editRecord ? '编辑组织' : '新增组织'}
|
||||
open={modalVisible}
|
||||
onCancel={() => setModalVisible(false)}
|
||||
onOk={handleSave}
|
||||
width={500}
|
||||
width={550}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form form={form} layout="vertical">
|
||||
<Form.Item name="name" label="组织名称" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
<Form.Item name="orgName" label="组织名称" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入组织名称" />
|
||||
</Form.Item>
|
||||
<Form.Item name="code" label="组织编码" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
|
||||
<Form.Item name="orgCode" label="组织编码" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入组织编码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="manager" label="负责人" rules={[{ required: true, message: '请输入负责人' }]}>
|
||||
<Input placeholder="请输入负责人" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="phone" label="联系电话" rules={[{ required: true, message: '请输入联系电话' }]}>
|
||||
<Input placeholder="请输入联系电话" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="email" label="邮箱">
|
||||
<Input placeholder="请输入邮箱" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="address" label="地址">
|
||||
<Input placeholder="请输入地址" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="remark" label="备注">
|
||||
<Input.TextArea rows={3} placeholder="请输入备注" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="status" label="状态">
|
||||
<Select>
|
||||
<Option value="0">正常</Option>
|
||||
<Option value="1">禁用</Option>
|
||||
<Option value={1}>正常</Option>
|
||||
<Option value={0}>禁用</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
Input, Popconfirm, Divider, InputNumber, Switch
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined, SettingOutlined, EditOutlined, DeleteOutlined, CloseOutlined
|
||||
PlusOutlined, EditOutlined, DeleteOutlined, CloseOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { getMenuList } from '../api/mune';
|
||||
import { buildPermTree, buildTreeFromFlat } from '../lib/utils';
|
||||
@@ -18,9 +18,6 @@ export default function Roles() {
|
||||
const [roles, setRoles] = useState([]);
|
||||
const [menuTree, setMenuTree] = useState([]);
|
||||
const [checkedKeys, setCheckedKeys] = useState<number[]>([]);
|
||||
const [permVisible, setPermVisible] = useState(false);
|
||||
const [currentRole, setCurrentRole] = useState(null);
|
||||
|
||||
const [roleModalVisible, setRoleModalVisible] = useState(false);
|
||||
const [roleForm] = Form.useForm();
|
||||
const [editRole, setEditRole] = useState(null);
|
||||
@@ -52,8 +49,6 @@ export default function Roles() {
|
||||
getRole();
|
||||
}, []);
|
||||
|
||||
|
||||
|
||||
// 新增角色
|
||||
const handleAddRole = () => {
|
||||
roleForm.resetFields();
|
||||
@@ -62,7 +57,6 @@ export default function Roles() {
|
||||
roleForm.setFieldsValue({
|
||||
status: true,
|
||||
roleSort: 1,
|
||||
|
||||
});
|
||||
setRoleModalVisible(true);
|
||||
};
|
||||
@@ -74,7 +68,6 @@ export default function Roles() {
|
||||
...record,
|
||||
status: record.status == 1,
|
||||
});
|
||||
// 🔥 编辑时自动勾选菜单
|
||||
setCheckedKeys((record.menuIds || []).map(Number));
|
||||
setRoleModalVisible(true);
|
||||
};
|
||||
@@ -96,17 +89,13 @@ export default function Roles() {
|
||||
// 提交保存角色
|
||||
const handleSaveRole = () => {
|
||||
roleForm.validateFields().then(values => {
|
||||
|
||||
|
||||
if (editRole) {
|
||||
|
||||
const params = {
|
||||
...values,
|
||||
menuIds: checkedKeys,
|
||||
status: values.status ? 1 : 0,
|
||||
roleSort: values.roleSort || 1,
|
||||
roleId: editRole.roleId
|
||||
|
||||
};
|
||||
editRoleApi(params).then(res => {
|
||||
if (res.code == 200) {
|
||||
@@ -119,16 +108,13 @@ export default function Roles() {
|
||||
}).catch(() => {
|
||||
messageApi.error("编辑失败");
|
||||
});
|
||||
|
||||
} else {
|
||||
const params = {
|
||||
...values,
|
||||
menuIds: checkedKeys,
|
||||
status: values.status ? 1 : 0,
|
||||
roleSort: values.roleSort || 1,
|
||||
|
||||
};
|
||||
// 新增
|
||||
addRole(params).then(res => {
|
||||
if (res.code == 200) {
|
||||
messageApi.success('新增角色成功');
|
||||
@@ -145,59 +131,76 @@ export default function Roles() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ padding: '16px', background: '#f4f7f9', minHeight: '100%' }}>
|
||||
<div style={{ padding: '20px' }}>
|
||||
{contextHolder}
|
||||
|
||||
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 16 }}>角色管理</div>
|
||||
{/* 统一卡片容器(和菜单管理一致) */}
|
||||
<AntdCard title="角色管理" style={{ borderRadius: 8 }}>
|
||||
{/* 顶部操作栏(和菜单管理统一) */}
|
||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={handleAddRole}
|
||||
>
|
||||
新增角色
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-start', marginBottom: 16 }}>
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAddRole}>
|
||||
新增角色
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Row gutter={[16, 16]}>
|
||||
{roles && roles.length > 0 ? (
|
||||
roles.map(role => (
|
||||
<Col xs={24} sm={12} md={8} lg={6} key={role.roleId}>
|
||||
<AntdCard
|
||||
size="small"
|
||||
hoverable
|
||||
style={{ borderRadius: 8 }}
|
||||
actions={[
|
||||
|
||||
<Button type="text" icon={<EditOutlined />} onClick={() => handleEditRole(role)}>
|
||||
编辑
|
||||
</Button>,
|
||||
<Popconfirm title="确定删除?" onConfirm={() => handleDeleteRole(role.roleId)}>
|
||||
<Button type="text" danger icon={<DeleteOutlined />}>删除</Button>
|
||||
</Popconfirm>
|
||||
]}
|
||||
>
|
||||
<Card.Meta
|
||||
title={<span style={{ fontWeight: 600 }}>{role.roleName}</span>}
|
||||
description={
|
||||
<Space direction="vertical" size={2}>
|
||||
<Text type="secondary">权限标识:{role.roleKey}</Text>
|
||||
<Text type="secondary">状态:{role.status == 1 ? '正常' : '停用'}</Text>
|
||||
<Text type="secondary">
|
||||
{role.admin && '【超级管理员】'}
|
||||
{role.manager && '【机构管理员】'}
|
||||
</Text>
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
</AntdCard>
|
||||
{/* 角色卡片列表 */}
|
||||
<Row gutter={[16, 16]}>
|
||||
{roles && roles.length > 0 ? (
|
||||
roles.map(role => (
|
||||
<Col xs={24} sm={12} md={8} lg={6} key={role.roleId}>
|
||||
<AntdCard
|
||||
size="small"
|
||||
hoverable
|
||||
style={{ borderRadius: 8 }}
|
||||
actions={[
|
||||
<Button
|
||||
type="text"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => handleEditRole(role)}
|
||||
>
|
||||
编辑
|
||||
</Button>,
|
||||
<Popconfirm
|
||||
title="确定删除该角色?"
|
||||
onConfirm={() => handleDeleteRole(role.roleId)}
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
]}
|
||||
>
|
||||
<Card.Meta
|
||||
title={<span style={{ fontWeight: 600 }}>{role.roleName}</span>}
|
||||
description={
|
||||
<Space direction="vertical" size={2}>
|
||||
<Text type="secondary">权限标识:{role.roleKey}</Text>
|
||||
<Text type="secondary">状态:{role.status == 1 ? '正常' : '停用'}</Text>
|
||||
<Text type="secondary">
|
||||
{role.admin && '【超级管理员】'}
|
||||
{role.manager && '【机构管理员】'}
|
||||
</Text>
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
))
|
||||
) : (
|
||||
<Col span={24}>
|
||||
<EmptyData height={260} description="暂无角色数据" />
|
||||
</Col>
|
||||
))
|
||||
) : (
|
||||
<Col span={24}>
|
||||
<EmptyData height={260} description="暂无角色数据" />
|
||||
</Col>
|
||||
)}
|
||||
</Row>
|
||||
|
||||
|
||||
)}
|
||||
</Row>
|
||||
</AntdCard>
|
||||
|
||||
{/* 新增/编辑弹窗 */}
|
||||
<Modal
|
||||
@@ -221,14 +224,13 @@ export default function Roles() {
|
||||
<InputNumber style={{ width: '100%' }} min={1} />
|
||||
</Form.Item>
|
||||
|
||||
{/* 三个 Switch 一行 */}
|
||||
{/* 状态 Switch */}
|
||||
<Row gutter={16}>
|
||||
<Col span={8}>
|
||||
<Form.Item name="status" label="状态" valuePropName="checked">
|
||||
<Switch checkedChildren="正常" unCheckedChildren="停用" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
</Row>
|
||||
|
||||
<Divider>菜单权限配置</Divider>
|
||||
|
||||
@@ -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