• Electron 弹出框
  • Artiely
  • #electron#nodejs
  • 2018-07-08
  • 131
  • 1 min read
  • loading...

Electron 弹出框

dialog 模块提供了 api 来展示原生的系统对话框,例如打开文件框,alert 框, 所以 web 应用可以给用户带来跟系统应用相同的体验。

dialog.showErrorBox('title','content');
复制成功
1

dialog.showMessageBox(
  {
    type: 'info',
    title: 'message',
    message: 'hello',
    buttons: ['ok', 'cancel'],
  },
  index => {
    if (index == 0) {
      console.log('You click ok.')
    } else {
      console.log('You click cancel')
    }
  }
)
复制成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

dialog.showOpenDialog({ properties: ['openFile', 'openDirectory'] }, files => {
  console.log(files)
})
复制成功
1
2
3

dialog.showSaveDialog(
  {
    title: 'save some file',
    filters: [
      { name: 'Images', extensions: ['jpg', 'png', 'gif'] },
      { name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] },
      { name: 'Custom File Type', extensions: ['as'] },
      { name: 'All Files', extensions: ['*'] },
    ],
  },
  filename => {
    console.log(filename)
  }
)
复制成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14