- 设备页增加「配置」按钮(devices.js) - 新增工装配置页面(fixture.html+js): 参数表单、5个操作按钮、通信日志区、基准参数表 - 新增车检器基准参数管理页面(vehicle_base_test.html+js): CRUD + 搜索 - 新增 fixture 蓝图(routes/fixture.py): 0x4A~0x4E 指令发送、参数CRUD、serialnet状态查询 - models.py: 新增 get_serialnet_by_id, tb_fixture_param/tb_vechicle_base_test CRUD - edc_server 子模块更新
53 lines
1.5 KiB
Python
53 lines
1.5 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
|
|
|
|
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)
|
|
|
|
# 初始化默认管理员
|
|
_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()
|