first commit

This commit is contained in:
2025-01-09 18:30:49 +08:00
commit ead83056ff
99 changed files with 27286 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>主界面</title>
</head>
<body>
<h2>子窗口及模态窗口</h2>
<button id="btn">新增窗口</button>
<script src="index.js"></script>
</body>
</html>

18
day01-sub-window/index.js Normal file
View File

@@ -0,0 +1,18 @@
const { remote } = require('electron')
window.addEventListener('DOMContentLoaded', () => {
let oBtn = document.getElementById('btn')
oBtn.addEventListener('click', () => {
let subWin = new remote.BrowserWindow({
width: 200,
height: 200,
parent: remote.getCurrentWindow(), // 设置父窗口
modal: true, // 设置模态窗口
})
subWin.loadFile('sub.html')
subWin.on('close', () => {
subWin = null
})
})
})

27
day01-sub-window/main.js Normal file
View File

@@ -0,0 +1,27 @@
const { app, BrowserWindow } = require('electron')
const createWindow = () => {
let mainWin = new BrowserWindow({
show: false,
width: 800,
height: 400,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
}
})
mainWin.loadFile('index.html')
mainWin.on('ready-to-show', () => {
mainWin.show()
})
mainWin.on('close', () => {
mainWin = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
app.quit()
})

1396
day01-sub-window/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
{
"name": "electron-life-cycle",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "nodemon --watch main.js --exec npm run build",
"build": "electron ."
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^11.2.1",
"nodemon": "^3.1.9"
}
}

10
day01-sub-window/sub.html Normal file
View File

@@ -0,0 +1,10 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>xxx窗口</title>
</head>
<body>
<h2>子窗口</h2>
</body>
</html>