From c03df200ab7dda6f685524e6f2facf50fdd8e33b Mon Sep 17 00:00:00 2001 From: xudan Date: Fri, 25 Jul 2025 16:47:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=BA=93=E4=BD=8D?= =?UTF-8?q?=E5=B1=8F=E5=B9=95=E7=9A=84=E4=B8=8B=E6=8B=89=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96API=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E5=A4=84=E7=90=86=EF=BC=8C=E6=94=B9=E8=BF=9B=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E6=A0=B7=E5=BC=8F=E5=92=8C=E7=94=A8=E6=88=B7=E4=BD=93?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 4 +- src/screens/LocationScreen.tsx | 276 +++++++++++++++++++++++++++------ src/screens/SettingsScreen.tsx | 53 ++++--- src/services/api.ts | 13 +- src/services/configService.ts | 1 + src/types/config.ts | 1 + 6 files changed, 282 insertions(+), 66 deletions(-) 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 ( - - - -