mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-05-14 11:52:07 +08:00
add service
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
28
electron/service/example.js
Normal file
28
electron/service/example.js
Normal file
@@ -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;
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { requestEggApi } from '@/api/main'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@@ -18,14 +17,6 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
test () {
|
||||
const params = {}
|
||||
requestEggApi('openDir', params).then(res => {
|
||||
if (res.code !== 0) {
|
||||
return false
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log('err:', err)
|
||||
})
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user