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}

) : (