| | |
| | | import React from 'react'; |
| | | import React, { useMemo } from 'react'; |
| | | import { |
| | | Stack, |
| | | TextField, |
| | |
| | | codeList, |
| | | onSave, |
| | | disableSave, |
| | | onDelete, |
| | | canDelete = false, |
| | | }) => { |
| | | const translate = useTranslate(); |
| | | const icon = <CheckBoxOutlineBlankIcon fontSize="small" />; |
| | |
| | | |
| | | const getOptionId = (option) => { |
| | | return option?.id; |
| | | }; |
| | | |
| | | const handleSaveClick = () => { |
| | | if (disableSave) { |
| | | return; |
| | | } |
| | | const confirmMsg = translate('page.map.area.saveConfirm', { _: '确认保存当前修改?' }); |
| | | if (window.confirm(confirmMsg)) { |
| | | onSave?.(); |
| | | } |
| | | }; |
| | | |
| | | const handleDeleteClick = () => { |
| | | if (!canDelete) { |
| | | return; |
| | | } |
| | | const confirmMsg = translate('page.map.area.deleteConfirm', { _: '删除后将无法恢复,确认删除?' }); |
| | | if (window.confirm(confirmMsg)) { |
| | | onDelete?.(); |
| | | } |
| | | }; |
| | | |
| | | return ( |
| | |
| | | </Paper> |
| | | </Box> |
| | | |
| | | <Box display="flex" justifyContent="flex-start"> |
| | | <Button variant="contained" onClick={onSave} disabled={disableSave}> |
| | | <Box display="flex" justifyContent="space-between" alignItems="center"> |
| | | <Button variant="contained" onClick={handleSaveClick} disabled={disableSave}> |
| | | {translate('common.action.save', { _: '保存' })} |
| | | </Button> |
| | | <Button variant="text" color="error" onClick={handleDeleteClick} disabled={!canDelete}> |
| | | {translate('common.action.delete', { _: '删除' })} |
| | | </Button> |
| | | </Box> |
| | | </Stack> |
| | | ); |
| | |
| | | import React, { useState, useEffect, useMemo } from 'react'; |
| | | import React, { useState, useEffect } from 'react'; |
| | | import { useTranslate } from "react-admin"; |
| | | import { |
| | | Drawer, |
| | |
| | | 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') { |
| | |
| | | setActiveTab(newValue); |
| | | }; |
| | | |
| | | const handleSaveBasic = () => { |
| | | // console.log({ |
| | | // name, |
| | | // agvIds: agvList.map(getAgvOptionId), |
| | | // }); |
| | | // placeholder for save logic |
| | | setInitialBasic({ |
| | | const handleSaveBasic = async () => { |
| | | const areaId = sprite?.data?.id; |
| | | if (!areaId) { |
| | | return; |
| | | } |
| | | const payload = { |
| | | areaId, |
| | | name, |
| | | agvIds: agvList.map(getAgvOptionId), |
| | | }); |
| | | }; |
| | | const success = await updateAreaData(payload); |
| | | if (success) { |
| | | setInitialBasic({ |
| | | name, |
| | | agvIds: payload.agvIds, |
| | | }); |
| | | fetchAreaInfo(areaId); |
| | | } |
| | | }; |
| | | |
| | | const handleDeleteArea = async () => { |
| | | const areaId = sprite?.data?.id; |
| | | if (!areaId) { |
| | | return; |
| | | } |
| | | const success = await removeArea(areaId); |
| | | if (success) { |
| | | onCancel?.(); |
| | | } |
| | | }; |
| | | |
| | | const handleSaveAdvanced = () => { |
| | |
| | | agvList.map(getAgvOptionId), |
| | | initialBasic.agvIds |
| | | ); |
| | | |
| | | return ( |
| | | <> |
| | | <Drawer |
| | |
| | | codeList={codeList} |
| | | onSave={handleSaveBasic} |
| | | disableSave={!basicDirty} |
| | | onDelete={handleDeleteArea} |
| | | canDelete={Boolean(sprite?.data?.id)} |
| | | /> |
| | | )} |
| | | {activeTab === 1 && ( |