diff --git a/app/controller/example.js b/app/controller/example.js index fe20b90..839c59e 100644 --- a/app/controller/example.js +++ b/app/controller/example.js @@ -10,27 +10,13 @@ class ExampleController extends BaseController { /** * test electron api */ - async testElectronApi() { + async test1() { const { ctx, service } = this; const body = ctx.request.body; const id = body.id; const data = {}; - await service.example.testElectronApi(id); - - this.sendSuccess(data); - } - - /** - * test2 - */ - test2() { - const { ctx, service } = this; - const body = ctx.request.body; - console.log('test2 params:', body); - const data = { - age: 32 - }; + await service.example.test1(id); this.sendSuccess(data); } diff --git a/app/router/example.js b/app/router/example.js index 8809579..f18a812 100644 --- a/app/router/example.js +++ b/app/router/example.js @@ -9,9 +9,7 @@ module.exports = app => { // upload file router.post('/api/example/uploadFile', controller.example.uploadFile); // test some electron api - router.post('/api/example/testElectronApi', controller.example.testElectronApi); - // test2 - router.post('/api/example/test2', controller.example.test2); + router.post('/api/example/test1', controller.example.test1); // message show router.post('/api/example/messageShow', controller.example.messageShow); // message show confirm diff --git a/app/service/example.js b/app/service/example.js index fc5bd04..e7bc50f 100644 --- a/app/service/example.js +++ b/app/service/example.js @@ -6,7 +6,7 @@ const socketClient = EeSocket.getClient(); class ExampleService extends Service { - async testElectronApi(id = 0) { + async test1(id = 0) { const res = await socketClient.call('controller.example.test', {name:"gsx"}, {age:12}); return null; diff --git a/electron/controller/example.js b/electron/controller/example.js index aedeec0..491e3bb 100644 --- a/electron/controller/example.js +++ b/electron/controller/example.js @@ -28,27 +28,20 @@ class ExampleController extends Controller { * @param event - IpcMainEvent 文档:https://www.electronjs.org/docs/latest/api/structures/ipc-main-event */ - constructor(ctx) { + constructor(ctx) { super(ctx); - - //this.myTimer = null; - - } + } /** * test */ - async test (args) { - let obj = { - status:'ok' - } + async test () { + const result = await this.service.example.test('electron'); // 调用egg的某个api - // const result = await this.app.curlEgg('post', '/api/v1/example/test2', {name: 'gsx2'}); - // console.log('fffffffffff: ', result); - //this.app.logger.info('ssssssssssssssssssss'); + // const result = await this.app.curlEgg('post', '/api/example/test2', {name: 'electron'}); - return obj; + return result; } /** @@ -59,8 +52,6 @@ class ExampleController extends Controller { let content = ''; content = '收到:' + args + ',返回:' + newMsg; - // let channel = "example.socketMessageStop"; - // event.reply(`${channel}`, '另外的数据'); return content; } diff --git a/electron/service/example.js b/electron/service/example.js new file mode 100644 index 0000000..f507158 --- /dev/null +++ b/electron/service/example.js @@ -0,0 +1,28 @@ +'use strict'; + +const Service = require('ee-core').Service; + +/** + * 示例服务 + * @class + */ +class ExampleService extends Service { + + constructor(ctx) { + super(ctx); + } + + /** + * test + */ + async test (args) { + let obj = { + status:'ok', + params: args + } + + return obj; + } +} + +module.exports = ExampleService; \ No newline at end of file diff --git a/frontend/src/api/main.js b/frontend/src/api/main.js index 3e1bdae..ad33b91 100644 --- a/frontend/src/api/main.js +++ b/frontend/src/api/main.js @@ -6,7 +6,7 @@ const eggApiroute = { messageShow: '/api/example/messageShow', messageShowConfirm: '/api/example/messageShowConfirm', dbOperation: '/api/example/dbOperation', - testElectronApi: '/api/example/testElectronApi', + test1: '/api/example/test1', } const ipcApiRoute = { diff --git a/frontend/src/views/base/testapi/Index.vue b/frontend/src/views/base/testapi/Index.vue index 9c58062..96e0c20 100644 --- a/frontend/src/views/base/testapi/Index.vue +++ b/frontend/src/views/base/testapi/Index.vue @@ -24,7 +24,7 @@ export default { const params = { id: id } - requestEggApi('testElectronApi', params).then(res => { + requestEggApi('test1', params).then(res => { if (res.code !== 0) { return false } diff --git a/frontend/src/views/other/Index.vue b/frontend/src/views/other/Index.vue index 8c2fd95..df5dc71 100644 --- a/frontend/src/views/other/Index.vue +++ b/frontend/src/views/other/Index.vue @@ -10,7 +10,6 @@