diff --git a/nkebao/src/pages/scenarios/ScenarioDetail.tsx b/nkebao/src/pages/scenarios/ScenarioDetail.tsx
index 40781f0b..2fae5d57 100644
--- a/nkebao/src/pages/scenarios/ScenarioDetail.tsx
+++ b/nkebao/src/pages/scenarios/ScenarioDetail.tsx
@@ -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
(null);
const [tasks, setTasks] = useState([]);
@@ -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}`);
};
diff --git a/nkebao/src/pages/scenarios/Scenarios.tsx b/nkebao/src/pages/scenarios/Scenarios.tsx
index d8d724a5..55858d4b 100644
--- a/nkebao/src/pages/scenarios/Scenarios.tsx
+++ b/nkebao/src/pages/scenarios/Scenarios.tsx
@@ -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() {
handleScenarioClick(scenario.id)}
+ onClick={() => handleScenarioClick(scenario.id,scenario.name)}
>