删除 index.html

This commit is contained in:
高峰君主 2024-10-20 20:17:37 +08:00
parent 8bb01e555c
commit 6abc3f2f9e

View File

@ -1,238 +0,0 @@
<!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>
/* 样式定义 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f5f5f5;
font-family: Arial, sans-serif;
}
.container {
background-color: white;
padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
border-radius: 10px;
width: 300px;
margin-bottom: 20px;
}
h2 {
text-align: center;
}
.button-container {
display: flex;
justify-content: space-between;
}
button {
padding: 10px 20px;
background-color: #333;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #555;
}
.function-buttons {
display: flex;
flex-wrap: wrap;
justify-content: center;
margin-top: 20px;
}
.function-buttons button {
width: 130px;
margin: 10px;
}
/* 开关容器的样式 */
.switch-container {
width: 100px;
height: 50px;
background-color: #ccc;
border-radius: 25px;
position: relative;
cursor: pointer;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
/* 开关按钮的样式 */
.switch {
width: 40px;
height: 40px;
background-color: white;
border-radius: 50%;
position: absolute;
top: 5px;
left: 5px;
transition: all 0.3s ease;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
/* 开启状态的样式 */
.switch.on {
left: 55px;
background-color: #4caf50; /* 绿色 */
}
</style>
</head>
<body>
<!-- 开关按钮部分 -->
<div class="switch-container" id="switch-container" style="margin-bottom: 20px;">
<div class="switch" id="switch"></div>
</div>
<!-- 功能按钮部分 -->
<div class="container">
<div class="function-buttons">
<a href="index.html"><button id="home">启动首页</button></a>
<a href="psw.html"><button id="unlock">解锁密码设置</button></a>
<a href="gncs.html"><button id="test">功能测试</button></a>
<a href="setting.html"><button id="settings">软件设置</button></a>
</div>
</div>
<script>
socket = null
// 开关按钮功能
const switchButton = document.getElementById('switch');
let isSwitchOn = false;
switchButton.addEventListener('click', function () {
if (isSwitchOn) {
const password = prompt("请输入密码以关闭开关:");
if (password === currentPassword) {
// socket.close(). then(() => {
// switchButton.classList.remove('on')
// alert('开关已关闭');
// isSwitchOn = false;
// socket = null
// })
switchButton.classList.remove('on')
alert('开关已关闭');
isSwitchOn = false;
} else {
alert('密码错误!');
}
} else {
//创建 WebSocket 连接
socket = new WebSocket('ws://localhost:45601');
// 打开连接时触发
socket.onopen = function(event) {
console.log('WebSocketOn.');
switchButton.classList.add('on');
isSwitchOn = true;
console.log(123)
};
// 接收到消息时触发
socket.onmessage = function(event) {
console.log('收到消息:', event.data);
// 根据服务器的响应处理逻辑
// 注意:服务器应该发送明确的消息格式以便客户端正确解析
};
// 连接关闭时触发
socket.onclose = function(event) {
console.log('WebSocketClose.');
};
// 连接出错时触发
socket.onerror = function(error) {
console.log('WebSocket Error:', error);
};
sendMessage({
"ClientEvent":"open",
"Content": null
}).then(() => {
switchButton.classList.add('on');
isSwitchOn = true;
console.log(123321)
})
switchButton.classList.add('on');
isSwitchOn = true;
console.log(123321)
}
});
function onMessage(data){
switch (data.Event){
case "near":
if (nearTest){
if (heavyAlert){
//把强提醒函数写这
}else{
alert("用眼过近!")
}
}
case "long":
if (longTest){
if (heavyAlert){
//把强提醒函数写这
fetch("http://localhost:45602/electronAlert", { method: 'POST' , body: "用眼过长!"})
}else{
alert("用眼过长!")
}
}
}
}
// 向服务器发送消息
function sendMessage(message) {
if (socket.readyState === WebSocket.OPEN) {
socket.send(message);
} else {
console.log('WebSocket 连接未打开.');
}
}
// 导航按钮逻辑
const navButtons = document.querySelectorAll('.function-buttons a');
navButtons.forEach(button => {
button.addEventListener('click', function (e) {
if (isSwitchOn) {
e.preventDefault(); // 阻止默认行为
const password = prompt("请输入密码以进行页面跳转:");
if (password === currentPassword) {
// 关闭开关
switchButton.classList.remove('on');
alert('开关已关闭');
isSwitchOn = false;
// 跳转到目标页面
window.location.href = button.href;
} else {
alert('密码错误!');
}
}
});
});
</script>
</body>
</html>