From bdd2d99e9bb6b0f4208c834d1b81166c3bf84bf0 Mon Sep 17 00:00:00 2001 From: gaoshuaixing <530353222@qq.com> Date: Mon, 11 Oct 2021 16:47:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=96=B0=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- asset/view_example.html | 2 +- electron/ipc/example.js | 32 ++++++++-- frontend/src/config/router.config.js | 5 ++ frontend/src/layouts/DemoMenu.vue | 6 ++ frontend/src/views/demo/window/Index.vue | 65 ++++++++++++++++++++ frontend/src/views/demo/windowview/Index.vue | 14 +++-- 6 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 frontend/src/views/demo/window/Index.vue diff --git a/asset/view_example.html b/asset/view_example.html index 7fee898..d480ac7 100644 --- a/asset/view_example.html +++ b/asset/view_example.html @@ -16,7 +16,7 @@
- 这里是 BrowserView 加载的html内容 + 这是一个html页面
\ No newline at end of file diff --git a/electron/ipc/example.js b/electron/ipc/example.js index d96931c..adb3171 100644 --- a/electron/ipc/example.js +++ b/electron/ipc/example.js @@ -44,7 +44,7 @@ exports.messageShowConfirm = function (event, channel, arg) { buttons: ['确认', '取消'], // 按钮及索引 }) let data = (res === 0) ? '点击确认按钮' : '点击取消按钮'; - console.log('[electron] [ipc] [example] [messageShowConfirm] 结果:', res, ); + console.log('[electron] [ipc] [example] [messageShowConfirm] 结果:', res); return data; } @@ -82,14 +82,14 @@ exports.loadViewContent = function (event, channel, arg) { } else { content = arg.content; } - + browserViewObj = new BrowserView(); MAIN_WINDOW.setBrowserView(browserViewObj) browserViewObj.setBounds({ x: 300, - y: 80, + y: 170, width: 650, - height: 480 + height: 400 }); browserViewObj.webContents.loadURL(content); return true @@ -101,4 +101,26 @@ exports.loadViewContent = function (event, channel, arg) { exports.removeViewContent = function () { MAIN_WINDOW.removeBrowserView(browserViewObj); return true -} \ No newline at end of file +} + +/** + * 打开新窗口 + */ + exports.createWindow = function (event, channel, arg) { + let content = null; + if (arg.type == 'html') { + content = path.join('file://', app.getAppPath(), arg.content) + } else { + content = arg.content; + } + + let winObj = new BrowserWindow({ + x: 10, + y: 10, + width: 980, + height: 650 + }) + winObj.loadURL(content); + + return winObj.id +} diff --git a/frontend/src/config/router.config.js b/frontend/src/config/router.config.js index c64960c..06b931a 100644 --- a/frontend/src/config/router.config.js +++ b/frontend/src/config/router.config.js @@ -33,6 +33,11 @@ export const constantRouterMap = [ name: 'DemoWindowViewIndex', component: () => import('@/views/demo/windowview/Index') }, + { + path: '/demo/window/index', + name: 'DemoWindowIndex', + component: () => import('@/views/demo/window/Index') + }, { path: '/demo/shortcut/index', name: 'DemoShortcutIndex', diff --git a/frontend/src/layouts/DemoMenu.vue b/frontend/src/layouts/DemoMenu.vue index 9f1adaa..aa2510e 100644 --- a/frontend/src/layouts/DemoMenu.vue +++ b/frontend/src/layouts/DemoMenu.vue @@ -42,6 +42,12 @@ export default { pageName: 'DemoWindowViewIndex', params: {} }, + 'menu_401' : { + icon: 'profile', + title: '窗口', + pageName: 'DemoWindowIndex', + params: {} + }, 'menu_500' : { icon: 'profile', title: '软件', diff --git a/frontend/src/views/demo/window/Index.vue b/frontend/src/views/demo/window/Index.vue new file mode 100644 index 0000000..5e9597a --- /dev/null +++ b/frontend/src/views/demo/window/Index.vue @@ -0,0 +1,65 @@ + + + diff --git a/frontend/src/views/demo/windowview/Index.vue b/frontend/src/views/demo/windowview/Index.vue index da58907..1fd281e 100644 --- a/frontend/src/views/demo/windowview/Index.vue +++ b/frontend/src/views/demo/windowview/Index.vue @@ -2,20 +2,26 @@
- 1. 嵌入更多的 web 内容 + 1. 嵌入web内容
加载百度页面 移除百度页面 + +
+
+ + 2. 嵌入html内容 + +
+
+ 加载html页面 移除html页面
-
- -