electron-egg electron-egg
首页
  • v4.x
  • v3.x
  • v2.x
插件
  • v4.x
  • v3.x
demo
支持
知识点
案例
交流
  • GitHub (opens new window)
  • Gitee (opens new window)
首页
  • v4.x
  • v3.x
  • v2.x
插件
  • v4.x
  • v3.x
demo
支持
知识点
案例
交流
  • GitHub (opens new window)
  • Gitee (opens new window)
❤️成为赞助商
  • 框架

  • 操作系统

    • 文件
    • 视图
    • 窗口
      • 桌面通知
      • 电源监控
      • 屏幕信息
      • 系统主题
    • 特效

    • 硬件

    • 优惠券
    • 异常处理
    目录

    窗口

    新窗口

    # 新窗口中加载web内容

      // frontend/src/views/os/window/Index.vue
      <script>
        let viewContent = {
              type: 'web',
              content: 'https://www.bilibili.com/',
              windowName: 'window-web',
              windowTitle: 'bilibili'
        },
        createWindow (index) {
          this.$ipc.invoke(ipcApiRoute.createWindow, viewContent).then(r => {
            console.log(r);
          })
        },
      </script> 
      
      // electron/controller/os.js
      /**
       * 打开新窗口
       */
      createWindow(args) {
        const { type, content, windowName, windowTitle } = args;
        let contentUrl = null;
        if (type == 'html') {
          contentUrl = path.join('file://', electronApp.getAppPath(), content)
        } else if (type == 'web') {
          contentUrl = content;
        } else if (type == 'vue') {
          let addr = 'http://localhost:8080'
          if (Ps.isProd()) {
            const mainServer = Conf.getValue('mainServer');
            addr = mainServer.protocol + mainServer.host + ':' + mainServer.port;
          }
          contentUrl = addr + content;
        } else {
          // some
        }
        console.log('contentUrl: ', contentUrl);
        const addonWindow = this.app.addon.window;
        let opt = {
          title: windowTitle
        }
        const win = addonWindow.create(windowName, opt);
        const winContentsId = win.webContents.id;
        // load page
        win.loadURL(contentUrl);
        return winContentsId;
      }
      
      // Make sure to add code blocks to your code group

      # 新窗口中加载html内容

        // frontend/src/views/os/window/Index.vue
        <script>
          let viewContent = {
                type: 'html',
                content: '/public/html/view_example.html',
                windowName: 'window-html',
                windowTitle: 'html window'
          },
          createWindow (index) {
            this.$ipc.invoke(ipcApiRoute.createWindow, viewContent).then(r => {
              console.log(r);
            })
          },
        </script> 
        
        // electron/controller/os.js
        // 同上
        
        // Make sure to add code blocks to your code group

        # 新窗口中加载当前项目页面

          // frontend/src/views/os/window/Index.vue
          <script>
            let viewContent = {
                  type: 'vue',
                  content: '/#/special/subwindow',
                  windowName: 'window-vue',
                  windowTitle: 'vue window'
            },
            createWindow (index) {
              this.$ipc.invoke(ipcApiRoute.createWindow, viewContent).then(r => {
                console.log(r);
              })
            },
          </script> 
          
          // electron/controller/os.js
          // 同上
          
          // Make sure to add code blocks to your code group

          # 完整代码

          • github前端代码 (opens new window)
          • github主进程代码 (opens new window)
          • gitee前端代码 (opens new window)
          • gitee主进程代码 (opens new window)
          上次更新: 2025/06/06, 07:21:49
          视图
          桌面通知

          ← 视图 桌面通知→

          Theme by Vdoing | Copyright © 2023-2025 哆啦好梦 | 京ICP备15041380号-2
          • 跟随系统
          • 浅色模式
          • 深色模式
          • 阅读模式
          ×