初始提交:5G 基站退服时长智能分析与故障闭环管控系统

Flask + SQLite 后端,免构建 React + ECharts 前端,含合成样例数据。
测试参考数据(FOR-TEST-ONLY)与运行时数据库不入库。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
treeandClaude Opus 5.5 committed 2026-11-18 14:01:48 +08:00
commit f8d1ccc526
39 files changed
+29010

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
import {GlassButton, GlassCheckbox, html} from 'vendor';
import {num} from '../format.js';
/**
* 通用表格。
* columns: [{key, title, render?(value, row), sortable?, wrap?}]
* sort: {key, asc},配合 onSort(key) 实现点击表头排序
* selected / onSelect: 传入时显示勾选列(selected 为 Set<id>)
*/
export function DataTable({columns, rows, rowKey = 'id', sort, onSort, selected, onSelect, maxHeight = 560}) {
const selectable = !!onSelect;
// 表头“全选”框的状态:全部选中 / 部分选中(显示横线)/ 未选中
let headerChecked = false;
if (selectable && rows.length > 0) {
const allOn = rows.every(r => selected.has(r[rowKey]));
const someOn = rows.some(r => selected.has(r[rowKey]));
if (allOn) {
headerChecked = true;
} else if (someOn) {
headerChecked = 'mixed';
}
}
const toggleAll = on => onSelect(new Set(on ? rows.map(r => r[rowKey]) : []));
const toggleOne = (id, on) => {
const next = new Set(selected);
on ? next.add(id) : next.delete(id);
onSelect(next);
};
const header = (c, i) => html`
<th key=${c.key + i} aria-sort=${sort?.key === c.key ? (sort.asc ? 'ascending' : 'descending') : undefined}>
${c.sortable && onSort
? html`<button className="th-sort" onClick=${() => onSort(c.key)}>
${c.title}<span aria-hidden="true">${sort?.key === c.key ? (sort.asc ? '↑' : '↓') : '↕'}</span>
</button>`
: c.title}
</th>`;
const row = (r, ri) => html`
<tr key=${r[rowKey] ?? ri}>
${selectable && html`
<td className="check">
<${GlassCheckbox} aria-label="选择" checked=${selected.has(r[rowKey])} onCheckedChange=${on => toggleOne(r[rowKey], on)}/>
</td>`}
${columns.map((c, i) => html`
<td key=${c.key + i} className=${c.wrap ? 'wrap' : undefined}>${c.render ? c.render(r[c.key], r) : r[c.key]}</td>`)}
</tr>`;
return html`
<div className="table-wrap" style=${{maxHeight}}>
<table>
<thead>
<tr>
${selectable && html`
<th className="check">
<${GlassCheckbox} aria-label="全选" checked=${headerChecked} onCheckedChange=${toggleAll}/>
</th>`}
${columns.map(header)}
</tr>
</thead>
<tbody>
${rows.length === 0 && html`<tr><td className="empty" colSpan=${columns.length + (selectable ? 1 : 0)}>暂无数据</td></tr>`}
${rows.map(row)}
</tbody>
</table>
</div>`;
}
/** 分页条 */
export function Pager({page, size, total, onPage, prefix}) {
const pages = Math.max(1, Math.ceil(total / size));
return html`
<div className="pager">
<span>${prefix ?? `共 ${num(total)} 条`} · 第 ${page}/${pages} 页</span>
<${GlassButton} variant="gray" controlSize="small" disabled=${page <= 1} onClick=${() => onPage(page - 1)}>上一页</${GlassButton}>
<${GlassButton} variant="gray" controlSize="small" disabled=${page >= pages} onClick=${() => onPage(page + 1)}>下一页</${GlassButton}>
</div>`;
}
+62
View File
@@ -0,0 +1,62 @@
/*
* ECharts 图表组件。
* html`<${EChart} option=${{xAxis: ..., series: [...]}} height=${320}/>`
* - 坐标轴、提示框、文字颜色由下面两套 Apple 风格主题统一提供,页面里只写数据相关的配置。
* - 跟随系统深浅色:主题变化时重建图表。
* - echarts.js 只在打开带图表的页面时才下载。
*/
import echarts from 'echarts';
import {html, useEffect, useGlassPolicy, useRef} from 'vendor';
import {PALETTE} from '../format.js';
// 柱子默认用中性灰(systemGray4 / 深色 systemGray3),需要强调的那一项由页面用 accentMax() 标成蓝色
function appleTheme({label, secondary, grid, line, tooltip, bar}) {
const axis = {
axisLine: {lineStyle: {color: line}}, axisTick: {show: false},
axisLabel: {color: secondary}, splitLine: {lineStyle: {color: grid}}, nameTextStyle: {color: secondary},
};
return {
color: PALETTE,
backgroundColor: 'transparent',
textStyle: {fontFamily: 'inherit', color: secondary},
categoryAxis: axis, valueAxis: axis,
legend: {textStyle: {color: secondary}},
tooltip: {backgroundColor: tooltip, borderWidth: 0, textStyle: {color: label},
extraCssText: 'border-radius:12px;box-shadow:0 8px 24px rgba(0,0,0,.16)'},
// 柱顶数字用次要文字色、去掉描边(默认描边在深色模式下会糊成一团)
bar: {barMaxWidth: 28, itemStyle: {borderRadius: 6, color: bar},
label: {color: secondary, fontSize: 11, textBorderWidth: 0}},
pie: {label: {color: secondary, textBorderWidth: 0}},
line: {smooth: true, symbolSize: 6, lineStyle: {width: 2.5}},
};
}
// 颜色取自 Apple 人机界面指南的系统色(label / secondaryLabel / separator / systemGray)
echarts.registerTheme('light', appleTheme({label: '#1d1d1f', secondary: '#6e6e73', grid: 'rgba(0,0,0,.06)',
line: '#d2d2d7', tooltip: 'rgba(255,255,255,.96)', bar: '#c7c7cc'}));
echarts.registerTheme('dark', appleTheme({label: '#f5f5f7', secondary: '#98989d', grid: 'rgba(255,255,255,.08)',
line: '#424245', tooltip: 'rgba(44,44,46,.96)', bar: '#48484a'}));
const GRID = {left: 12, right: 18, top: 30, bottom: 10, containLabel: true};
export function EChart({option, height = 320}) {
const box = useRef(null);
const chart = useRef(null);
const {resolvedTheme, reduceMotion} = useGlassPolicy();
// 创建 / 主题切换时重建;容器尺寸变化时自适应
useEffect(() => {
chart.current = echarts.init(box.current, resolvedTheme);
const ro = new ResizeObserver(() => chart.current.resize());
ro.observe(box.current);
return () => { ro.disconnect(); chart.current.dispose(); };
}, [resolvedTheme]);
// 页面每次渲染都会传入新的 option 对象;内容没变时跳过重绘(例如打开弹窗不会让图表重播动画)
const key = JSON.stringify(option);
useEffect(() => {
chart.current.setOption({animation: !reduceMotion, grid: GRID, ...option}, true);
}, [key, resolvedTheme, reduceMotion]);
return html`<div ref=${box} style=${{height}}></div>`;
}
+34
View File
@@ -0,0 +1,34 @@
import {GlassButton, GlassDialog, html, useState} from 'vendor';
/**
* 表单弹窗:提交时把表单内所有带 name 的字段收集成对象,交给 onSubmit(data)。
* onSubmit 抛出异常(校验失败、接口报错)时弹窗保持打开,成功则自动关闭。
*/
export function FormDialog({onClose, title, description = '', submitText = '保存', onSubmit, children}) {
const [busy, setBusy] = useState(false);
const submit = async e => {
e.preventDefault();
const data = Object.fromEntries([...new FormData(e.currentTarget)].map(([k, v]) => [k, String(v).trim()]));
setBusy(true);
try {
await onSubmit(data);
onClose();
} catch {
// 错误已由 onSubmit 提示,弹窗保持打开
} finally {
setBusy(false);
}
};
return html`
<${GlassDialog} open onOpenChange=${o => !o && onClose()} title=${title} description=${description} className="form-dialog">
<form onSubmit=${submit}>
<div className="form-grid">${children}</div>
<div className="dialog-actions">
<${GlassButton} type="button" variant="gray" onClick=${onClose}>取消</${GlassButton}>
<${GlassButton} type="submit" variant="glassProminent" loading=${busy}>${submitText}</${GlassButton}>
</div>
</form>
</${GlassDialog}>`;
}
+26
View File
@@ -0,0 +1,26 @@
/* 导航图标:20px 线性图标,颜色跟随文字(currentColor)。新增图标时在 PATHS 中加一项。 */
import {html} from 'vendor';
const PATHS = {
dashboard: 'M3 3h6v8H3zM11 3h6v5h-6zM11 10h6v7h-6zM3 13h6v4H3z',
outages: 'M4 4h12M4 8h12M4 12h8M4 16h6M15 13v4M13 15h4',
import: 'M10 3v10M6 9l4 4 4-4M4 15v2h12v-2',
sites: 'M10 17V9M6 6a5.5 5.5 0 0 1 8 0M3.5 3.5a9 9 0 0 1 13 0M8 17h4',
rank: 'M4 16V10M8 16V6M12 16v-4M16 16V4',
rootcause: 'M9 3a6 6 0 1 0 0 12A6 6 0 0 0 9 3zM13.5 13.5 17 17M9 6v3l2 2',
impact: 'M3 15l4-5 3 3 4-6 3 3M3 17h14',
stats: 'M10 3v7h7A7 7 0 1 1 10 3zM12.5 1.5v6h6a6 6 0 0 0-6-6z',
reports: 'M5 2h7l4 4v12H5zM12 2v4h4M8 11h6M8 14h4',
users: 'M7 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM2 17a5 5 0 0 1 10 0M13 4a3 3 0 0 1 0 5M15 12a5 5 0 0 1 3 5',
logout: 'M8 4H4v12h4M12 6l4 4-4 4M16 10H8',
menu: 'M3 5h14M3 10h14M3 15h14',
filter: 'M3 5h14M6 10h8M9 15h2',
};
export function Icon({name, size = 20}) {
return html`
<svg width=${size} height=${size} viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6"
strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d=${PATHS[name]}/>
</svg>`;
}
+66
View File
@@ -0,0 +1,66 @@
/* 内容层组件。只放有实际逻辑的组件;纯布局直接写 className(.grid / .row / .grow / .note / .chips,见 app.css)。 */
import {Card, Fragment, html, Picker, useState} from 'vendor';
import {CAUSE_COLOR, LEVEL_TONE, STATUS_TONE} from '../format.js';
/** 内容卡片:不透明,可带标题栏。span 为 12 栅格中占的列数 */
export function Section({title, hint, extra, span = 12, children}) {
return html`
<${Card} radius=${18} padding=${20} className=${`section span-${span}`}>
${(title || extra) && html`
<header className="section-head">
<h3>${title}</h3>
${hint && html`<span className="hint">${hint}</span>`}
<span className="grow"></span>
${extra}
</header>`}
${children}
</${Card}>`;
}
/** 指标卡 */
export function Kpi({title, value, unit, sub}) {
return html`
<div className="kpi">
<div className="kpi-title">${title}</div>
<div className="kpi-value">${value}<small>${unit}</small></div>
${sub && html`<div className="kpi-sub">${sub}</div>`}
</div>`;
}
/** 彩色文字标签(颜色之外始终带文字,不单靠颜色传达状态) */
export const LevelTag = ({value}) => value && html`<span className="tag" data-tone=${LEVEL_TONE[value]}>${value}</span>`;
/** 闭环状态标签:未闭环(待处理 / 处理中)前面加一个圆点,和侧边栏“未闭环”数量的圆点是同一个记号 */
export function StatusTag({value}) {
if (!value) return null;
let dot = null;
if (value !== '已闭环') {
dot = html`<i className="dot" aria-hidden="true"></i>`;
}
return html`<span className="tag" data-tone=${STATUS_TONE[value]}>${dot}${value}</span>`;
}
/** 根因:色点 + 名称 */
export const Cause = ({value}) => value && html`
<span className="cause"><i style=${{background: CAUSE_COLOR[value] || '#8e8e93'}}></i>${value}</span>`;
export const Loading = () => html`<div className="loading"><span></span>加载中…</div>`;
/**
* 下拉选择(组件库 Picker)。options 可以是字符串数组或 {value, label} 数组。
* - 传 onChange:受控用法,用于筛选条件。
* - 传 name:表单用法,value 为初始值;Picker 本身不参与表单提交,所以用隐藏 input 带上选中值。
* - 传 all:最前面加一个值为 '' 的“全部”选项。
*/
export function Select({label, options, all, value, onChange, name, showLabel = false}) {
const items = options.map(o => (typeof o === 'string' ? {value: o, label: o} : o));
if (all) items.unshift({value: '', label: all});
const [own, setOwn] = useState(value ?? items[0]?.value ?? '');
const current = onChange ? value ?? '' : own;
return html`
<${Fragment}>
<${Picker} label=${label} labelHidden=${!showLabel} options=${items} presentation="menu"
value=${current} onValueChange=${onChange || setOwn}/>
${name && html`<input type="hidden" name=${name} value=${current}/>`}
</${Fragment}>`;
}