Files
RGKT/rg-09112127/html/test_button_click.html
2025-10-10 19:44:14 +08:00

330 lines
9.3 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>按钮点击测试</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 800px;
margin: 0 auto;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.test-section {
margin: 20px 0;
padding: 20px;
border: 2px solid #4ecdc4;
border-radius: 10px;
}
.game-area {
display: flex;
gap: 20px;
margin: 20px 0;
}
.math-card {
flex: 1;
background: #f8f9fa;
padding: 20px;
border-radius: 10px;
text-align: center;
border: 2px solid #dee2e6;
}
.equation {
font-size: 24px;
font-weight: bold;
margin-bottom: 15px;
color: #333;
}
.select-btn {
background: #4ecdc4;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
.select-btn:hover {
background: #45b7aa;
}
.option-btn {
background: #28a745;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
font-size: 16px;
}
.option-btn:hover {
background: #218838;
}
.status {
margin: 10px 0;
padding: 10px;
border-radius: 5px;
font-weight: bold;
}
.success {
background: #d4edda;
color: #155724;
}
.info {
background: #d1ecf1;
color: #0c5460;
}
button {
background: #4ecdc4;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #45b7aa;
}
.log {
background: #f8f9fa;
padding: 15px;
border-radius: 5px;
max-height: 300px;
overflow-y: auto;
font-family: monospace;
font-size: 12px;
white-space: pre-wrap;
border: 1px solid #dee2e6;
}
/* 体感交互容器样式 */
.box-body {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(255, 255, 255, 0.95);
border-radius: 15px;
padding: 20px;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
z-index: 2000;
max-width: 500px;
text-align: center;
}
.box-body img {
max-width: 100%;
height: auto;
border-radius: 10px;
margin: 10px 0;
}
.box-body div {
margin: 10px 0;
padding: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>🔘 按钮点击测试</h1>
<div class="test-section">
<h3>📋 测试说明</h3>
<p>这个页面用于测试体感交互按钮点击功能。</p>
<ul>
<li>点击"启动体感交互"按钮</li>
<li>允许摄像头权限</li>
<li>举起左手或右手</li>
<li>观察按钮是否被正确点击</li>
</ul>
</div>
<div class="test-section">
<h3>🎮 比大小游戏按钮</h3>
<div class="game-area">
<div class="math-card" id="leftCard">
<div class="equation" id="leftEquation">5 + 3</div>
<button class="select-btn" id="leftBtn">选择</button>
</div>
<div class="math-card" id="rightCard">
<div class="equation" id="rightEquation">2 + 7</div>
<button class="select-btn" id="rightBtn">选择</button>
</div>
</div>
</div>
<div class="test-section">
<h3>🎯 示例游戏选项</h3>
<div>
<button class="option-btn" onclick="selectOption(1)">选项1</button>
<button class="option-btn" onclick="selectOption(2)">选项2</button>
<button class="option-btn" onclick="selectOption(3)">选项3</button>
<button class="option-btn" onclick="selectOption(4)">选项4</button>
</div>
</div>
<div class="test-section">
<h3>📊 点击状态</h3>
<div id="clickStatus" class="status info">等待按钮点击...</div>
</div>
<div class="test-section">
<h3>🔧 控制面板</h3>
<button onclick="startBodySensation()">启动体感交互</button>
<button onclick="stopBodySensation()">停止体感交互</button>
<button onclick="testManualClick()">手动测试点击</button>
<button onclick="clearLog()">清除日志</button>
</div>
<div class="test-section">
<h3>📝 调试日志</h3>
<div id="debugLog" class="log">等待日志输出...</div>
</div>
</div>
<!-- 体感交互容器用于directBodySensation.js -->
<div class="box-body" style="display: none">
<div id="bodyConnectionStatus">未连接到服务器</div>
<img id="bodyVideoFeed" src="" alt="体感检测视频" />
<div id="bodyHandStatus">等待检测...</div>
</div>
<!-- 引入体感交互脚本 -->
<script src="../js/directBodySensation.js"></script>
<script>
let clickCount = { left: 0, right: 0, option: 0 };
// 比大小游戏按钮点击事件
document.getElementById("leftBtn").addEventListener("click", function () {
clickCount.left++;
updateClickStatus();
log(`✅ 左手按钮被点击 (第${clickCount.left}次)`);
});
document
.getElementById("rightBtn")
.addEventListener("click", function () {
clickCount.right++;
updateClickStatus();
log(`✅ 右手按钮被点击 (第${clickCount.right}次)`);
});
// 示例游戏选项点击事件
function selectOption(option) {
clickCount.option++;
updateClickStatus();
log(`✅ 选项${option}被点击 (第${clickCount.option}次)`);
}
// 更新点击状态
function updateClickStatus() {
const statusDiv = document.getElementById("clickStatus");
statusDiv.textContent = `左手: ${clickCount.left}次, 右手: ${clickCount.right}次, 选项: ${clickCount.option}`;
statusDiv.className = "status success";
}
// 启动体感交互
function startBodySensation() {
log("正在启动体感交互系统...");
try {
if (typeof showBody === "function") {
showBody();
log("✅ 体感交互系统已启动");
} else {
log("❌ 体感交互系统未加载");
}
} catch (error) {
log(`❌ 启动体感交互错误: ${error.message}`);
}
}
// 停止体感交互
function stopBodySensation() {
log("正在停止体感交互系统...");
try {
if (typeof showBody === "function") {
showBody(); // 再次调用会切换状态
log("✅ 体感交互系统已停止");
} else {
log("❌ 体感交互系统未加载");
}
} catch (error) {
log(`❌ 停止体感交互错误: ${error.message}`);
}
}
// 手动测试点击
function testManualClick() {
log("手动测试按钮点击...");
const leftBtn = document.getElementById("leftBtn");
const rightBtn = document.getElementById("rightBtn");
if (leftBtn) {
log("测试左手按钮点击");
leftBtn.click();
}
setTimeout(() => {
if (rightBtn) {
log("测试右手按钮点击");
rightBtn.click();
}
}, 1000);
}
// 清除日志
function clearLog() {
document.getElementById("debugLog").textContent = "日志已清除...";
clickCount = { left: 0, right: 0, option: 0 };
updateClickStatus();
}
// 日志函数
function log(message) {
const logDiv = document.getElementById("debugLog");
const timestamp = new Date().toLocaleTimeString();
logDiv.textContent += `[${timestamp}] ${message}\n`;
logDiv.scrollTop = logDiv.scrollHeight;
console.log(message);
}
// 重写 console.log 来捕获体感交互的日志
const originalLog = console.log;
console.log = function (...args) {
originalLog.apply(console, args);
const message = args.join(" ");
// 捕获体感交互相关日志
if (
message.includes("clickBth") ||
message.includes("找到的按钮") ||
message.includes("点击了") ||
message.includes("准备点击") ||
message.includes("成功点击") ||
message.includes("未找到")
) {
log(message);
}
};
// 页面加载完成后自动初始化
document.addEventListener("DOMContentLoaded", function () {
log("🔘 按钮点击测试页面已加载");
log("✅ 页面初始化完成,可以开始测试");
});
</script>
</body>
</html>