diff --git a/config.json b/config.json index 6be8fcd..4259bce 100644 --- a/config.json +++ b/config.json @@ -9,7 +9,9 @@ "apiEndpoints": { "getTasks": "/api/vwed-task/list", "getTaskDetail": "/api/vwed-task/{taskId}", - "runTask": "/api/vwed-task-edit/run" + "runTask": "/api/vwed-task-edit/run", + "getLocationList": "/api/vwed-operate-point/list", + "batchUpdateLocation": "/api/vwed-operate-point/batch-status" }, "taskApiEndpoints": { "getTaskList": "/task", diff --git a/src/screens/LocationScreen.tsx b/src/screens/LocationScreen.tsx index 2e72ec9..557aa44 100644 --- a/src/screens/LocationScreen.tsx +++ b/src/screens/LocationScreen.tsx @@ -1,7 +1,16 @@ import React, { useEffect, useState, useCallback } from 'react'; -import { StyleSheet, View, FlatList, Text, ActivityIndicator, Alert } from 'react-native'; -import { SearchBar, CheckBox, Button, useTheme, Overlay, ListItem } from '@rneui/themed'; +import { + StyleSheet, + View, + FlatList, + Text, + ActivityIndicator, + Alert, + RefreshControl, +} from 'react-native'; +import { SearchBar, CheckBox, Button, Overlay, ListItem } from '@rneui/themed'; import api from '../services/api'; +import { getConfig } from '../services/configService'; interface Location { id: string; @@ -13,20 +22,35 @@ interface Location { } const LocationScreen = () => { - const { theme } = useTheme(); const [locations, setLocations] = useState([]); const [search, setSearch] = useState(''); const [loading, setLoading] = useState(true); const [selectedLocations, setSelectedLocations] = useState([]); const [isOverlayVisible, setOverlayVisible] = useState(false); + const [isRefreshing, setIsRefreshing] = useState(false); const fetchData = useCallback(async (query = '') => { setLoading(true); try { - const response = await api.get('/api/vwed-operate-point/list', { + const config = await getConfig(); + const endpoint = + (config?.apiEndpoints as any)?.getLocationList || + '/api/vwed-operate-point/list'; + + const response = await api.get(endpoint, { params: { layer_name: query }, }); - setLocations(response.storage_locations); + console.log('API Response:', response); // 调试日志 + // API 拦截器已经处理了响应,直接使用返回的数据 + const data = response as any; + if (data && data.storage_locations) { + setLocations(data.storage_locations); + } else if (Array.isArray(data)) { + setLocations(data); + } else { + console.warn('Unexpected response format:', data); + setLocations([]); + } } catch (error) { console.error(error); Alert.alert('错误', '加载库位列表失败。'); @@ -43,9 +67,20 @@ const LocationScreen = () => { fetchData(search); }; + const handleRefresh = useCallback(async () => { + setIsRefreshing(true); + try { + await fetchData(search); + } catch (error) { + console.error('刷新失败:', error); + } finally { + setIsRefreshing(false); + } + }, [fetchData, search]); + const toggleSelection = (id: string) => { setSelectedLocations(prev => - prev.includes(id) ? prev.filter(item => item !== id) : [...prev, id] + prev.includes(id) ? prev.filter(item => item !== id) : [...prev, id], ); }; @@ -56,12 +91,19 @@ const LocationScreen = () => { } setOverlayVisible(false); try { - const response = await api.put('/api/vwed-operate-point/batch-status', { + const config = await getConfig(); + const endpoint = + (config?.apiEndpoints as any)?.batchUpdateLocation || + '/api/vwed-operate-point/batch-status'; + + const response = await api.put(endpoint, { layer_names: selectedLocations, action: action, }); - const { success_count, failed_count, results } = response; + console.log('Batch Update Response:', response); // 调试日志 + // API 拦截器已经处理了响应,直接使用返回的数据 + const { success_count, failed_count, results } = response as any; let message = `批量操作完成:\n成功 ${success_count} 个, 失败 ${failed_count} 个。\n\n`; if (failed_count > 0) { message += '失败详情:\n'; @@ -75,7 +117,7 @@ const LocationScreen = () => { fetchData(search); setSelectedLocations([]); - } catch (error) { + } catch (error: any) { console.error(error); Alert.alert('错误', `批量操作失败: ${error.message}`); } @@ -91,72 +133,137 @@ const LocationScreen = () => { ]; const renderItem = ({ item }: { item: Location }) => ( - + toggleSelection(item.id)} - containerStyle={{ backgroundColor: 'transparent' }} + containerStyle={styles.checkboxContainer} + checkedColor="#4CAF50" + uncheckedColor="#666" /> - {item.layer_name} - {item.is_occupied ? '是' : '否'} - {item.is_locked ? '是' : '否'} - {item.is_empty_tray ? '是' : '否'} - {item.is_disabled ? '是' : '否'} + {item.layer_name} + + {item.is_occupied ? '是' : '否'} + + + {item.is_locked ? '是' : '否'} + + + {item.is_empty_tray ? '是' : '否'} + + + {item.is_disabled ? '是' : '否'} + ); if (loading) { return ( - + + 加载中... ); } return ( - - - -