2025-07-21 15:36:11 +08:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { View, StyleSheet, ScrollView } from 'react-native';
|
2025-07-21 15:59:44 +08:00
|
|
|
import { TextInput, Menu, Button, Divider, Text } from 'react-native-paper';
|
2025-07-21 15:10:39 +08:00
|
|
|
import { Task, RobotAction } from '../types/task';
|
2025-07-21 15:59:44 +08:00
|
|
|
import { LOCATIONS, ROBOT_ACTIONS, PAYLOADS, LOCATIONS_BAYS } from '../data/mockData';
|
2025-07-21 15:10:39 +08:00
|
|
|
|
|
|
|
interface TaskFormProps {
|
|
|
|
task: Task;
|
|
|
|
onTaskChange: (updatedTask: Task) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TaskForm: React.FC<TaskFormProps> = ({ task, onTaskChange }) => {
|
2025-07-21 15:59:44 +08:00
|
|
|
const [menuVisible, setMenuVisible] = useState<{ [key: string]: boolean }>({});
|
2025-07-21 15:36:11 +08:00
|
|
|
|
2025-07-21 15:59:44 +08:00
|
|
|
const openMenu = (name: string) => setMenuVisible(prev => ({ ...prev, [name]: true }));
|
|
|
|
const closeMenu = (name: string) => setMenuVisible(prev => ({ ...prev, [name]: false }));
|
|
|
|
|
|
|
|
const handleParamChange = (field: string, value: string | RobotAction) => {
|
|
|
|
const updatedTask = {
|
|
|
|
...task,
|
|
|
|
parameters: {
|
|
|
|
...task.parameters,
|
|
|
|
[field]: value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
onTaskChange(updatedTask);
|
2025-07-21 15:10:39 +08:00
|
|
|
};
|
|
|
|
|
2025-07-21 15:59:44 +08:00
|
|
|
const renderDropdown = (
|
|
|
|
name: string,
|
|
|
|
label: string,
|
|
|
|
value: string,
|
|
|
|
items: { label: string, value: string }[]
|
|
|
|
) => (
|
|
|
|
<View style={styles.input}>
|
|
|
|
<Text>{label}</Text>
|
|
|
|
<Menu
|
|
|
|
visible={menuVisible[name]}
|
|
|
|
onDismiss={() => closeMenu(name)}
|
|
|
|
anchor={
|
|
|
|
<Button onPress={() => openMenu(name)} mode="outlined">
|
|
|
|
{value || `选择${label}`}
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ScrollView style={{ maxHeight: 200 }}>
|
|
|
|
{items.map(item => (
|
|
|
|
<Menu.Item
|
|
|
|
key={item.value}
|
|
|
|
onPress={() => {
|
|
|
|
handleParamChange(name, item.value);
|
|
|
|
closeMenu(name);
|
|
|
|
}}
|
|
|
|
title={item.label}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</ScrollView>
|
|
|
|
</Menu>
|
|
|
|
</View>
|
|
|
|
);
|
2025-07-21 15:10:39 +08:00
|
|
|
|
2025-07-21 15:59:44 +08:00
|
|
|
return (
|
|
|
|
<ScrollView contentContainerStyle={styles.container}>
|
|
|
|
<TextInput
|
|
|
|
label="任务名称"
|
|
|
|
value={task.name}
|
|
|
|
onChangeText={text => onTaskChange({ ...task, name: text })}
|
|
|
|
style={styles.input}
|
|
|
|
mode="outlined"
|
|
|
|
/>
|
2025-07-21 15:10:39 +08:00
|
|
|
|
2025-07-21 15:59:44 +08:00
|
|
|
{renderDropdown('startLocation', '起点', task.parameters.startLocation, LOCATIONS)}
|
|
|
|
{renderDropdown('endLocation', '终点', task.parameters.endLocation, LOCATIONS)}
|
|
|
|
|
|
|
|
<TextInput
|
|
|
|
label="途经点 (可选)"
|
|
|
|
value={task.parameters.waypoint || ''}
|
|
|
|
onChangeText={text => handleParamChange('waypoint', text)}
|
|
|
|
style={styles.input}
|
|
|
|
mode="outlined"
|
|
|
|
/>
|
|
|
|
|
|
|
|
{renderDropdown('robotAction', '机器人动作', task.parameters.robotAction, ROBOT_ACTIONS)}
|
|
|
|
{renderDropdown('payload', '载荷', task.parameters.payload, PAYLOADS)}
|
|
|
|
{renderDropdown('locationBay', '库位', task.parameters.locationBay, LOCATIONS_BAYS)}
|
2025-07-21 15:36:11 +08:00
|
|
|
|
2025-07-21 15:59:44 +08:00
|
|
|
</ScrollView>
|
|
|
|
);
|
2025-07-21 15:10:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2025-07-21 15:59:44 +08:00
|
|
|
container: {
|
|
|
|
padding: 16,
|
|
|
|
},
|
|
|
|
input: {
|
|
|
|
marginBottom: 16,
|
|
|
|
},
|
2025-07-21 15:10:39 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export default TaskForm;
|