代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- <button id="openBtn">打开文件</button> -->
<img src='' id='images'>
<button id="saveBtn">保存文件</button>
<button id="messageBtn">弹出对话框</button>
</body>
<script>
//引入dialog
const {dialog} = require('electron').remote
// var openBtn = document.getElementById('openBtn');
// openBtn.onclick = function(){
// //打开文件选择对话框
// dialog.showOpenDialog({
// title:'请选择你喜欢的小姐姐照片' , //弹窗名:左上角
// defaultPath:'./img/1.jpg', //默认路径的设置(默认根目录)
// filters:[ //过滤器
// {name:'只jpg',extensions:['jpg','png']},
// {name:'png',extensions:['png']}
// ],
// buttonLabel:'打开图片', //自定义
// }).then(result=>{
// let image = document.getElementById('images')
// image.setAttribute("src",result.filePaths[0]);
// console.log(result)
// }).catch(err=>{
// console.log(err)
// })
// }
//保存文件
const fs = require('fs') //流处理
var saveBtn = document.getElementById('saveBtn')
saveBtn.onclick = function(){
dialog.showSaveDialog({ //打开保存
title:'保存文件',
}).then(result=>{
console.log(result)
fs.writeFileSync(result.filePath,'技术胖一个前端爱好者')//将字符串写入选择的位置(需要包含文件名)
}).catch(err=>{
console.log(err)
})
}
var messageBtn = document.getElementById('messageBtn')
messageBtn.onclick = function(){
dialog.showMessageBox({
type:'warning',
title:'去不去由你',
message:'是不是要跟胖哥去红袖招?',
buttons:['我要去','不去了']
}).then(result=>{
console.log(result)
})
}
</script>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。