This commit is contained in:
2026-05-21 00:12:44 +08:00
commit 4ba2b730de
7 changed files with 171 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
package-lock.json
node_modules
.idea
+18
View File
@@ -0,0 +1,18 @@
# 全局npm镜像
registry=https://registry.npmmirror.com
# electron 镜像
electron_mirror=https://npmmirror.com/mirrors/electron/
electron_builder_binaries_mirror=https://npmmirror.com/mirrors/electron-builder-binaries/
# node-sass 镜像
sass_binary_site=https://npmmirror.com/mirrors/node-sass/
# puppeteer 镜像
puppeteer_download_host=https://npmmirror.com/mirrors
# sharp 镜像
sharp_dist_base_url=https://npmmirror.com/mirrors/sharp-libvips/
# 禁止严格ssl
strict-ssl=false
+75
View File
@@ -0,0 +1,75 @@
<!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 {
font-family: 'Segoe UI', Arial, sans-serif;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
}
.container {
text-align: center;
padding: 40px;
background: rgba(255, 255, 255, 0.1);
border-radius: 20px;
backdrop-filter: blur(10px);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
h1 {
font-size: 28px;
margin-bottom: 30px;
color: #00d9ff;
}
.counter-display {
font-size: 72px;
font-weight: bold;
color: #00ff88;
text-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
margin: 20px 0;
font-variant-numeric: tabular-nums;
}
.info {
margin-top: 30px;
font-size: 14px;
color: #888;
}
.status {
display: inline-block;
padding: 5px 15px;
background: #00ff88;
color: #1a1a2e;
border-radius: 20px;
font-weight: bold;
font-size: 12px;
}
</style>
</head>
<body>
<div class="container">
<h1>实时计数器</h1>
<div class="counter-display" id="counter">0</div>
<div class="info">
<span class="status">运行中</span>
</div>
</div>
<script src="renderer.js"></script>
</body>
</html>
+34
View File
@@ -0,0 +1,34 @@
const { app, BrowserWindow } = require('electron');
const path = require('path');
let win;
function createWindow() {
win = new BrowserWindow({
width: 500,
height: 400,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
}
});
win.loadFile('index.html');
// 打开开发者工具方便调试
// win.webContents.openDevTools();
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
+18
View File
@@ -0,0 +1,18 @@
{
"name": "electron-counter",
"version": "1.0.0",
"description": "Electron app with live counter",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"devDependencies": {
"electron": "^28.3.3"
},
"build": {
"appId": "com.example.electron-counter",
"win": {
"target": "nsis"
}
}
}
+7
View File
@@ -0,0 +1,7 @@
const { contextBridge, ipcRenderer } = require('electron');
// 暴露安全的 API 给渲染进程
contextBridge.exposeInMainWorld('electronAPI', {
// 可扩展更多功能
platform: process.platform
});
+16
View File
@@ -0,0 +1,16 @@
// 死循环计数器,每秒增加并刷新 UI
let count = 0;
const counterElement = document.getElementById('counter');
function updateCounter() {
count++;
counterElement.textContent = count.toLocaleString();
// 立即安排下一次更新
setTimeout(updateCounter, 1000);
}
// 启动计数器
updateCounter();
console.log('计数器已启动');