feat: 新增 edc-web Flask 前端管理系统 + 需求文档
- edc-web: Flask 项目骨架(设备管理、测试操作、测试信息三大页面) - edc_server: 升级子模块(tb_serialnet 透传支持) - docs: 测试工装EDC管理系统需求文档
This commit is contained in:
0
edc-web/app/routes/__init__.py
Normal file
0
edc-web/app/routes/__init__.py
Normal file
BIN
edc-web/app/routes/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
edc-web/app/routes/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
edc-web/app/routes/__pycache__/devices.cpython-311.pyc
Normal file
BIN
edc-web/app/routes/__pycache__/devices.cpython-311.pyc
Normal file
Binary file not shown.
BIN
edc-web/app/routes/__pycache__/test_data.cpython-311.pyc
Normal file
BIN
edc-web/app/routes/__pycache__/test_data.cpython-311.pyc
Normal file
Binary file not shown.
BIN
edc-web/app/routes/__pycache__/test_op.cpython-311.pyc
Normal file
BIN
edc-web/app/routes/__pycache__/test_op.cpython-311.pyc
Normal file
Binary file not shown.
28
edc-web/app/routes/devices.py
Normal file
28
edc-web/app/routes/devices.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""设备页面 API"""
|
||||
|
||||
from flask import Blueprint, jsonify, render_template, request
|
||||
from app.models import get_all_devices, update_device_name
|
||||
|
||||
bp = Blueprint("devices", __name__)
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def index():
|
||||
"""设备列表页(默认首页)"""
|
||||
return render_template("devices.html")
|
||||
|
||||
|
||||
@bp.route("/api/devices")
|
||||
def api_devices():
|
||||
"""获取所有设备列表"""
|
||||
devices = get_all_devices()
|
||||
return jsonify(devices)
|
||||
|
||||
|
||||
@bp.route("/api/devices/<int:device_id>/name", methods=["PUT"])
|
||||
def api_update_name(device_id):
|
||||
"""修改设备名称"""
|
||||
data = request.get_json()
|
||||
name = data.get("name", "")
|
||||
update_device_name(device_id, name)
|
||||
return jsonify({"ok": True})
|
||||
60
edc-web/app/routes/test_data.py
Normal file
60
edc-web/app/routes/test_data.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""测试信息 API"""
|
||||
|
||||
import csv
|
||||
import io
|
||||
from flask import Blueprint, jsonify, render_template, request, Response
|
||||
from app.models import get_test_data, get_all_test_data_for_export
|
||||
|
||||
bp = Blueprint("test_data", __name__)
|
||||
|
||||
|
||||
@bp.route("/test-data")
|
||||
def test_data_page():
|
||||
"""测试信息页"""
|
||||
return render_template("test_data.html")
|
||||
|
||||
|
||||
@bp.route("/api/test-data")
|
||||
def api_test_data():
|
||||
"""分页查询测试数据"""
|
||||
page = request.args.get("page", 1, type=int)
|
||||
per_page = request.args.get("per_page", 20, type=int)
|
||||
serial = request.args.get("serial", "", type=str)
|
||||
date_from = request.args.get("date_from", "", type=str)
|
||||
date_to = request.args.get("date_to", "", type=str)
|
||||
|
||||
records, total = get_test_data(page, per_page, serial, date_from, date_to)
|
||||
return jsonify({
|
||||
"records": records,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"per_page": per_page,
|
||||
"pages": (total + per_page - 1) // per_page if total > 0 else 1,
|
||||
})
|
||||
|
||||
|
||||
@bp.route("/api/test-data/export")
|
||||
def api_export():
|
||||
"""导出测试数据为 CSV"""
|
||||
serial = request.args.get("serial", "", type=str)
|
||||
date_from = request.args.get("date_from", "", type=str)
|
||||
date_to = request.args.get("date_to", "", type=str)
|
||||
|
||||
records = get_all_test_data_for_export(serial, date_from, date_to)
|
||||
|
||||
output = io.StringIO()
|
||||
writer = csv.writer(output)
|
||||
|
||||
# 表头
|
||||
if records:
|
||||
headers = [k for k in records[0].keys()]
|
||||
writer.writerow(headers)
|
||||
for r in records:
|
||||
writer.writerow(r.values())
|
||||
|
||||
output.seek(0)
|
||||
return Response(
|
||||
output.getvalue(),
|
||||
mimetype="text/csv",
|
||||
headers={"Content-Disposition": "attachment; filename=test_data.csv"},
|
||||
)
|
||||
76
edc-web/app/routes/test_op.py
Normal file
76
edc-web/app/routes/test_op.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""测试操作 API"""
|
||||
|
||||
import time
|
||||
from flask import Blueprint, jsonify, render_template, request
|
||||
from app.models import (
|
||||
get_device_by_id,
|
||||
insert_serialnet,
|
||||
get_serialnet_stats,
|
||||
get_latest_test_state,
|
||||
get_automation_averages,
|
||||
)
|
||||
|
||||
bp = Blueprint("test_op", __name__)
|
||||
|
||||
# DG430 指令 (addr=0x01, ADDR=0x81)
|
||||
# XOR/SUM 预计算值
|
||||
COMMANDS = {
|
||||
"B0": "7F8101B03032", # 开始测试
|
||||
"B1": "7F8101B13133", # 测试复原
|
||||
"BA": "7F8101BA3A3C", # 电机前进
|
||||
"BB": "7F8101BB3B3D", # 电机后退
|
||||
"BC": "7F8101BC3C3E", # 电机停止
|
||||
}
|
||||
|
||||
|
||||
@bp.route("/test/<int:dnt_id>")
|
||||
def test_page(dnt_id):
|
||||
"""测试操作页面"""
|
||||
device = get_device_by_id(dnt_id)
|
||||
if not device:
|
||||
return "设备不存在", 404
|
||||
return render_template("test_op.html", device=device)
|
||||
|
||||
|
||||
@bp.route("/api/command", methods=["POST"])
|
||||
def api_command():
|
||||
"""发送单次指令"""
|
||||
data = request.get_json()
|
||||
dnt_id = data.get("dnt_id")
|
||||
cmd = data.get("cmd", "").upper()
|
||||
|
||||
if cmd not in COMMANDS:
|
||||
return jsonify({"ok": False, "error": f"未知指令: {cmd}"}), 400
|
||||
|
||||
send_pkg = COMMANDS[cmd]
|
||||
record_id = insert_serialnet(dnt_id, send_pkg)
|
||||
return jsonify({"ok": True, "record_id": record_id, "send_pkg": send_pkg})
|
||||
|
||||
|
||||
@bp.route("/api/automation/start", methods=["POST"])
|
||||
def api_automation_start():
|
||||
"""开始自动化测试"""
|
||||
data = request.get_json()
|
||||
dnt_id = data.get("dnt_id")
|
||||
count = int(data.get("count", 1))
|
||||
|
||||
# 插入第一条 0xB0 指令
|
||||
record_id = insert_serialnet(dnt_id, COMMANDS["B0"])
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
"total": count,
|
||||
"first_record_id": record_id,
|
||||
})
|
||||
|
||||
|
||||
@bp.route("/api/automation/<int:dnt_id>/progress")
|
||||
def api_automation_progress(dnt_id):
|
||||
"""获取自动化进度"""
|
||||
stats = get_serialnet_stats(dnt_id)
|
||||
latest = get_latest_test_state(dnt_id)
|
||||
averages = get_automation_averages(dnt_id)
|
||||
return jsonify({
|
||||
"stats": stats,
|
||||
"latest": latest,
|
||||
"averages": averages,
|
||||
})
|
||||
Reference in New Issue
Block a user