From 79faa92a3767e27bdea1fe05ebb3a433e1e11576 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Oct 2020 16:17:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20electron=20systemAPI?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/static/css/main.css | 4 ++- electron-main/preload.js | 2 ++ main.js | 7 +++-- src/services/back.js | 11 -------- src/services/system.js | 27 ++++++++++++++++++ src/views/login/index.vue | 47 ++++++++++++++++---------------- src/views/main_web/cloud.vue | 2 +- src/views/main_web/workspace.vue | 2 +- 8 files changed, 63 insertions(+), 39 deletions(-) create mode 100644 electron-main/preload.js delete mode 100644 src/services/back.js create mode 100644 src/services/system.js diff --git a/dist/static/css/main.css b/dist/static/css/main.css index 32028044..20f9afe6 100644 --- a/dist/static/css/main.css +++ b/dist/static/css/main.css @@ -2895,7 +2895,6 @@ button:focus { .user_Img img { max-width: 100px; max-height: 100px; - cursor: pointer; } .userNamelabel { @@ -3060,6 +3059,9 @@ button:focus { .eidtimg { position: relative; } +.eidtimg > img { + cursor: pointer; +} .eidtimg>div { position: absolute; diff --git a/electron-main/preload.js b/electron-main/preload.js new file mode 100644 index 00000000..cd4c6daa --- /dev/null +++ b/electron-main/preload.js @@ -0,0 +1,2 @@ +global.electron = require('electron'); +global.os = require('os'); \ No newline at end of file diff --git a/main.js b/main.js index 9e05d973..e676d366 100644 --- a/main.js +++ b/main.js @@ -7,10 +7,13 @@ const url = require('url') function createWindow() { // Create the browser window. const mainWindow = new BrowserWindow({ - width: 800, + width: 1080, height: 600, webPreferences: { - // preload: path.join(__dirname, 'preload.js') + nodeIntegration: true, + // javascript: true, + // plugins: true, + preload: path.join(__dirname, 'electron-main', 'preload.js'), } }) diff --git a/src/services/back.js b/src/services/back.js deleted file mode 100644 index 68d26c91..00000000 --- a/src/services/back.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * 模拟客户端back server - * 目前还不知道back的API及具体实现,暂时先抑制代码报错 - */ - -const back = { - -} - - -export default back; diff --git a/src/services/system.js b/src/services/system.js new file mode 100644 index 00000000..358c4da7 --- /dev/null +++ b/src/services/system.js @@ -0,0 +1,27 @@ +/** + * 模拟客户端back server + * 目前还不知道back的API及具体实现,暂时先抑制代码报错 + */ + +export const isClient = process.env.IS_CLIENT; + +const noop = () => {}; + +const safeCall = f => isClient ? f : noop; + +const system = { + isClient, + test: safeCall(() => { + console.log('客户端 electron API 检测:', global.electron); + }), + /** + * 系统打开只当文件 + */ + openFile: safeCall((filePath) => { + const { shell } = global.electron; + shell.openPath(filePath); + }), +} + + +export default system; diff --git a/src/views/login/index.vue b/src/views/login/index.vue index bfc48838..ab73d2d3 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -229,7 +229,7 @@