From bdd4dc38321202f6b2f001db5fc79f99dfa272ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AC=94=E8=AE=B0=E6=9C=AC=E9=87=8C=E7=9A=84=E6=B0=B8?= =?UTF-8?q?=E5=B9=B3?= Date: Mon, 7 Jul 2025 18:11:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9C=AC=E6=AC=A1=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=86=85=E5=AE=B9=E5=A6=82=E4=B8=8B=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E8=8E=B7=E5=AE=A2=E6=9A=82=E6=97=B6=E6=90=9E?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nkebao/src/pages/Home.tsx | 8 +- nkebao/src/pages/scenarios/ScenarioDetail.tsx | 108 ++++++++++++------ 2 files changed, 75 insertions(+), 41 deletions(-) diff --git a/nkebao/src/pages/Home.tsx b/nkebao/src/pages/Home.tsx index 28cbe3192..495c83557 100644 --- a/nkebao/src/pages/Home.tsx +++ b/nkebao/src/pages/Home.tsx @@ -15,28 +15,28 @@ const stats = { const scenarioFeatures = [ { - id: "douyin", + id: "3", name: "抖音获客", value: 156, icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-QR8ManuDplYTySUJsY4mymiZkDYnQ9.png", color: "bg-red-100", }, { - id: "xiaohongshu", + id: "4", name: "小红书获客", value: 89, icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-yvnMxpoBUzcvEkr8DfvHgPHEo1kmQ3.png", color: "bg-pink-100", }, { - id: "gongzhonghao", + id: "6", name: "公众号获客", value: 234, icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-Gsg0CMf5tsZb41mioszdjqU1WmsRxW.png", color: "bg-green-100", }, { - id: "haibao", + id: "1", name: "海报获客", value: 167, icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-x92XJgXy4MI7moNYlA1EAes2FqDxMH.png", diff --git a/nkebao/src/pages/scenarios/ScenarioDetail.tsx b/nkebao/src/pages/scenarios/ScenarioDetail.tsx index 2fae5d577..2c6ec6f56 100644 --- a/nkebao/src/pages/scenarios/ScenarioDetail.tsx +++ b/nkebao/src/pages/scenarios/ScenarioDetail.tsx @@ -84,40 +84,48 @@ export default function ScenarioDetail() { // 获取计划列表 const response = await fetchPlanList(scenarioId, 1, 20); - console.log('API响应:', response); // 添加调试日志 - console.log('响应码:', response?.code); - console.log('响应数据:', response?.data); - console.log('响应消息:', response?.msg); - - // 暂时放宽检查,只要有数据就使用 - if (response && response.data && response.data.list && response.data.list.length > 0) { + // 设置计划列表(可能为空) + if (response && response.data && response.data.list) { setTasks(response.data.list); - - // 计算统计数据 - 添加安全检查 - const totalCustomers = response.data.list.reduce((sum, task) => { - return sum + (task.stats?.acquired || 0); - }, 0); - const todayCustomers = response.data.list.reduce((sum, task) => { - return sum + (task.stats?.acquired || 0); - }, 0); - - // 构建场景数据 - const scenarioData: ScenarioData = { - id: scenarioId, - name: getScenarioName(), - image: '', // 可以根据需要设置图片 - description: getScenarioDescription(scenarioId), - totalPlans: response.data.list.length, - totalCustomers, - todayCustomers: Math.floor(todayCustomers * 0.1), // 模拟今日数据 - growth: `+${Math.floor(Math.random() * 20) + 5}%`, - }; - - setScenario(scenarioData); - } + } else { + setTasks([]); + } + + // 计算统计数据 - 添加安全检查 + const planList = response?.data?.list || []; + const totalCustomers = planList.reduce((sum, task) => { + return sum + (task.stats?.acquired || 0); + }, 0); + const todayCustomers = Math.floor(totalCustomers * 0.1); // 模拟今日数据 + + // 构建场景数据(无论是否有计划都要创建) + const scenarioData: ScenarioData = { + id: scenarioId, + name: getScenarioName(), + image: '', // 可以根据需要设置图片 + description: getScenarioDescription(scenarioId), + totalPlans: planList.length, + totalCustomers, + todayCustomers, + growth: `+${Math.floor(Math.random() * 20) + 5}%`, + }; + + setScenario(scenarioData); } catch (error) { console.error('获取场景数据失败:', error); - + // 即使API失败也要创建基本的场景数据 + const scenarioData: ScenarioData = { + id: scenarioId, + name: getScenarioName(), + image: '', + description: getScenarioDescription(scenarioId), + totalPlans: 0, + totalCustomers: 0, + todayCustomers: 0, + growth: '+0%', + }; + setScenario(scenarioData); + setTasks([]); } finally { setLoading(false); } @@ -317,7 +325,7 @@ export default function ScenarioDetail() { ); } - if (error || !scenario) { + if (error) { return (
-

{error || '场景不存在'}

+

{error}

) : (