From 1bc33546a044cbc84dd9595c19dbcd9a4e309fc9 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期六, 10 一月 2026 14:06:10 +0800
Subject: [PATCH] #
---
zy-acs-flow/src/map/areaSettings/index.jsx | 102 ++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 80 insertions(+), 22 deletions(-)
diff --git a/zy-acs-flow/src/map/areaSettings/index.jsx b/zy-acs-flow/src/map/areaSettings/index.jsx
index bd0e797..d86d5be 100644
--- a/zy-acs-flow/src/map/areaSettings/index.jsx
+++ b/zy-acs-flow/src/map/areaSettings/index.jsx
@@ -1,4 +1,4 @@
-import React, { useState, useEffect, useMemo } from 'react';
+import React, { useState, useEffect } from 'react';
import { useTranslate } from "react-admin";
import {
Drawer,
@@ -17,13 +17,17 @@
import { PAGE_DRAWER_WIDTH } from '@/config/setting';
import AreaBasicTab from './AreaBasicTab';
import AreaAdvancedTab from './AreaAdvancedTab';
-import { getAreaInfo, fetchAgvListAll } from '../http';
+import { getAreaInfo, fetchAgvListAll, updateAreaData, removeArea } from '../http';
+import * as Tool from '../tool';
const getAgvOptionId = (option) => {
- if (typeof option === 'string') {
- return option;
+ if (option == null) {
+ return '';
}
- return option?.value ?? option?.id ?? option?.agvNo ?? option?.code ?? option?.name ?? '';
+ if (typeof option === 'string' || typeof option === 'number') {
+ return String(option);
+ }
+ return option?.id ?? '';
};
const areAgvSelectionsEqual = (aIds = [], bIds = []) => {
@@ -36,7 +40,10 @@
const mapSelectionToOptions = (selection = [], options = []) => {
const optionMap = new Map(options.map(option => [getAgvOptionId(option), option]));
- return selection.map(item => optionMap.get(getAgvOptionId(item)) || item);
+ return selection
+ .map(item => optionMap.get(item) || null)
+ .filter(Boolean);
+
};
const AreaSettings = (props) => {
@@ -56,8 +63,10 @@
const [code, setCode] = useState('');
const [maxCount, setMaxCount] = useState('');
const [speedLimit, setSpeedLimit] = useState('');
- const [memo, setMemo] = useState('');
+ const [startPoint, setStartPoint] = useState({ x: '', y: '' });
+ const [endPoint, setEndPoint] = useState({ x: '', y: '' });
const [priority, setPriority] = useState('');
+ const [memo, setMemo] = useState('');
const [agvOptions, setAgvOptions] = useState([]);
const [initialBasic, setInitialBasic] = useState({ name: '', agvIds: [] });
const [curAreaInfo, setCurAreaInfo] = useState(null);
@@ -77,8 +86,10 @@
setCode('');
setMaxCount('');
setSpeedLimit('');
- setMemo('');
+ setStartPoint({ x: '', y: '' });
+ setEndPoint({ x: '', y: '' });
setPriority('');
+ setMemo('');
setAgvList([]);
setCodeList([]);
setInitialBasic({ name: '', agvIds: [] });
@@ -100,8 +111,16 @@
setCode(curAreaInfo.code || '');
setMaxCount(curAreaInfo.maxCount ?? '');
setSpeedLimit(curAreaInfo.speedLimit ?? '');
- setMemo(curAreaInfo.memo || '');
+ setStartPoint({
+ x: curAreaInfo.start?.x ?? '',
+ y: curAreaInfo.start?.y ?? '',
+ });
+ setEndPoint({
+ x: curAreaInfo.end?.x ?? '',
+ y: curAreaInfo.end?.y ?? '',
+ });
setPriority(curAreaInfo.priority ?? '');
+ setMemo(curAreaInfo.memo || '');
const selected = curAreaInfo.agvList || [];
const normalizedSelection = mapSelectionToOptions(selected, agvOptions);
@@ -120,25 +139,60 @@
setActiveTab(newValue);
};
- const handleSaveBasic = () => {
- // placeholder for save logic
- setInitialBasic({
+ const submitAreaUpdate = async (payload = {}) => {
+ const id = sprite?.data?.id;
+ if (!id) {
+ return;
+ }
+ const data = await updateAreaData({ id, ...payload });
+ if (data) {
+ setCurAreaInfo(data);
+ if (sprite) {
+ Tool.updateAreaSpriteName(sprite, data.name || name);
+ }
+ }
+ };
+
+ const handleSaveBasic = async () => {
+ await submitAreaUpdate({
name,
agvIds: agvList.map(getAgvOptionId),
});
};
- const handleSaveAdvanced = () => {
- // placeholder for save logic
+ const handleSaveAdvanced = async () => {
+ await submitAreaUpdate({
+ name,
+ agvIds: agvList.map(getAgvOptionId),
+ code,
+ maxCount,
+ speedLimit,
+ priority,
+ memo,
+ start: startPoint,
+ end: endPoint,
+ });
};
- const codeListText = (codeList || []).join('\n');
+ const handleDeleteArea = async () => {
+ const id = sprite?.data?.id;
+ if (!id) {
+ return;
+ }
+ const success = await removeArea(id);
+ if (success) {
+ if (sprite) {
+ Tool.removeAreaSprite(sprite);
+ }
+ onCancel?.();
+ }
+ };
+
const basicDirty = name !== initialBasic.name
|| !areAgvSelectionsEqual(
agvList.map(getAgvOptionId),
initialBasic.agvIds
);
-
return (
<>
<Drawer
@@ -155,7 +209,7 @@
<Typography variant="h6" flex="1">
{sprite
? translate(`page.map.devices.${sprite?.data?.type?.toLowerCase()}`) + ' - ' + sprite?.data?.name
- : translate('page.map.settings.title')}
+ : translate('page.map.area.title')}
</Typography>
<IconButton onClick={handleClose} size="small">
<CloseIcon />
@@ -184,8 +238,8 @@
variant="fullWidth"
sx={{ mb: 0 }}
>
- <Tab label={translate('page.map.area.basic', { _: '鍩虹' })} />
- <Tab label={translate('page.map.area.advanced', { _: '楂樼骇' })} />
+ <Tab label={translate('page.map.area.tabs.basic')} />
+ <Tab label={translate('page.map.area.tabs.advanced')} />
</Tabs>
<Divider />
@@ -198,9 +252,11 @@
agvOptions={agvOptions}
agvList={agvList}
setAgvList={setAgvList}
- codeListText={codeListText}
+ codeList={codeList}
onSave={handleSaveBasic}
disableSave={!basicDirty}
+ onDelete={handleDeleteArea}
+ canDelete={Boolean(sprite?.data?.id)}
/>
)}
{activeTab === 1 && (
@@ -211,10 +267,12 @@
setMaxQty={setMaxCount}
speedLimit={speedLimit}
setSpeedLimit={setSpeedLimit}
- shapeData={memo}
- setShapeData={setMemo}
+ startPoint={startPoint}
+ endPoint={endPoint}
priority={priority}
setPriority={setPriority}
+ memo={memo}
+ setMemo={setMemo}
onSave={handleSaveAdvanced}
/>
)}
--
Gitblit v1.9.1