feat: 柜子详情页添加接触器控制按钮(pow_on/pow_off)
This commit is contained in:
parent
a3d7dc0dc0
commit
c3eed024b6
@ -79,6 +79,9 @@ export const cabinetApi = {
|
|||||||
delete: (id: number) => api.delete(`/cabinets/${id}`),
|
delete: (id: number) => api.delete(`/cabinets/${id}`),
|
||||||
regenerateAuth: (id: number) => api.post<{ auth_str: string }>(`/cabinets/${id}/regenerate-auth`),
|
regenerateAuth: (id: number) => api.post<{ auth_str: string }>(`/cabinets/${id}/regenerate-auth`),
|
||||||
getDetail: (id: number) => api.get<CabinetDetail>(`/cabinets/${id}`),
|
getDetail: (id: number) => api.get<CabinetDetail>(`/cabinets/${id}`),
|
||||||
|
// 接触器控制
|
||||||
|
powOn: (id: number) => api.post(`/cabinets/${id}/pow-on`),
|
||||||
|
powOff: (id: number) => api.post(`/cabinets/${id}/pow-off`),
|
||||||
};
|
};
|
||||||
|
|
||||||
// 组织树 API
|
// 组织树 API
|
||||||
|
|||||||
@ -13,6 +13,8 @@ import {
|
|||||||
Grid,
|
Grid,
|
||||||
Button,
|
Button,
|
||||||
Descriptions,
|
Descriptions,
|
||||||
|
Message,
|
||||||
|
Modal,
|
||||||
} from '@arco-design/web-react';
|
} from '@arco-design/web-react';
|
||||||
import { IconLeft, IconDesktop } from '@arco-design/web-react/icon';
|
import { IconLeft, IconDesktop } from '@arco-design/web-react/icon';
|
||||||
import { cabinetApi, type CabinetDetail } from '@/api/devices';
|
import { cabinetApi, type CabinetDetail } from '@/api/devices';
|
||||||
@ -41,6 +43,7 @@ export default function CabinetDetail() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [detail, setDetail] = useState<CabinetDetail | null>(null);
|
const [detail, setDetail] = useState<CabinetDetail | null>(null);
|
||||||
|
const [powLoading, setPowLoading] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
@ -54,6 +57,52 @@ export default function CabinetDetail() {
|
|||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
|
/** 接触器合闸 */
|
||||||
|
const handlePowOn = () => {
|
||||||
|
if (!id) return;
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认操作',
|
||||||
|
content: '确定要合闸恢复380V供电吗?',
|
||||||
|
onOk: async () => {
|
||||||
|
setPowLoading(true);
|
||||||
|
try {
|
||||||
|
await cabinetApi.powOn(Number(id));
|
||||||
|
Message.success('合闸指令已发送');
|
||||||
|
// 刷新详情
|
||||||
|
const res = await cabinetApi.getDetail(Number(id));
|
||||||
|
setDetail(res.data);
|
||||||
|
} catch {
|
||||||
|
Message.error('操作失败');
|
||||||
|
} finally {
|
||||||
|
setPowLoading(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 接触器分闸 */
|
||||||
|
const handlePowOff = () => {
|
||||||
|
if (!id) return;
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认操作',
|
||||||
|
content: '确定要分闸切断380V供电吗?',
|
||||||
|
onOk: async () => {
|
||||||
|
setPowLoading(true);
|
||||||
|
try {
|
||||||
|
await cabinetApi.powOff(Number(id));
|
||||||
|
Message.success('分闸指令已发送');
|
||||||
|
// 刷新详情
|
||||||
|
const res = await cabinetApi.getDetail(Number(id));
|
||||||
|
setDetail(res.data);
|
||||||
|
} catch {
|
||||||
|
Message.error('操作失败');
|
||||||
|
} finally {
|
||||||
|
setPowLoading(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
@ -104,6 +153,7 @@ export default function CabinetDetail() {
|
|||||||
|
|
||||||
{/* 柜子信息 */}
|
{/* 柜子信息 */}
|
||||||
<Card title="基本信息" size="small">
|
<Card title="基本信息" size="small">
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
|
||||||
<Descriptions
|
<Descriptions
|
||||||
data={[
|
data={[
|
||||||
{ label: '抽象 ID', value: detail.abstract_id },
|
{ label: '抽象 ID', value: detail.abstract_id },
|
||||||
@ -115,6 +165,25 @@ export default function CabinetDetail() {
|
|||||||
layout="horizontal"
|
layout="horizontal"
|
||||||
labelStyle={{ paddingRight: 36 }}
|
labelStyle={{ paddingRight: 36 }}
|
||||||
/>
|
/>
|
||||||
|
<div style={{ display: 'flex', gap: 8 }}>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
status="success"
|
||||||
|
loading={powLoading}
|
||||||
|
onClick={handlePowOn}
|
||||||
|
>
|
||||||
|
合闸供电
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
status="danger"
|
||||||
|
loading={powLoading}
|
||||||
|
onClick={handlePowOff}
|
||||||
|
>
|
||||||
|
分闸断电
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* 仓控板列表 */}
|
{/* 仓控板列表 */}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user