docs(design): 删除磁盘监控设计文档并更新前端页面结构规范
- 删除 frontend/src/views/systemMonitor/2026-04-22-disk-monitor-design.md 设计文档 - 删除 frontend/src/views/tools/addLedger/API_DEBUG.md 调试文档 - 在 AGENTS.md 中新增前端页面结构归档章节,规范复杂工具页结构 - 明确 index.vue、components/、utils/ 职责边界和拆分原则 - 规定页面级类型和 contract 脚本管理方式 - 统一复杂页面拆分优先顺序和注意事项
This commit is contained in:
@@ -51,8 +51,98 @@ let chart: echarts.ECharts | any = null
|
||||
let isPanPointerDown = false
|
||||
let currentGroup: string | undefined
|
||||
|
||||
interface ChartDataZoomPayload {
|
||||
dataZoomId?: string
|
||||
start?: unknown
|
||||
end?: unknown
|
||||
startValue?: unknown
|
||||
endValue?: unknown
|
||||
}
|
||||
|
||||
const getChartViewportRoot = () => chart?.getZr()?.painter?.getViewportRoot?.() as HTMLElement | undefined
|
||||
|
||||
const clampPercent = (value: number) => Math.min(Math.max(value, 0), 100)
|
||||
|
||||
const getFiniteNumber = (value: unknown) => {
|
||||
const numberValue = Number(value)
|
||||
|
||||
return Number.isFinite(numberValue) ? numberValue : undefined
|
||||
}
|
||||
|
||||
const normalizeZoomPercentRange = (start?: unknown, end?: unknown) => {
|
||||
const startPercent = getFiniteNumber(start)
|
||||
const endPercent = getFiniteNumber(end)
|
||||
|
||||
if (startPercent === undefined || endPercent === undefined) return null
|
||||
|
||||
return {
|
||||
start: clampPercent(Math.min(startPercent, endPercent)),
|
||||
end: clampPercent(Math.max(startPercent, endPercent))
|
||||
}
|
||||
}
|
||||
|
||||
const getXAxisData = () => {
|
||||
const xAxisData = props.options?.xAxis?.data
|
||||
|
||||
return Array.isArray(xAxisData) ? xAxisData : []
|
||||
}
|
||||
|
||||
const resolveAxisDataIndex = (value: unknown) => {
|
||||
const xAxisData = getXAxisData()
|
||||
if (!xAxisData.length) return -1
|
||||
|
||||
const numberValue = getFiniteNumber(value)
|
||||
if (numberValue !== undefined) {
|
||||
const roundedIndex = Math.round(numberValue)
|
||||
if (roundedIndex >= 0 && roundedIndex < xAxisData.length) return roundedIndex
|
||||
}
|
||||
|
||||
return xAxisData.findIndex(item => item === value || String(item) === String(value))
|
||||
}
|
||||
|
||||
const resolveZoomRangeFromAxisValues = (startValue: unknown, endValue: unknown) => {
|
||||
const xAxisData = getXAxisData()
|
||||
if (xAxisData.length <= 1) return null
|
||||
|
||||
const startIndex = resolveAxisDataIndex(startValue)
|
||||
const endIndex = resolveAxisDataIndex(endValue)
|
||||
|
||||
if (startIndex < 0 || endIndex < 0) return null
|
||||
|
||||
const maxIndex = xAxisData.length - 1
|
||||
|
||||
return normalizeZoomPercentRange(
|
||||
(Math.min(startIndex, endIndex) / maxIndex) * 100,
|
||||
(Math.max(startIndex, endIndex) / maxIndex) * 100
|
||||
)
|
||||
}
|
||||
|
||||
const resolveCurrentDataZoomRange = (zoomPayload: ChartDataZoomPayload) => {
|
||||
const dataZoomOptions = chart?.getOption?.()?.dataZoom
|
||||
const dataZoomList = Array.isArray(dataZoomOptions) ? dataZoomOptions : dataZoomOptions ? [dataZoomOptions] : []
|
||||
const candidateList = zoomPayload.dataZoomId
|
||||
? dataZoomList.filter((item: { id?: string }) => item.id === zoomPayload.dataZoomId)
|
||||
: dataZoomList
|
||||
|
||||
for (const item of candidateList) {
|
||||
const range = normalizeZoomPercentRange(item?.start, item?.end)
|
||||
if (range) return range
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
const resolveChartDataZoomRange = (zoomPayload: ChartDataZoomPayload) => {
|
||||
const percentRange = normalizeZoomPercentRange(zoomPayload?.start, zoomPayload?.end)
|
||||
if (percentRange) return percentRange
|
||||
|
||||
// 框选放大会返回 startValue/endValue,这里统一换算成百分比后再同步给外部工具栏状态。
|
||||
const valueRange = resolveZoomRangeFromAxisValues(zoomPayload?.startValue, zoomPayload?.endValue)
|
||||
if (valueRange) return valueRange
|
||||
|
||||
return resolveCurrentDataZoomRange(zoomPayload)
|
||||
}
|
||||
|
||||
const getAxisPixel = (dataIndex: number) => {
|
||||
const pixelValue = chart?.convertToPixel?.({ xAxisIndex: 0 }, dataIndex)
|
||||
|
||||
@@ -302,15 +392,14 @@ const buildChartOptions = () => {
|
||||
const bindChartEvents = () => {
|
||||
chart.off('datazoom')
|
||||
chart.on('datazoom', (params: any) => {
|
||||
const zoomPayload = Array.isArray(params.batch) ? params.batch[0] : params
|
||||
const start = Number(zoomPayload?.start)
|
||||
const end = Number(zoomPayload?.end)
|
||||
const zoomPayload = (Array.isArray(params.batch) ? params.batch[0] : params) as ChartDataZoomPayload
|
||||
const zoomRange = resolveChartDataZoomRange(zoomPayload)
|
||||
|
||||
if (!Number.isFinite(start) || !Number.isFinite(end)) return
|
||||
if (!zoomRange) return
|
||||
|
||||
emit('chart-data-zoom', {
|
||||
start,
|
||||
end
|
||||
start: zoomRange.start,
|
||||
end: zoomRange.end
|
||||
})
|
||||
})
|
||||
bindPanCursorEvents()
|
||||
|
||||
Reference in New Issue
Block a user