Flask + SQLite 后端,免构建 React + ECharts 前端,含合成样例数据。 测试参考数据(FOR-TEST-ONLY)与运行时数据库不入库。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
4.7 KiB
JavaScript
89 lines
4.7 KiB
JavaScript
import {Fragment, GlassButton, html, SearchField, TextField, useState, useToast} from 'vendor';
|
||
import {api, useApp, useFetch} from '../api.js';
|
||
import {EChart} from '../components/EChart.js';
|
||
import {DataTable} from '../components/DataTable.js';
|
||
import {FormDialog} from '../components/FormDialog.js';
|
||
import {Loading, Section, Select} from '../components/ui.js';
|
||
|
||
const SCENE_FIELDS = [
|
||
{key: 'long_min', title: '超长阈值(分钟)'}, {key: 'freq_count', title: '高频阈值(次/月)'},
|
||
{key: 'users_per_cell', title: '单小区在线用户'}, {key: 'gb_per_cell_h', title: '单小区话务(GB/h)', step: '0.1'},
|
||
];
|
||
|
||
export default function Sites() {
|
||
const {meta, isAdmin} = useApp();
|
||
const toast = useToast();
|
||
const {data, reload} = useFetch('/api/sites');
|
||
const [scene, setScene] = useState('');
|
||
const [keyword, setKeyword] = useState('');
|
||
const [editScene, setEditScene] = useState(null);
|
||
const [editSite, setEditSite] = useState(null);
|
||
|
||
if (!data) return html`<${Loading}/>`;
|
||
|
||
const sites = data.rows.filter(r =>
|
||
(!scene || r.scene === scene) && (!keyword || r.site_name.includes(keyword) || r.ne_id.includes(keyword)));
|
||
|
||
// 保存场景阈值或站点分级:成功提示并刷新,失败提示并让弹窗保持打开
|
||
const save = async (url, body, message) => {
|
||
try {
|
||
await api(url, {method: 'PUT', json: body});
|
||
} catch (e) {
|
||
toast({message: e.message, tone: 'error'});
|
||
throw e;
|
||
}
|
||
toast({message, tone: 'success'});
|
||
reload();
|
||
};
|
||
const editColumn = onEdit => isAdmin
|
||
? [{key: '_edit', title: '', render: (_, r) => html`
|
||
<${GlassButton} variant="tinted" controlSize="small" onClick=${() => onEdit(r)}>编辑</${GlassButton}>`}]
|
||
: [];
|
||
|
||
const mixChart = {
|
||
tooltip: {trigger: 'axis', axisPointer: {type: 'shadow'}},
|
||
legend: {top: 0, icon: 'roundRect', itemWidth: 10},
|
||
grid: {left: 12, right: 12, top: 36, bottom: 6, containLabel: true},
|
||
xAxis: {type: 'category', data: meta.scenes},
|
||
yAxis: {type: 'value'},
|
||
series: meta.site_types.map(t => ({
|
||
type: 'bar', name: t, stack: 'sites', itemStyle: {borderRadius: 0},
|
||
data: meta.scenes.map(s => data.rows.filter(r => r.scene === s && r.site_type === t).length),
|
||
})),
|
||
};
|
||
const siteFilters = html`<${Fragment}>
|
||
<${Select} label="场景" all="全部场景" options=${meta.scenes} value=${scene} onChange=${setScene}/>
|
||
<${SearchField} aria-label="站点名称关键字" placeholder="站点名称 / 编号" value=${keyword} onValueChange=${setKeyword}/>
|
||
</${Fragment}>`;
|
||
|
||
return html`
|
||
<div className="grid">
|
||
<${Section} span=${7} title="分场景阈值配置" hint="阈值用于超长 / 高频站点判定,用户数与话务用于影响评估">
|
||
<${DataTable} rowKey="scene" rows=${data.scenes} columns=${[{key: 'scene', title: '场景'}, ...SCENE_FIELDS, ...editColumn(setEditScene)]}/>
|
||
</${Section}>
|
||
<${Section} span=${5} title="场景 × 站型 站点数量"><${EChart} option=${mixChart}/></${Section}>
|
||
<${Section} title="站点场景标签与站型分级" extra=${siteFilters}>
|
||
<${DataTable} rowKey="ne_id" rows=${sites} columns=${[
|
||
{key: 'ne_id', title: '基站编号'}, {key: 'site_name', title: '站点名称'}, {key: 'vendor', title: '厂家'},
|
||
{key: 'district', title: '片区'}, {key: 'scene', title: '场景标签'}, {key: 'site_type', title: '站型'},
|
||
{key: 'cells', title: '小区数'}, {key: 'lng', title: '经度'}, {key: 'lat', title: '纬度'},
|
||
...editColumn(setEditSite)]}/>
|
||
</${Section}>
|
||
|
||
${editScene && html`
|
||
<${FormDialog} onClose=${() => setEditScene(null)} title=${`场景阈值 · ${editScene.scene}`} description="保存后立即生效"
|
||
onSubmit=${d => save(`/api/scenes/${editScene.scene}`, d, '阈值已更新')}>
|
||
${SCENE_FIELDS.map(f => html`
|
||
<${TextField} key=${f.key} name=${f.key} label=${f.title} type="number" step=${f.step || '1'} min="0" required
|
||
defaultValue=${editScene[f.key]}/>`)}
|
||
</${FormDialog}>`}
|
||
${editSite && html`
|
||
<${FormDialog} onClose=${() => setEditSite(null)} title="编辑站点分级" description=${`${editSite.ne_id} · ${editSite.site_name}`}
|
||
onSubmit=${d => save(`/api/sites/${editSite.ne_id}`, d, '站点已更新')}>
|
||
<${Select} name="district" label="片区" showLabel options=${meta.regions} value=${editSite.district}/>
|
||
<${Select} name="scene" label="场景标签" showLabel options=${meta.scenes} value=${editSite.scene}/>
|
||
<${Select} name="site_type" label="站型" showLabel options=${meta.site_types} value=${editSite.site_type}/>
|
||
</${FormDialog}>`}
|
||
</div>`;
|
||
}
|