- 新增 /device-logs 设备事件日志管理页 (admin 权限) - 支持按设备序列号/事件类型筛选查询 - 支持 admin 按条件删除日志 - 不同事件类型彩色标识 (在线=绿, 离线=红, 通信不良=橙) - 新增 /api/devices/<id>/status 设备状态 API - 设备列表页:每 5s 异步刷新所有设备在线状态 - 测试操作页:顶部显示设备状态,每 5s 异步刷新 - dnt_info state 支持三态显示 (在线/离线/通信不良) - 导航栏增加「设备日志」入口 (admin only)
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
"""Flask 应用工厂"""
|
|
|
|
from flask import Flask
|
|
from app.config import Config
|
|
|
|
|
|
def create_app() -> Flask:
|
|
app = Flask(__name__)
|
|
app.config.from_object(Config)
|
|
|
|
# 初始化认证
|
|
from app.auth import init_auth, auth_bp
|
|
init_auth(app)
|
|
app.register_blueprint(auth_bp)
|
|
|
|
# 注册蓝图
|
|
from app.routes.devices import bp as devices_bp
|
|
from app.routes.test_op import bp as test_op_bp
|
|
from app.routes.test_data import bp as test_data_bp
|
|
from app.routes.fixture import bp as fixture_bp
|
|
from app.routes.users import bp as users_bp
|
|
from app.routes.logs import bp as logs_bp
|
|
from app.routes.device_logs import bp as device_logs_bp
|
|
|
|
app.register_blueprint(devices_bp)
|
|
app.register_blueprint(test_op_bp)
|
|
app.register_blueprint(test_data_bp)
|
|
app.register_blueprint(fixture_bp)
|
|
app.register_blueprint(users_bp)
|
|
app.register_blueprint(logs_bp)
|
|
app.register_blueprint(device_logs_bp)
|
|
|
|
# 初始化默认管理员
|
|
_ensure_admin()
|
|
|
|
return app
|
|
|
|
|
|
def _ensure_admin():
|
|
"""如果没有任何用户,创建默认 admin/admin123"""
|
|
from app.models import get_conn
|
|
from werkzeug.security import generate_password_hash
|
|
conn = get_conn()
|
|
try:
|
|
with conn.cursor() as cur:
|
|
cur.execute("SELECT COUNT(*) as cnt FROM tb_user")
|
|
if cur.fetchone()["cnt"] == 0:
|
|
cur.execute(
|
|
"INSERT INTO tb_user (username, password_hash, role) VALUES (%s,%s,%s)",
|
|
("admin", generate_password_hash("admin123"), "admin"),
|
|
)
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|