删除历史项目
This commit is contained in:
@@ -1,7 +0,0 @@
|
|||||||
from .main import StatsDashboardPlugin
|
|
||||||
|
|
||||||
def get_plugin():
|
|
||||||
"""获取插件实例"""
|
|
||||||
return StatsDashboardPlugin()
|
|
||||||
|
|
||||||
__all__ = ['StatsDashboardPlugin', 'get_plugin']
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
enable = false
|
|
||||||
host = "0.0.0.0"
|
|
||||||
port = 8888
|
|
||||||
username = "admin"
|
|
||||||
password = "admin123"
|
|
||||||
auto_start = "True"
|
|
||||||
@@ -1,371 +0,0 @@
|
|||||||
import logging
|
|
||||||
import threading
|
|
||||||
import time
|
|
||||||
import os
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from flask import Flask, render_template, request, jsonify, redirect, url_for, session, send_from_directory
|
|
||||||
|
|
||||||
from db.connection import DBConnectionManager
|
|
||||||
from db.message_storage import MessageStorageDB
|
|
||||||
from db.stats_db import StatsDBOperator
|
|
||||||
from utils.wechat.contact_manager import ContactManager
|
|
||||||
from robot_cmd.robot_command import GroupBotManager, Feature, PermissionStatus
|
|
||||||
|
|
||||||
class DashboardServer:
|
|
||||||
"""统计看板服务器"""
|
|
||||||
|
|
||||||
def __init__(self, host: str = "0.0.0.0", port: int = 8888,
|
|
||||||
username: str = "admin", password: str = "admin123"):
|
|
||||||
self.host = host
|
|
||||||
self.port = port
|
|
||||||
self.username = username
|
|
||||||
self.password = password
|
|
||||||
self.logger = logging.getLogger("DashboardServer")
|
|
||||||
|
|
||||||
# 修正:使用单例模式获取数据库连接
|
|
||||||
self.db_manager = DBConnectionManager.get_instance()
|
|
||||||
self.stats_db = StatsDBOperator(self.db_manager)
|
|
||||||
self.message_storage = MessageStorageDB(self.db_manager)
|
|
||||||
# 获取联系人管理器实例
|
|
||||||
self.contact_manager = ContactManager.get_instance()
|
|
||||||
self.app = self._create_app()
|
|
||||||
self._stop_event = threading.Event()
|
|
||||||
self._server = None # 添加:存储服务器实例
|
|
||||||
|
|
||||||
def _create_app(self) -> Flask:
|
|
||||||
"""创建Flask应用"""
|
|
||||||
app = Flask(__name__)
|
|
||||||
app.secret_key = "stats_dashboard_secret_key"
|
|
||||||
|
|
||||||
# 添加:实现基本的身份验证
|
|
||||||
def check_auth():
|
|
||||||
auth = request.authorization
|
|
||||||
if not auth or auth.username != self.username or auth.password != self.password:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
# 静态文件目录
|
|
||||||
static_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static')
|
|
||||||
|
|
||||||
@app.route('/static/<path:filename>')
|
|
||||||
def serve_static(filename):
|
|
||||||
return send_from_directory(static_folder, filename)
|
|
||||||
|
|
||||||
# 添加一个路由处理favicon请求
|
|
||||||
@app.route('/favicon.ico')
|
|
||||||
def favicon():
|
|
||||||
return send_from_directory(os.path.join(app.root_path, 'static'),
|
|
||||||
'favicon.ico', mimetype='image/vnd.microsoft.icon')
|
|
||||||
@app.route('/')
|
|
||||||
def index():
|
|
||||||
return render_template('index.html')
|
|
||||||
|
|
||||||
@app.route('/plugins')
|
|
||||||
def plugins():
|
|
||||||
return render_template('plugins.html')
|
|
||||||
|
|
||||||
@app.route('/users')
|
|
||||||
def users_page():
|
|
||||||
return render_template('users.html')
|
|
||||||
|
|
||||||
@app.route('/groups')
|
|
||||||
def groups():
|
|
||||||
return render_template('groups.html')
|
|
||||||
|
|
||||||
@app.route('/errors')
|
|
||||||
def errors():
|
|
||||||
return render_template('errors.html')
|
|
||||||
|
|
||||||
# 在_create_app方法中添加新的路由
|
|
||||||
@app.route('/robot_management')
|
|
||||||
def robot_management():
|
|
||||||
return render_template('robot_management.html')
|
|
||||||
|
|
||||||
@app.route('/api/robot/groups')
|
|
||||||
def api_robot_groups():
|
|
||||||
# 获取所有群组列表
|
|
||||||
|
|
||||||
groups = GroupBotManager.get_group_list()
|
|
||||||
group_data = []
|
|
||||||
|
|
||||||
for group_id in groups:
|
|
||||||
group_name = self.contact_manager.get_nickname(group_id)
|
|
||||||
robot_status = GroupBotManager.get_group_permission(group_id, Feature.ROBOT)
|
|
||||||
group_data.append({
|
|
||||||
"group_id": group_id,
|
|
||||||
"group_name": group_name,
|
|
||||||
"robot_status": robot_status.value
|
|
||||||
})
|
|
||||||
|
|
||||||
return jsonify({"success": True, "data": group_data})
|
|
||||||
|
|
||||||
@app.route('/api/robot/group/<group_id>/permissions')
|
|
||||||
def api_robot_group_permissions(group_id):
|
|
||||||
|
|
||||||
permissions = GroupBotManager.list_group_permissions(group_id)
|
|
||||||
permission_data = []
|
|
||||||
|
|
||||||
for feature, status in permissions.items():
|
|
||||||
permission_data.append({
|
|
||||||
"feature_id": feature.value,
|
|
||||||
"feature_name": feature.name,
|
|
||||||
"feature_description": feature.description,
|
|
||||||
"status": status.value
|
|
||||||
})
|
|
||||||
|
|
||||||
return jsonify({"success": True, "data": permission_data})
|
|
||||||
|
|
||||||
@app.route('/api/robot/group/<group_id>/permissions', methods=['POST'])
|
|
||||||
def api_update_robot_permissions(group_id):
|
|
||||||
# 更新群组功能权限
|
|
||||||
|
|
||||||
data = request.json
|
|
||||||
feature_id = data.get('feature_id')
|
|
||||||
status = data.get('status')
|
|
||||||
|
|
||||||
try:
|
|
||||||
feature = Feature(int(feature_id))
|
|
||||||
new_status = PermissionStatus(status)
|
|
||||||
|
|
||||||
# 特殊处理ROBOT功能
|
|
||||||
if feature == Feature.ROBOT:
|
|
||||||
r = self.db_manager.get_redis_connection()
|
|
||||||
if new_status == PermissionStatus.ENABLED:
|
|
||||||
GroupBotManager.local_cache["group_list"].add(group_id)
|
|
||||||
r.sadd("group:list", group_id)
|
|
||||||
else:
|
|
||||||
GroupBotManager.local_cache["group_list"].remove(group_id)
|
|
||||||
r.srem("group:list", group_id)
|
|
||||||
|
|
||||||
GroupBotManager.set_group_permission(group_id, feature, new_status)
|
|
||||||
return jsonify({"success": True})
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"更新群组权限失败: {e}")
|
|
||||||
return jsonify({"success": False, "error": str(e)}), 400
|
|
||||||
|
|
||||||
@app.route('/api/robot/batch_operation', methods=['POST'])
|
|
||||||
def api_robot_batch_operation():
|
|
||||||
# 批量操作接口
|
|
||||||
data = request.json
|
|
||||||
operation = data.get('operation')
|
|
||||||
group_ids = data.get('group_ids', [])
|
|
||||||
|
|
||||||
results = {}
|
|
||||||
|
|
||||||
try:
|
|
||||||
if operation == 'remove_groups':
|
|
||||||
for group_id in group_ids:
|
|
||||||
result = GroupBotManager.remove_group(group_id)
|
|
||||||
results[group_id] = result
|
|
||||||
|
|
||||||
return jsonify({"success": True, "results": results})
|
|
||||||
else:
|
|
||||||
return jsonify({"success": False, "error": "不支持的操作类型"}), 400
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"批量操作失败: {e}")
|
|
||||||
return jsonify({"success": False, "error": str(e)}), 400
|
|
||||||
|
|
||||||
# 添加:手动添加群组的API接口
|
|
||||||
@app.route('/api/robot/add_group', methods=['POST'])
|
|
||||||
def api_add_group():
|
|
||||||
try:
|
|
||||||
data = request.json
|
|
||||||
group_id = data.get('group_id')
|
|
||||||
|
|
||||||
if not group_id or not group_id.strip():
|
|
||||||
return jsonify({"success": False, "error": "群组ID不能为空"}), 400
|
|
||||||
|
|
||||||
group_id = group_id.strip()
|
|
||||||
|
|
||||||
# 检查群组是否已存在
|
|
||||||
if group_id in GroupBotManager.local_cache["group_list"]:
|
|
||||||
return jsonify({"success": False, "error": "该群组已存在"}), 400
|
|
||||||
|
|
||||||
# 添加群组到列表并启用机器人功能
|
|
||||||
GroupBotManager.local_cache["group_list"].add(group_id)
|
|
||||||
r = self.db_manager.get_redis_connection()
|
|
||||||
r.sadd("group:list", group_id)
|
|
||||||
|
|
||||||
# 设置ROBOT功能为启用状态
|
|
||||||
GroupBotManager.set_group_permission(group_id, Feature.ROBOT, PermissionStatus.ENABLED)
|
|
||||||
|
|
||||||
# 获取群组名称(如果可能)
|
|
||||||
group_name = self.contact_manager.get_nickname(group_id)
|
|
||||||
|
|
||||||
return jsonify({
|
|
||||||
"success": True,
|
|
||||||
"message": f"群组 {group_id} 已成功添加",
|
|
||||||
"group": {
|
|
||||||
"group_id": group_id,
|
|
||||||
"group_name": group_name,
|
|
||||||
"robot_status": "enabled"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"添加群组失败: {e}")
|
|
||||||
return jsonify({"success": False, "error": str(e)}), 500
|
|
||||||
|
|
||||||
@app.route('/api/plugin_stats')
|
|
||||||
def api_plugin_stats():
|
|
||||||
days = request.args.get('days', 7, type=int)
|
|
||||||
stats = self.stats_db.get_plugin_stats(days)
|
|
||||||
return jsonify({"success": True, "data": stats})
|
|
||||||
|
|
||||||
@app.route('/api/user_stats')
|
|
||||||
def api_user_stats():
|
|
||||||
days = request.args.get('days', 7, type=int)
|
|
||||||
limit = request.args.get('limit', 10, type=int)
|
|
||||||
stats = self.stats_db.get_user_stats(days, limit)
|
|
||||||
|
|
||||||
# 将用户ID转换为名称
|
|
||||||
for item in stats:
|
|
||||||
if 'user_id' in item:
|
|
||||||
user_id = item['user_id']
|
|
||||||
item['user_name'] = self.contact_manager.get_nickname(user_id)
|
|
||||||
|
|
||||||
return jsonify({"success": True, "data": stats})
|
|
||||||
|
|
||||||
@app.route('/api/group_stats')
|
|
||||||
def api_group_stats():
|
|
||||||
days = request.args.get('days', 7, type=int)
|
|
||||||
limit = request.args.get('limit', 10, type=int)
|
|
||||||
stats = self.stats_db.get_group_stats(days, limit)
|
|
||||||
|
|
||||||
# 将群ID转换为名称
|
|
||||||
for item in stats:
|
|
||||||
if 'group_id' in item:
|
|
||||||
group_id = item['group_id']
|
|
||||||
item['group_name'] = self.contact_manager.get_nickname(group_id)
|
|
||||||
|
|
||||||
return jsonify({"success": True, "data": stats})
|
|
||||||
|
|
||||||
@app.route('/api/error_logs')
|
|
||||||
def api_error_logs():
|
|
||||||
days = request.args.get('days', 7, type=int)
|
|
||||||
limit = request.args.get('limit', 50, type=int)
|
|
||||||
logs = self.stats_db.get_error_logs(days, limit)
|
|
||||||
return jsonify({"success": True, "data": logs})
|
|
||||||
|
|
||||||
@app.route('/api/error_detail/<int:error_id>')
|
|
||||||
def api_error_detail(error_id):
|
|
||||||
detail = self.stats_db.get_error_detail(error_id)
|
|
||||||
return jsonify({"success": True, "data": detail})
|
|
||||||
|
|
||||||
# 修改:添加错误处理的API路由示例
|
|
||||||
@app.route('/api/dashboard_summary')
|
|
||||||
def api_dashboard_summary():
|
|
||||||
try:
|
|
||||||
days = request.args.get('days', 7, type=int)
|
|
||||||
summary = self.stats_db.get_dashboard_summary(days)
|
|
||||||
|
|
||||||
# 转换用户和群组ID为名称
|
|
||||||
if 'top_users' in summary:
|
|
||||||
for user in summary['top_users']:
|
|
||||||
if 'user_id' in user:
|
|
||||||
user['user_name'] = self.contact_manager.get_nickname(user['user_id'])
|
|
||||||
|
|
||||||
if 'top_groups' in summary:
|
|
||||||
for group in summary['top_groups']:
|
|
||||||
if 'group_id' in group:
|
|
||||||
group['group_name'] = self.contact_manager.get_nickname(group['group_id'])
|
|
||||||
|
|
||||||
self.logger.info(f"看板主页统计数据: {summary}")
|
|
||||||
return jsonify({"success": True, "data": summary})
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"获取仪表盘摘要数据出错: {e}")
|
|
||||||
return jsonify({"success": False, "error": str(e)}), 500
|
|
||||||
|
|
||||||
@app.route('/api/plugin_trend')
|
|
||||||
def api_plugin_trend():
|
|
||||||
days = request.args.get('days', 7, type=int)
|
|
||||||
plugin_name = request.args.get('plugin_name', '')
|
|
||||||
trend = self.stats_db.get_plugin_trend(plugin_name, days)
|
|
||||||
|
|
||||||
# 如果趋势数据中包含用户或群组ID,也进行转换
|
|
||||||
if isinstance(trend, list):
|
|
||||||
for item in trend:
|
|
||||||
if 'user_id' in item:
|
|
||||||
item['user_name'] = self.contact_manager.get_nickname(item['user_id'])
|
|
||||||
if 'group_id' in item:
|
|
||||||
item['group_name'] = self.contact_manager.get_nickname(item['group_id'])
|
|
||||||
|
|
||||||
self.logger.info(f"看板主页/api/plugin_trend: {trend}")
|
|
||||||
return jsonify({"success": True, "data": trend})
|
|
||||||
|
|
||||||
@app.route('/api/robot/group/<group_id>/message_trend', methods=['GET'])
|
|
||||||
def get_group_message_trend(group_id):
|
|
||||||
"""获取群组消息趋势数据"""
|
|
||||||
try:
|
|
||||||
days = request.args.get('days', default=7, type=int)
|
|
||||||
# 获取消息存储实例
|
|
||||||
trend_data = self.message_storage.get_message_trend(group_id, days)
|
|
||||||
|
|
||||||
# 格式化数据为前端需要的格式
|
|
||||||
dates = []
|
|
||||||
counts = []
|
|
||||||
for item in trend_data:
|
|
||||||
# 将日期转换为字符串
|
|
||||||
if isinstance(item['date'], datetime):
|
|
||||||
date_str = item['date'].strftime('%Y-%m-%d')
|
|
||||||
else:
|
|
||||||
date_str = str(item['date'])
|
|
||||||
|
|
||||||
dates.append(date_str)
|
|
||||||
counts.append(item['message_count'])
|
|
||||||
|
|
||||||
return jsonify({
|
|
||||||
'success': True,
|
|
||||||
'data': {
|
|
||||||
'dates': dates,
|
|
||||||
'counts': counts
|
|
||||||
}
|
|
||||||
})
|
|
||||||
except Exception as e:
|
|
||||||
return jsonify({
|
|
||||||
'success': False,
|
|
||||||
'error': str(e)
|
|
||||||
})
|
|
||||||
|
|
||||||
return app
|
|
||||||
|
|
||||||
def run(self) -> None:
|
|
||||||
"""运行服务器"""
|
|
||||||
try:
|
|
||||||
self.logger.info(f"启动统计看板服务器,地址: {self.host}:{self.port}")
|
|
||||||
# 修改:使用线程安全的方式运行服务器
|
|
||||||
from werkzeug.serving import make_server
|
|
||||||
self._server = make_server(self.host, self.port, self.app)
|
|
||||||
self._server.serve_forever()
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"运行统计看板服务器出错: {e}")
|
|
||||||
|
|
||||||
def stop(self) -> None:
|
|
||||||
"""停止服务器"""
|
|
||||||
try:
|
|
||||||
self.logger.info("正在停止统计看板服务器...")
|
|
||||||
self._stop_event.set()
|
|
||||||
|
|
||||||
# 关闭服务器
|
|
||||||
if self._server:
|
|
||||||
self._server.shutdown()
|
|
||||||
self._server = None
|
|
||||||
|
|
||||||
# 等待所有线程完成
|
|
||||||
time.sleep(0.5) # 给线程一些时间来完成
|
|
||||||
|
|
||||||
self.logger.info("统计看板服务器已完全停止")
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"停止统计看板服务器出错: {e}")
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
"""析构函数,确保资源被释放"""
|
|
||||||
try:
|
|
||||||
if hasattr(self, '_server') and self._server:
|
|
||||||
self.stop()
|
|
||||||
except Exception as e:
|
|
||||||
if hasattr(self, 'logger'):
|
|
||||||
self.logger.error(f"DashboardServer 析构时出错: {e}")
|
|
||||||
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
import logging
|
|
||||||
import threading
|
|
||||||
from typing import Dict, Any, Tuple, Optional, List
|
|
||||||
|
|
||||||
from plugin_common.plugin_interface import PluginInterface, PluginStatus
|
|
||||||
from .dashboard_server import DashboardServer
|
|
||||||
|
|
||||||
|
|
||||||
class StatsDashboardPlugin(PluginInterface):
|
|
||||||
"""统计看板插件"""
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
return "统计看板"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def version(self) -> str:
|
|
||||||
return "1.0.0"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def description(self) -> str:
|
|
||||||
return "提供插件使用统计数据的可视化界面"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def author(self) -> str:
|
|
||||||
return "Trae AI"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def command_prefix(self) -> Optional[str]:
|
|
||||||
return "" # 不需要前缀,直接匹配命令
|
|
||||||
|
|
||||||
@property
|
|
||||||
def commands(self) -> List[str]:
|
|
||||||
return []
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
self.logger = logging.getLogger("StatsDashboard")
|
|
||||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
|
||||||
self.server = None
|
|
||||||
self.server_thread = None
|
|
||||||
|
|
||||||
def initialize(self, config: Dict[str, Any]) -> bool:
|
|
||||||
|
|
||||||
if not self._config["enable"]:
|
|
||||||
self.logger.info("统计看板插件已禁用")
|
|
||||||
return False
|
|
||||||
|
|
||||||
# 创建看板服务器
|
|
||||||
self.server = DashboardServer(
|
|
||||||
host=self._config["host"],
|
|
||||||
port=self._config["port"],
|
|
||||||
username=self._config["username"],
|
|
||||||
password=self._config["password"]
|
|
||||||
)
|
|
||||||
|
|
||||||
# 如果配置为自动启动,则启动服务器
|
|
||||||
if self._config["auto_start"]:
|
|
||||||
self.start_server()
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def start_server(self) -> bool:
|
|
||||||
"""启动看板服务器"""
|
|
||||||
if self.server_thread and self.server_thread.is_alive():
|
|
||||||
self.logger.warning("服务器已经在运行中")
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.server_thread = threading.Thread(target=self.server.run, daemon=True)
|
|
||||||
self.server_thread.start()
|
|
||||||
self.logger.info(f"统计看板服务器已启动,访问地址: http://{self._config['host']}:{self._config['port']}")
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"启动统计看板服务器失败: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def stop_server(self) -> bool:
|
|
||||||
"""停止看板服务器"""
|
|
||||||
if not self.server_thread or not self.server_thread.is_alive():
|
|
||||||
self.logger.warning("服务器未运行")
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
|
||||||
# 修改:添加超时处理和错误检查
|
|
||||||
self.server.stop()
|
|
||||||
# 等待线程结束,但设置超时
|
|
||||||
self.server_thread.join(timeout=5)
|
|
||||||
|
|
||||||
# 检查线程是否真的结束了
|
|
||||||
if self.server_thread.is_alive():
|
|
||||||
self.logger.warning("服务器停止超时,可能需要手动终止")
|
|
||||||
return False
|
|
||||||
|
|
||||||
self.logger.info("统计看板服务器已停止")
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"停止统计看板服务器失败: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def match_command(self, content: str) -> bool:
|
|
||||||
"""匹配命令"""
|
|
||||||
return content.strip().startswith("/stats")
|
|
||||||
|
|
||||||
def process_message(self, message: Dict[str, Any]) -> Tuple[bool, str]:
|
|
||||||
return False, ""
|
|
||||||
|
|
||||||
def shutdown(self) -> None:
|
|
||||||
"""关闭插件"""
|
|
||||||
if self.server:
|
|
||||||
self.stop_server()
|
|
||||||
|
|
||||||
def start(self) -> bool:
|
|
||||||
"""启动插件"""
|
|
||||||
self.LOG.info(f"[{self.name}] 插件已启动")
|
|
||||||
self.status = PluginStatus.RUNNING
|
|
||||||
return True
|
|
||||||
|
|
||||||
def stop(self) -> bool:
|
|
||||||
"""停止插件"""
|
|
||||||
self.LOG.info(f"[{self.name}] 插件已停止")
|
|
||||||
self.status = PluginStatus.STOPPED
|
|
||||||
return True
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB |
@@ -1,186 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="zh-CN">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>{% block title %}机器人管理后台{% endblock %}</title>
|
|
||||||
<!-- 添加favicon -->
|
|
||||||
<link rel="icon" href="/static/favicon.ico" type="image/x-icon">
|
|
||||||
<link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon">
|
|
||||||
<!-- Element UI CSS -->
|
|
||||||
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
|
|
||||||
<!-- 图表库 -->
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
||||||
<!-- Vue.js -->
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
|
|
||||||
<!-- Element UI JS -->
|
|
||||||
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
|
|
||||||
<!-- Axios -->
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
|
|
||||||
}
|
|
||||||
.app-container {
|
|
||||||
height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
.header {
|
|
||||||
background-color: #409EFF;
|
|
||||||
color: white;
|
|
||||||
padding: 0 20px;
|
|
||||||
height: 60px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
.main-container {
|
|
||||||
display: flex;
|
|
||||||
flex: 1;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
.sidebar {
|
|
||||||
width: 200px;
|
|
||||||
background-color: #545c64;
|
|
||||||
height: 100%;
|
|
||||||
overflow-y: auto;
|
|
||||||
}
|
|
||||||
.content {
|
|
||||||
flex: 1;
|
|
||||||
padding: 20px;
|
|
||||||
overflow-y: auto;
|
|
||||||
background-color: #f0f2f5;
|
|
||||||
}
|
|
||||||
.el-menu {
|
|
||||||
border-right: none;
|
|
||||||
}
|
|
||||||
.chart-container {
|
|
||||||
background-color: white;
|
|
||||||
padding: 20px;
|
|
||||||
border-radius: 4px;
|
|
||||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
.stats-card {
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% block head %}{% endblock %}
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="app" class="app-container">
|
|
||||||
<header class="header">
|
|
||||||
<h2>机器人管理后台</h2>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<div class="main-container">
|
|
||||||
<!-- 左侧菜单 -->
|
|
||||||
<div class="sidebar">
|
|
||||||
<el-menu
|
|
||||||
:default-active="currentView"
|
|
||||||
class="el-menu-vertical-demo"
|
|
||||||
background-color="#545c64"
|
|
||||||
text-color="#fff"
|
|
||||||
active-text-color="#ffd04b"
|
|
||||||
@select="handleSelect">
|
|
||||||
<el-menu-item index="1">
|
|
||||||
<i class="el-icon-s-home"></i>
|
|
||||||
<span slot="title">首页概览</span>
|
|
||||||
</el-menu-item>
|
|
||||||
<el-menu-item index="2">
|
|
||||||
<i class="el-icon-s-grid"></i>
|
|
||||||
<span slot="title">插件统计</span>
|
|
||||||
</el-menu-item>
|
|
||||||
<el-menu-item index="3">
|
|
||||||
<i class="el-icon-user"></i>
|
|
||||||
<span slot="title">用户统计</span>
|
|
||||||
</el-menu-item>
|
|
||||||
<el-menu-item index="4">
|
|
||||||
<i class="el-icon-s-cooperation"></i>
|
|
||||||
<span slot="title">群组统计</span>
|
|
||||||
</el-menu-item>
|
|
||||||
<el-menu-item index="5">
|
|
||||||
<i class="el-icon-warning"></i>
|
|
||||||
<span slot="title">错误日志</span>
|
|
||||||
</el-menu-item>
|
|
||||||
|
|
||||||
<!-- 在左侧菜单中添加群机器人管理选项 -->
|
|
||||||
<!-- 找到el-menu标签内的菜单项列表,添加以下内容 -->
|
|
||||||
<el-menu-item index="6">
|
|
||||||
<i class="el-icon-setting"></i>
|
|
||||||
<span slot="title">群机器人管理</span>
|
|
||||||
</el-menu-item>
|
|
||||||
</el-menu>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 右侧内容区 -->
|
|
||||||
<div class="content">
|
|
||||||
<!-- 时间范围选择器 -->
|
|
||||||
<el-row :gutter="20" style="margin-bottom: 20px;">
|
|
||||||
<el-col :span="24">
|
|
||||||
<el-card shadow="hover">
|
|
||||||
<el-form :inline="true" size="small">
|
|
||||||
<el-form-item label="统计时间范围">
|
|
||||||
<el-select v-model="timeRange" @change="loadData">
|
|
||||||
<el-option label="最近7天" value="7"></el-option>
|
|
||||||
<el-option label="最近30天" value="30"></el-option>
|
|
||||||
<el-option label="最近90天" value="90"></el-option>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item>
|
|
||||||
<el-button type="primary" @click="loadData">刷新数据</el-button>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
|
|
||||||
<!-- 内容区域 -->
|
|
||||||
{% block content %}{% endblock %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 基础 Vue 实例 -->
|
|
||||||
<script>
|
|
||||||
const baseApp = {
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
currentView: '1',
|
|
||||||
timeRange: '7',
|
|
||||||
charts: {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
handleSelect(key, keyPath) {
|
|
||||||
this.currentView = key;
|
|
||||||
// 添加页面跳转逻辑
|
|
||||||
const routes = {
|
|
||||||
'1': '/',
|
|
||||||
'2': '/plugins',
|
|
||||||
'3': '/users',
|
|
||||||
'4': '/groups',
|
|
||||||
'5': '/errors',
|
|
||||||
'6': '/robot_management'
|
|
||||||
};
|
|
||||||
|
|
||||||
// 如果当前不在对应页面,则跳转
|
|
||||||
const currentPath = window.location.pathname;
|
|
||||||
const targetPath = routes[key];
|
|
||||||
if (currentPath !== targetPath && targetPath !== undefined) {
|
|
||||||
window.location.href = targetPath;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
loadData() {
|
|
||||||
// 由子组件实现
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{% block scripts %}{% endblock %}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
{% extends "base.html" %}
|
|
||||||
|
|
||||||
{% block title %}错误日志 - 机器人管理后台{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<!-- 错误日志 -->
|
|
||||||
<div>
|
|
||||||
<el-row :gutter="20">
|
|
||||||
<el-col :span="24">
|
|
||||||
<el-card shadow="hover">
|
|
||||||
<div slot="header">
|
|
||||||
<span>错误日志</span>
|
|
||||||
</div>
|
|
||||||
<el-table {% raw %}:data="errorLogs"{% 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="error_message" label="错误信息" :show-overflow-tooltip="true"></el-table-column>
|
|
||||||
<el-table-column prop="created_at" label="时间"></el-table-column>
|
|
||||||
<el-table-column label="用户">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<span v-if="scope.row.user_id">
|
|
||||||
{% raw %}{{ scope.row.user_name || scope.row.user_id }} ({{ scope.row.user_id }}){% endraw %}
|
|
||||||
</span>
|
|
||||||
<span v-else>-</span>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="群组">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<span v-if="scope.row.group_id">
|
|
||||||
{% raw %}{{ scope.row.group_name || scope.row.group_id }} ({{ scope.row.group_id }}){% endraw %}
|
|
||||||
</span>
|
|
||||||
<span v-else>-</span>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="操作">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-button size="mini" type="primary" @click="viewErrorDetail(scope.row)">查看详情</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
<div class="pagination-container" style="margin-top: 20px; text-align: right;">
|
|
||||||
<el-pagination
|
|
||||||
@size-change="handleSizeChange"
|
|
||||||
@current-change="handleCurrentChange"
|
|
||||||
:current-page="currentPage"
|
|
||||||
:page-sizes="[10, 20, 50, 100]"
|
|
||||||
:page-size="pageSize"
|
|
||||||
layout="total, sizes, prev, pager, next, jumper"
|
|
||||||
:total="totalErrors">
|
|
||||||
</el-pagination>
|
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
|
|
||||||
<!-- 错误详情对话框 -->
|
|
||||||
<el-dialog title="错误详情" :visible.sync="errorDetailVisible" width="70%">
|
|
||||||
<div>
|
|
||||||
<p><strong>插件名称:</strong> {% raw %}{{ errorDetail.plugin_name }}{% endraw %}</p>
|
|
||||||
<p><strong>命令:</strong> {% raw %}{{ errorDetail.command }}{% endraw %}</p>
|
|
||||||
<p><strong>用户ID:</strong> {% raw %}{{ errorDetail.user_id }}{% endraw %}</p>
|
|
||||||
<p><strong>群组ID:</strong> {% raw %}{{ errorDetail.group_id || '无' }}{% endraw %}</p>
|
|
||||||
<p><strong>时间:</strong> {% raw %}{{ errorDetail.created_at }}{% endraw %}</p>
|
|
||||||
<p><strong>错误信息:</strong> {% raw %}{{ errorDetail.error_message }}{% endraw %}</p>
|
|
||||||
<div v-if="errorDetail.stack_trace">
|
|
||||||
<p><strong>堆栈跟踪:</strong></p>
|
|
||||||
<pre>{% raw %}{{ errorDetail.stack_trace }}{% endraw %}</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
<script>
|
|
||||||
new Vue({
|
|
||||||
el: '#app',
|
|
||||||
mixins: [baseApp],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
errorLogs: [],
|
|
||||||
errorDetail: {},
|
|
||||||
errorDetailVisible: false,
|
|
||||||
currentPage: 1,
|
|
||||||
pageSize: 20,
|
|
||||||
totalErrors: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.currentView = '5';
|
|
||||||
this.loadData();
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
loadData() {
|
|
||||||
const days = parseInt(this.timeRange);
|
|
||||||
this.loadErrorLogs(days);
|
|
||||||
},
|
|
||||||
loadErrorLogs(days) {
|
|
||||||
axios.get(`/api/error_logs?days=${days}&limit=${this.pageSize}&offset=${(this.currentPage - 1) * this.pageSize}`)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
this.errorLogs = response.data.data.logs || [];
|
|
||||||
this.totalErrors = response.data.data.total || 0;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('加载错误日志出错:', error);
|
|
||||||
this.$message.error('加载错误日志出错');
|
|
||||||
});
|
|
||||||
},
|
|
||||||
viewErrorDetail(error) {
|
|
||||||
// 如果已有错误ID,直接加载详情
|
|
||||||
if (error.id) {
|
|
||||||
this.loadErrorDetail(error.id);
|
|
||||||
} else {
|
|
||||||
// 否则直接显示当前行的数据
|
|
||||||
this.errorDetail = error;
|
|
||||||
this.errorDetailVisible = true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
loadErrorDetail(errorId) {
|
|
||||||
axios.get(`/api/error_detail/${errorId}`)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
this.errorDetail = response.data.data || {};
|
|
||||||
this.errorDetailVisible = true;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('加载错误详情出错:', error);
|
|
||||||
this.$message.error('加载错误详情出错');
|
|
||||||
});
|
|
||||||
},
|
|
||||||
handleSizeChange(size) {
|
|
||||||
this.pageSize = size;
|
|
||||||
this.currentPage = 1; // 重置到第一页
|
|
||||||
this.loadData();
|
|
||||||
},
|
|
||||||
handleCurrentChange(page) {
|
|
||||||
this.currentPage = page;
|
|
||||||
this.loadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
{% extends "base.html" %}
|
|
||||||
|
|
||||||
{% block title %}群组统计 - 机器人管理后台{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<!-- 群组统计 -->
|
|
||||||
<div>
|
|
||||||
<el-row :gutter="20">
|
|
||||||
<el-col :span="24">
|
|
||||||
<el-card shadow="hover">
|
|
||||||
<div slot="header">
|
|
||||||
<span>群组活跃度排行</span>
|
|
||||||
</div>
|
|
||||||
<el-table {% raw %}:data="groupStats"{% endraw %} style="width: 100%" border>
|
|
||||||
<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></el-table-column>
|
|
||||||
<el-table-column prop="used_plugins" label="使用插件数" sortable></el-table-column>
|
|
||||||
<el-table-column prop="unique_users" label="唯一用户数" sortable></el-table-column>
|
|
||||||
<el-table-column prop="success_calls" label="成功次数" sortable></el-table-column>
|
|
||||||
<el-table-column prop="failed_calls" label="失败次数" sortable></el-table-column>
|
|
||||||
<el-table-column label="成功率" sortable>
|
|
||||||
<template slot-scope="scope">
|
|
||||||
{% raw %} {{ (scope.row.success_calls / scope.row.total_calls * 100).toFixed(2) }}{% endraw %}%
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="操作">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-button size="mini" type="primary" @click="viewGroupDetail(scope.row)">查看详情</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
<script>
|
|
||||||
new Vue({
|
|
||||||
el: '#app',
|
|
||||||
mixins: [baseApp],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
groupStats: []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.currentView = '4';
|
|
||||||
this.loadData();
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
loadData() {
|
|
||||||
const days = parseInt(this.timeRange);
|
|
||||||
this.loadGroupStats(days);
|
|
||||||
},
|
|
||||||
loadGroupStats(days) {
|
|
||||||
axios.get(`/api/group_stats?days=${days}&limit=20`)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
this.groupStats = response.data.data || [];
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('加载群组统计数据出错:', error);
|
|
||||||
this.$message.error('加载群组统计数据出错');
|
|
||||||
});
|
|
||||||
},
|
|
||||||
viewGroupDetail(group) {
|
|
||||||
this.$message.info('群组详情功能开发中');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,386 +0,0 @@
|
|||||||
{% extends "base.html" %}
|
|
||||||
|
|
||||||
{% block title %}首页概览 - 机器人管理后台{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<!-- 首页概览 -->
|
|
||||||
<div>
|
|
||||||
<el-row :gutter="20">
|
|
||||||
<el-col :span="4">
|
|
||||||
<el-card shadow="hover" class="stats-card">
|
|
||||||
<div slot="header">
|
|
||||||
<span>总调用次数</span>
|
|
||||||
</div>
|
|
||||||
<div style="font-size: 24px; text-align: center;">
|
|
||||||
{% raw %}{{ totalCalls }}{% endraw %}
|
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="4">
|
|
||||||
<el-card shadow="hover" class="stats-card">
|
|
||||||
<div slot="header">
|
|
||||||
<span>成功率</span>
|
|
||||||
</div>
|
|
||||||
<div style="font-size: 24px; text-align: center;">
|
|
||||||
{% raw %}{{ successRate.toFixed(2) }}{% endraw %}%
|
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="4">
|
|
||||||
<el-card shadow="hover" class="stats-card">
|
|
||||||
<div slot="header">
|
|
||||||
<span>活跃用户数</span>
|
|
||||||
</div>
|
|
||||||
<div style="font-size: 24px; text-align: center;">
|
|
||||||
{% raw %}{{ activeUsers }}{% endraw %}
|
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="4">
|
|
||||||
<el-card shadow="hover" class="stats-card">
|
|
||||||
<div slot="header">
|
|
||||||
<span>活跃群组数</span>
|
|
||||||
</div>
|
|
||||||
<div style="font-size: 24px; text-align: center;">
|
|
||||||
{% raw %}{{ activeGroups }}{% endraw %}
|
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="4">
|
|
||||||
<el-card shadow="hover" class="stats-card">
|
|
||||||
<div slot="header">
|
|
||||||
<span>平均响应时间</span>
|
|
||||||
</div>
|
|
||||||
<div style="font-size: 24px; text-align: center;">
|
|
||||||
{% raw %}{{ avgResponseTime.toFixed(2) }}{% endraw %} ms
|
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
|
|
||||||
<!-- 添加热门用户、群组和插件 -->
|
|
||||||
<el-row :gutter="20" style="margin-top: 20px;">
|
|
||||||
<el-col :span="8">
|
|
||||||
<el-card shadow="hover">
|
|
||||||
<div slot="header">
|
|
||||||
<span>热门用户</span>
|
|
||||||
</div>
|
|
||||||
<el-table :data="topUsers" style="width: 100%">
|
|
||||||
<!-- 修改:将用户ID改为用户信息,使用固定像素宽度 -->
|
|
||||||
<el-table-column label="用户信息" min-width="180">
|
|
||||||
<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="调用次数" width="80" align="center"></el-table-column>
|
|
||||||
</el-table>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="8">
|
|
||||||
<el-card shadow="hover">
|
|
||||||
<div slot="header">
|
|
||||||
<span>热门群组</span>
|
|
||||||
</div>
|
|
||||||
<el-table :data="topGroups" style="width: 100%">
|
|
||||||
<!-- 修改:将群组ID改为群组信息,使用固定像素宽度 -->
|
|
||||||
<el-table-column label="群组信息" min-width="180">
|
|
||||||
<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="调用次数" width="80" align="center"></el-table-column>
|
|
||||||
</el-table>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="8">
|
|
||||||
<el-card shadow="hover">
|
|
||||||
<div slot="header">
|
|
||||||
<span>热门插件</span>
|
|
||||||
</div>
|
|
||||||
<el-table :data="topPlugins" style="width: 100%">
|
|
||||||
<el-table-column prop="plugin_name" label="插件名称" min-width="180"></el-table-column>
|
|
||||||
<el-table-column prop="total_calls" label="调用次数" width="80" align="center"></el-table-column>
|
|
||||||
</el-table>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
|
|
||||||
<el-row :gutter="20">
|
|
||||||
<el-col :span="12">
|
|
||||||
<div class="chart-container">
|
|
||||||
<h3>插件使用排行</h3>
|
|
||||||
<canvas id="pluginChart" width="400" height="200"></canvas>
|
|
||||||
</div>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="12">
|
|
||||||
<div class="chart-container">
|
|
||||||
<h3>成功率分析</h3>
|
|
||||||
<canvas id="successRateChart" width="400" height="200"></canvas>
|
|
||||||
</div>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
|
|
||||||
<el-row :gutter="20">
|
|
||||||
<el-col :span="24">
|
|
||||||
<div class="chart-container">
|
|
||||||
<h3>使用趋势</h3>
|
|
||||||
<canvas id="trendChart" width="800" height="200"></canvas>
|
|
||||||
</div>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
<script>
|
|
||||||
new Vue({
|
|
||||||
el: '#app',
|
|
||||||
mixins: [baseApp],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
totalCalls: 0,
|
|
||||||
successRate: 0,
|
|
||||||
activeUsers: 0,
|
|
||||||
activeGroups: 0,
|
|
||||||
avgResponseTime: 0, // 确保这里初始化为数字
|
|
||||||
topUsers: [],
|
|
||||||
topGroups: [],
|
|
||||||
topPlugins: [],
|
|
||||||
pluginStats: [],
|
|
||||||
charts: {} // 添加charts对象
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.currentView = '1';
|
|
||||||
this.loadData();
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
loadData() {
|
|
||||||
const days = parseInt(this.timeRange);
|
|
||||||
this.loadDashboardSummary(days);
|
|
||||||
this.loadPluginStats(days);
|
|
||||||
this.loadPluginTrend(days);
|
|
||||||
},
|
|
||||||
loadDashboardSummary(days) {
|
|
||||||
axios.get(`/api/dashboard_summary?days=${days}`)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
const data = response.data.data;
|
|
||||||
this.totalCalls = parseInt(data.total_calls) || 0;
|
|
||||||
this.successRate = parseFloat(data.success_rate) || 0;
|
|
||||||
this.activeUsers = data.active_users || 0;
|
|
||||||
this.activeGroups = data.active_groups || 0;
|
|
||||||
this.avgResponseTime = parseFloat(data.avg_response_time) || 0;
|
|
||||||
this.topUsers = data.top_users || [];
|
|
||||||
this.topGroups = data.top_groups || [];
|
|
||||||
this.topPlugins = data.top_plugins || [];
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('加载仪表盘摘要数据出错:', error);
|
|
||||||
this.$message.error('加载仪表盘摘要数据出错');
|
|
||||||
});
|
|
||||||
},
|
|
||||||
loadPluginStats(days) {
|
|
||||||
axios.get(`/api/plugin_stats?days=${days}`)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
this.pluginStats = response.data.data || [];
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.renderPluginChart();
|
|
||||||
this.renderSuccessRateChart();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('加载插件统计数据出错:', error);
|
|
||||||
this.$message.error('加载插件统计数据出错');
|
|
||||||
});
|
|
||||||
},
|
|
||||||
loadPluginTrend(days) {
|
|
||||||
axios.get(`/api/plugin_trend?days=${days}`)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
const trendData = response.data.data || [];
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.renderTrendChart(trendData);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('加载插件趋势数据出错:', error);
|
|
||||||
this.$message.error('加载插件趋势数据出错');
|
|
||||||
});
|
|
||||||
},
|
|
||||||
renderPluginChart() {
|
|
||||||
const ctx = document.getElementById('pluginChart').getContext('2d');
|
|
||||||
|
|
||||||
// 销毁旧图表
|
|
||||||
if (this.charts.pluginChart) {
|
|
||||||
this.charts.pluginChart.destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 准备数据
|
|
||||||
const sortedData = [...this.pluginStats].sort((a, b) => b.total_calls - a.total_calls).slice(0, 10);
|
|
||||||
// 修改这里:将插件名称和指令组合作为标签
|
|
||||||
const labels = sortedData.map(item => `${item.plugin_name}(${item.command})`);
|
|
||||||
const data = sortedData.map(item => item.total_calls);
|
|
||||||
|
|
||||||
// 创建新图表
|
|
||||||
this.charts.pluginChart = new Chart(ctx, {
|
|
||||||
type: 'bar',
|
|
||||||
data: {
|
|
||||||
labels: labels,
|
|
||||||
datasets: [{
|
|
||||||
label: '调用次数',
|
|
||||||
data: data,
|
|
||||||
backgroundColor: 'rgba(54, 162, 235, 0.6)',
|
|
||||||
borderColor: 'rgba(54, 162, 235, 1)',
|
|
||||||
borderWidth: 1
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
responsive: true,
|
|
||||||
scales: {
|
|
||||||
y: {
|
|
||||||
beginAtZero: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
renderSuccessRateChart() {
|
|
||||||
const ctx = document.getElementById('successRateChart').getContext('2d');
|
|
||||||
|
|
||||||
// 销毁旧图表
|
|
||||||
if (this.charts.successRateChart) {
|
|
||||||
this.charts.successRateChart.destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 准备数据
|
|
||||||
const sortedData = [...this.pluginStats]
|
|
||||||
.filter(item => item.total_calls > 0)
|
|
||||||
.sort((a, b) => (b.success_calls / b.total_calls) - (a.success_calls / a.total_calls))
|
|
||||||
.slice(0, 10);
|
|
||||||
|
|
||||||
// 修改这里:将插件名称和指令组合作为标签
|
|
||||||
const labels = sortedData.map(item => `${item.plugin_name}(${item.command})`);
|
|
||||||
const data = sortedData.map(item => (item.success_calls / item.total_calls) * 100);
|
|
||||||
|
|
||||||
// 创建新图表
|
|
||||||
this.charts.successRateChart = new Chart(ctx, {
|
|
||||||
type: 'bar',
|
|
||||||
data: {
|
|
||||||
labels: labels,
|
|
||||||
datasets: [{
|
|
||||||
label: '成功率(%)',
|
|
||||||
data: data,
|
|
||||||
backgroundColor: 'rgba(75, 192, 192, 0.6)',
|
|
||||||
borderColor: 'rgba(75, 192, 192, 1)',
|
|
||||||
borderWidth: 1
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
responsive: true,
|
|
||||||
scales: {
|
|
||||||
y: {
|
|
||||||
beginAtZero: true,
|
|
||||||
max: 100
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
renderTrendChart(trendData) {
|
|
||||||
const ctx = document.getElementById('trendChart').getContext('2d');
|
|
||||||
|
|
||||||
// 销毁旧图表
|
|
||||||
if (this.charts && this.charts.trendChart) {
|
|
||||||
this.charts.trendChart.destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确保charts对象存在
|
|
||||||
if (!this.charts) {
|
|
||||||
this.charts = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 准备数据 - 修改字段名匹配和数据类型转换
|
|
||||||
const labels = trendData.map(item => item.date); // 使用date而不是stat_date
|
|
||||||
const totalData = trendData.map(item => parseInt(item.total_calls) || 0); // 确保转换为数字
|
|
||||||
const successData = trendData.map(item => parseInt(item.success_calls) || 0);
|
|
||||||
const errorData = trendData.map(item => parseInt(item.failed_calls) || 0); // 使用failed_calls而不是error_calls
|
|
||||||
|
|
||||||
console.log('处理后的趋势数据:', { labels, totalData, successData, errorData });
|
|
||||||
|
|
||||||
// 创建新图表
|
|
||||||
this.charts.trendChart = new Chart(ctx, {
|
|
||||||
type: 'line',
|
|
||||||
data: {
|
|
||||||
labels: labels,
|
|
||||||
datasets: [
|
|
||||||
{
|
|
||||||
label: '总调用',
|
|
||||||
data: totalData,
|
|
||||||
fill: false,
|
|
||||||
backgroundColor: 'rgba(54, 162, 235, 0.6)',
|
|
||||||
borderColor: 'rgba(54, 162, 235, 1)',
|
|
||||||
tension: 0.1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '成功调用',
|
|
||||||
data: successData,
|
|
||||||
fill: false,
|
|
||||||
backgroundColor: 'rgba(75, 192, 192, 0.6)',
|
|
||||||
borderColor: 'rgba(75, 192, 192, 1)',
|
|
||||||
tension: 0.1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '失败调用',
|
|
||||||
data: errorData,
|
|
||||||
fill: false,
|
|
||||||
backgroundColor: 'rgba(255, 99, 132, 0.6)',
|
|
||||||
borderColor: 'rgba(255, 99, 132, 1)',
|
|
||||||
tension: 0.1
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
responsive: true,
|
|
||||||
maintainAspectRatio: true,
|
|
||||||
scales: {
|
|
||||||
y: {
|
|
||||||
beginAtZero: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block styles %}
|
|
||||||
<style>
|
|
||||||
.stats-card {
|
|
||||||
margin-bottom: 15px;
|
|
||||||
height: 120px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.chart-container {
|
|
||||||
margin-bottom: 20px;
|
|
||||||
padding: 10px;
|
|
||||||
background-color: #fff;
|
|
||||||
border-radius: 4px;
|
|
||||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.chart-container h3 {
|
|
||||||
margin-top: 0;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
font-size: 16px;
|
|
||||||
color: #606266;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,255 +0,0 @@
|
|||||||
{% 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 %}
|
|
||||||
@@ -1,473 +0,0 @@
|
|||||||
{% extends "base.html" %}
|
|
||||||
|
|
||||||
{% block title %}群机器人管理 - 机器人管理后台{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<!-- 群机器人管理 -->
|
|
||||||
<div>
|
|
||||||
<el-row :gutter="20">
|
|
||||||
<el-col :span="24">
|
|
||||||
<el-card shadow="hover">
|
|
||||||
<div slot="header" class="clearfix">
|
|
||||||
<span>群机器人管理</span>
|
|
||||||
<el-button
|
|
||||||
type="primary"
|
|
||||||
size="small"
|
|
||||||
style="float: right; margin-left: 10px;"
|
|
||||||
@click="showAddGroupDialog">
|
|
||||||
添加群组
|
|
||||||
</el-button>
|
|
||||||
<el-input
|
|
||||||
placeholder="搜索群组..."
|
|
||||||
v-model="searchQuery"
|
|
||||||
style="width: 200px; float: right"
|
|
||||||
clearable>
|
|
||||||
</el-input>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 群组列表 -->
|
|
||||||
<el-table
|
|
||||||
:data="filteredGroups"
|
|
||||||
style="width: 100%"
|
|
||||||
border
|
|
||||||
@selection-change="handleSelectionChange">
|
|
||||||
<el-table-column type="selection" width="55"></el-table-column>
|
|
||||||
<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 label="机器人状态" width="120">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-tag
|
|
||||||
:type="scope.row.robot_status === 'enabled' ? 'success' : 'danger'">
|
|
||||||
{% raw %}{{ scope.row.robot_status === 'enabled' ? '已启用' : '已关闭' }}{% endraw %}
|
|
||||||
</el-tag>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="操作" width="280">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-button
|
|
||||||
size="mini"
|
|
||||||
type="primary"
|
|
||||||
@click="viewGroupPermissions(scope.row)">
|
|
||||||
查看权限
|
|
||||||
</el-button>
|
|
||||||
<el-button
|
|
||||||
size="mini"
|
|
||||||
:type="scope.row.robot_status === 'enabled' ? 'danger' : 'success'"
|
|
||||||
@click="toggleRobotStatus(scope.row)">
|
|
||||||
{% raw %}{{ scope.row.robot_status === 'enabled' ? '关闭' : '启用' }}{% endraw %}
|
|
||||||
</el-button>
|
|
||||||
<el-button
|
|
||||||
size="mini"
|
|
||||||
type="info"
|
|
||||||
@click="viewMessageTrend(scope.row)">
|
|
||||||
消息趋势
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
|
|
||||||
<!-- 批量操作按钮 -->
|
|
||||||
<div style="margin-top: 20px" v-if="selectedGroups.length > 0">
|
|
||||||
<el-alert
|
|
||||||
title="批量操作"
|
|
||||||
type="info"
|
|
||||||
:closable="false">
|
|
||||||
<span>已选择 {% raw %}{{ selectedGroups.length }}{% endraw %} 个群组</span>
|
|
||||||
</el-alert>
|
|
||||||
<div style="margin-top: 10px">
|
|
||||||
<el-button type="success" size="small" @click="batchEnableRobot">批量启用</el-button>
|
|
||||||
<el-button type="danger" size="small" @click="batchDisableRobot">批量关闭</el-button>
|
|
||||||
<el-button type="warning" size="small" @click="batchRemoveGroups">批量移除</el-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
|
|
||||||
<!-- 群组权限管理对话框 -->
|
|
||||||
<el-dialog
|
|
||||||
:title="currentGroupName + ' 功能权限管理'"
|
|
||||||
:visible.sync="permissionDialogVisible"
|
|
||||||
width="70%">
|
|
||||||
<el-table :data="permissions" style="width: 100%" border>
|
|
||||||
<el-table-column prop="feature_id" label="功能ID" width="80"></el-table-column>
|
|
||||||
<el-table-column prop="feature_description" label="功能描述"></el-table-column>
|
|
||||||
<el-table-column label="状态" width="100">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-tag
|
|
||||||
:type="scope.row.status === 'enabled' ? 'success' : 'danger'">
|
|
||||||
{% raw %}{{ scope.row.status === 'enabled' ? '已启用' : '已关闭' }}{% endraw %}
|
|
||||||
</el-tag>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="操作" width="120">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-switch
|
|
||||||
v-model="scope.row.statusBool"
|
|
||||||
active-color="#13ce66"
|
|
||||||
inactive-color="#ff4949"
|
|
||||||
@change="togglePermission(scope.row)">
|
|
||||||
</el-switch>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
<div slot="footer" class="dialog-footer">
|
|
||||||
<el-button @click="enableAllPermissions" type="success">一键启用全部</el-button>
|
|
||||||
<el-button @click="disableAllPermissions" type="danger">一键关闭全部</el-button>
|
|
||||||
<el-button @click="permissionDialogVisible = false">关闭</el-button>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
|
|
||||||
<!-- 添加群组对话框 -->
|
|
||||||
<el-dialog
|
|
||||||
title="添加群组"
|
|
||||||
:visible.sync="addGroupDialogVisible"
|
|
||||||
width="30%">
|
|
||||||
<el-form :model="addGroupForm" :rules="addGroupRules" ref="addGroupForm">
|
|
||||||
<el-form-item label="群组ID" prop="groupId">
|
|
||||||
<el-input v-model="addGroupForm.groupId" placeholder="请输入群组ID"></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
<span slot="footer" class="dialog-footer">
|
|
||||||
<el-button @click="addGroupDialogVisible = false">取消</el-button>
|
|
||||||
<el-button type="primary" @click="submitAddGroup">确定</el-button>
|
|
||||||
</span>
|
|
||||||
</el-dialog>
|
|
||||||
|
|
||||||
<!-- 群组消息趋势对话框 -->
|
|
||||||
<el-dialog
|
|
||||||
title="群组消息趋势"
|
|
||||||
:visible.sync="messageTrendDialogVisible"
|
|
||||||
width="70%">
|
|
||||||
<div class="chart-container">
|
|
||||||
<h3>{% raw %}{{ currentGroupName }}{% endraw %} 消息趋势</h3>
|
|
||||||
<canvas id="messageTrendChart" width="800" height="400"></canvas>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
<script>
|
|
||||||
new Vue({
|
|
||||||
el: '#app',
|
|
||||||
mixins: [baseApp],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
groups: [],
|
|
||||||
permissions: [],
|
|
||||||
currentGroupId: null,
|
|
||||||
currentGroupName: '',
|
|
||||||
searchQuery: '',
|
|
||||||
selectedGroups: [],
|
|
||||||
permissionDialogVisible: false,
|
|
||||||
// 添加群组相关数据
|
|
||||||
addGroupDialogVisible: false,
|
|
||||||
addGroupForm: {
|
|
||||||
groupId: ''
|
|
||||||
},
|
|
||||||
addGroupRules: {
|
|
||||||
groupId: [
|
|
||||||
{ required: true, message: '请输入群组ID', trigger: 'blur' },
|
|
||||||
{ pattern: /^\S+$/, message: '群组ID不能包含空格', trigger: 'blur' }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
// 添加消息趋势相关数据
|
|
||||||
messageTrendDialogVisible: false,
|
|
||||||
messageTrendData: {
|
|
||||||
dates: [],
|
|
||||||
counts: []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
filteredGroups() {
|
|
||||||
if (!this.searchQuery) return this.groups;
|
|
||||||
const query = this.searchQuery.toLowerCase();
|
|
||||||
return this.groups.filter(group =>
|
|
||||||
(group.group_id && group.group_id.toLowerCase().includes(query)) ||
|
|
||||||
(group.group_name && group.group_name.toLowerCase().includes(query))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.currentView = '6'; // 设置当前菜单项
|
|
||||||
this.loadGroups();
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
loadGroups() {
|
|
||||||
axios.get('/api/robot/groups')
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
this.groups = response.data.data || [];
|
|
||||||
} else {
|
|
||||||
this.$message.error('加载群组失败');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('加载群组失败:', error);
|
|
||||||
this.$message.error('加载群组失败: ' + error.message);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
handleSelectionChange(selection) {
|
|
||||||
this.selectedGroups = selection.map(item => item.group_id);
|
|
||||||
},
|
|
||||||
viewGroupPermissions(group) {
|
|
||||||
this.currentGroupId = group.group_id;
|
|
||||||
this.currentGroupName = group.group_name || group.group_id;
|
|
||||||
|
|
||||||
axios.get(`/api/robot/group/${group.group_id}/permissions`)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
// 添加布尔值属性用于switch组件
|
|
||||||
const permissionsData = response.data.data || [];
|
|
||||||
this.permissions = permissionsData.map(p => ({
|
|
||||||
...p,
|
|
||||||
statusBool: p.status === 'enabled'
|
|
||||||
}));
|
|
||||||
this.permissionDialogVisible = true;
|
|
||||||
} else {
|
|
||||||
this.$message.error('加载权限失败');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('加载权限失败:', error);
|
|
||||||
this.$message.error('加载权限失败: ' + error.message);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
togglePermission(permission) {
|
|
||||||
const newStatus = permission.statusBool ? 'enabled' : 'disabled';
|
|
||||||
|
|
||||||
axios.post(`/api/robot/group/${this.currentGroupId}/permissions`, {
|
|
||||||
feature_id: permission.feature_id,
|
|
||||||
status: newStatus
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
permission.status = newStatus;
|
|
||||||
this.$message.success('更新权限成功');
|
|
||||||
} else {
|
|
||||||
// 恢复原状态
|
|
||||||
permission.statusBool = !permission.statusBool;
|
|
||||||
this.$message.error('更新权限失败');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
// 恢复原状态
|
|
||||||
permission.statusBool = !permission.statusBool;
|
|
||||||
console.error('更新权限失败:', error);
|
|
||||||
this.$message.error('更新权限失败: ' + error.message);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
enableAllPermissions() {
|
|
||||||
this.updateAllPermissions('enabled');
|
|
||||||
},
|
|
||||||
disableAllPermissions() {
|
|
||||||
this.updateAllPermissions('disabled');
|
|
||||||
},
|
|
||||||
updateAllPermissions(status) {
|
|
||||||
axios.post(`/api/robot/group/${this.currentGroupId}/permissions`, {
|
|
||||||
status: status
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
// 更新本地数据
|
|
||||||
this.permissions.forEach(p => {
|
|
||||||
p.status = status;
|
|
||||||
p.statusBool = status === 'enabled';
|
|
||||||
});
|
|
||||||
this.$message.success('批量更新权限成功');
|
|
||||||
} else {
|
|
||||||
this.$message.error('批量更新权限失败');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('批量更新权限失败:', error);
|
|
||||||
this.$message.error('批量更新权限失败: ' + error.message);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
toggleRobotStatus(group) {
|
|
||||||
const newStatus = group.robot_status === 'enabled' ? 'disabled' : 'enabled';
|
|
||||||
|
|
||||||
axios.post(`/api/robot/group/${group.group_id}/status`, {
|
|
||||||
status: newStatus
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
group.robot_status = newStatus;
|
|
||||||
this.$message.success('更新机器人状态成功');
|
|
||||||
} else {
|
|
||||||
this.$message.error('更新机器人状态失败');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('更新机器人状态失败:', error);
|
|
||||||
this.$message.error('更新机器人状态失败: ' + error.message);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
showAddGroupDialog() {
|
|
||||||
this.addGroupForm.groupId = '';
|
|
||||||
this.addGroupDialogVisible = true;
|
|
||||||
},
|
|
||||||
submitAddGroup() {
|
|
||||||
this.$refs.addGroupForm.validate(valid => {
|
|
||||||
if (valid) {
|
|
||||||
axios.post('/api/robot/group', {
|
|
||||||
group_id: this.addGroupForm.groupId
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
this.addGroupDialogVisible = false;
|
|
||||||
this.$message.success('添加群组成功');
|
|
||||||
// 重新加载群组列表
|
|
||||||
this.loadGroups();
|
|
||||||
} else {
|
|
||||||
this.$message.error('添加群组失败');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('添加群组失败:', error);
|
|
||||||
this.$message.error('添加群组失败: ' + error.message);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
batchEnableRobot() {
|
|
||||||
this.batchUpdateRobotStatus('enabled');
|
|
||||||
},
|
|
||||||
batchDisableRobot() {
|
|
||||||
this.batchUpdateRobotStatus('disabled');
|
|
||||||
},
|
|
||||||
batchUpdateRobotStatus(status) {
|
|
||||||
if (this.selectedGroups.length === 0) {
|
|
||||||
this.$message.warning('请先选择群组');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
axios.post('/api/robot/batch_operation', {
|
|
||||||
operation: 'update_status',
|
|
||||||
group_ids: this.selectedGroups,
|
|
||||||
status: status
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
// 更新本地数据
|
|
||||||
this.groups.forEach(g => {
|
|
||||||
if (this.selectedGroups.includes(g.group_id)) {
|
|
||||||
g.robot_status = status;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.$message.success('批量更新状态成功');
|
|
||||||
} else {
|
|
||||||
this.$message.error('批量更新状态失败');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('批量更新状态失败:', error);
|
|
||||||
this.$message.error('批量更新状态失败: ' + error.message);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
batchRemoveGroups() {
|
|
||||||
if (this.selectedGroups.length === 0) {
|
|
||||||
this.$message.warning('请先选择群组');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.$confirm(`确定要批量移除 ${this.selectedGroups.length} 个群组吗? 此操作将清除这些群组的所有设置。`, '警告', {
|
|
||||||
confirmButtonText: '确定',
|
|
||||||
cancelButtonText: '取消',
|
|
||||||
type: 'danger'
|
|
||||||
}).then(() => {
|
|
||||||
axios.post('/api/robot/batch_operation', {
|
|
||||||
operation: 'remove_groups',
|
|
||||||
group_ids: this.selectedGroups
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
// 从列表中移除这些群组
|
|
||||||
this.groups = this.groups.filter(g => !this.selectedGroups.includes(g.group_id));
|
|
||||||
this.selectedGroups = [];
|
|
||||||
this.$message.success('批量移除成功');
|
|
||||||
} else {
|
|
||||||
this.$message.error('批量移除失败');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('批量移除失败:', error);
|
|
||||||
this.$message.error('批量移除失败: ' + error.message);
|
|
||||||
});
|
|
||||||
}).catch(() => {});
|
|
||||||
},
|
|
||||||
// 添加查看消息趋势的方法
|
|
||||||
viewMessageTrend(group) {
|
|
||||||
this.currentGroupId = group.group_id;
|
|
||||||
this.currentGroupName = group.group_name || group.group_id;
|
|
||||||
|
|
||||||
// 获取消息趋势数据
|
|
||||||
const days = parseInt(this.timeRange || 7);
|
|
||||||
axios.get(`/api/robot/group/${group.group_id}/message_trend?days=${days}`)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
this.messageTrendData = response.data.data || { dates: [], counts: [] };
|
|
||||||
this.messageTrendDialogVisible = true;
|
|
||||||
|
|
||||||
// 在下一个DOM更新周期渲染图表
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.renderMessageTrendChart();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.$message.error('加载消息趋势失败');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('加载消息趋势失败:', error);
|
|
||||||
this.$message.error('加载消息趋势失败: ' + error.message);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
// 渲染消息趋势图表
|
|
||||||
renderMessageTrendChart() {
|
|
||||||
const ctx = document.getElementById('messageTrendChart').getContext('2d');
|
|
||||||
|
|
||||||
// 销毁旧图表
|
|
||||||
if (this.charts && this.charts.messageTrendChart) {
|
|
||||||
this.charts.messageTrendChart.destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确保charts对象存在
|
|
||||||
if (!this.charts) {
|
|
||||||
this.charts = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建新图表
|
|
||||||
this.charts.messageTrendChart = new Chart(ctx, {
|
|
||||||
type: 'line',
|
|
||||||
data: {
|
|
||||||
labels: this.messageTrendData.dates,
|
|
||||||
datasets: [
|
|
||||||
{
|
|
||||||
label: '消息数量',
|
|
||||||
data: this.messageTrendData.counts,
|
|
||||||
fill: false,
|
|
||||||
backgroundColor: 'rgba(75, 192, 192, 0.6)',
|
|
||||||
borderColor: 'rgba(75, 192, 192, 1)',
|
|
||||||
tension: 0.1
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
responsive: true,
|
|
||||||
scales: {
|
|
||||||
y: {
|
|
||||||
beginAtZero: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
{% 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="userStats"{% endraw %} style="width: 100%" border>
|
|
||||||
<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></el-table-column>
|
|
||||||
<el-table-column prop="success_calls" label="成功次数" sortable></el-table-column>
|
|
||||||
<el-table-column prop="failed_calls" label="失败次数" sortable></el-table-column>
|
|
||||||
<el-table-column label="成功率" sortable>
|
|
||||||
<template slot-scope="scope">
|
|
||||||
{% raw %}{{ (scope.row.success_calls / scope.row.total_calls * 100).toFixed(2) }}{% endraw %}%
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="操作">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-button size="mini" type="primary" {% raw %}@click="viewUserDetail(scope.row)"{% endraw %}>查看详情</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
<script>
|
|
||||||
new Vue({
|
|
||||||
el: '#app',
|
|
||||||
mixins: [baseApp],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
userStats: []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.currentView = '3';
|
|
||||||
this.loadData();
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
loadData() {
|
|
||||||
const days = parseInt(this.timeRange);
|
|
||||||
this.loadUserStats(days);
|
|
||||||
},
|
|
||||||
loadUserStats(days) {
|
|
||||||
axios.get(`/api/user_stats?days=${days}&limit=20`)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
this.userStats = response.data.data || [];
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('加载用户统计数据出错:', error);
|
|
||||||
this.$message.error('加载用户统计数据出错');
|
|
||||||
});
|
|
||||||
},
|
|
||||||
viewUserDetail(user) {
|
|
||||||
this.$message.info('用户详情功能开发中');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
Reference in New Issue
Block a user