#
vincentlu
2025-12-16 01e6aae8ac9ceea44a4a36199d27d24f5cf565df
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,16 @@
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';
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 +39,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) => {
@@ -86,10 +92,13 @@
    }, [sprite]);
    useEffect(() => {
        if (!open) {
            return;
        }
        fetchAgvListAll().then((options) => {
            setAgvOptions(options || []);
        });
    }, []);
    }, [open]);
    useEffect(() => {
        if (curAreaInfo) {
@@ -117,25 +126,43 @@
        setActiveTab(newValue);
    };
    const handleSaveBasic = () => {
        // placeholder for save logic
        setInitialBasic({
    const handleSaveBasic = async () => {
        console.log(agvList);
        const id = sprite?.data?.id;
        if (!id) {
            return;
        }
        const payload = {
            id,
            name,
            agvIds: agvList.map(getAgvOptionId),
        });
        };
        const data = await updateAreaData(payload);
        if (data) {
            setCurAreaInfo(data);
        }
    };
    const handleDeleteArea = async () => {
        const id = sprite?.data?.id;
        if (!id) {
            return;
        }
        const success = await removeArea(id);
        if (success) {
            onCancel?.();
        }
    };
    const handleSaveAdvanced = () => {
        // placeholder for save logic
    };
    const codeListText = (codeList || []).join('\n');
    const basicDirty = name !== initialBasic.name
        || !areAgvSelectionsEqual(
            agvList.map(getAgvOptionId),
            initialBasic.agvIds
        );
    return (
        <>
            <Drawer
@@ -195,9 +222,11 @@
                                                agvOptions={agvOptions}
                                                agvList={agvList}
                                                setAgvList={setAgvList}
                                                codeListText={codeListText}
                                                codeList={codeList}
                                                onSave={handleSaveBasic}
                                                disableSave={!basicDirty}
                                                onDelete={handleDeleteArea}
                                                canDelete={Boolean(sprite?.data?.id)}
                                            />
                                        )}
                                        {activeTab === 1 && (