Initial screen starter scaffold

This commit is contained in:
Mac mini git server 2026-05-29 00:26:43 +08:00
commit d136b9dddc
49 changed files with 2966 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
node_modules/
dist/
.env
.env.*
.DS_Store
*.log
coverage/
data/
uploads/

53
README.md Normal file
View File

@ -0,0 +1,53 @@
# Dev Screen Starter
Dev Screen Starter 是一个面向项目交付的大屏开发基础框架。它不提供拖拽式设计器,而是为每个客户项目提供可复用的屏幕适配、图表容器、数据刷新、调试工具和部署骨架。
## 定位
适合这种工作流:
1. 接到客户大屏项目。
2. 根据需求新建一个项目页面。
3. 图表、布局、业务逻辑按客户定制开发。
4. 复用基础框架能力,减少重复搭建成本。
不适合:
- 让非技术人员拖拽搭屏。
- 做通用低代码平台。
- 维护复杂组件配置市场。
## 技术栈
- React
- TypeScript
- Vite
- ECharts
- pnpm workspace
## 目录
```txt
apps/demo-screen/ 示例客户大屏
packages/screen-core/ 屏幕适配、舞台、布局基础能力
packages/charts/ ECharts 容器、状态封装、主题工具
packages/data/ HTTP、轮询、mock、数据转换
packages/debug/ 开发调试面板和日志工具
templates/project-basic/ 新客户项目模板
doc/ 项目规划和实施文档
```
## 命令
```bash
pnpm install
pnpm dev
pnpm typecheck
pnpm build
```
## 项目文档
- [项目规划](doc/project-plan.md)
- [项目框架说明](doc/framework.md)
- [交付流程](doc/delivery-workflow.md)

View File

@ -0,0 +1,12 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>客户Demo态势大屏</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

View File

@ -0,0 +1,27 @@
{
"name": "@dev-screen-starter/customer-demo",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --host 0.0.0.0",
"build": "tsc --noEmit && vite build",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@dev-screen-starter/charts": "workspace:*",
"@dev-screen-starter/data": "workspace:*",
"@dev-screen-starter/debug": "workspace:*",
"@dev-screen-starter/screen-core": "workspace:*",
"@vitejs/plugin-react": "^5.0.4",
"echarts": "^6.0.0",
"react": "^19.1.1",
"react-dom": "^19.1.1",
"vite": "^7.1.7"
},
"devDependencies": {
"@types/react": "^19.1.16",
"@types/react-dom": "^19.1.9",
"typescript": "^5.9.2"
}
}

View File

@ -0,0 +1,18 @@
import { MetricCard, ScreenStage } from '@dev-screen-starter/screen-core'
export function ProjectScreen() {
return (
<ScreenStage background="#061826">
<header className="screen-title">
<span>客户Demo态势大屏</span>
<strong>大屏总览</strong>
</header>
<section className="metric-row">
<MetricCard label="指标一" value="--" />
<MetricCard label="指标二" value="--" />
<MetricCard label="指标三" value="--" />
</section>
</ScreenStage>
)
}

View File

@ -0,0 +1,5 @@
import { createRoot } from 'react-dom/client'
import { ProjectScreen } from './ProjectScreen'
import './screen.css'
createRoot(document.getElementById('root')!).render(<ProjectScreen />)

View File

@ -0,0 +1,82 @@
* {
box-sizing: border-box;
}
body {
margin: 0;
background: #05090d;
color: #dce8f5;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.screen-viewport {
background: #05090d;
height: 100vh;
overflow: hidden;
position: relative;
width: 100vw;
}
.screen-stage {
left: 50%;
overflow: hidden;
position: absolute;
top: 50%;
transform-origin: center center;
}
.screen-title {
left: 56px;
position: absolute;
top: 42px;
}
.screen-title span {
color: #88a1bd;
display: block;
font-size: 16px;
margin-bottom: 8px;
}
.screen-title strong {
color: #f1f7ff;
font-size: 42px;
}
.metric-row {
display: grid;
gap: 24px;
grid-template-columns: repeat(3, 1fr);
left: 56px;
position: absolute;
right: 56px;
top: 150px;
}
.metric-card {
background: rgb(9 26 42 / 88%);
border: 1px solid rgb(88 130 171 / 42%);
border-radius: 8px;
min-height: 148px;
padding: 22px 24px;
}
.metric-card span {
color: #9fb4cc;
display: block;
font-size: 16px;
margin-bottom: 18px;
}
.metric-card strong {
color: #f0f7ff;
font-size: 48px;
line-height: 1;
}
.metric-card small {
color: #9fb4cc;
font-size: 18px;
margin-left: 8px;
}

View File

@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"types": ["vite/client"]
},
"include": ["src", "vite.config.ts"]
}

View File

@ -0,0 +1,6 @@
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [react()]
})

View File

@ -0,0 +1,12 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Demo Screen</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

View File

@ -0,0 +1,28 @@
{
"name": "@dev-screen-starter/demo-screen",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --host 0.0.0.0",
"build": "tsc --noEmit && vite build",
"typecheck": "tsc --noEmit",
"preview": "vite preview --host 0.0.0.0"
},
"dependencies": {
"@dev-screen-starter/charts": "workspace:*",
"@dev-screen-starter/data": "workspace:*",
"@dev-screen-starter/debug": "workspace:*",
"@dev-screen-starter/screen-core": "workspace:*",
"@vitejs/plugin-react": "^5.0.4",
"echarts": "^6.0.0",
"react": "^19.1.1",
"react-dom": "^19.1.1",
"vite": "^7.1.7"
},
"devDependencies": {
"@types/react": "^19.1.16",
"@types/react-dom": "^19.1.9",
"typescript": "^5.9.2"
}
}

View File

@ -0,0 +1,38 @@
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 orderTrend = {
xAxis: ['08:00', '10:00', '12:00', '14:00', '16:00', '18:00'],
values: [120, 240, 380, 520, 760, 920]
}
export const channelOrders = {
categories: ['小程序', 'App', '门店', '渠道商', '客服'],
values: [420, 360, 280, 190, 130]
}
export const regionRank = {
categories: ['华东', '华南', '华北', '西南', '东北'],
values: [960, 820, 680, 520, 390]
}
export const orderShare = [
{ name: '标准订单', value: 56 },
{ name: '加急订单', value: 24 },
{ name: '售后工单', value: 12 },
{ name: '异常订单', value: 8 }
]
export const qualityRadar = {
indicators: [
{ name: '响应', max: 100 },
{ name: '履约', max: 100 },
{ name: '成本', max: 100 },
{ name: '质量', max: 100 },
{ name: '满意度', max: 100 }
],
values: [88, 76, 68, 92, 84]
}

View File

@ -0,0 +1,5 @@
import { createRoot } from 'react-dom/client'
import { DemoOverview } from './pages/DemoOverview'
import './styles/screen.css'
createRoot(document.getElementById('root')!).render(<DemoOverview />)

View File

@ -0,0 +1,85 @@
import {
createBarOption,
createGaugeOption,
createLineOption,
createPieOption,
createRadarOption,
createRankBarOption,
EChart
} from '@dev-screen-starter/charts'
import { DebugBadge } from '@dev-screen-starter/debug'
import { MetricCard, Panel, ScreenStage } from '@dev-screen-starter/screen-core'
import { channelOrders, metrics, orderShare, orderTrend, qualityRadar, regionRank } from '../demo/mockData'
export function DemoOverview() {
return (
<ScreenStage background="#061826">
<header className="screen-title">
<span>客户项目大屏模板</span>
<strong>运营态势总览</strong>
</header>
<section className="metric-row">
{metrics.map((metric) => (
<MetricCard key={metric.label} {...metric} />
))}
</section>
<section className="chart-grid">
<Panel title="折线图:订单趋势">
<EChart
option={createLineOption({
categories: orderTrend.xAxis,
values: orderTrend.values,
name: '订单',
color: '#63a4ff'
})}
/>
</Panel>
<Panel title="柱状图:渠道订单">
<EChart
option={createBarOption({
categories: channelOrders.categories,
values: channelOrders.values,
name: '订单',
color: '#56d08a'
})}
/>
</Panel>
<Panel title="排名条:区域排行">
<EChart
option={createRankBarOption({
categories: regionRank.categories,
values: regionRank.values,
name: '订单',
color: '#7aa7ff'
})}
/>
</Panel>
<Panel title="环图:订单结构">
<EChart option={createPieOption({ data: orderShare })} />
</Panel>
<Panel title="仪表盘:履约率">
<EChart option={createGaugeOption({ name: '履约率', value: 87, unit: '%', color: '#56d08a' })} />
</Panel>
<Panel title="雷达图:运营质量">
<EChart
option={createRadarOption({
indicators: qualityRadar.indicators,
values: qualityRadar.values,
name: '质量评分',
color: '#d8a13e'
})}
/>
</Panel>
</section>
<DebugBadge enabled scale={1} />
</ScreenStage>
)
}

View File

@ -0,0 +1,143 @@
* {
box-sizing: border-box;
}
body {
margin: 0;
background: #05090d;
color: #dce8f5;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.screen-viewport {
background: #05090d;
height: 100vh;
overflow: hidden;
position: relative;
width: 100vw;
}
.screen-stage {
left: 50%;
overflow: hidden;
position: absolute;
top: 50%;
transform-origin: center center;
}
.screen-title {
display: flex;
flex-direction: column;
gap: 8px;
left: 56px;
position: absolute;
top: 42px;
}
.screen-title span {
color: #88a1bd;
font-size: 16px;
}
.screen-title strong {
color: #f1f7ff;
font-size: 42px;
letter-spacing: 0;
}
.metric-row {
display: grid;
gap: 24px;
grid-template-columns: repeat(3, 1fr);
left: 56px;
position: absolute;
right: 56px;
top: 150px;
}
.metric-card {
background: rgb(9 26 42 / 88%);
border: 1px solid rgb(88 130 171 / 42%);
border-radius: 8px;
min-height: 148px;
padding: 22px 24px;
}
.metric-card span {
color: #9fb4cc;
display: block;
font-size: 16px;
margin-bottom: 18px;
}
.metric-card strong {
color: #f0f7ff;
font-size: 48px;
line-height: 1;
}
.metric-card small {
color: #9fb4cc;
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 {
color: #d7e6f7;
font-size: 18px;
font-weight: 700;
margin-bottom: 12px;
}
.screen-panel-body {
flex: 1;
min-height: 0;
}
.chart-grid {
bottom: 56px;
display: grid;
gap: 20px;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, minmax(0, 1fr));
left: 56px;
position: absolute;
right: 56px;
top: 340px;
}
.chart-host {
height: 100%;
width: 100%;
}
.debug-badge {
background: rgb(3 8 13 / 80%);
border: 1px solid rgb(100 135 170 / 35%);
border-radius: 6px;
bottom: 18px;
color: #9fb4cc;
display: flex;
gap: 12px;
padding: 8px 10px;
position: absolute;
right: 18px;
}

View File

@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"types": ["vite/client"]
},
"include": ["src", "vite.config.ts"]
}

View File

@ -0,0 +1,9 @@
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [react()],
server: {
port: 5173
}
})

74
doc/delivery-workflow.md Normal file
View File

@ -0,0 +1,74 @@
# 大屏项目交付流程
## 1. 接需求
确认内容:
- 屏幕尺寸和播放设备。
- 是否 1920x1080、4K、拼接屏或特殊比例。
- 页面数量。
- 指标定义。
- 数据接口来源。
- 刷新频率。
- 是否需要实时推送。
- 是否需要离线展示。
- 客户视觉参考。
## 2. 新建项目
```bash
pnpm new customer-a 客户A运营大屏
pnpm install
pnpm --filter @dev-screen-starter/customer-a dev
```
## 3. 实现页面
推荐顺序:
1. 先定设计稿尺寸和布局。
2. 写静态页面。
3. 接 mock 数据。
4. 接真实接口。
5. 做不同屏幕适配验证。
6. 做截图验收。
## 4. 数据接入
低频数据:
- HTTP + `usePollingData`
中频数据:
- SSE 或 WebSocket
高频数据:
- 项目单独实现实时通道,不放进 starter 的默认能力。
## 5. 验收
检查项:
- 目标屏幕比例下没有裁切错误。
- 4K 或客户实际设备下文字清晰。
- 图表 resize 正常。
- loading、empty、error 状态可接受。
- 接口断开时页面不崩溃。
- 浏览器全屏展示正常。
- 构建产物可以独立部署。
## 6. 部署
推荐:
- `pnpm --filter <project> build`
- 将 `dist/` 部署到 Nginx 或客户静态服务。
- 数据接口通过环境变量配置。
后续可以补充:
- Dockerfile
- Nginx config
- CI 构建脚本

144
doc/framework.md Normal file
View File

@ -0,0 +1,144 @@
# 项目框架说明
## 1. 框架原则
Dev Screen Starter 只复用基础能力,不复用完整业务页面。每个客户大屏都应该是明确的代码实现,而不是通用 JSON 配置渲染。
框架关注:
- 屏幕适配
- 图表生命周期
- 数据刷新
- 调试体验
- 项目模板
- 部署约定
业务项目关注:
- 客户视觉风格
- 页面布局
- 指标定义
- 图表配置
- 数据接口
- 动效和交互
## 2. screen-core
`screen-core` 提供大屏运行的基础组件。
### ScreenStage
职责:
- 固定设计稿尺寸,默认 `1920x1080`。
- 根据浏览器窗口自动缩放。
- 支持 `fit`、`fill`、`stretch`、`none`。
使用方式:
```tsx
<ScreenStage background="#061826">
<YourScreen />
</ScreenStage>
```
### Panel
用于常规图表面板或信息区域。
### MetricCard
用于指标展示。项目中可以直接使用,也可以复制后按客户视觉重写。
## 3. charts
`charts` 提供 ECharts 基础封装。
### EChart
职责:
- 初始化 ECharts 实例。
- 监听容器尺寸变化并自动 resize。
- 支持 loading 状态。
- 组件卸载时自动 dispose。
### withChartDefaults
提供基础 tooltip、grid、文字风格配置。项目里可以按客户视觉覆盖。
### 图表工厂
图表工厂只生成 ECharts option,不限制项目继续覆盖配置。
当前提供:
- `createLineOption`:折线图,支持单序列和多序列。
- `createBarOption`:柱状图,支持单序列和多序列。
- `createRankBarOption`:横向排名条。
- `createPieOption`:饼图/环图。
- `createGaugeOption`:仪表盘。
- `createRadarOption`:雷达图。
推荐用法:
```tsx
<EChart
option={createLineOption({
categories: ['08:00', '10:00', '12:00'],
values: [120, 240, 380],
name: '订单'
})}
/>
```
## 4. data
`data` 提供轻量数据工具。
### requestJson
封装基础 JSON 请求。
### usePollingData
用于定时刷新接口数据。
适合:
- 30 秒刷新指标。
- 5 秒刷新告警。
- 项目开发时接 mock loader。
不适合:
- 高频毫秒级数据。
- 大规模实时流。
这些场景建议按项目单独实现 WebSocket、SSE 或 MQTT。
## 5. debug
`debug` 提供开发时调试组件。
### DebugBadge
显示缩放比例、数据更新时间等轻量信息。生产环境默认不显示,项目可显式打开。
## 6. 项目模板
`templates/project-basic` 是新客户项目起点。
创建命令:
```bash
pnpm new customer-a 客户A运营大屏
```
生成:
```txt
apps/customer-a/
```
然后开发人员在该目录内自由实现客户页面。

109
doc/project-plan.md Normal file
View File

@ -0,0 +1,109 @@
# Dev Screen Starter 项目计划
## 1. 项目目标
Dev Screen Starter 不做拖拽式大屏设计器,而是提供一套项目型大屏开发基础框架。每次接到客户项目时,开发人员基于模板新建项目页面,根据客户需求定制布局、图表、数据接口和视觉风格。
核心目标:
- 5 分钟创建一个新客户大屏项目。
- 复用屏幕适配、图表容器、数据刷新、调试工具和部署骨架。
- 保持每个项目的代码自由度,避免被低代码配置体系限制。
- 让客户只看到高质量运行页,不接触编辑器。
## 2. 不做什么
- 不做拖拽编辑器。
- 不做组件市场。
- 不做配置化属性面板。
- 不做客户自助搭屏。
- 不做通用低代码平台。
## 3. 技术路线
基础技术栈:
- React
- TypeScript
- Vite
- ECharts
- pnpm workspace
推荐部署方式:
- 静态构建产物部署到 Nginx、对象存储或客户服务器。
- 数据接口由客户系统、轻量代理服务或项目后端提供。
- 高频实时数据按项目需要接 WebSocket、SSE 或 MQTT。
## 4. 项目结构
```txt
apps/
demo-screen/ 示例大屏项目
packages/
screen-core/ 屏幕适配、舞台、基础面板、指标卡
charts/ ECharts 容器和通用图表默认配置
data/ 请求、轮询、mock、数据转换
debug/ 开发调试浮层
templates/
project-basic/ 新客户项目模板
scripts/
create-project.mjs 新建项目脚本
doc/
project-plan.md
framework.md
delivery-workflow.md
```
## 5. 第一阶段
目标:建立可复用基础框架和示例大屏。
交付内容:
- `ScreenStage`:负责设计稿尺寸和屏幕适配。
- `Panel`:常规大屏面板容器。
- `MetricCard`:常见指标卡。
- `EChart`:ECharts 自动初始化、销毁和 resize。
- `usePollingData`:基础轮询数据 hook。
- `DebugBadge`:开发环境调试浮层。
- `demo-screen`:示例大屏项目。
- `project-basic`:新客户项目模板。
- `pnpm new <name> [title]`:新建项目命令。
## 6. 第二阶段
目标:提升项目交付效率。
计划内容:
- 增加 `ChartPanel` 组合组件。
- 增加常用图表 option 工厂:
- 折线图
- 柱状图
- 饼图
- 排名列表
- 增加 mock/real 数据切换约定。
- 增加 `.env` 示例。
- 增加 Dockerfile 和 Nginx 静态部署模板。
## 7. 第三阶段
目标:沉淀项目经验和可复制交付流程。
计划内容:
- 建立客户项目目录规范。
- 建立视觉主题模板。
- 建立数据接口适配规范。
- 建立截图验收清单。
- 建立大屏上线检查清单。
## 8. 成功标准
- 新项目能通过模板快速创建。
- 示例大屏可运行、可构建。
- 1920x1080 设计稿能适配不同屏幕。
- 图表容器能自动 resize。
- 项目开发时能清楚看到调试信息。
- 每个客户项目可以自由写代码,不受设计器配置限制。

20
package.json Normal file
View File

@ -0,0 +1,20 @@
{
"name": "dev-screen-starter",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "pnpm --filter @dev-screen-starter/demo-screen dev",
"build": "pnpm -r build",
"typecheck": "pnpm -r typecheck",
"new": "node scripts/create-project.mjs"
},
"devDependencies": {
"typescript": "^5.9.2"
},
"pnpm": {
"onlyBuiltDependencies": [
"esbuild"
]
}
}

View File

@ -0,0 +1,21 @@
{
"name": "@dev-screen-starter/charts",
"version": "0.1.0",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts"
},
"scripts": {
"build": "tsc --noEmit",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"echarts": "^6.0.0",
"react": "^19.1.1"
},
"devDependencies": {
"@types/react": "^19.1.16",
"typescript": "^5.9.2"
}
}

View File

@ -0,0 +1,44 @@
import * as echarts from 'echarts'
import { useEffect, useRef } from 'react'
type EChartProps = {
option: echarts.EChartsOption
loading?: boolean
className?: string
}
export function EChart({ option, loading = false, className = '' }: EChartProps) {
const hostRef = useRef<HTMLDivElement | null>(null)
const chartRef = useRef<echarts.ECharts | null>(null)
useEffect(() => {
if (!hostRef.current) {
return
}
chartRef.current = echarts.init(hostRef.current)
const observer = new ResizeObserver(() => chartRef.current?.resize())
observer.observe(hostRef.current)
return () => {
observer.disconnect()
chartRef.current?.dispose()
chartRef.current = null
}
}, [])
useEffect(() => {
chartRef.current?.setOption(option, true)
}, [option])
useEffect(() => {
if (loading) {
chartRef.current?.showLoading()
return
}
chartRef.current?.hideLoading()
}, [loading])
return <div className={`chart-host ${className}`} ref={hostRef} />
}

View File

@ -0,0 +1,26 @@
import type { EChartsOption } from 'echarts'
export const baseChartTextStyle = {
color: '#d7e4f2',
fontFamily: 'Inter, ui-sans-serif, system-ui'
}
export const withChartDefaults = (option: EChartsOption): EChartsOption => ({
textStyle: baseChartTextStyle,
grid: {
top: 32,
right: 24,
bottom: 32,
left: 48,
containLabel: true
},
tooltip: {
trigger: 'axis',
backgroundColor: '#101722',
borderColor: '#314154',
textStyle: {
color: '#d7e4f2'
}
},
...option
})

View File

@ -0,0 +1,3 @@
export * from './EChart'
export * from './chartTheme'
export * from './optionFactories'

View File

@ -0,0 +1,263 @@
import type { EChartsOption } from 'echarts'
import { withChartDefaults } from './chartTheme'
type DataPoint = {
name: string
value: number
}
type AxisChartInput = {
categories: string[]
values: number[]
name?: string
color?: string
}
type MultiSeriesInput = {
categories: string[]
series: Array<{
name: string
values: number[]
color?: string
}>
}
type PieChartInput = {
data: DataPoint[]
radius?: string | [string, string]
}
type GaugeChartInput = {
name?: string
value: number
min?: number
max?: number
unit?: string
color?: string
}
type RadarChartInput = {
indicators: Array<{
name: string
max: number
}>
values: number[]
name?: string
color?: string
}
const axisLine = { lineStyle: { color: '#35506c' } }
const axisLabel = { color: '#9fb4cc' }
const splitLine = { lineStyle: { color: '#173047' } }
export function createLineOption(input: AxisChartInput | MultiSeriesInput): EChartsOption {
const series = 'series' in input
? input.series.map((item) => ({
name: item.name,
type: 'line' as const,
smooth: true,
data: item.values,
areaStyle: { color: `${item.color ?? '#63a4ff'}22` },
lineStyle: { color: item.color ?? '#63a4ff', width: 3 },
symbolSize: 8
}))
: [
{
name: input.name,
type: 'line' as const,
smooth: true,
data: input.values,
areaStyle: { color: `${input.color ?? '#63a4ff'}22` },
lineStyle: { color: input.color ?? '#63a4ff', width: 3 },
symbolSize: 8
}
]
return withChartDefaults({
legend: 'series' in input ? { top: 0, textStyle: axisLabel } : undefined,
xAxis: {
type: 'category',
data: input.categories,
axisLine,
axisLabel
},
yAxis: {
type: 'value',
splitLine,
axisLabel
},
series
})
}
export function createBarOption(input: AxisChartInput | MultiSeriesInput): EChartsOption {
const series = 'series' in input
? input.series.map((item) => ({
name: item.name,
type: 'bar' as const,
data: item.values,
barMaxWidth: 28,
itemStyle: { color: item.color ?? '#63a4ff', borderRadius: [4, 4, 0, 0] }
}))
: [
{
name: input.name,
type: 'bar' as const,
data: input.values,
barMaxWidth: 32,
itemStyle: { color: input.color ?? '#63a4ff', borderRadius: [4, 4, 0, 0] }
}
]
return withChartDefaults({
legend: 'series' in input ? { top: 0, textStyle: axisLabel } : undefined,
xAxis: {
type: 'category',
data: input.categories,
axisLine,
axisLabel
},
yAxis: {
type: 'value',
splitLine,
axisLabel
},
series
})
}
export function createRankBarOption(input: AxisChartInput): EChartsOption {
return withChartDefaults({
grid: {
top: 16,
right: 24,
bottom: 16,
left: 80,
containLabel: true
},
xAxis: {
type: 'value',
splitLine,
axisLabel
},
yAxis: {
type: 'category',
data: input.categories,
inverse: true,
axisLine: { show: false },
axisTick: { show: false },
axisLabel
},
series: [
{
name: input.name,
type: 'bar',
data: input.values,
barMaxWidth: 18,
label: {
show: true,
position: 'right',
color: '#d7e4f2'
},
itemStyle: { color: input.color ?? '#63a4ff', borderRadius: [0, 4, 4, 0] }
}
]
})
}
export function createPieOption(input: PieChartInput): EChartsOption {
return withChartDefaults({
tooltip: {
trigger: 'item',
backgroundColor: '#101722',
borderColor: '#314154',
textStyle: { color: '#d7e4f2' }
},
legend: {
bottom: 0,
textStyle: axisLabel
},
series: [
{
type: 'pie',
radius: input.radius ?? ['46%', '68%'],
center: ['50%', '45%'],
avoidLabelOverlap: true,
label: { color: '#d7e4f2' },
data: input.data
}
]
})
}
export function createGaugeOption(input: GaugeChartInput): EChartsOption {
const max = input.max ?? 100
return {
tooltip: {
formatter: `{b}: {c}${input.unit ?? ''}`
},
series: [
{
name: input.name,
type: 'gauge',
min: input.min ?? 0,
max,
progress: {
show: true,
width: 14,
itemStyle: { color: input.color ?? '#63a4ff' }
},
axisLine: {
lineStyle: {
width: 14,
color: [[1, '#173047']]
}
},
axisTick: { show: false },
splitLine: { length: 8, lineStyle: { color: '#466886' } },
axisLabel: { color: '#9fb4cc' },
pointer: { width: 4 },
detail: {
formatter: `{value}${input.unit ?? ''}`,
color: '#f0f7ff',
fontSize: 32
},
data: [{ name: input.name, value: input.value }]
}
]
}
}
export function createRadarOption(input: RadarChartInput): EChartsOption {
return withChartDefaults({
tooltip: {
trigger: 'item',
backgroundColor: '#101722',
borderColor: '#314154',
textStyle: { color: '#d7e4f2' }
},
radar: {
indicator: input.indicators,
axisName: { color: '#9fb4cc' },
splitLine: { lineStyle: { color: '#24425e' } },
splitArea: { areaStyle: { color: ['rgba(36, 66, 94, 0.16)', 'rgba(36, 66, 94, 0.05)'] } },
axisLine: { lineStyle: { color: '#24425e' } }
},
series: [
{
name: input.name,
type: 'radar',
data: [
{
name: input.name,
value: input.values,
areaStyle: { color: `${input.color ?? '#63a4ff'}33` },
lineStyle: { color: input.color ?? '#63a4ff', width: 2 },
itemStyle: { color: input.color ?? '#63a4ff' }
}
]
}
]
})
}

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx"
},
"include": ["src"]
}

View File

@ -0,0 +1,20 @@
{
"name": "@dev-screen-starter/debug",
"version": "0.1.0",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts"
},
"scripts": {
"build": "tsc --noEmit",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"react": "^19.1.1"
},
"devDependencies": {
"@types/react": "^19.1.16",
"typescript": "^5.9.2"
}
}

View File

@ -0,0 +1,20 @@
type DebugBadgeProps = {
enabled?: boolean
scale?: number
updatedAt?: string
}
const defaultEnabled = typeof location !== 'undefined' && location.hostname === 'localhost'
export function DebugBadge({ enabled = defaultEnabled, scale, updatedAt }: DebugBadgeProps) {
if (!enabled) {
return null
}
return (
<aside className="debug-badge">
{scale ? <span>scale {scale.toFixed(3)}</span> : null}
{updatedAt ? <span>updated {new Date(updatedAt).toLocaleTimeString()}</span> : null}
</aside>
)
}

View File

@ -0,0 +1 @@
export * from './DebugBadge'

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx"
},
"include": ["src"]
}

View File

@ -0,0 +1,20 @@
{
"name": "@dev-screen-starter/screen-core",
"version": "0.1.0",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts"
},
"scripts": {
"build": "tsc --noEmit",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"react": "^19.1.1"
},
"devDependencies": {
"@types/react": "^19.1.16",
"typescript": "^5.9.2"
}
}

View File

@ -0,0 +1,18 @@
type MetricCardProps = {
label: string
value: string | number
unit?: string
tone?: 'blue' | 'green' | 'amber'
}
export function MetricCard({ label, value, unit, tone = 'blue' }: MetricCardProps) {
return (
<div className={`metric-card tone-${tone}`}>
<span>{label}</span>
<strong>
{value}
{unit ? <small>{unit}</small> : null}
</strong>
</div>
)
}

View File

@ -0,0 +1,16 @@
import type { ReactNode } from 'react'
type PanelProps = {
title?: string
className?: string
children: ReactNode
}
export function Panel({ title, className = '', children }: PanelProps) {
return (
<section className={`screen-panel ${className}`}>
{title ? <header>{title}</header> : null}
<div className="screen-panel-body">{children}</div>
</section>
)
}

View File

@ -0,0 +1,37 @@
import { type CSSProperties, type ReactNode, useEffect, useMemo, useState } from 'react'
import { calculateStageScale, type ScaleMode } from './scale'
type ScreenStageProps = {
width?: number
height?: number
scaleMode?: ScaleMode
background?: string
children: ReactNode
}
export function ScreenStage({ width = 1920, height = 1080, scaleMode = 'fit', background = '#061826', children }: ScreenStageProps) {
const [viewport, setViewport] = useState({ width: window.innerWidth, height: window.innerHeight })
useEffect(() => {
const onResize = () => setViewport({ width: window.innerWidth, height: window.innerHeight })
window.addEventListener('resize', onResize)
return () => window.removeEventListener('resize', onResize)
}, [])
const scale = useMemo(() => calculateStageScale({ width, height, scaleMode }, viewport.width, viewport.height), [height, scaleMode, viewport.height, viewport.width, width])
const stageStyle: CSSProperties = {
width,
height,
background,
transform: `translate(-50%, -50%) scale(${scale.scaleX}, ${scale.scaleY})`
}
return (
<main className="screen-viewport">
<section className="screen-stage" style={stageStyle}>
{children}
</section>
</main>
)
}

View File

@ -0,0 +1,4 @@
export * from './scale'
export * from './ScreenStage'
export * from './Panel'
export * from './MetricCard'

View File

@ -0,0 +1,30 @@
export type ScaleMode = 'fit' | 'fill' | 'stretch' | 'none'
export type ScreenSize = {
width: number
height: number
scaleMode?: ScaleMode
}
export type StageScale = {
scaleX: number
scaleY: number
}
export function calculateStageScale(screen: ScreenSize, viewportWidth: number, viewportHeight: number): StageScale {
const scaleMode = screen.scaleMode ?? 'fit'
if (scaleMode === 'none') {
return { scaleX: 1, scaleY: 1 }
}
const scaleX = viewportWidth / screen.width
const scaleY = viewportHeight / screen.height
if (scaleMode === 'stretch') {
return { scaleX, scaleY }
}
const scale = scaleMode === 'fill' ? Math.max(scaleX, scaleY) : Math.min(scaleX, scaleY)
return { scaleX: scale, scaleY: scale }
}

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx"
},
"include": ["src"]
}

1310
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

4
pnpm-workspace.yaml Normal file
View File

@ -0,0 +1,4 @@
packages:
- apps/*
- packages/*
- templates/*

View File

@ -0,0 +1,41 @@
import { cp, mkdir, readFile, writeFile } from 'node:fs/promises'
import { existsSync } from 'node:fs'
import { resolve } from 'node:path'
const name = process.argv[2]
const title = process.argv.slice(3).join(' ') || name
if (!name) {
console.error('Usage: pnpm new <project-name> [project title]')
process.exit(1)
}
const root = resolve(import.meta.dirname, '..')
const templateDir = resolve(root, 'templates/project-basic')
const targetDir = resolve(root, `apps/${name}`)
if (existsSync(targetDir)) {
console.error(`Project already exists: apps/${name}`)
process.exit(1)
}
await mkdir(resolve(root, 'apps'), { recursive: true })
await cp(templateDir, targetDir, { recursive: true })
const replacements = new Map([
['__PROJECT_NAME__', `@dev-screen-starter/${name}`],
['__PROJECT_TITLE__', title]
])
const files = ['package.json', 'index.html', 'src/ProjectScreen.tsx']
for (const file of files) {
const path = resolve(targetDir, file)
let content = await readFile(path, 'utf-8')
for (const [from, to] of replacements) {
content = content.replaceAll(from, to)
}
await writeFile(path, content)
}
console.log(`Created apps/${name}`)

View File

@ -0,0 +1,12 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>__PROJECT_TITLE__</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

View File

@ -0,0 +1,27 @@
{
"name": "__PROJECT_NAME__",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --host 0.0.0.0",
"build": "tsc --noEmit && vite build",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@dev-screen-starter/charts": "workspace:*",
"@dev-screen-starter/data": "workspace:*",
"@dev-screen-starter/debug": "workspace:*",
"@dev-screen-starter/screen-core": "workspace:*",
"@vitejs/plugin-react": "^5.0.4",
"echarts": "^6.0.0",
"react": "^19.1.1",
"react-dom": "^19.1.1",
"vite": "^7.1.7"
},
"devDependencies": {
"@types/react": "^19.1.16",
"@types/react-dom": "^19.1.9",
"typescript": "^5.9.2"
}
}

View File

@ -0,0 +1,18 @@
import { MetricCard, ScreenStage } from '@dev-screen-starter/screen-core'
export function ProjectScreen() {
return (
<ScreenStage background="#061826">
<header className="screen-title">
<span>__PROJECT_TITLE__</span>
<strong>大屏总览</strong>
</header>
<section className="metric-row">
<MetricCard label="指标一" value="--" />
<MetricCard label="指标二" value="--" />
<MetricCard label="指标三" value="--" />
</section>
</ScreenStage>
)
}

View File

@ -0,0 +1,5 @@
import { createRoot } from 'react-dom/client'
import { ProjectScreen } from './ProjectScreen'
import './screen.css'
createRoot(document.getElementById('root')!).render(<ProjectScreen />)

View File

@ -0,0 +1,82 @@
* {
box-sizing: border-box;
}
body {
margin: 0;
background: #05090d;
color: #dce8f5;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.screen-viewport {
background: #05090d;
height: 100vh;
overflow: hidden;
position: relative;
width: 100vw;
}
.screen-stage {
left: 50%;
overflow: hidden;
position: absolute;
top: 50%;
transform-origin: center center;
}
.screen-title {
left: 56px;
position: absolute;
top: 42px;
}
.screen-title span {
color: #88a1bd;
display: block;
font-size: 16px;
margin-bottom: 8px;
}
.screen-title strong {
color: #f1f7ff;
font-size: 42px;
}
.metric-row {
display: grid;
gap: 24px;
grid-template-columns: repeat(3, 1fr);
left: 56px;
position: absolute;
right: 56px;
top: 150px;
}
.metric-card {
background: rgb(9 26 42 / 88%);
border: 1px solid rgb(88 130 171 / 42%);
border-radius: 8px;
min-height: 148px;
padding: 22px 24px;
}
.metric-card span {
color: #9fb4cc;
display: block;
font-size: 16px;
margin-bottom: 18px;
}
.metric-card strong {
color: #f0f7ff;
font-size: 48px;
line-height: 1;
}
.metric-card small {
color: #9fb4cc;
font-size: 18px;
margin-left: 8px;
}

View File

@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"types": ["vite/client"]
},
"include": ["src", "vite.config.ts"]
}

View File

@ -0,0 +1,6 @@
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [react()]
})

14
tsconfig.base.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"skipLibCheck": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true
}
}