feat(web): 更新侧边栏和顶部导航组件,新增日志趋势图表组件,增强前端展示能力
This commit is contained in:
152
web/src/components/charts/LogTrendChart.vue
Normal file
152
web/src/components/charts/LogTrendChart.vue
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
<template>
|
||||||
|
<div class="log-trend-chart">
|
||||||
|
<div class="chart-legend">
|
||||||
|
<span><i style="background:#10b981"></i>日志总量</span>
|
||||||
|
<span><i style="background:#ef4444"></i>失败数</span>
|
||||||
|
</div>
|
||||||
|
<div class="chart-body">
|
||||||
|
<Bar :data="chartData" :options="chartOptions" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { Bar } from 'vue-chartjs'
|
||||||
|
import {
|
||||||
|
Chart as ChartJS,
|
||||||
|
CategoryScale,
|
||||||
|
LinearScale,
|
||||||
|
BarElement,
|
||||||
|
PointElement,
|
||||||
|
LineElement,
|
||||||
|
Tooltip,
|
||||||
|
Legend
|
||||||
|
} from 'chart.js'
|
||||||
|
import { useAnimationProgress } from '../../composables/useAnimationProgress.js'
|
||||||
|
|
||||||
|
ChartJS.register(CategoryScale, LinearScale, BarElement, PointElement, LineElement, Tooltip, Legend)
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
labels: { type: Array, required: true },
|
||||||
|
totals: { type: Array, required: true },
|
||||||
|
failures: { type: Array, required: true }
|
||||||
|
})
|
||||||
|
|
||||||
|
const progress = useAnimationProgress([
|
||||||
|
() => props.labels,
|
||||||
|
() => props.totals,
|
||||||
|
() => props.failures
|
||||||
|
], 1000)
|
||||||
|
|
||||||
|
const scaleSeries = (series) =>
|
||||||
|
series.map((value) => Math.round(Number(value || 0) * progress.value))
|
||||||
|
|
||||||
|
const maxTotal = computed(() => Math.max(...props.totals.map((value) => Number(value || 0)), 1))
|
||||||
|
|
||||||
|
const chartData = computed(() => ({
|
||||||
|
labels: props.labels,
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: '日志总量',
|
||||||
|
data: scaleSeries(props.totals),
|
||||||
|
backgroundColor: '#10b981',
|
||||||
|
borderRadius: 4,
|
||||||
|
barPercentage: 0.58,
|
||||||
|
categoryPercentage: 0.56,
|
||||||
|
order: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '失败数',
|
||||||
|
data: scaleSeries(props.failures),
|
||||||
|
borderColor: '#ef4444',
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
borderWidth: 2,
|
||||||
|
pointBackgroundColor: '#ffffff',
|
||||||
|
pointBorderColor: '#ef4444',
|
||||||
|
pointBorderWidth: 2,
|
||||||
|
pointRadius: 3,
|
||||||
|
pointHoverRadius: 5,
|
||||||
|
type: 'line',
|
||||||
|
order: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
|
||||||
|
const chartOptions = computed(() => ({
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
animation: {
|
||||||
|
duration: 900,
|
||||||
|
easing: 'easeOutQuart'
|
||||||
|
},
|
||||||
|
interaction: {
|
||||||
|
mode: 'index',
|
||||||
|
intersect: false
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: { display: false },
|
||||||
|
tooltip: {
|
||||||
|
backgroundColor: 'rgba(255,255,255,0.96)',
|
||||||
|
titleColor: '#1e293b',
|
||||||
|
bodyColor: '#64748b',
|
||||||
|
borderColor: '#e2e8f0',
|
||||||
|
borderWidth: 1,
|
||||||
|
padding: 10,
|
||||||
|
boxPadding: 4,
|
||||||
|
cornerRadius: 6,
|
||||||
|
usePointStyle: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
grid: { display: false },
|
||||||
|
ticks: {
|
||||||
|
color: '#64748b',
|
||||||
|
font: { size: 11 }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
beginAtZero: true,
|
||||||
|
suggestedMax: Math.max(maxTotal.value, 4),
|
||||||
|
grid: { color: '#f1f5f9' },
|
||||||
|
ticks: {
|
||||||
|
color: '#64748b',
|
||||||
|
font: { size: 11 },
|
||||||
|
precision: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.log-trend-chart {
|
||||||
|
height: 208px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-legend {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
color: #475569;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-legend i {
|
||||||
|
display: inline-block;
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
margin-right: 4px;
|
||||||
|
border-radius: 2px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-body {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -74,6 +74,7 @@ const sidebarMeta = {
|
|||||||
approval: { label: '审批中心', badge: '12' },
|
approval: { label: '审批中心', badge: '12' },
|
||||||
policies: { label: '知识管理' },
|
policies: { label: '知识管理' },
|
||||||
audit: { label: '任务规则中心' },
|
audit: { label: '任务规则中心' },
|
||||||
|
logs: { label: '日志管理' },
|
||||||
employees: { label: '员工管理' },
|
employees: { label: '员工管理' },
|
||||||
settings: { label: '系统设置' }
|
settings: { label: '系统设置' }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,11 +100,21 @@
|
|||||||
<template v-else-if="isRequests">
|
<template v-else-if="isRequests">
|
||||||
<div class="kpi-chips">
|
<div class="kpi-chips">
|
||||||
<div v-for="kpi in requestKpis" :key="kpi.label" class="kpi-chip" :style="{ '--chip-color': kpi.color }">
|
<div v-for="kpi in requestKpis" :key="kpi.label" class="kpi-chip" :style="{ '--chip-color': kpi.color }">
|
||||||
<span class="chip-value">{{ kpi.value }}<small>单</small></span>
|
<span class="chip-value">{{ kpi.value }}<small>单</small></span>
|
||||||
<span class="chip-label">{{ kpi.label }}</span>
|
<span class="chip-label">{{ kpi.label }}</span>
|
||||||
<span class="chip-delta" :class="kpi.trend">{{ kpi.delta }} <i :class="kpi.arrow"></i></span>
|
<span class="chip-delta" :class="kpi.trend">{{ kpi.delta }} <i :class="kpi.arrow"></i></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else-if="isLogs">
|
||||||
|
<div class="kpi-chips">
|
||||||
|
<div v-for="kpi in logsKpis" :key="kpi.label" class="kpi-chip" :style="{ '--chip-color': kpi.color }">
|
||||||
|
<span class="chip-value">{{ kpi.value }}<small>{{ kpi.unit }}</small></span>
|
||||||
|
<span class="chip-label">{{ kpi.label }}</span>
|
||||||
|
<span class="chip-delta" :class="kpi.trend">{{ kpi.meta }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-else-if="isApproval">
|
<template v-else-if="isApproval">
|
||||||
@@ -162,6 +172,10 @@ const props = defineProps({
|
|||||||
type: Object,
|
type: Object,
|
||||||
default: () => null
|
default: () => null
|
||||||
},
|
},
|
||||||
|
logsSummary: {
|
||||||
|
type: Object,
|
||||||
|
default: () => null
|
||||||
|
},
|
||||||
requestSummary: {
|
requestSummary: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => null
|
default: () => null
|
||||||
@@ -170,6 +184,10 @@ const props = defineProps({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
|
logDetailMode: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
detailAlerts: {
|
detailAlerts: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => []
|
default: () => []
|
||||||
@@ -193,6 +211,7 @@ const isChat = computed(() => props.activeView === 'chat')
|
|||||||
const isOverview = computed(() => props.activeView === 'overview')
|
const isOverview = computed(() => props.activeView === 'overview')
|
||||||
const isRequestDetail = computed(() => props.activeView === 'requests' && props.detailMode)
|
const isRequestDetail = computed(() => props.activeView === 'requests' && props.detailMode)
|
||||||
const isRequests = computed(() => props.activeView === 'requests')
|
const isRequests = computed(() => props.activeView === 'requests')
|
||||||
|
const isLogs = computed(() => props.activeView === 'logs' && !props.logDetailMode)
|
||||||
const isApproval = computed(() => props.activeView === 'approval')
|
const isApproval = computed(() => props.activeView === 'approval')
|
||||||
const isPolicies = computed(() => props.activeView === 'policies')
|
const isPolicies = computed(() => props.activeView === 'policies')
|
||||||
const isEmployees = computed(() => props.activeView === 'employees')
|
const isEmployees = computed(() => props.activeView === 'employees')
|
||||||
@@ -211,6 +230,21 @@ const requestKpis = computed(() => {
|
|||||||
{ label: '已完成', value: completed, delta: '已归档', trend: 'up', arrow: 'mdi mdi-arrow-up' , color: '#10b981' }
|
{ label: '已完成', value: completed, delta: '已归档', trend: 'up', arrow: 'mdi mdi-arrow-up' , color: '#10b981' }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const logsKpis = computed(() => {
|
||||||
|
const summary = props.logsSummary ?? {}
|
||||||
|
const total = Number(summary.total ?? 0)
|
||||||
|
const running = Number(summary.running ?? 0)
|
||||||
|
const completed = Number(summary.completed ?? 0)
|
||||||
|
const failed = Number(summary.failed ?? 0)
|
||||||
|
|
||||||
|
return [
|
||||||
|
{ label: 'Hermes 总任务', value: total, unit: '条', meta: '当前', trend: 'up', color: '#10b981' },
|
||||||
|
{ label: '运行中', value: running, unit: '条', meta: running > 0 ? '实时执行' : '暂无执行', trend: running > 0 ? 'up' : 'down', color: '#3b82f6' },
|
||||||
|
{ label: '已完成', value: completed, unit: '条', meta: total ? `占比 ${Math.round((completed / total) * 100)}%` : '等待数据', trend: 'up', color: '#10b981' },
|
||||||
|
{ label: '失败数', value: failed, unit: '条', meta: failed > 0 ? '需要关注' : '运行正常', trend: failed > 0 ? 'down' : 'up', color: '#ef4444' }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
const chatKpis = [
|
const chatKpis = [
|
||||||
{ label: '今日已问数', value: 86, unit: '次', meta: '较昨日 +18', trend: 'up', color: '#10b981' },
|
{ label: '今日已问数', value: 86, unit: '次', meta: '较昨日 +18', trend: 'up', color: '#10b981' },
|
||||||
|
|||||||
Reference in New Issue
Block a user