feat: 本次提交更新内容如下

场景获客暂时缓存,目前没问题
This commit is contained in:
笔记本里的永平
2025-07-07 18:00:08 +08:00
parent 86f7718d2b
commit b33ce7275d
4 changed files with 33 additions and 176 deletions

View File

@@ -21,11 +21,6 @@ import TrafficDistributionDetail from './pages/workspace/traffic-distribution/De
import Scenarios from './pages/scenarios/Scenarios';
import NewPlan from './pages/scenarios/NewPlan';
import ScenarioDetail from './pages/scenarios/ScenarioDetail';
// 导入具体场景组件
import DouyinScenario from './pages/scenarios/douyin/DouyinScenario';
import XiaohongshuScenario from './pages/scenarios/xiaohongshu/XiaohongshuScenario';
import GongzhonghaoScenario from './pages/scenarios/gongzhonghao/GongzhonghaoScenario';
import HaibaoScenario from './pages/scenarios/haibao/HaibaoScenario';
import Profile from './pages/profile/Profile';
import Plans from './pages/plans/Plans';
import PlanDetail from './pages/plans/PlanDetail';
@@ -63,12 +58,7 @@ function App() {
<Route path="/workspace/traffic-distribution/:id" element={<TrafficDistributionDetail />} />
<Route path="/scenarios" element={<Scenarios />} />
<Route path="/scenarios/new" element={<NewPlan />} />
{/* 具体场景路由 - 必须在通用路由之前 */}
<Route path="/scenarios/douyin" element={<DouyinScenario />} />
<Route path="/scenarios/xiaohongshu" element={<XiaohongshuScenario />} />
<Route path="/scenarios/gongzhonghao" element={<GongzhonghaoScenario />} />
<Route path="/scenarios/haibao" element={<HaibaoScenario />} />
{/* 通用场景路由 */}
{/* 通用场景路由 - 支持查询参数传递name */}
<Route path="/scenarios/:scenarioId" element={<ScenarioDetail />} />
<Route path="/profile" element={<Profile />} />
<Route path="/plans" element={<Plans />} />

View File

@@ -213,7 +213,7 @@ export default function Home() {
<div
key={scenario.id}
className="block flex-1 cursor-pointer"
onClick={() => navigate(`/scenarios/${scenario.id}`)}
onClick={() => navigate(`/scenarios/${scenario.id}?name=${encodeURIComponent(scenario.name)}`)}
>
<div className="flex flex-col items-center text-center space-y-2">
<div className={`w-12 h-12 rounded-full ${scenario.color} flex items-center justify-center`}>

View File

@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { useParams, useNavigate, useSearchParams } from 'react-router-dom';
import PageHeader from '@/components/PageHeader';
import Layout from '@/components/Layout';
import BottomNav from '@/components/BottomNav';
@@ -28,6 +28,7 @@ interface ApiSettings {
export default function ScenarioDetail() {
const { scenarioId } = useParams<{ scenarioId: string }>();
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const { toast } = useToast();
const [scenario, setScenario] = useState<ScenarioData | null>(null);
const [tasks, setTasks] = useState<Task[]>([]);
@@ -103,7 +104,7 @@ export default function ScenarioDetail() {
// 构建场景数据
const scenarioData: ScenarioData = {
id: scenarioId,
name: getChannelName(scenarioId),
name: getScenarioName(),
image: '', // 可以根据需要设置图片
description: getScenarioDescription(scenarioId),
totalPlans: response.data.list.length,
@@ -113,83 +114,10 @@ export default function ScenarioDetail() {
};
setScenario(scenarioData);
} else {
// API返回错误使用模拟数据
console.warn('API返回错误或无数据使用模拟数据:', response?.msg, '响应码:', response?.code);
const mockTasks: Task[] = [
{
id: '1',
name: `${getChannelName(scenarioId)}计划A`,
status: 'running',
stats: {
devices: Math.floor(Math.random() * 10) + 3,
acquired: Math.floor(Math.random() * 500) + 100,
added: Math.floor(Math.random() * 300) + 50,
},
lastUpdated: new Date().toLocaleString('zh-CN'),
executionTime: new Date().toLocaleString('zh-CN'),
nextExecutionTime: '2024-02-09 17:25:36',
trend: Array.from({ length: 7 }, (_, i) => ({
date: `2024-02-${String(i + 1).padStart(2, '0')}`,
customers: Math.floor(Math.random() * 100) + 50,
})),
},
];
setTasks(mockTasks);
const scenarioData: ScenarioData = {
id: scenarioId,
name: getChannelName(scenarioId),
image: '',
description: getScenarioDescription(scenarioId),
totalPlans: mockTasks.length,
totalCustomers: mockTasks[0].stats.acquired,
todayCustomers: Math.floor(mockTasks[0].stats.acquired * 0.1),
growth: `+${Math.floor(Math.random() * 20) + 5}%`,
};
setScenario(scenarioData);
}
}
} catch (error) {
console.error('获取场景数据失败:', error);
setError('获取场景数据失败,请稍后重试');
// 网络错误时使用模拟数据
const mockTasks: Task[] = [
{
id: '1',
name: `${getChannelName(scenarioId)}计划A`,
status: 'running',
stats: {
devices: Math.floor(Math.random() * 10) + 3,
acquired: Math.floor(Math.random() * 500) + 100,
added: Math.floor(Math.random() * 300) + 50,
},
lastUpdated: new Date().toLocaleString('zh-CN'),
executionTime: new Date().toLocaleString('zh-CN'),
nextExecutionTime: '2024-02-09 17:25:36',
trend: Array.from({ length: 7 }, (_, i) => ({
date: `2024-02-${String(i + 1).padStart(2, '0')}`,
customers: Math.floor(Math.random() * 100) + 50,
})),
},
];
setTasks(mockTasks);
const scenarioData: ScenarioData = {
id: scenarioId,
name: getChannelName(scenarioId),
image: '',
description: getScenarioDescription(scenarioId),
totalPlans: mockTasks.length,
totalCustomers: mockTasks[0].stats.acquired,
todayCustomers: Math.floor(mockTasks[0].stats.acquired * 0.1),
growth: `+${Math.floor(Math.random() * 20) + 5}%`,
};
setScenario(scenarioData);
} finally {
setLoading(false);
}
@@ -198,6 +126,28 @@ export default function ScenarioDetail() {
fetchScenarioData();
}, [scenarioId]);
// 获取场景名称 - 优先使用URL查询参数其次使用映射
const getScenarioName = () => {
// 优先使用URL查询参数中的name
const urlName = searchParams.get('name');
if (urlName) {
return urlName;
}
// 如果没有URL参数使用映射
return getChannelName(scenarioId || '');
};
// 更新场景数据中的名称
useEffect(() => {
if (scenario) {
setScenario(prev => prev ? {
...prev,
name: getScenarioName()
} : null);
}
}, [searchParams, scenarioId]);
const handleEditPlan = (taskId: string) => {
navigate(`/scenarios/${scenarioId}/edit/${taskId}`);
};

View File

@@ -58,93 +58,10 @@ export default function Scenarios() {
}));
setScenarios(transformedScenarios);
} else {
// API返回错误使用模拟数据作为降级方案
console.warn('API返回错误使用模拟数据:', response?.msg);
const mockScenarios: Scenario[] = [
{
id: "douyin",
name: "抖音获客",
image: 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-QR8ManuDplYTySUJsY4mymiZkDYnQ9.png',
description: scenarioDescriptions['douyin'],
count: 156,
growth: "+12%",
status: "active",
},
{
id: "xiaohongshu",
name: "小红书获客",
image: 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-yvnMxpoBUzcvEkr8DfvHgPHEo1kmQ3.png',
description: scenarioDescriptions['xiaohongshu'],
count: 89,
growth: "+8%",
status: "active",
},
{
id: "gongzhonghao",
name: "公众号获客",
image: 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-Gsg0CMf5tsZb41mioszdjqU1WmsRxW.png',
description: scenarioDescriptions['gongzhonghao'],
count: 234,
growth: "+15%",
status: "active",
},
{
id: "haibao",
name: "海报获客",
image: 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-x92XJgXy4MI7moNYlA1EAes2FqDxMH.png',
description: scenarioDescriptions['haibao'],
count: 167,
growth: "+10%",
status: "active",
},
];
setScenarios(mockScenarios);
}
}
} catch (error) {
console.error('获取场景数据失败:', error);
setError('获取场景数据失败,请稍后重试');
// 网络错误时也使用模拟数据
const mockScenarios: Scenario[] = [
{
id: "douyin",
name: "抖音获客",
image: 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-QR8ManuDplYTySUJsY4mymiZkDYnQ9.png',
description: scenarioDescriptions['douyin'],
count: 156,
growth: "+12%",
status: "active",
},
{
id: "xiaohongshu",
name: "小红书获客",
image: 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-yvnMxpoBUzcvEkr8DfvHgPHEo1kmQ3.png',
description: scenarioDescriptions['xiaohongshu'],
count: 89,
growth: "+8%",
status: "active",
},
{
id: "gongzhonghao",
name: "公众号获客",
image: 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-Gsg0CMf5tsZb41mioszdjqU1WmsRxW.png',
description: scenarioDescriptions['gongzhonghao'],
count: 234,
growth: "+15%",
status: "active",
},
{
id: "haibao",
name: "海报获客",
image: 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-x92XJgXy4MI7moNYlA1EAes2FqDxMH.png',
description: scenarioDescriptions['haibao'],
count: 167,
growth: "+10%",
status: "active",
},
];
setScenarios(mockScenarios);
} finally {
setLoading(false);
}
@@ -153,8 +70,8 @@ export default function Scenarios() {
fetchScenarios();
}, []);
const handleScenarioClick = (scenarioId: string) => {
navigate(`/scenarios/${scenarioId}`);
const handleScenarioClick = (scenarioId: string,scenarioName:string) => {
navigate(`/scenarios/${scenarioId}?name=${encodeURIComponent(scenarioName)}`);
};
const handleNewPlan = () => {
@@ -240,7 +157,7 @@ export default function Scenarios() {
<div
key={scenario.id}
className="bg-white rounded-lg shadow overflow-hidden hover:shadow-md transition-shadow cursor-pointer"
onClick={() => handleScenarioClick(scenario.id)}
onClick={() => handleScenarioClick(scenario.id,scenario.name)}
>
<div className="p-4 flex flex-col items-center">
<div className="w-12 h-12 bg-gray-200 rounded-full flex items-center justify-center mb-2">