Files
GarbageCanCenter_Woer_face/tests/browser/harness.html
T

148 lines
6.7 KiB
HTML

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>星元智灵异常场景测试</title>
<link rel="stylesheet" href="../../app/src/main/assets/www/styles.css" />
</head>
<body>
<main id="app" class="app-shell" aria-live="polite"></main>
<div id="toast" class="toast" role="status"></div>
<script>
(function () {
var params = new URLSearchParams(location.search);
var scenario = params.get("scenario") || "pass";
var baselineDelay = Number(params.get("baselineDelay") || 30);
var weightQueryCounts = {};
var connectionCheckCount = 0;
if (params.get("clear") === "1") localStorage.clear();
window.__nativeCalls = [];
function record(method, json) {
var payload = {};
try { payload = JSON.parse(json || "{}"); } catch (error) {}
window.__nativeCalls.push({ method: method, payload: payload, at: Date.now() });
document.documentElement.setAttribute("data-native-calls", JSON.stringify(window.__nativeCalls));
return payload;
}
function emitConnection(payload, delay) {
window.setTimeout(function () {
if (window.ZhitouSerial) window.ZhitouSerial.onConnectionCheck(payload);
}, delay || 20);
}
window.XingyuanNative = {
configure: function (json) { record("configure", json); },
startHeartbeat: function (json) { record("startHeartbeat", json); },
scanMediaFiles: function () { return "[]"; },
loadLocalBackups: function () { return "[]"; },
fetchWorkContext: function () {
return JSON.stringify([{ machineNo: "TEST-01", persons: ["测试员"], batches: ["BATCH-01"] }]);
},
requestConnectionCheck: function (json) {
var request = record("requestConnectionCheck", json);
connectionCheckCount += 1;
var serialOnline = scenario !== "serial-fail" && scenario !== "all-fail" &&
!(scenario === "serial-recover" && connectionCheckCount < 3);
var networkOnline = scenario !== "network-fail" && scenario !== "all-fail";
emitConnection({
requestId: request.requestId,
mode: request.mode,
serialOnline: serialOnline,
networkOnline: networkOnline,
tcpConnected: networkOnline,
httpReachable: networkOnline,
pingOk: networkOnline
}, scenario === "slow-check" ? 4300 : 20);
},
queryWeight: function (json) {
var request = record("queryWeight", json);
var port = Number(request.port || 1);
weightQueryCounts[port] = Number(weightQueryCounts[port] || 0) + 1;
if (scenario !== "weight-missing" && !(scenario === "baseline-missing" && weightQueryCounts[port] === 1)) {
window.setTimeout(function () {
if (window.ZhitouSerial) {
window.ZhitouSerial.onThrowWeight({
port: port,
weight: 5,
beforeWeight: 5,
afterWeight: 5,
queryResponse: true
});
}
}, baselineDelay);
}
return true;
},
queryFill: function (json) { record("queryFill", json); return true; },
queryTemperature: function (json) { record("queryTemperature", json); return true; },
openThrowDoor: function (json) { record("openThrowDoor", json); return scenario !== "open-fail"; },
closeThrowDoor: function (json) { record("closeThrowDoor", json); return scenario !== "close-fail"; },
reportXingyuanDelivery: function (json) { record("reportXingyuanDelivery", json); return true; },
saveLocalBackup: function (json) { record("saveLocalBackup", json); return "/tmp/test-backup.json"; },
setFaceRecognitionActive: function (json) { record("setFaceRecognitionActive", json); },
setFacePreviewLayout: function (json) { record("setFacePreviewLayout", json); },
prepareFaceEnrollment: function (json) { record("prepareFaceEnrollment", json); return true; },
getFaceRecognitionStatus: function () {
return JSON.stringify({ ok: true, status: "ready", message: "SeetaFace6 识别引擎已就绪", enrolledCount: 1 });
},
enrollCurrentFace: function (json) {
record("enrollCurrentFace", json);
return JSON.stringify({ ok: true, message: "人脸录入成功" });
},
setFaceMatchThreshold: function (json) {
var request = record("setFaceMatchThreshold", json);
return JSON.stringify({ ok: true, threshold: Number(request.threshold || 0.75) });
},
listFacePeople: function () {
var people = scenario === "no-people" ? [] : [
{ faceId: "FACE-1000", employeeNo: "1000", name: "测试员" }
];
return JSON.stringify({ ok: true, people: people, count: people.length });
},
verifyMember: function (json) {
var request = record("verifyMember", json);
if (scenario === "auth-fail") return JSON.stringify({ ok: false, error: "测试鉴权失败" });
return JSON.stringify({
ok: true,
memberCode: request.idContent || "1000",
employeeNo: request.idContent || "1000",
memberId: "MEMBER-TEST",
name: "测试员"
});
},
listSerialPorts: function () {
return JSON.stringify({
ok: true,
ports: [
{ path: "/dev/ttyS0", readable: true, writable: true },
{ path: "/dev/ttysWK0", readable: true, writable: true },
{ path: "/dev/ttyUSB0", readable: true, writable: true }
]
});
}
};
})();
</script>
<script src="../../app/src/main/assets/www/app.js?v=1.2.18"></script>
<script>
(function () {
var scenario = new URLSearchParams(location.search).get("scenario") || "pass";
if (scenario !== "camera-fail") return;
window.setTimeout(function () {
var receiver = window.ZhitouSerial || window.XingyuanSerial;
if (receiver && typeof receiver.onFaceStatus === "function") {
receiver.onFaceStatus({
status: "camera_error",
message: "摄像头启动失败:设备被占用",
enrolledCount: 1
});
}
}, 3400);
})();
</script>
</body>
</html>