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

BIN
day03-clipboard/c.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

View File

@@ -0,0 +1,18 @@
<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>
<input type="text" placeholder="输入需要复制的内容">
<button>复制</button>
<br><br>
<input type="text" placeholder="将内容粘贴至此处">
<button>粘贴</button>
<br><br>
<button id="clipImg">将图片拷贝至剪切板再粘贴至界面</button>
<script src="index.js"></script>
</body>
</html>

31
day03-clipboard/index.js Normal file
View File

@@ -0,0 +1,31 @@
const { clipboard, nativeImage } = require('electron')
window.onload = () => {
// 获取元素
let aBtn = document.getElementsByTagName('button')
let aInput = document.getElementsByTagName('input')
let oBtn = document.getElementById('clipImg')
let ret = null
aBtn[0].onclick = () => {
// 复制内容
ret = clipboard.writeText(aInput[0].value)
}
aBtn[1].onclick = () => {
// 粘贴内容
aInput[1].value = clipboard.readText(ret)
}
oBtn.onclick = () => {
// 将图片放置于剪切板的时候要求图片类型属于 nativeImage 类型
let oImage = nativeImage.createFromPath('c.png')
clipboard.writeImage(oImage)
// 将剪切板中的图片作为 DOM 元素显示在界面上
let oImg = clipboard.readImage()
let oImgDom = new Image()
oImgDom.src = oImg.toDataURL() // 转换为base64
document.body.appendChild(oImgDom)
}
}

22
day03-clipboard/main.js Normal file
View File

@@ -0,0 +1,22 @@
const { app, BrowserWindow } = require('electron')
const createWindow = () => {
let mainWin = new BrowserWindow({
width: 800,
height: 400,
show: false,
webPreferences: {
enableRemoteModule: true,
nodeIntegration: 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
day03-clipboard/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"
}
}