mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-05-14 19:52:10 +08:00
1
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
@@ -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: {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user