This commit is contained in:
gaoshuaixing
2020-12-30 11:39:20 +08:00
parent 7a6e1325bb
commit be06d62916
83 changed files with 2282 additions and 0 deletions

57
app/controller/base.js Normal file
View File

@@ -0,0 +1,57 @@
'use strict';
const Controller = require('egg').Controller;
class BaseController extends Controller {
constructor(ctx) {
super(ctx);
}
/*
* return success
* @params: object data
* @params: string msg
* @return: object { success, code, msg, data }
*/
sendSuccess(data, msg) {
const { ctx } = this;
ctx.body = {
success: true,
code: 0,
msg,
data,
};
ctx.status = 200;
}
/*
* return fail
* @params: object data
* @params: string msg
* @return: object { success, code, msg, data }
*/
sendFail(data, msg, code) {
const { ctx } = this;
ctx.body = {
success: false,
code,
msg,
data,
};
ctx.status = 200;
}
/*
* return sendData
* @params: object data
* @params: string msg
* @return: object { success, code, msg, data }
*/
sendData(data) {
const { ctx } = this;
ctx.body = data;
ctx.status = 200;
}
}
module.exports = BaseController;

22
app/controller/test.js Normal file
View File

@@ -0,0 +1,22 @@
'use strict';
const BaseController = require('./base');
class TestController extends BaseController {
async index() {
const { app, ctx, service } = this;
const query = ctx.request.query;
console.log('env:%j', app.config.env);
const res = 0;
const data = {
env: app.config.env,
};
console.log('res:%j', res);
this.sendSuccess(data, 'ok');
}
}
module.exports = TestController;

28
app/controller/v1/home.js Normal file
View File

@@ -0,0 +1,28 @@
'use strict';
const BaseController = require('../base');
class HomeController extends BaseController {
async index() {
const { ctx } = this;
const data = {
title: 'hello electron-egg'
};
await ctx.render('index.ejs', data);
}
async hello() {
const { ctx } = this;
const data = {
title: 'hello'
};
await ctx.render('hello.ejs', data);
}
}
module.exports = HomeController;

View File

@@ -0,0 +1,30 @@
'use strict';
const BaseController = require('../base');
class SettingController extends BaseController {
async autoLaunchEnable() {
const self = this;
const { ctx } = this;
const data = {
title: 'hello electron-egg'
};
self.sendSuccess(data);
}
async autoLaunchDisable() {
const self = this;
const { ctx } = this;
const data = {
title: 'hello'
};
self.sendSuccess(data);
}
}
module.exports = SettingController;