新增Dashboard未登录二维码引导与倒计时

This commit is contained in:
liuwei
2026-05-07 11:10:00 +08:00
parent c628afc530
commit 86f8d57874
5 changed files with 900 additions and 1 deletions

View File

@@ -12,6 +12,36 @@ robot_bp = Blueprint('robot', __name__, url_prefix='/robot')
LOG = logger
def _serialize_login_qr_state(server) -> dict:
"""把 Robot 中的二维码登录态整理成 Dashboard 接口输出。"""
robot = getattr(server, "robot", None)
if robot is None or not hasattr(robot, "get_ipad_login_qr_state"):
return {
"logged_in": False,
"active": False,
"status": "unavailable",
"status_text": "机器人运行态暂不可用",
"current": {},
"history": [],
"server_now": datetime.now().timestamp(),
}
state = robot.get_ipad_login_qr_state() or {}
return {
"logged_in": bool(state.get("logged_in", False)),
"active": bool(state.get("active", False)),
"status": str(state.get("status", "idle") or "idle"),
"status_text": str(state.get("status_text", "尚未进入扫码登录流程") or "尚未进入扫码登录流程"),
"runtime_running": bool(state.get("runtime_running", False)),
"wxid": str(state.get("wxid", "") or ""),
"nickname": str(state.get("nickname", "") or ""),
"updated_at": float(state.get("updated_at", 0) or 0),
"server_now": float(state.get("server_now", datetime.now().timestamp()) or datetime.now().timestamp()),
"current": dict(state.get("current", {}) or {}),
"history": [dict(item or {}) for item in (state.get("history", []) or [])],
}
def _build_group_ops_profile(server, group_id: str, group_name: str, peak_hours: list, plugin_stats: list) -> dict:
"""构建群运营 2.0 所需的群画像摘要。
@@ -423,6 +453,21 @@ def robot_management():
return redirect('/contacts')
@robot_bp.route('/api/login_qr_status', methods=['GET'])
@login_required
def api_login_qr_status():
"""返回当前二维码登录状态,供 Dashboard 首页弹窗轮询。"""
try:
server = current_app.dashboard_server
return jsonify({
"success": True,
"data": _serialize_login_qr_state(server),
})
except Exception as e:
LOG.error(f"获取登录二维码状态失败: {e}")
return jsonify({"success": False, "error": str(e)}), 500
# API路由
@robot_bp.route('/api/groups')
@login_required