Просмотр исходного кода

🐛 fix(components): 修复TypeScript未使用变量警告并优化错误处理

- 在PrintConfigManagement组件中,将useQuery的onError回调重构为useEffect,以正确解构error属性并处理查询错误
- 在OrderManagement组件中,为未使用的变量`triggeringOrder`、`isTriggering`、`handleCheckTradeManaged`和`handleTriggerPaymentSuccess`添加void语句,消除TypeScript警告
- 移除未使用的Play图标导入
- 优化sendDeliverySuccessNotification函数中的错误消息,当所有API路径尝试失败时,包含最后捕获的错误信息以提供更多上下文
- 改进configList的类型检查逻辑,使用更精确的`typeof configList === 'object'`条件
yourname 3 недель назад
Родитель
Сommit
00805919f3

+ 9 - 4
packages/feie-printer-management-ui-mt/src/components/PrintConfigManagement.tsx

@@ -229,6 +229,7 @@ export const PrintConfigManagement: React.FC<PrintConfigManagementProps> = ({
     data: configList,
     isLoading,
     isError,
+    error,
     refetch
   } = useQuery<ConfigListResponse>({
     queryKey: ['printConfigs', tenantId],
@@ -246,11 +247,15 @@ export const PrintConfigManagement: React.FC<PrintConfigManagementProps> = ({
     staleTime: 0, // 设置为0,每次重新进入页面都重新获取
     gcTime: 0, // 设置为0,不缓存数据
     refetchOnMount: true, // 组件挂载时重新获取
-    refetchOnWindowFocus: true, // 窗口获得焦点时重新获取
-    onError: (error: Error) => {
+    refetchOnWindowFocus: true // 窗口获得焦点时重新获取
+  });
+
+  // 处理查询错误
+  useEffect(() => {
+    if (error) {
       toast.error(`获取配置列表失败: ${error.message}`);
     }
-  });
+  }, [error]);
 
   // 当租户ID准备好时,立即重新获取数据
   useEffect(() => {
@@ -272,7 +277,7 @@ export const PrintConfigManagement: React.FC<PrintConfigManagementProps> = ({
 
     if (configList) {
       // 检查是否是 ConfigListResponse 类型(有 data 属性)
-      if ('data' in configList && Array.isArray(configList.data)) {
+      if (typeof configList === 'object' && 'data' in configList && Array.isArray(configList.data)) {
         console.debug('configList 是 ConfigListResponse 类型');
         configArray = configList.data;
       } else if (Array.isArray(configList)) {

+ 7 - 2
packages/order-management-ui-mt/src/components/OrderManagement.tsx

@@ -4,7 +4,7 @@ import { useForm } from 'react-hook-form';
 import { zodResolver } from '@hookform/resolvers/zod';
 import { format } from 'date-fns';
 import { toast } from 'sonner';
-import { Search, Edit, Eye, Package, Truck, Check, Printer, Play } from 'lucide-react';
+import { Search, Edit, Eye, Package, Truck, Check, Printer } from 'lucide-react';
 
 // 获取认证token的工具函数
 const getAuthToken = (): string | null => {
@@ -498,6 +498,8 @@ export const OrderManagement = () => {
   const [isPrinting, setIsPrinting] = useState(false);
   const [triggeringOrder, setTriggeringOrder] = useState<OrderResponse | null>(null);
   const [isTriggering, setIsTriggering] = useState(false);
+  void triggeringOrder; // 避免TypeScript未使用变量警告
+  void isTriggering; // 避免TypeScript未使用变量警告
   // 用于防止重复提交的请求ID缓存
   const [recentPrintRequests, setRecentPrintRequests] = useState<Map<string, number>>(new Map());
 
@@ -633,6 +635,7 @@ export const OrderManagement = () => {
       toast.error('检查交易管理状态失败,请重试');
     }
   };
+  void handleCheckTradeManaged; // 避免TypeScript未使用变量警告
 
   // 处理编辑订单
   const handleEditOrder = (order: OrderResponse) => {
@@ -1057,7 +1060,8 @@ const sendDeliverySuccessNotification = async (order: OrderResponse, deliveryDat
       }
 
       if (!response) {
-        throw new Error('所有API路径尝试失败');
+        const errorMessage = lastError ? `所有API路径尝试失败,最后错误: ${lastError.message}` : '所有API路径尝试失败';
+        throw new Error(errorMessage);
       }
 
       if (!response.ok) {
@@ -1104,6 +1108,7 @@ const sendDeliverySuccessNotification = async (order: OrderResponse, deliveryDat
       setTriggeringOrder(null);
     }
   };
+  void handleTriggerPaymentSuccess; // 避免TypeScript未使用变量警告
 
   // 处理打印订单
   const handlePrintOrder = async (order: OrderResponse) => {