From afdd41d6a3e48cb3dc673227adacc4484c386c43 Mon Sep 17 00:00:00 2001 From: mairuiming Date: Wed, 22 Oct 2025 16:19:28 +0800 Subject: [PATCH] 1 1 --- src/App.tsx | 179 ++++++++++++++++------------------------------------ 1 file changed, 54 insertions(+), 125 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 892f513..cb09d7f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,6 +3,7 @@ import { Button, Typography, List, Card, Space, Divider, Spin, Table, Select, Mo import { useState, useEffect } from 'react'; import { addDays, format, isWeekend } from 'date-fns'; import { zhCN } from 'date-fns/locale'; +import { executePricingQuery, executeSecondaryProcessQuery, executePricingDetailsQuery } from './services/apiService'; const { Title, Text } = Typography; @@ -1869,82 +1870,48 @@ export default function App() { const executeQuery = async (packId: string, packType: string) => { setQueryLoading(true); try { - // 调用后端API - const response = await fetch('http://localhost:3001/api/query/pricing', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ packId, packType }) - }); + // 使用 apiService 中的函数 + const data = await executePricingQuery(packId, packType, selectedLabels); + setQueryResults(data); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - - const result = await response.json(); - - if (result.success) { - setQueryResults(result.data); + // 处理品类属性填充到标签8的逻辑保持不变 + if (data && data.length > 0) { + const label8Options = labelOptions['标签8'] || []; + const matchingCategoryValues: string[] = []; - // 处理品类属性填充到标签8 - if (result.data && result.data.length > 0) { - // 收集所有匹配标签8选项的品类属性值 - const label8Options = labelOptions['标签8'] || []; - const matchingCategoryValues: string[] = []; - - result.data.forEach((record: any) => { - if (record.品类属性 && record.品类属性.trim() !== '') { - const categoryValue = record.品类属性.trim(); - const matchingOption = label8Options.find(option => - option.value === categoryValue || option.label === categoryValue - ); - - // 如果找到匹配且不重复,则添加到数组中 - if (matchingOption && !matchingCategoryValues.includes(categoryValue)) { - matchingCategoryValues.push(categoryValue); - } - } - }); - - if (matchingCategoryValues.length > 0) { - console.log('找到匹配的品类属性值:', matchingCategoryValues); - console.log('标签8的选项:', labelOptions['标签8']); + data.forEach((record: any) => { + if (record.品类属性 && record.品类属性.trim() !== '') { + const categoryValue = record.品类属性.trim(); + const matchingOption = label8Options.find(option => + option.value === categoryValue || option.label === categoryValue + ); - // 填充到标签8(多选) - setSelectedLabels(prev => ({ - ...prev, - '标签8': matchingCategoryValues - })); - - console.log('已将品类属性填充到标签8:', matchingCategoryValues); - - if (bitable.ui.showToast) { - await bitable.ui.showToast({ - toastType: 'success', - message: `已将 ${matchingCategoryValues.length} 个品类属性填充到标签8: ${matchingCategoryValues.join(', ')}` - }); - } - } else { - console.log('所有品类属性值都不在标签8选项中'); - - if (bitable.ui.showToast) { - await bitable.ui.showToast({ - toastType: 'info', - message: '查询结果中的品类属性值都不在标签8预设选项中,未自动填充' - }); + if (matchingOption && !matchingCategoryValues.includes(categoryValue)) { + matchingCategoryValues.push(categoryValue); } } - } + }); - if (bitable.ui.showToast) { - await bitable.ui.showToast({ - toastType: 'success', - message: result.message - }); + if (matchingCategoryValues.length > 0) { + setSelectedLabels(prev => ({ + ...prev, + '标签8': matchingCategoryValues + })); + + if (bitable.ui.showToast) { + await bitable.ui.showToast({ + toastType: 'success', + message: `已将 ${matchingCategoryValues.length} 个品类属性填充到标签8: ${matchingCategoryValues.join(', ')}` + }); + } } - } else { - throw new Error(result.message || '查询失败'); + } + + if (bitable.ui.showToast) { + await bitable.ui.showToast({ + toastType: 'success', + message: '查询成功' + }); } } catch (error: any) { @@ -1961,37 +1928,18 @@ export default function App() { }; // 执行二次工艺查询 - const executeSecondaryProcessQuery = async (packId: string, packType: string) => { + const executeSecondaryProcessQueryLocal = async (packId: string, packType: string) => { setSecondaryProcessLoading(true); try { - // 调用后端API - const response = await fetch('http://localhost:3001/api/query/secondary-process', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ packId, packType }) - }); + const data = await executeSecondaryProcessQuery(packId, packType); + setSecondaryProcessResults(data); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + if (bitable.ui.showToast) { + await bitable.ui.showToast({ + toastType: 'success', + message: '二次工艺查询成功' + }); } - - const result = await response.json(); - - if (result.success) { - setSecondaryProcessResults(result.data); - - if (bitable.ui.showToast) { - await bitable.ui.showToast({ - toastType: 'success', - message: result.message - }); - } - } else { - throw new Error(result.message || '二次工艺查询失败'); - } - } catch (error: any) { console.error('二次工艺查询出错:', error); if (bitable.ui.showToast) { @@ -2006,37 +1954,18 @@ export default function App() { }; // 执行定价详情查询 - const executePricingDetailsQuery = async (packId: string) => { + const executePricingDetailsQueryLocal = async (packId: string) => { setPricingDetailsLoading(true); try { - // 调用后端API - const response = await fetch('http://localhost:3001/api/query/pricing-details', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ packId }) - }); + const data = await executePricingDetailsQuery(packId); + setPricingDetailsResults(data); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + if (bitable.ui.showToast) { + await bitable.ui.showToast({ + toastType: 'success', + message: '定价详情查询成功' + }); } - - const result = await response.json(); - - if (result.success) { - setPricingDetailsResults(result.data); - - if (bitable.ui.showToast) { - await bitable.ui.showToast({ - toastType: 'success', - message: result.message - }); - } - } else { - throw new Error(result.message || '定价详情查询失败'); - } - } catch (error: any) { console.error('定价详情查询出错:', error); if (bitable.ui.showToast) { @@ -2105,7 +2034,7 @@ export default function App() { return; } - await executeSecondaryProcessQuery(packId, packType); + await executeSecondaryProcessQueryLocal(packId, packType); }; // 处理定价详情查询 @@ -2128,7 +2057,7 @@ export default function App() { return; } - await executePricingDetailsQuery(packId); + await executePricingDetailsQueryLocal(packId); };