From ea59ceeef21ae29a46c893c7beb9588e4e0e68f8 Mon Sep 17 00:00:00 2001 From: liuwei Date: Fri, 11 Apr 2025 17:51:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E7=99=BB=E5=BD=95=E8=B4=A6?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/dashboard/blueprints/system.py | 11 +++++++- admin/dashboard/server.py | 41 ++++++++++++++++++++++++++++ admin/dashboard/templates/index.html | 39 ++++++++++++++++++++++++++ plugin_common/plugin_manager.py | 8 +++--- 4 files changed, 94 insertions(+), 5 deletions(-) diff --git a/admin/dashboard/blueprints/system.py b/admin/dashboard/blueprints/system.py index cc64a92..b592fe3 100644 --- a/admin/dashboard/blueprints/system.py +++ b/admin/dashboard/blueprints/system.py @@ -86,4 +86,13 @@ def api_wx_logs(): }) except Exception as e: logger.error(f"获取微信日志失败: {e}") - return jsonify({"success": False, "error": str(e)}), 500 \ No newline at end of file + return jsonify({"success": False, "error": str(e)}), 500 + +# 在现有路由下添加 +@system_bp.route('/api/current_user_info', methods=['GET']) +@login_required +def get_current_user_info(): + """获取当前登录的微信用户信息""" + dashboard_server = current_app.dashboard_server + result = dashboard_server.get_current_user_info() + return jsonify(result) diff --git a/admin/dashboard/server.py b/admin/dashboard/server.py index 4c39bc7..41d10c8 100644 --- a/admin/dashboard/server.py +++ b/admin/dashboard/server.py @@ -44,6 +44,8 @@ class DashboardServer: self.contact_manager = robot_instance.contact_manager self.plugin_manager = robot_instance.plugin_manager self.plugin_registry = robot_instance.plugin_registry + # 获取WCF实例 + self.wcf = robot_instance.wcf self.logger.info("使用Robot实例的对象进行初始化") else: self.logger.error("未提供Robot实例,Dashboard无法正常工作") @@ -165,3 +167,42 @@ class DashboardServer: self._server.shutdown() self.logger.info("服务器已停止") + + def get_current_user_info(self): + """获取当前登录的微信用户信息""" + try: + if not self.wcf: + self.logger.error("WCF实例不可用,无法获取当前用户信息") + return {"success": False, "message": "WCF实例不可用"} + + # 获取当前登录的微信ID + wx_id = self.wcf.get_self_wxid() + if not wx_id: + return {"success": False, "message": "未获取到微信ID"} + + # 获取用户详细信息 + user_info = self.wcf.get_user_info() + + # 获取头像 + avatar_path = None + try: + avatar_path = self.wcf.get_avatar(wx_id) + except Exception as e: + self.logger.warning(f"获取用户头像失败: {e}") + + return { + "success": True, + "data": { + "wx_id": wx_id, + "nickname": user_info.get("nickname", "未知用户"), + "avatar": avatar_path, + "signature": user_info.get("signature", ""), + "gender": user_info.get("gender", 0), + "country": user_info.get("country", ""), + "province": user_info.get("province", ""), + "city": user_info.get("city", "") + } + } + except Exception as e: + self.logger.error(f"获取当前用户信息失败: {e}") + return {"success": False, "message": f"获取用户信息出错: {str(e)}"} diff --git a/admin/dashboard/templates/index.html b/admin/dashboard/templates/index.html index c3f40a5..5387c82 100644 --- a/admin/dashboard/templates/index.html +++ b/admin/dashboard/templates/index.html @@ -6,6 +6,28 @@
+ + +
+ 当前登录微信账号 +
+
+
+ +
+
+
{% raw %}{{ currentUser.data.nickname }}{% endraw %}
+
微信号: {% raw %}{{ currentUser.data.wx_id }}{% endraw %}
+
{% raw %}{{ currentUser.data.signature || '暂无签名' }}{% endraw %}
+
+
+
+ +
{% raw %}{{ currentUser.message || '未获取到用户信息' }}{% endraw %}
+
+
+
+
@@ -252,6 +274,8 @@ this.loadData(); // 加载系统信息 this.loadSystemInfo(); + // 加载当前用户信息 + this.loadCurrentUserInfo(); // 设置定时刷新系统信息(每30秒) this.systemInfoTimer = setInterval(this.loadSystemInfo, 30000); }, @@ -279,6 +303,21 @@ .catch(error => { console.error('加载系统信息出错:', error); }); + }, + // 添加获取当前用户信息的方法 + loadCurrentUserInfo() { + axios.get('/api/current_user_info') + .then(response => { + this.currentUser = response.data; + }) + .catch(error => { + console.error('加载当前用户信息出错:', error); + this.currentUser = { + success: false, + message: '获取用户信息失败', + data: {} + }; + }); }, // 添加获取进度条状态的方法 getProgressStatus(value) { diff --git a/plugin_common/plugin_manager.py b/plugin_common/plugin_manager.py index ae8b2a7..69107e6 100644 --- a/plugin_common/plugin_manager.py +++ b/plugin_common/plugin_manager.py @@ -436,20 +436,20 @@ class PluginManager: display_name, plugin = self.find_plugin_by_name(name) if not plugin: - self.LOG.info(f"PluginManager:插件 {name} 未加载") + self.LOG.debug(f"PluginManager:插件 {name} 未加载") return False if plugin.status == PluginStatus.RUNNING: - self.LOG.info(f"PluginManager:插件 {display_name} 已经在运行") + self.LOG.debug(f"PluginManager:插件 {display_name} 已经在运行") return True if plugin.start(): plugin.status = PluginStatus.RUNNING - self.LOG.info(f"PluginManager:插件 {display_name} 状态变更为在运行") + self.LOG.debug(f"PluginManager:插件 {display_name} 状态变更为在运行") return True else: plugin.status = PluginStatus.ERROR - self.LOG.info(f"PluginManager:插件 {display_name} 状态变更为异常") + self.LOG.debug(f"PluginManager:插件 {display_name} 状态变更为异常") return False def stop_plugin(self, name: str) -> bool: