Make starter project delivery-ready
This commit is contained in:
1 parent
5b300dee0d
commit
d7bfde754b
22 files changed
+695
-71
No files matched your search
@@ -0,0 +1,3 @@
|
||||
VITE_API_BASE_URL=http://localhost:3000
|
||||
VITE_WS_URL=ws://localhost:3000/ws/screen
|
||||
VITE_ENABLE_STAGE_DEBUG=true
|
||||
@@ -1,17 +1,91 @@
|
||||
import { MetricCard, ScreenStage } from '@dev-screen-starter/screen-core'
|
||||
import { ChartPanel, createAreaTrendOption, createRankBarOption } from '@dev-screen-starter/charts'
|
||||
import { useScreenDataSources } from '@dev-screen-starter/data'
|
||||
import { MetricCard, ScreenStage, type ScaleMode } from '@dev-screen-starter/screen-core'
|
||||
import { CornerFrame, Divider, GlowPanel, ScrollTable, SectionTitle, StatusPill } from '@dev-screen-starter/visual-kit'
|
||||
import { screenDataSources } from './dataSources'
|
||||
|
||||
const scaleModes: ScaleMode[] = ['fit', 'fill', 'stretch', 'none']
|
||||
|
||||
function readScaleMode(): ScaleMode {
|
||||
if (typeof window === 'undefined') {
|
||||
return 'fit'
|
||||
}
|
||||
|
||||
const value = new URLSearchParams(window.location.search).get('scaleMode')
|
||||
return scaleModes.includes(value as ScaleMode) ? (value as ScaleMode) : 'fit'
|
||||
}
|
||||
|
||||
export function ProjectScreen() {
|
||||
const scaleMode = readScaleMode()
|
||||
const data = useScreenDataSources(screenDataSources)
|
||||
const metrics = data.metrics.data ?? []
|
||||
const trend = data.trend.data
|
||||
const rank = data.rank.data
|
||||
const alerts = data.alerts.data ?? []
|
||||
const debug = import.meta.env.VITE_ENABLE_STAGE_DEBUG === 'true'
|
||||
|
||||
return (
|
||||
<ScreenStage background="#061826">
|
||||
<ScreenStage background="#061826" scaleMode={scaleMode} debug={debug}>
|
||||
<header className="screen-title">
|
||||
<span>__PROJECT_TITLE__</span>
|
||||
<strong>大屏总览</strong>
|
||||
<small>scaleMode={scaleMode}</small>
|
||||
</header>
|
||||
|
||||
<section className="status-strip">
|
||||
<CornerFrame>
|
||||
<SectionTitle title="运行态" subtitle="Project starter" size="sm" />
|
||||
<Divider />
|
||||
<div className="status-row">
|
||||
<StatusPill label="稳定" />
|
||||
<StatusPill label="预警" status="warning" />
|
||||
<StatusPill label="异常" status="danger" />
|
||||
</div>
|
||||
</CornerFrame>
|
||||
|
||||
<GlowPanel title="实时告警" tone="amber">
|
||||
<ScrollTable
|
||||
columns={[
|
||||
{ key: 'time', title: '时间', width: '68px' },
|
||||
{ key: 'area', title: '区域' },
|
||||
{ key: 'status', title: '状态' }
|
||||
]}
|
||||
rows={alerts}
|
||||
/>
|
||||
</GlowPanel>
|
||||
</section>
|
||||
|
||||
<section className="metric-row">
|
||||
<MetricCard label="指标一" value="--" />
|
||||
<MetricCard label="指标二" value="--" />
|
||||
<MetricCard label="指标三" value="--" />
|
||||
{metrics.map((metric) => (
|
||||
<MetricCard key={metric.label} {...metric} />
|
||||
))}
|
||||
</section>
|
||||
|
||||
<section className="chart-grid">
|
||||
<ChartPanel
|
||||
title="趋势图"
|
||||
option={
|
||||
trend
|
||||
? createAreaTrendOption({
|
||||
categories: trend.categories,
|
||||
values: trend.values,
|
||||
name: '订单'
|
||||
})
|
||||
: null
|
||||
}
|
||||
/>
|
||||
<ChartPanel
|
||||
title="区域排行"
|
||||
option={
|
||||
rank
|
||||
? createRankBarOption({
|
||||
categories: rank.categories,
|
||||
values: rank.values,
|
||||
name: '订单'
|
||||
})
|
||||
: null
|
||||
}
|
||||
/>
|
||||
</section>
|
||||
</ScreenStage>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { defineDataSources, httpSource, mockSource, websocketSource } from '@dev-screen-starter/data'
|
||||
import { alerts, metrics, rank, trend } from './mockData'
|
||||
|
||||
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL
|
||||
const wsUrl = import.meta.env.VITE_WS_URL
|
||||
|
||||
export const screenDataSources = defineDataSources({
|
||||
metrics: mockSource({
|
||||
data: metrics,
|
||||
intervalMs: 15000
|
||||
}),
|
||||
|
||||
trend: mockSource({
|
||||
data: trend
|
||||
}),
|
||||
|
||||
rank: mockSource({
|
||||
data: rank
|
||||
}),
|
||||
|
||||
alerts: mockSource({
|
||||
data: alerts,
|
||||
intervalMs: 10000
|
||||
}),
|
||||
|
||||
// Replace the mock source above with this source when the customer API is ready.
|
||||
overviewApi: httpSource({
|
||||
enabled: false,
|
||||
baseUrl: apiBaseUrl,
|
||||
url: '/api/screen/overview',
|
||||
timeoutMs: 8000,
|
||||
intervalMs: 10000
|
||||
}),
|
||||
|
||||
// Enable this source for pushed event streams.
|
||||
realtimeAlerts: websocketSource({
|
||||
enabled: false,
|
||||
url: wsUrl,
|
||||
mode: 'append',
|
||||
maxItems: 20,
|
||||
reconnect: { enabled: true, maxRetries: 10, delayMs: 3000 },
|
||||
heartbeat: { message: 'ping', intervalMs: 30000 }
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { ProjectScreen } from './ProjectScreen'
|
||||
import '@dev-screen-starter/visual-kit/styles.css'
|
||||
import './screen.css'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(<ProjectScreen />)
|
||||
@@ -0,0 +1,21 @@
|
||||
export const metrics = [
|
||||
{ label: '今日订单', value: 1280, unit: '单', tone: 'blue' as const },
|
||||
{ label: '在线设备', value: 342, unit: '台', tone: 'green' as const },
|
||||
{ label: '告警数量', value: 17, unit: '条', tone: 'amber' as const }
|
||||
]
|
||||
|
||||
export const trend = {
|
||||
categories: ['08:00', '10:00', '12:00', '14:00', '16:00', '18:00'],
|
||||
values: [120, 240, 380, 520, 760, 920]
|
||||
}
|
||||
|
||||
export const rank = {
|
||||
categories: ['华东', '华南', '华北', '西南', '东北'],
|
||||
values: [960, 820, 680, 520, 390]
|
||||
}
|
||||
|
||||
export const alerts = [
|
||||
{ time: '18:20', area: '华东仓', status: '履约延迟' },
|
||||
{ time: '18:12', area: '华南仓', status: '库存预警' },
|
||||
{ time: '17:48', area: '华北仓', status: '接口抖动' }
|
||||
]
|
||||
@@ -27,6 +27,9 @@ body {
|
||||
}
|
||||
|
||||
.screen-title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
left: 56px;
|
||||
position: absolute;
|
||||
top: 42px;
|
||||
@@ -34,9 +37,7 @@ body {
|
||||
|
||||
.screen-title span {
|
||||
color: #88a1bd;
|
||||
display: block;
|
||||
font-size: 16px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.screen-title strong {
|
||||
@@ -44,6 +45,32 @@ body {
|
||||
font-size: 42px;
|
||||
}
|
||||
|
||||
.screen-title small {
|
||||
border: 1px solid rgb(99 164 255 / 22%);
|
||||
border-radius: 999px;
|
||||
color: #9fb4cc;
|
||||
font-size: 12px;
|
||||
padding: 5px 9px;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.status-strip {
|
||||
display: grid;
|
||||
gap: 18px;
|
||||
grid-template-columns: 0.9fr 1.1fr;
|
||||
height: 150px;
|
||||
left: 720px;
|
||||
position: absolute;
|
||||
right: 56px;
|
||||
top: 42px;
|
||||
}
|
||||
|
||||
.status-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.metric-row {
|
||||
display: grid;
|
||||
gap: 24px;
|
||||
@@ -51,7 +78,7 @@ body {
|
||||
left: 56px;
|
||||
position: absolute;
|
||||
right: 56px;
|
||||
top: 150px;
|
||||
top: 230px;
|
||||
}
|
||||
|
||||
.metric-card {
|
||||
@@ -80,3 +107,88 @@ body {
|
||||
font-size: 18px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.tone-green {
|
||||
border-color: rgb(78 170 116 / 42%);
|
||||
}
|
||||
|
||||
.tone-amber {
|
||||
border-color: rgb(216 161 62 / 42%);
|
||||
}
|
||||
|
||||
.screen-panel {
|
||||
background: rgb(8 22 36 / 86%);
|
||||
border: 1px solid rgb(88 130 171 / 36%);
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.screen-panel header {
|
||||
align-items: center;
|
||||
color: #d7e6f7;
|
||||
display: flex;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.screen-panel-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.chart-grid {
|
||||
bottom: 56px;
|
||||
display: grid;
|
||||
gap: 20px;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
left: 56px;
|
||||
position: absolute;
|
||||
right: 56px;
|
||||
top: 420px;
|
||||
}
|
||||
|
||||
.chart-host {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chart-panel-body {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.chart-panel-state {
|
||||
align-items: center;
|
||||
color: #88a1bd;
|
||||
display: flex;
|
||||
height: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.chart-panel-state.is-error {
|
||||
color: #ff9fa7;
|
||||
}
|
||||
|
||||
.screen-stage-debug {
|
||||
background: rgb(3 8 13 / 84%);
|
||||
border: 1px solid rgb(100 135 170 / 35%);
|
||||
border-radius: 6px;
|
||||
bottom: 18px;
|
||||
color: #9fb4cc;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
max-width: min(760px, calc(100vw - 36px));
|
||||
padding: 8px 10px;
|
||||
position: absolute;
|
||||
right: 18px;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.screen-stage-debug span {
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
Reference in new issue
Block a user