feat: 本次提交更新内容如下
场景获客暂时搞定
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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 (
|
||||
<Layout
|
||||
header={
|
||||
@@ -330,7 +338,7 @@ export default function ScenarioDetail() {
|
||||
>
|
||||
<div className="bg-gray-50 min-h-screen flex items-center justify-center">
|
||||
<div className="text-center">
|
||||
<p className="text-red-500 mb-4">{error || '场景不存在'}</p>
|
||||
<p className="text-red-500 mb-4">{error}</p>
|
||||
<button
|
||||
onClick={() => window.location.reload()}
|
||||
className="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors"
|
||||
@@ -343,6 +351,27 @@ export default function ScenarioDetail() {
|
||||
);
|
||||
}
|
||||
|
||||
if (!scenario) {
|
||||
return (
|
||||
<Layout
|
||||
header={
|
||||
<PageHeader
|
||||
title="场景详情"
|
||||
defaultBackPath="/scenarios"
|
||||
/>
|
||||
}
|
||||
footer={<BottomNav />}
|
||||
>
|
||||
<div className="bg-gray-50 min-h-screen flex items-center justify-center">
|
||||
<div className="flex flex-col items-center space-y-4">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-blue-500" />
|
||||
<p className="text-gray-500">加载场景数据中...</p>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout
|
||||
header={
|
||||
@@ -406,13 +435,18 @@ export default function ScenarioDetail() {
|
||||
</div>
|
||||
|
||||
{tasks.length === 0 ? (
|
||||
<div className="p-8 text-center text-gray-500">
|
||||
<p>暂无获客计划</p>
|
||||
<div className="p-8 text-center">
|
||||
<div className="mb-4">
|
||||
<Users className="h-12 w-12 text-gray-300 mx-auto mb-3" />
|
||||
<p className="text-gray-500 text-lg font-medium mb-2">暂无获客计划</p>
|
||||
<p className="text-gray-400 text-sm">创建您的第一个获客计划,开始获取客户</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={handleCreateNewPlan}
|
||||
className="mt-2 text-blue-600 hover:text-blue-700"
|
||||
className="inline-flex items-center px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors"
|
||||
>
|
||||
立即创建
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
创建第一个计划
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user