From 6a21ef01e7e2695718b5cb5252d3859b1d88cebd Mon Sep 17 00:00:00 2001 From: gaoshuaixing Date: Mon, 21 Feb 2022 14:29:07 +0800 Subject: [PATCH] 1 --- app/controller/example.js | 11 -------- app/router/example.js | 2 -- app/service/example.js | 6 ++--- app/service/socket.js | 36 -------------------------- frontend/src/views/base/file/Index.vue | 2 +- package.json | 1 + 6 files changed, 4 insertions(+), 54 deletions(-) delete mode 100644 app/service/socket.js diff --git a/app/controller/example.js b/app/controller/example.js index e49d033..9981ea0 100644 --- a/app/controller/example.js +++ b/app/controller/example.js @@ -131,17 +131,6 @@ class ExampleController extends BaseController { self.sendSuccess(data); } - async getWsUrl() { - const self = this; - const { service } = this; - const data = {}; - - const addr = await service.socket.getWsUrl(); - data.url = addr; - - self.sendSuccess(data); - } - async dbOperation() { const self = this; const { ctx, service } = this; diff --git a/app/router/example.js b/app/router/example.js index 86d55ff..1a2aebe 100644 --- a/app/router/example.js +++ b/app/router/example.js @@ -11,8 +11,6 @@ module.exports = app => { router.post('/api/example/executeJS', controller.example.executeJS); // upload file router.post('/api/example/uploadFile', controller.example.uploadFile); - // get ws url - router.post('/api/example/getWsUrl', controller.example.getWsUrl); // add test data router.post('/api/example/addTestData', controller.example.addTestData); // delete test data diff --git a/app/service/example.js b/app/service/example.js index 6cc2307..841f7cf 100644 --- a/app/service/example.js +++ b/app/service/example.js @@ -91,14 +91,12 @@ class ExampleService extends Service { } async selectDir() { - const result = await socketClient.call('controller.example.selectDir'); - console.log('selectDir: result:', result); - if (!result.data) { + if (!result) { return ''; } - return result.data; + return result; } async messageShow() { diff --git a/app/service/socket.js b/app/service/socket.js deleted file mode 100644 index f0e1a33..0000000 --- a/app/service/socket.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -const BaseService = require('./base'); -const io = require('socket.io-client'); - -this.instance = null; - -class SocketService extends BaseService { - - instance() { - if (!SocketService.instance) { - const port = this.service.storage.getElectronIPCPort(); - const url = 'http://localhost:' + port; - const instance = io(url); - SocketService.instance = instance; - } - return SocketService.instance; - } - - call (method = '', params) { - return new Promise((resolve, reject) => { - this.instance().emit('ipc', { cmd: method, params: params }, (response) => { - resolve(response); - }); - }); - } - - async getWsUrl () { - const port = this.service.storage.getElectronIPCPort(); - const url = 'http://localhost:' + port; - - return url; - } -} - -module.exports = SocketService; diff --git a/frontend/src/views/base/file/Index.vue b/frontend/src/views/base/file/Index.vue index 356b763..8b49991 100644 --- a/frontend/src/views/base/file/Index.vue +++ b/frontend/src/views/base/file/Index.vue @@ -110,7 +110,7 @@ export default { action_url: process.env.VUE_APP_API_BASE_URL + '/api/example/uploadFile', image_info: [], num: 0, - dir_path: "D:\\www\\xing\\electron-egg", + dir_path: "D:\\www\\electron-egg", }; }, methods: { diff --git a/package.json b/package.json index 7d6ab8a..c1d64ca 100755 --- a/package.json +++ b/package.json @@ -105,6 +105,7 @@ "egg-cors": "^2.2.3", "egg-scripts": "^2.15.2", "egg-view-ejs": "^2.0.1", + "electron-is": "^3.0.0", "lodash": "^4.17.21" } }