将看板功能独立,方便独立维护功能。
This commit is contained in:
255
admin/dashboard/templates/plugins.html
Normal file
255
admin/dashboard/templates/plugins.html
Normal file
@@ -0,0 +1,255 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}插件统计 - 机器人管理后台{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<!-- 插件统计 -->
|
||||
<div>
|
||||
<el-row {% raw %}:gutter="20"{% endraw %}>
|
||||
<el-col {% raw %}:span="24"{% endraw %}>
|
||||
<el-card shadow="hover">
|
||||
<div slot="header">
|
||||
<span>插件使用统计</span>
|
||||
</div>
|
||||
<el-table {% raw %}:data="pluginStats"{% endraw %} style="width: 100%" border>
|
||||
<el-table-column prop="plugin_name" label="插件名称"></el-table-column>
|
||||
<el-table-column prop="command" label="触发指令"></el-table-column>
|
||||
<el-table-column prop="total_calls" label="调用次数" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.total_calls) || 0 }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="success_calls" label="成功次数" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.success_calls) || 0 }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="failed_calls" label="失败次数" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.failed_calls) || 0 }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="成功率" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.total_calls) > 0 ? ((parseInt(scope.row.success_calls) / parseInt(scope.row.total_calls)) * 100).toFixed(2) : '100.00' }}{% endraw %}%
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="平均响应时间" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ (scope.row.avg_process_time || 0).toFixed(2) }}{% endraw %}ms
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作">
|
||||
<template slot-scope="scope">
|
||||
<el-button size="mini" type="primary" {% raw %}@click="viewPluginTrend(scope.row)"{% endraw %}>查看趋势</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-table {% raw %}:data="pluginUsers"{% endraw %} style="width: 100%" border v-if="showUserStats">
|
||||
<el-table-column label="用户">
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ scope.row.user_name || scope.row.user_id }} ({{ scope.row.user_id }}){% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="total_calls" label="调用次数" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.total_calls) || 0 }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="success_calls" label="成功次数" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.success_calls) || 0 }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="failed_calls" label="失败次数" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.failed_calls) || 0 }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="成功率" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.total_calls) > 0 ? ((parseInt(scope.row.success_calls) / parseInt(scope.row.total_calls)) * 100).toFixed(2) : '100.00' }}{% endraw %}%
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="平均响应时间" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ (scope.row.avg_process_time || 0).toFixed(2) }}{% endraw %}ms
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作">
|
||||
<template slot-scope="scope">
|
||||
<el-button size="mini" type="primary" {% raw %}@click="viewPluginTrend(scope.row)"{% endraw %}>查看趋势</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-table {% raw %}:data="pluginGroups"{% endraw %} style="width: 100%" border v-if="showGroupStats">
|
||||
<el-table-column label="群组">
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ scope.row.group_name || scope.row.group_id }} ({{ scope.row.group_id }}){% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="total_calls" label="调用次数" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.total_calls) || 0 }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="success_calls" label="成功次数" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.success_calls) || 0 }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="failed_calls" label="失败次数" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.failed_calls) || 0 }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="成功率" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ parseInt(scope.row.total_calls) > 0 ? ((parseInt(scope.row.success_calls) / parseInt(scope.row.total_calls)) * 100).toFixed(2) : '100.00' }}{% endraw %}%
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="平均响应时间" sortable>
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ (scope.row.avg_process_time || 0).toFixed(2) }}{% endraw %}ms
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作">
|
||||
<template slot-scope="scope">
|
||||
<el-button size="mini" type="primary" {% raw %}@click="viewPluginTrend(scope.row)"{% endraw %}>查看趋势</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 插件趋势对话框 -->
|
||||
<el-dialog title="插件使用趋势" {% raw %}:visible.sync="pluginTrendVisible"{% endraw %} width="70%">
|
||||
<div class="chart-container">
|
||||
<h3>{% raw %}{{ selectedPlugin ? selectedPlugin.plugin_name : '' }}{% endraw %} 使用趋势</h3>
|
||||
<canvas id="pluginTrendChart" width="800" height="400"></canvas>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
mixins: [baseApp],
|
||||
data() {
|
||||
return {
|
||||
pluginStats: [],
|
||||
pluginTrendVisible: false,
|
||||
selectedPlugin: null
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.currentView = '2';
|
||||
this.loadData();
|
||||
},
|
||||
methods: {
|
||||
loadData() {
|
||||
const days = parseInt(this.timeRange);
|
||||
this.loadPluginStats(days);
|
||||
},
|
||||
loadPluginStats(days) {
|
||||
axios.get(`/api/plugin_stats?days=${days}`)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.pluginStats = response.data.data || [];
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('加载插件统计数据出错:', error);
|
||||
this.$message.error('加载插件统计数据出错');
|
||||
});
|
||||
},
|
||||
viewPluginTrend(plugin) {
|
||||
this.selectedPlugin = plugin;
|
||||
this.pluginTrendVisible = true;
|
||||
|
||||
// 加载插件趋势数据
|
||||
const days = parseInt(this.timeRange);
|
||||
axios.get(`/api/plugin_trend?days=${days}&plugin_name=${plugin.plugin_name}`)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const trendData = response.data.data || [];
|
||||
this.$nextTick(() => {
|
||||
this.renderPluginTrendChart(trendData, plugin.plugin_name);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('加载插件趋势数据出错:', error);
|
||||
this.$message.error('加载插件趋势数据出错');
|
||||
});
|
||||
},
|
||||
renderPluginTrendChart(trendData, pluginName) {
|
||||
const ctx = document.getElementById('pluginTrendChart').getContext('2d');
|
||||
|
||||
// 销毁旧图表
|
||||
if (this.charts && this.charts.pluginTrendChart) {
|
||||
this.charts.pluginTrendChart.destroy();
|
||||
}
|
||||
|
||||
// 确保charts对象存在
|
||||
if (!this.charts) {
|
||||
this.charts = {};
|
||||
}
|
||||
|
||||
// 准备数据
|
||||
const labels = trendData.map(item => item.date || item.stat_date);
|
||||
const totalData = trendData.map(item => parseInt(item.total_calls) || 0);
|
||||
const successData = trendData.map(item => parseInt(item.success_calls) || 0);
|
||||
const failedData = trendData.map(item => parseInt(item.failed_calls) || 0);
|
||||
|
||||
// 创建新图表
|
||||
this.charts.pluginTrendChart = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: [
|
||||
{
|
||||
label: `${pluginName} 总调用`,
|
||||
data: totalData,
|
||||
fill: false,
|
||||
backgroundColor: 'rgba(54, 162, 235, 0.6)',
|
||||
borderColor: 'rgba(54, 162, 235, 1)',
|
||||
tension: 0.1
|
||||
},
|
||||
{
|
||||
label: `${pluginName} 成功调用`,
|
||||
data: successData,
|
||||
fill: false,
|
||||
backgroundColor: 'rgba(75, 192, 192, 0.6)',
|
||||
borderColor: 'rgba(75, 192, 192, 1)',
|
||||
tension: 0.1
|
||||
},
|
||||
{
|
||||
label: `${pluginName} 失败调用`,
|
||||
data: failedData,
|
||||
fill: false,
|
||||
backgroundColor: 'rgba(255, 99, 132, 0.6)',
|
||||
borderColor: 'rgba(255, 99, 132, 1)',
|
||||
tension: 0.1
|
||||
}
|
||||
]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user