• Electron dialog 弹出框


    dialog 模块提供了 api 来展示原生的系统对话框,例如打开文件框,alert 框,
    所以 web 应用可以给用户带来跟系统应用相同的体验。
    dialog.js
    var {remote}=require('electron');
    
    
    //https://electronjs.org/docs/api/dialog
    var errorDom=document.querySelector('#error');
    
    var mesageBoxDom=document.querySelector('#mesageBox');
    
    
    var openDialogDom=document.querySelector('#openDialog');
    
    var saveDialogDom=document.querySelector('#saveDialog');
    
    
    errorDom.onclick=function(){ 
        remote.dialog.showErrorBox('警告','操作有误');
    
    }
    
    mesageBoxDom.onclick=function(){
        remote.dialog.showMessageBox({
            type:'info',
            title:'提示信息',
            message:'内容',
            buttons:['ok','no']
    
        },function(index){
    
            console.log(index)
        })
    
    
    }
    
    openDialogDom.onclick=function(){
    
    
            remote.dialog.showOpenDialog({
    
                // properties:['openDirectory','openFile']
    
                properties:['openFile']
    
            },function(data){
    
    
                    console.log(data);
    
                    //["C:UsersAdministratorDesktop新建文件夹jsindex.js"]
            })
    
    }
    
    saveDialogDom.onclick=function(){
    
    
        remote.dialog.showSaveDialog({
    
            title:'save file',
            defaultPath:"aaa.jpg",
            filters: [
                {name: 'Images', extensions: ['jpg', 'png', 'gif']},
                {name: 'Movies', extensions: ['mkv', 'avi', 'mp4']},
                {name: 'Custom File Type', extensions: ['as']},
                {name: 'All Files', extensions: ['*']}
              ]
    
        },function(path){
            console.log(path);
    
            // C:UsersAdministratorDesktop新建文件夹jsaaa.jpg
    
            //保存以后会打印保存的路径  , 但是不会实现真的保存功能  (具体保存什么数据可以写在nodejs里面)
        })
    }

    index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Document</title>
    </head>
    <body>
      
    
      <button id="error">失败提示框</button>
    
      <br>  
      <br>  
    
      <button id="mesageBox">showMessageBox</button>
    
      <br>  
      <br>  
    
      <button id="openDialog">showOpenDialog</button>
    
      
      <br>  
      <br>  
    
      <button id="saveDialog">showSaveDialog</button>
    
    
      <script src="renderer/dialog.js"></script>
    
    </body>
    </html>
  • 相关阅读:
    zzulioj1908: 小火山的围棋梦想
    zzulioj1913: 小火山的计算能力
    zullioj1905: 小火山的跳子游戏
    HDU 1025:Constructing Roads In JGShining's Kingdom
    HDU 1257:最少拦截系统
    HDU1051:Wooden Sticks
    HDU1950:Bridging signals
    HDU1087:Super Jumping! Jumping! Jumping!
    HDU5256: 序列变换
    3.SpringBoot配置文件以及自动配置原理
  • 原文地址:https://www.cnblogs.com/loaderman/p/12150341.html
Copyright © 2020-2023  润新知