import {html, useState} from 'vendor'; import {useApp, useFetch} from '../api.js'; import {accentMax, CAUSE_COLOR, num, shortSite} from '../format.js'; import {EChart} from '../components/EChart.js'; import {DataTable} from '../components/DataTable.js'; import {Loading, Section, Select} from '../components/ui.js'; const DIMS = [ {value: 'scene', label: '场景'}, {value: 'region', label: '片区'}, {value: 'site_type', label: '站型'}, {value: 'vendor', label: '厂家'}, {value: 'month', label: '月份'}, {value: 'root_cause', label: '判定根因'}, {value: 'cause_category', label: '上报原因'}, {value: 'cause_code', label: '原因码'}, {value: 'level', label: '断站分级'}, {value: 'site_name', label: '基站'}, ]; const COLUMNS = [ {key: 'key', title: '维度值'}, {key: 'count', title: '退服次数', sortable: true}, {key: 'total_min', title: '累计时长(分)', sortable: true}, {key: 'avg_min', title: '平均时长(分)', sortable: true}, {key: 'max_min', title: '最长单次(分)', sortable: true}, {key: 'long_count', title: '超长次数', sortable: true}, {key: 'long_ratio', title: '超长占比(%)', sortable: true}, {key: 'sites', title: '涉及站点', sortable: true}, {key: 'users', title: '受影响用户', sortable: true, render: num}, {key: 'loss_gb', title: '业务损失(GB)', sortable: true, render: num}, ]; /** 多维统计:选择维度 → 后端分组聚合;点击表头切换排序指标,图表同步显示该指标前 20 名 */ export default function Stats() { const {filters} = useApp(); const [dim, setDim] = useState('scene'); const [sort, setSort] = useState({key: 'total_min', asc: false}); const {data} = useFetch('/api/stats', {...filters, dim, sort: sort.key, asc: sort.asc ? 1 : 0}); const onSort = key => setSort(s => ({key, asc: s.key === key ? !s.asc : false})); const top = data ? data.rows.slice(0, 20) : []; const metric = COLUMNS.find(c => c.key === sort.key).title; // 按根因统计时每根柱子用各自的根因色(全站统一);其他维度只把第一名标成强调色 let barData; if (dim === 'root_cause') { barData = top.map(r => ({value: r[sort.key], itemStyle: {color: CAUSE_COLOR[r.key]}})); } else { barData = accentMax(top.map(r => r[sort.key])); } const chart = { tooltip: {trigger: 'axis', axisPointer: {type: 'shadow'}}, xAxis: {type: 'category', data: top.map(r => (dim === 'site_name' ? shortSite(r.key) : r.key)), axisLabel: {rotate: top.length > 8 ? 30 : 0}}, yAxis: {type: 'value', name: metric}, series: [{type: 'bar', name: metric, barMaxWidth: 34, data: barData}], }; return html` <${Section}>