feat: Dashboard 接真 API,题图渐变占位,排播占位,近9期收视柱图,颜色按年度目标判定
This commit is contained in:
@@ -34,6 +34,33 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
color: var(--color-primary-green);
|
color: var(--color-primary-green);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-placeholder-gradient {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: linear-gradient(135deg, #6b8e6b 0%, #a8c89a 50%, #d4e6b5 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.change-cover-btn {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 6px;
|
||||||
|
right: 6px;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.placeholder-label {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
z-index: 2;
|
||||||
|
color: rgba(255,255,255,0.85);
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* KPI Cards */
|
/* KPI Cards */
|
||||||
|
|||||||
@@ -1,32 +1,30 @@
|
|||||||
import { Row, Col, Card, Avatar, Tooltip } from 'antd'
|
import { useState, useEffect } from 'react'
|
||||||
|
import { Row, Col, Card, Avatar, Tooltip, Button } from 'antd'
|
||||||
import {
|
import {
|
||||||
BarChartOutlined,
|
BarChartOutlined,
|
||||||
EyeOutlined,
|
EyeOutlined,
|
||||||
CalendarOutlined,
|
CalendarOutlined,
|
||||||
FireOutlined,
|
FireOutlined,
|
||||||
|
PictureOutlined,
|
||||||
} from '@ant-design/icons'
|
} from '@ant-design/icons'
|
||||||
|
import useAuthStore from '../../stores/authStore'
|
||||||
|
import { listEpisodes } from '../../services/episodeService'
|
||||||
|
import { listTargets } from '../../services/yearlyTargetService'
|
||||||
import './Dashboard.css'
|
import './Dashboard.css'
|
||||||
|
|
||||||
// 假数据:近 9 期收视(基础目标 0.6,摸高目标 0.9)
|
/**
|
||||||
const fakeEpisodes = [
|
* 收视份额颜色判定(极易写反,禁止凭直觉):
|
||||||
{ id: 1, title: '第 1247 期 现代防空反导大对决', editor: 'simonkoson', share: 0.72 },
|
* audience_share > stretch_target → 🔴 红(优秀)
|
||||||
{ id: 2, title: '第 1246 期 深海暗战', editor: 'simonkoson', share: 0.85 },
|
* base_target ≤ audience_share ≤ stretch_target → 🔵 蓝(达标)
|
||||||
{ id: 3, title: '第 1245 期 隐形战场', editor: 'simonkoson', share: 0.94 },
|
* audience_share < base_target → 🟢 绿(待提升)
|
||||||
{ id: 4, title: '第 1244 期 无人机革命', editor: 'simonkoson', share: 0.65 },
|
* 判色取该期 air_date 所属年份的 yearly_targets 行(不是当前年)。
|
||||||
{ id: 5, title: '第 1243 期 核潜艇传奇', editor: 'simonkoson', share: 0.58 },
|
*/
|
||||||
{ id: 6, title: '第 1242 期 电子战风暴', editor: 'simonkoson', share: 0.88 },
|
function getShareColor(share, targets, airYear) {
|
||||||
{ id: 7, title: '第 1241 期 太空博弈', editor: 'simonkoson', share: 0.91 },
|
const target = targets.find(t => t.year === airYear)
|
||||||
{ id: 8, title: '第 1240 期 装甲对决', editor: 'simonkoson', share: 0.67 },
|
if (!target) return '#999'
|
||||||
{ id: 9, title: '第 1239 期 隐身战机', editor: 'simonkoson', share: 0.55 },
|
if (share > target.stretch_target) return '#cf1322' // 红=优秀
|
||||||
]
|
if (share >= target.base_target) return '#6b8e6b' // 蓝=达标
|
||||||
|
return '#d4a017' // 绿=待提升
|
||||||
const BASE_TARGET = 0.6
|
|
||||||
const STRETCH_TARGET = 0.9
|
|
||||||
|
|
||||||
function getBarColor(share) {
|
|
||||||
if (share > STRETCH_TARGET) return '#cf1322' // 红=优秀
|
|
||||||
if (share >= BASE_TARGET) return '#6b8e6b' // 蓝=达标
|
|
||||||
return '#d4a017' // 绿=待提升
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBarHeight(share) {
|
function getBarHeight(share) {
|
||||||
@@ -38,16 +36,63 @@ function getShortTitle(title) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Dashboard() {
|
function Dashboard() {
|
||||||
|
const { user } = useAuthStore()
|
||||||
|
const [episodes, setEpisodes] = useState([])
|
||||||
|
const [targets, setTargets] = useState([])
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
Promise.all([
|
||||||
|
listEpisodes(limit = 9),
|
||||||
|
listTargets(),
|
||||||
|
]).then(([epData, tgtData]) => {
|
||||||
|
// 按 air_date 倒序取前 9
|
||||||
|
const sorted = (epData || []).sort((a, b) => new Date(b.air_date) - new Date(a.air_date)).slice(0, 9)
|
||||||
|
setEpisodes(sorted)
|
||||||
|
setTargets(tgtData || [])
|
||||||
|
setLoading(false)
|
||||||
|
}).catch(() => {
|
||||||
|
setLoading(false)
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// 显示最近有份额数据的期次(最多9个,不够用真实数据补位)
|
||||||
|
const hasShare = episodes.filter(e => e.audience_share != null)
|
||||||
|
const displayEpisodes = hasShare.length >= 5 ? hasShare.slice(0, 9) : episodes.slice(0, Math.max(9, hasShare.length || 5))
|
||||||
|
|
||||||
|
const bestEpisode = [...displayEpisodes].filter(e => e.audience_share != null).sort((a, b) => b.audience_share - a.audience_share)[0]
|
||||||
|
|
||||||
|
const showChangeCoverBtn = user?.role === 'zhipianren' || user?.role === 'zebian'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="dashboard">
|
<div className="dashboard">
|
||||||
{/* 顶部 Banner */}
|
{/* 顶部 Banner */}
|
||||||
<div className="dashboard-banner">
|
<div className="dashboard-banner">
|
||||||
<div className="banner-text">
|
<div className="banner-text">
|
||||||
<h2>本月收视最佳</h2>
|
<h2>本月收视最佳</h2>
|
||||||
<p>第 1245 期 隐形战场 · 收视份额 0.94</p>
|
{bestEpisode ? (
|
||||||
|
<p>
|
||||||
|
第 {bestEpisode.episode_number} 期 {bestEpisode.program_name} ·
|
||||||
|
收视份额 {bestEpisode.audience_share}
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<p>暂无收视数据</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
{/* 题图渐变占位 */}
|
||||||
<div className="banner-image-placeholder">
|
<div className="banner-image-placeholder">
|
||||||
<span>题图位 · 待 Phase 2 实装</span>
|
<div className="banner-placeholder-gradient" />
|
||||||
|
{showChangeCoverBtn && (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
icon={<PictureOutlined />}
|
||||||
|
disabled
|
||||||
|
className="change-cover-btn"
|
||||||
|
>
|
||||||
|
更换题图
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<span className="placeholder-label">敬请期待</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -59,8 +104,8 @@ function Dashboard() {
|
|||||||
<EyeOutlined style={{ color: '#6b8e6b', fontSize: 24 }} />
|
<EyeOutlined style={{ color: '#6b8e6b', fontSize: 24 }} />
|
||||||
</div>
|
</div>
|
||||||
<div className="kpi-info">
|
<div className="kpi-info">
|
||||||
<span className="kpi-value">0.82</span>
|
<span className="kpi-value">{displayEpisodes.filter(e => e.audience_share).length || '--'}</span>
|
||||||
<span className="kpi-label">本期平均收视</span>
|
<span className="kpi-label">近 9 期已录</span>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -70,8 +115,10 @@ function Dashboard() {
|
|||||||
<FireOutlined style={{ color: '#ff9800', fontSize: 24 }} />
|
<FireOutlined style={{ color: '#ff9800', fontSize: 24 }} />
|
||||||
</div>
|
</div>
|
||||||
<div className="kpi-info">
|
<div className="kpi-info">
|
||||||
<span className="kpi-value">98.6%</span>
|
<span className="kpi-value">
|
||||||
<span className="kpi-label">完成率</span>
|
{bestEpisode ? (bestEpisode.audience_share * 100).toFixed(1) + '%' : '--'}
|
||||||
|
</span>
|
||||||
|
<span className="kpi-label">最佳收视份额</span>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -81,8 +128,8 @@ function Dashboard() {
|
|||||||
<CalendarOutlined style={{ color: '#2196f3', fontSize: 24 }} />
|
<CalendarOutlined style={{ color: '#2196f3', fontSize: 24 }} />
|
||||||
</div>
|
</div>
|
||||||
<div className="kpi-info">
|
<div className="kpi-info">
|
||||||
<span className="kpi-value">6</span>
|
<span className="kpi-value">{targets.length || '--'}</span>
|
||||||
<span className="kpi-label">未来待排期</span>
|
<span className="kpi-label">年度目标条数</span>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -95,35 +142,43 @@ function Dashboard() {
|
|||||||
<Card className="content-card" title="热点雷达">
|
<Card className="content-card" title="热点雷达">
|
||||||
<div className="placeholder-text">
|
<div className="placeholder-text">
|
||||||
<BarChartOutlined style={{ fontSize: 32, color: '#ccc', marginBottom: 8 }} />
|
<BarChartOutlined style={{ fontSize: 32, color: '#ccc', marginBottom: 8 }} />
|
||||||
<p>模块 H · Phase 4c 实施</p>
|
<p>热点雷达 · Phase 4c</p>
|
||||||
<small>热点雷达将在 Phase 4c 开发,作为编导个人首页的核心功能</small>
|
<small>编导个人首页核心功能,Phase 4c 实施</small>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
{/* 近 9 期收视柱图 */}
|
{/* 近 9 期收视柱图 */}
|
||||||
<Col span={8}>
|
<Col span={8}>
|
||||||
<Card className="content-card" title="近 9 期收视">
|
<Card className="content-card" title="近 9 期收视" loading={loading}>
|
||||||
<div className="chart-container">
|
<div className="chart-container">
|
||||||
<div className="bars-wrapper">
|
<div className="bars-wrapper">
|
||||||
{fakeEpisodes.map((ep) => (
|
{displayEpisodes.map((ep) => {
|
||||||
<div key={ep.id} className="bar-item">
|
const airYear = new Date(ep.air_date).getFullYear()
|
||||||
<Tooltip title={`${ep.title} · ${ep.share}`}>
|
const color = ep.audience_share != null
|
||||||
<div
|
? getShareColor(ep.audience_share, targets, airYear)
|
||||||
className="bar"
|
: '#ccc'
|
||||||
style={{
|
return (
|
||||||
height: getBarHeight(ep.share),
|
<div key={ep.id} className="bar-item">
|
||||||
backgroundColor: getBarColor(ep.share),
|
<Tooltip title={`${ep.program_name} · ${ep.audience_share ?? '无数据'}`}>
|
||||||
}}
|
<div
|
||||||
/>
|
className="bar"
|
||||||
</Tooltip>
|
style={{
|
||||||
<div className="bar-label-top">{getShortTitle(ep.title)}</div>
|
height: ep.audience_share != null ? getBarHeight(ep.audience_share) : 20,
|
||||||
<div className="bar-label-bottom">
|
backgroundColor: color,
|
||||||
<Avatar size={20} style={{ fontSize: 10 }}>{ep.editor[0]}</Avatar>
|
}}
|
||||||
<span>{ep.editor}</span>
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
<div className="bar-label-top">{getShortTitle(ep.program_name)}</div>
|
||||||
|
<div className="bar-label-bottom">
|
||||||
|
<Avatar size={20} style={{ fontSize: 10 }}>
|
||||||
|
{(ep.editor_name_snapshot || '?')[0]}
|
||||||
|
</Avatar>
|
||||||
|
<span>{ep.editor_name_snapshot || '未知'}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)
|
||||||
))}
|
})}
|
||||||
</div>
|
</div>
|
||||||
<div className="chart-legend">
|
<div className="chart-legend">
|
||||||
<span className="legend-item"><span className="dot" style={{ background: '#cf1322' }}></span>红=优秀</span>
|
<span className="legend-item"><span className="dot" style={{ background: '#cf1322' }}></span>红=优秀</span>
|
||||||
@@ -136,11 +191,11 @@ function Dashboard() {
|
|||||||
|
|
||||||
{/* 排播计划 */}
|
{/* 排播计划 */}
|
||||||
<Col span={8}>
|
<Col span={8}>
|
||||||
<Card className="content-card" title="排播计划">
|
<Card className="content-card" title="未来排播计划">
|
||||||
<div className="placeholder-text">
|
<div className="placeholder-text">
|
||||||
<CalendarOutlined style={{ fontSize: 32, color: '#ccc', marginBottom: 8 }} />
|
<CalendarOutlined style={{ fontSize: 32, color: '#ccc', marginBottom: 8 }} />
|
||||||
<p>模块 F · Phase 4b 实施</p>
|
<p>排播计划 · Phase 4b</p>
|
||||||
<small>甘特图排期将在 Phase 4b 开发,使用 frappe-gantt 实现拖拽排期</small>
|
<small>甘特图排期使用 frappe-gantt 实现,Phase 4b 开发</small>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
Reference in New Issue
Block a user