上传文件至 /

来自宫瑞骏的提交
This commit is contained in:
高峰君主 2024-10-20 20:22:18 +08:00
parent 18f821d4f8
commit 8140d0fdfa
4 changed files with 460 additions and 0 deletions

159
gncs.html Normal file
View File

@ -0,0 +1,159 @@
<!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: 400px;
margin-bottom: 20px;
}
h2 {
text-align: center;
margin-bottom: 20px;
}
.function-item {
display: flex;
justify-content: space-between;
align-items: center;
margin: 10px 0;
padding: 10px;
background-color: #f0f0f0;
border-radius: 5px;
}
.function-item span {
font-size: 18px;
color: #333;
}
.toggle-btn {
width: 60px;
height: 30px;
background-color: #ccc;
border-radius: 15px;
position: relative;
cursor: pointer;
transition: background-color 0.3s;
}
.toggle-btn::before {
content: "";
position: absolute;
width: 28px;
height: 28px;
background-color: white;
border-radius: 50%;
top: 1px;
left: 1px;
transition: transform 0.3s;
}
.toggle-btn.active {
background-color: #4caf50;
}
.toggle-btn.active::before {
transform: translateX(30px);
}
/* 导航栏样式 */
.navbar {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
display: flex;
justify-content: space-around;
background-color: #333;
padding: 10px 0;
}
.navbar a {
color: white;
text-decoration: none;
font-size: 16px;
}
.navbar a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h2>功能测试页面</h2>
<div class="function-item">
<span>摄像头</span>
<div class="toggle-btn" id="camera-btn"></div>
</div>
<div class="function-item">
<span>人脸距离过近</span>
<div class="toggle-btn" id="face-btn"></div>
</div>
<div class="function-item">
<span>屏幕锁定密码解锁</span>
<div class="toggle-btn" id="unlock-btn"></div>
</div>
</div>
<!-- JavaScript -->
<script>
// 获取所有开关按钮
const cameraBtn = document.getElementById('camera-btn');
const faceBtn = document.getElementById('face-btn');
const unlockBtn = document.getElementById('unlock-btn');
// 存储当前打开的测试按钮
let activeButton = null;
// 切换开关按钮状态并控制逻辑
function toggleButton(btn, testName) {
if (btn === activeButton) {
// 如果点击的是已经激活的按钮,则关闭它
btn.classList.remove('active');
activeButton = null;
alert(`${testName} 停止`);
} else {
// 关闭当前已激活的按钮(如果有)
if (activeButton) {
activeButton.classList.remove('active');
alert(`上一个测试已停止`);
}
// 激活新按钮
btn.classList.add('active');
activeButton = btn;
alert(`${testName} 启动`);
}
}
// 绑定点击事件
cameraBtn.addEventListener('click', () => toggleButton(cameraBtn, '摄像头'));
faceBtn.addEventListener('click', () => toggleButton(faceBtn, '人脸距离过近'));
unlockBtn.addEventListener('click', () => toggleButton(unlockBtn, '屏幕锁定密码解锁'));
</script>
<!-- 导航栏 -->
<div class="navbar">
<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>
</body>
</html>

238
index.html Normal file
View File

@ -0,0 +1,238 @@
<!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>

46
index.js Normal file
View File

@ -0,0 +1,46 @@
const { app, BrowserWindow } = require('electron');
const { spawn } = require('child_process');
const path = require('path');
const flaskProcess = spawn('python', [path.join(__dirname, 'app.py')]);
flaskProcess.stdout.on('data', (data) => {
console.log(`Flask: ${data}`);
});
// 监听Node.js进程的关闭事件
process.on('SIGINT', () => {
console.log('Closing Node.js application and Python script...');
// 杀掉Python进程
pythonProcess.kill('SIGINT');
// 完全退出Node.js应用
process.exit();
});
let mainWindow;
app.whenReady().then(() => {
mainWindow = new BrowserWindow({
width: 430,
height: 680,
icon: path.join(__dirname, 'assets', 'icon.ico'),
webPreferences: {
nodeIntegration: false, // 禁用 Node 集成
contextIsolation: true, // 启用上下文隔离
},
});
// 加载 HTTP 服务的 URL
mainWindow.loadURL('http://127.0.0.1:5000/');
mainWindow.on('closed', () => {
mainWindow = null;
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "iteyes",
"version": "1.0.0",
"description": "A program that intelligently controls eye health",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron .",
"package": "electron-packager . needle-server --platform=win32 --arch=x64 --out=./out --asar --app-version=1.0.0 --overwrite --ignore=node_modules --electron-version=$(npm list electron --depth=0 | jq -r '.dependencies.electron.version')"
},
"author": "宫瑞骏,张晓星",
"license": "ISC",
"devDependencies": {
"electron": "^33.0.1",
"electron-packager": "^17.1.2"
}
}