From b33ce7275d7b6a61b030c10a2ec65c5978893bdd 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:00:08 +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=E7=BC=93?= =?UTF-8?q?=E5=AD=98=EF=BC=8C=E7=9B=AE=E5=89=8D=E6=B2=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nkebao/src/App.tsx | 12 +- nkebao/src/pages/Home.tsx | 2 +- nkebao/src/pages/scenarios/ScenarioDetail.tsx | 104 +++++------------- nkebao/src/pages/scenarios/Scenarios.tsx | 91 +-------------- 4 files changed, 33 insertions(+), 176 deletions(-) diff --git a/nkebao/src/App.tsx b/nkebao/src/App.tsx index a12caac0..83c41992 100644 --- a/nkebao/src/App.tsx +++ b/nkebao/src/App.tsx @@ -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() { } /> } /> } /> - {/* 具体场景路由 - 必须在通用路由之前 */} - } /> - } /> - } /> - } /> - {/* 通用场景路由 */} + {/* 通用场景路由 - 支持查询参数传递name */} } /> } /> } /> diff --git a/nkebao/src/pages/Home.tsx b/nkebao/src/pages/Home.tsx index 0c9cada7..28cbe319 100644 --- a/nkebao/src/pages/Home.tsx +++ b/nkebao/src/pages/Home.tsx @@ -213,7 +213,7 @@ export default function Home() {
navigate(`/scenarios/${scenario.id}`)} + onClick={() => navigate(`/scenarios/${scenario.id}?name=${encodeURIComponent(scenario.name)}`)} >
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)} >