mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-15 03:42:51 +00:00
优化crud的动态参数
This commit is contained in:
parent
11749da7c4
commit
c971260ee1
24
.vscode/config.code-snippets
vendored
Normal file
24
.vscode/config.code-snippets
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"config": {
|
||||
"prefix": "config",
|
||||
"body": [
|
||||
"import { Application } from 'egg';",
|
||||
"import { ModuleConfig } from 'midwayjs-cool-core';",
|
||||
"",
|
||||
"/**",
|
||||
" * 模块配置",
|
||||
" */",
|
||||
"export default (app: Application) => {",
|
||||
" return {",
|
||||
" // 模块名称",
|
||||
" name: 'xxx',",
|
||||
" // 模块描述",
|
||||
" describe: 'xxx',",
|
||||
" // 中间件",
|
||||
" middlewares: [],",
|
||||
" } as ModuleConfig;",
|
||||
"};"
|
||||
],
|
||||
"description": "cool-admin config代码片段"
|
||||
}
|
||||
}
|
||||
33
.vscode/controller.code-snippets
vendored
33
.vscode/controller.code-snippets
vendored
@ -2,30 +2,21 @@
|
||||
"controller": {
|
||||
"prefix": "controller",
|
||||
"body": [
|
||||
"import { BaseController } from 'egg-cool-controller';",
|
||||
"import router from 'egg-cool-router';\n",
|
||||
|
||||
"import { Provide } from '@midwayjs/decorator';",
|
||||
"import { CoolController, BaseController } from 'midwayjs-cool-core';",
|
||||
"",
|
||||
"/**",
|
||||
"* 控制器功能描述",
|
||||
" * 描述",
|
||||
" */",
|
||||
"@router.prefix(['add', 'delete', 'update', 'info', 'list', 'page'])",
|
||||
"export default class XXXController extends BaseController {",
|
||||
"\tinit() {",
|
||||
"\t\tthis.setEntity(this.ctx.repo.xxx);",
|
||||
"\t\tthis.setService(this.ctx.service.xxx);",
|
||||
"\t}\n",
|
||||
|
||||
"\t/**",
|
||||
"\t* 其他接口",
|
||||
"\t*/",
|
||||
"\t@router.post('/xxx')",
|
||||
"\tasync xxx() {",
|
||||
"\t\tawait this.OpService.xxx(this.getBody());",
|
||||
"\t\tthis.res();",
|
||||
"\t}",
|
||||
"@Provide()",
|
||||
"@CoolController({",
|
||||
" api: ['add', 'delete', 'update', 'info', 'list', 'page'],",
|
||||
" entity: 实体",
|
||||
"})",
|
||||
"export class XxxController extends BaseController {",
|
||||
"",
|
||||
"}"
|
||||
],
|
||||
"description": "cool-admin controller代码片段 node后端"
|
||||
"description": "cool-admin controller代码片段"
|
||||
}
|
||||
}
|
||||
|
||||
22
.vscode/entity.code-snippets
vendored
Normal file
22
.vscode/entity.code-snippets
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"entity": {
|
||||
"prefix": "entity",
|
||||
"body": [
|
||||
"import { EntityModel } from '@midwayjs/orm';",
|
||||
"import { BaseEntity } from 'midwayjs-cool-core';",
|
||||
"import { Column } from 'typeorm';",
|
||||
"",
|
||||
"/**",
|
||||
" * 描述",
|
||||
" */",
|
||||
"@EntityModel('xxx_xxx_xxx')",
|
||||
"export class XxxEntity extends BaseEntity {",
|
||||
"",
|
||||
" @Column({comment: '描述'})",
|
||||
" xxx: string;",
|
||||
"",
|
||||
"}",
|
||||
],
|
||||
"description": "cool-admin entity代码片段"
|
||||
}
|
||||
}
|
||||
29
.vscode/middleware.code-snippets
vendored
Normal file
29
.vscode/middleware.code-snippets
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"middleware": {
|
||||
"prefix": "middleware",
|
||||
"body": [
|
||||
"import { Provide } from '@midwayjs/decorator';",
|
||||
"import { IWebMiddleware, IMidwayWebNext, IMidwayWebContext } from '@midwayjs/web';",
|
||||
"",
|
||||
"/**",
|
||||
" * 描述",
|
||||
" */",
|
||||
"@Provide()",
|
||||
"export class XxxMiddleware implements IWebMiddleware {",
|
||||
"",
|
||||
" resolve() {",
|
||||
" return async (ctx: IMidwayWebContext, next: IMidwayWebNext) => {",
|
||||
" // 控制器前执行的逻辑",
|
||||
" const startTime = Date.now();",
|
||||
" // 执行下一个 Web 中间件,最后执行到控制器",
|
||||
" await next();",
|
||||
" // 控制器之后执行的逻辑",
|
||||
" console.log(Date.now() - startTime);",
|
||||
" };",
|
||||
" }",
|
||||
"",
|
||||
"}",
|
||||
],
|
||||
"description": "cool-admin middleware代码片段"
|
||||
}
|
||||
}
|
||||
29
.vscode/service.code-snippets
vendored
Normal file
29
.vscode/service.code-snippets
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"service": {
|
||||
"prefix": "service",
|
||||
"body": [
|
||||
"import { Provide } from '@midwayjs/decorator';",
|
||||
"import { BaseService } from 'midwayjs-cool-core';",
|
||||
"import { InjectEntityModel } from '@midwayjs/orm';",
|
||||
"import { Repository } from 'typeorm';",
|
||||
"",
|
||||
"/**",
|
||||
" * 描述",
|
||||
" */",
|
||||
"@Provide()",
|
||||
"export class XxxService extends BaseService {",
|
||||
"",
|
||||
" @InjectEntityModel(实体)",
|
||||
" xxxEntity: Repository<实体>;",
|
||||
"",
|
||||
" /**",
|
||||
" * 描述",
|
||||
" */",
|
||||
" async xxx() {",
|
||||
"",
|
||||
" }",
|
||||
"}"
|
||||
],
|
||||
"description": "cool-admin service代码片段"
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,8 @@
|
||||
"@midwayjs/web": "^2.7.7",
|
||||
"egg": "^2.29.3",
|
||||
"egg-scripts": "^2.13.0",
|
||||
"egg-view-nunjucks": "^2.3.0",
|
||||
"ipip-ipdb": "^0.3.0",
|
||||
"midwayjs-cool-core": "file:/Users/ap/Documents/srcs/cool-admin/midway-core/core/dist",
|
||||
"midwayjs-cool-redis": "file:/Users/ap/Documents/srcs/cool-admin/midway-core/redis/dist",
|
||||
"mysql2": "^2.2.5"
|
||||
|
||||
63
src/app/extend/helper.ts
Normal file
63
src/app/extend/helper.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import * as ipdb from 'ipip-ipdb';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
/**
|
||||
* 帮助类
|
||||
*/
|
||||
export default class Helper {
|
||||
/**
|
||||
* 获得请求IP
|
||||
*/
|
||||
public static async getReqIP() {
|
||||
// @ts-ignore
|
||||
const req = this.ctx.req;
|
||||
return (req.headers['x-forwarded-for'] || // 判断是否有反向代理 IP
|
||||
req.connection.remoteAddress || // 判断 connection 的远程 IP
|
||||
req.socket.remoteAddress || // 判断后端的 socket 的 IP
|
||||
req.connection.socket.remoteAddress).replace('::ffff:', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据IP获得请求地址
|
||||
* @param ip 为空时则为当前请求的IP地址
|
||||
*/
|
||||
public static async getIpAddr(ip?: string) {
|
||||
try {
|
||||
if (!ip) {
|
||||
ip = await this.getReqIP();
|
||||
}
|
||||
const bst = new ipdb.BaseStation('app/resource/ipip/ipipfree.ipdb');
|
||||
const result = bst.findInfo(ip, 'CN');
|
||||
const addArr: any = [];
|
||||
if (result) {
|
||||
addArr.push(result.countryName);
|
||||
addArr.push(result.regionName);
|
||||
addArr.push(result.cityName);
|
||||
return _.uniq(addArr).join('');
|
||||
}
|
||||
// @ts-ignore
|
||||
} catch (err) {
|
||||
return '无法获取地址信息';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除对象的空值属性
|
||||
* @param obj
|
||||
*/
|
||||
public static async removeEmptyP (obj) {
|
||||
Object.keys(obj).forEach(key => {
|
||||
if (obj[key] === null || obj[key] === '' || obj[key] === 'undefined') {
|
||||
delete obj[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 线程阻塞毫秒数
|
||||
* @param ms
|
||||
*/
|
||||
public static sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
16
src/app/modules/admin/config.ts
Normal file
16
src/app/modules/admin/config.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { Application } from "egg";
|
||||
import { ModuleConfig } from 'midwayjs-cool-core';
|
||||
|
||||
/**
|
||||
* 模块的配置
|
||||
*/
|
||||
export default (app: Application) => {
|
||||
return {
|
||||
// 模块名称
|
||||
name: '权限管理',
|
||||
// 模块描述
|
||||
describe: '基础的权限管理功能,包括登录,权限校验',
|
||||
// 中间件
|
||||
middlewares: ['adminLogsMiddleware'],
|
||||
} as ModuleConfig;
|
||||
};
|
||||
23
src/app/modules/admin/controller/sys/role.ts
Normal file
23
src/app/modules/admin/controller/sys/role.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { Provide } from '@midwayjs/decorator';
|
||||
import { CoolController, BaseController } from 'midwayjs-cool-core';
|
||||
import { AdminSysRoleEntity } from '../../entity/sys/role';
|
||||
|
||||
/**
|
||||
* 系统角色
|
||||
*/
|
||||
@Provide()
|
||||
@CoolController({
|
||||
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
|
||||
entity: AdminSysRoleEntity,
|
||||
pageQueryOp: {
|
||||
keyWordLikeFields: ['name', 'label'],
|
||||
where: (async () => {
|
||||
return [
|
||||
['label != :label', { label: 'admin' }],
|
||||
]
|
||||
})
|
||||
}
|
||||
})
|
||||
export class AdminSysRoleController extends BaseController {
|
||||
|
||||
}
|
||||
28
src/app/modules/admin/controller/sys/user.ts
Normal file
28
src/app/modules/admin/controller/sys/user.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { Body, Inject, Post, Provide } from '@midwayjs/decorator';
|
||||
import { CoolController, BaseController } from 'midwayjs-cool-core';
|
||||
import { AdminSysUserEntity } from '../../entity/sys/user';
|
||||
import { AdminSysUserService } from '../../service/sys/user';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*/
|
||||
@Provide()
|
||||
@CoolController({
|
||||
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
|
||||
entity: AdminSysUserEntity
|
||||
})
|
||||
export class AdminSysUserController extends BaseController {
|
||||
|
||||
@Inject()
|
||||
adminSysUserService: AdminSysUserService;
|
||||
|
||||
/**
|
||||
* 移动部门
|
||||
*/
|
||||
@Post('/move')
|
||||
async move(@Body() departmentId: number, @Body() userIds: []) {
|
||||
await this.adminSysUserService.move(departmentId, userIds);
|
||||
this.ok();
|
||||
}
|
||||
|
||||
}
|
||||
25
src/app/modules/admin/entity/sys/role.ts
Normal file
25
src/app/modules/admin/entity/sys/role.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { EntityModel } from '@midwayjs/orm';
|
||||
import { BaseEntity } from 'midwayjs-cool-core';
|
||||
import { Column, Index } from 'typeorm';
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*/
|
||||
@EntityModel('admin_sys_role')
|
||||
export class AdminSysRoleEntity extends BaseEntity {
|
||||
|
||||
@Column({ comment: '用户ID' })
|
||||
userId: string;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column({ comment: '名称' })
|
||||
name: string;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column({ comment: '角色标签', nullable: true, length: 50 })
|
||||
label: string;
|
||||
|
||||
@Column({ comment: '备注', nullable: true })
|
||||
remark: string;
|
||||
|
||||
}
|
||||
46
src/app/modules/admin/entity/sys/user.ts
Normal file
46
src/app/modules/admin/entity/sys/user.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { EntityModel } from '@midwayjs/orm';
|
||||
import { BaseEntity } from 'midwayjs-cool-core';
|
||||
import { Column, Index } from 'typeorm';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*/
|
||||
@EntityModel('admin_sys_user')
|
||||
export class AdminSysUserEntity extends BaseEntity {
|
||||
|
||||
@Index()
|
||||
@Column({ comment: '部门ID', type: 'bigint', nullable: true })
|
||||
departmentId: number;
|
||||
|
||||
@Column({ comment: '姓名', nullable: true })
|
||||
name: string;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column({ comment: '用户名', length: 100 })
|
||||
username: string;
|
||||
|
||||
@Column({ comment: '密码' })
|
||||
password: string;
|
||||
|
||||
@Column({ comment: '密码版本, 作用是改完密码,让原来的token失效', default: 1 })
|
||||
passwordV: number;
|
||||
|
||||
@Column({ comment: '昵称', nullable: true })
|
||||
nickName: string;
|
||||
|
||||
@Column({ comment: '头像', nullable: true })
|
||||
headImg: string;
|
||||
|
||||
@Index()
|
||||
@Column({ comment: '手机', nullable: true, length: 20 })
|
||||
phone: string;
|
||||
|
||||
@Column({ comment: '邮箱', nullable: true })
|
||||
email: string;
|
||||
|
||||
@Column({ comment: '备注', nullable: true, length: 500 })
|
||||
remark: string;
|
||||
|
||||
@Column({ comment: '状态 0:禁用 1:启用', default: 1, type: 'tinyint' })
|
||||
status: number;
|
||||
}
|
||||
21
src/app/modules/admin/middleware/logs.ts
Normal file
21
src/app/modules/admin/middleware/logs.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { Provide } from '@midwayjs/decorator';
|
||||
import { IWebMiddleware, IMidwayWebNext, IMidwayWebContext } from '@midwayjs/web';
|
||||
|
||||
/**
|
||||
* 日志中间件
|
||||
*/
|
||||
@Provide()
|
||||
export class AdminLogsMiddleware implements IWebMiddleware {
|
||||
|
||||
resolve() {
|
||||
return async (ctx: IMidwayWebContext, next: IMidwayWebNext) => {
|
||||
// 控制器前执行的逻辑
|
||||
const startTime = Date.now();
|
||||
// 执行下一个 Web 中间件,最后执行到控制器
|
||||
await next();
|
||||
// 控制器之后执行的逻辑
|
||||
console.log(Date.now() - startTime);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
32
src/app/modules/admin/service/sys/user.ts
Normal file
32
src/app/modules/admin/service/sys/user.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { Provide } from '@midwayjs/decorator';
|
||||
import { BaseService } from 'midwayjs-cool-core';
|
||||
import { InjectEntityModel } from '@midwayjs/orm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { AdminSysUserEntity } from '../../entity/sys/user';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*/
|
||||
@Provide()
|
||||
export class AdminSysUserService extends BaseService {
|
||||
|
||||
@InjectEntityModel(AdminSysUserEntity)
|
||||
adminSysUserEntity: Repository<AdminSysUserEntity>;
|
||||
|
||||
/**
|
||||
* 移动部门
|
||||
* @param departmentId
|
||||
* @param userIds
|
||||
*/
|
||||
async move(departmentId, userIds) {
|
||||
await this.adminSysUserEntity.createQueryBuilder()
|
||||
.update().set({ departmentId })
|
||||
.where('id =: (:userIds)', { userIds })
|
||||
.execute();
|
||||
}
|
||||
|
||||
async test(){
|
||||
// const a = await this.adminSysUserEntity.find();
|
||||
// console.log(a);
|
||||
}
|
||||
}
|
||||
1
src/app/modules/文件夹说明.md
Normal file
1
src/app/modules/文件夹说明.md
Normal file
@ -0,0 +1 @@
|
||||
这里编写模块代码, 如系统模块、电商的商品模块等
|
||||
64
src/app/public/css/welcome.css
Normal file
64
src/app/public/css/welcome.css
Normal file
@ -0,0 +1,64 @@
|
||||
body {
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
background: #222;
|
||||
}
|
||||
|
||||
.reveal {
|
||||
position: relative;
|
||||
display: flex;
|
||||
color: #6ee1f5;
|
||||
font-size: 2em;
|
||||
font-family: Raleway, sans-serif;
|
||||
letter-spacing: 3px;
|
||||
text-transform: uppercase;
|
||||
white-space: pre;
|
||||
}
|
||||
.reveal span {
|
||||
opacity: 0;
|
||||
transform: scale(0);
|
||||
animation: fadeIn 2.4s forwards;
|
||||
}
|
||||
.reveal::before, .reveal::after {
|
||||
position: absolute;
|
||||
content: "";
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 2px;
|
||||
height: 100%;
|
||||
background: white;
|
||||
opacity: 0;
|
||||
transform: scale(0);
|
||||
}
|
||||
.reveal::before {
|
||||
left: 50%;
|
||||
animation: slideLeft 1.5s cubic-bezier(0.7, -0.6, 0.3, 1.5) forwards;
|
||||
}
|
||||
.reveal::after {
|
||||
right: 50%;
|
||||
animation: slideRight 1.5s cubic-bezier(0.7, -0.6, 0.3, 1.5) forwards;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
@keyframes slideLeft {
|
||||
to {
|
||||
left: -6%;
|
||||
opacity: 1;
|
||||
transform: scale(0.9);
|
||||
}
|
||||
}
|
||||
@keyframes slideRight {
|
||||
to {
|
||||
right: -6%;
|
||||
opacity: 1;
|
||||
transform: scale(0.9);
|
||||
}
|
||||
}
|
||||
BIN
src/app/public/favicon.ico
Normal file
BIN
src/app/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
13
src/app/public/js/welcome.js
Normal file
13
src/app/public/js/welcome.js
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
let duration = 0.8;
|
||||
let delay = 0.3;
|
||||
let revealText = document.querySelector(".reveal");
|
||||
let letters = revealText.textContent.split("");
|
||||
revealText.textContent = "";
|
||||
let middle = letters.filter(e => e !== " ").length / 2;
|
||||
letters.forEach((letter, i) => {
|
||||
let span = document.createElement("span");
|
||||
span.textContent = letter;
|
||||
span.style.animationDelay = `${delay + Math.abs(i - middle) * 0.1}s`;
|
||||
revealText.append(span);
|
||||
});
|
||||
1
src/app/public/uploads/说明.md
Normal file
1
src/app/public/uploads/说明.md
Normal file
@ -0,0 +1 @@
|
||||
文件上传路径
|
||||
BIN
src/app/resource/ipipfree.ipdb
Normal file
BIN
src/app/resource/ipipfree.ipdb
Normal file
Binary file not shown.
18
src/app/view/welcome.html
Normal file
18
src/app/view/welcome.html
Normal file
@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||
<title>COOL-AMIND 一个很酷的后台权限管理系统</title>
|
||||
<meta name="keywords" content="cool-admin,后台管理系统,vue,element-ui,nodejs" />
|
||||
<meta name="description" content="element-ui、egg.js、midway.js、mysql、redis、node.js、前后端分离、权限管理、快速开发, COOL-AMIND 一个很酷的后台权限管理系统" />
|
||||
<link rel="stylesheet" href="css/welcome.css">
|
||||
|
||||
<body>
|
||||
<div class="reveal">{{text}}</div>
|
||||
<script src="js/welcome.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -1,4 +1,6 @@
|
||||
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
export type DefaultConfig = PowerPartial<EggAppConfig>;
|
||||
|
||||
@ -10,6 +12,36 @@ export default (appInfo: EggAppInfo) => {
|
||||
// 启用中间件 这里需要设置为 [] 否则CoolController设置的中间件也会无效
|
||||
config.middleware = [];
|
||||
|
||||
// 模板渲染 用法 https://nunjucks.bootcss.com
|
||||
config.view = {
|
||||
root: [
|
||||
path.join(appInfo.baseDir, 'app/view'),
|
||||
].join(','),
|
||||
defaultViewEngine: 'nunjucks',
|
||||
defaultExtension: '.html',
|
||||
mapping: {
|
||||
'.html': 'nunjucks',
|
||||
},
|
||||
};
|
||||
|
||||
// 靜態目錄及緩存設置
|
||||
config.static = {
|
||||
prefix: '/',
|
||||
dir: path.join(appInfo.baseDir, 'app/public'),
|
||||
dynamic: true,
|
||||
preload: false,
|
||||
// maxAge: 31536000,
|
||||
maxAge: 0,
|
||||
buffer: false,
|
||||
};
|
||||
|
||||
// 修改默认的 favicon.ico
|
||||
config.siteFile = {
|
||||
'/favicon.ico': fs.readFileSync(path.join(appInfo.baseDir, 'app/public/favicon.ico')),
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 关闭安全校验
|
||||
config.security = {
|
||||
csrf: {
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
import { EggPlugin } from 'egg';
|
||||
export default {
|
||||
static: false, // default is true
|
||||
static: true, // default is true
|
||||
view: true,
|
||||
nunjucks: {
|
||||
enable: true,
|
||||
package: 'egg-view-nunjucks',
|
||||
}
|
||||
} as EggPlugin;
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
import { Provide } from '@midwayjs/decorator';
|
||||
import { CoolController, BaseController } from 'midwayjs-cool-core';
|
||||
import { Role } from '../entity/role';
|
||||
|
||||
@Provide()
|
||||
@CoolController({
|
||||
api: ['add','delete','update','info','list','page'],
|
||||
entity: 实体,
|
||||
pageQueryOp: {
|
||||
fieldEq: ['id', 'name'],
|
||||
keyWordLikeFields: ['a.name'],
|
||||
select: ['a.*, b.name AS roleName'],
|
||||
leftJoin: [
|
||||
{
|
||||
entity: Role,
|
||||
alias: 'b',
|
||||
condition: 'a.id = b.userId'
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
export class XxxController extends BaseController {
|
||||
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
import { Get, Provide, Inject } from '@midwayjs/decorator';
|
||||
import { CoolController, CoolCache } from 'midwayjs-cool-core';
|
||||
|
||||
@Provide()
|
||||
@CoolController()
|
||||
export class Home1Controller {
|
||||
@Inject('cool:cache')
|
||||
coolCache: CoolCache;
|
||||
@Get('/1')
|
||||
async home() {
|
||||
const data = await this.coolCache.get('a');
|
||||
console.log('获得到的数据', data)
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
import { Rule, RuleType } from "@midwayjs/decorator";
|
||||
|
||||
export class TestDTO {
|
||||
|
||||
@Rule(RuleType.string().required())
|
||||
firstName: string;
|
||||
|
||||
@Rule(RuleType.string().max(10))
|
||||
lastName: string;
|
||||
|
||||
@Rule(RuleType.number().max(60))
|
||||
age: number;
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
import { EntityModel } from '@midwayjs/orm';
|
||||
import { BaseModel } from 'midwayjs-cool-core';
|
||||
import { Column } from 'typeorm';
|
||||
|
||||
@EntityModel('role')
|
||||
export class Role extends BaseModel {
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column('bigint')
|
||||
userId: number;
|
||||
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
import { EntityModel } from '@midwayjs/orm';
|
||||
import { BaseModel } from 'midwayjs-cool-core';
|
||||
import { Column } from 'typeorm';
|
||||
import { Rule, RuleType } from "@midwayjs/decorator";
|
||||
|
||||
@EntityModel('user')
|
||||
export class User extends BaseModel {
|
||||
|
||||
@Rule(RuleType.string().required())
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Rule(RuleType.number().max(18))
|
||||
@Column('int')
|
||||
age: number;
|
||||
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
import { Provide } from '@midwayjs/decorator';
|
||||
import { IWebMiddleware, IMidwayWebNext, IMidwayWebContext } from '@midwayjs/web';
|
||||
|
||||
@Provide()
|
||||
export class ReportMiddleware implements IWebMiddleware {
|
||||
|
||||
resolve() {
|
||||
return async (ctx: IMidwayWebContext, next: IMidwayWebNext) => {
|
||||
console.log('请求进来了')
|
||||
const startTime = Date.now();
|
||||
await next();
|
||||
console.log('请求时间', Date.now() - startTime);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
import { Provide } from '@midwayjs/decorator';
|
||||
import { IWebMiddleware, IMidwayWebNext, IMidwayWebContext } from '@midwayjs/web';
|
||||
|
||||
@Provide()
|
||||
export class ReportMiddleware1 implements IWebMiddleware {
|
||||
|
||||
resolve() {
|
||||
return async (ctx: IMidwayWebContext, next: IMidwayWebNext) => {
|
||||
console.log('请求进来了1111')
|
||||
const startTime = Date.now();
|
||||
await next();
|
||||
console.log('请求时间1111', Date.now() - startTime);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
import { Provide } from '@midwayjs/decorator';
|
||||
import { IUserOptions } from '../interface';
|
||||
|
||||
@Provide()
|
||||
export class UserService {
|
||||
async getUser(options: IUserOptions) {
|
||||
return {
|
||||
uid: options.uid,
|
||||
username: 'mockedName',
|
||||
phone: '12345678901',
|
||||
email: 'xxx.xxx@xxx.com',
|
||||
};
|
||||
}
|
||||
}
|
||||
19
src/welcome.ts
Normal file
19
src/welcome.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Get, Inject, Provide } from '@midwayjs/decorator';
|
||||
import { Context } from 'egg';
|
||||
import { CoolController, BaseController } from 'midwayjs-cool-core';
|
||||
|
||||
/**
|
||||
* 欢迎界面
|
||||
*/
|
||||
@Provide()
|
||||
@CoolController('/')
|
||||
export class WelcomeController extends BaseController {
|
||||
|
||||
@Inject()
|
||||
ctx: Context;
|
||||
|
||||
@Get('/')
|
||||
public async welcome () {
|
||||
await this.ctx.render('welcome', { text: 'HELLO COOL-ADMIN' });
|
||||
}
|
||||
}
|
||||
3
typings/config/index.d.ts
vendored
3
typings/config/index.d.ts
vendored
@ -10,9 +10,11 @@ import 'egg-multipart';
|
||||
import 'egg-security';
|
||||
import 'egg-logrotator';
|
||||
import 'egg-schedule';
|
||||
import 'egg-static';
|
||||
import 'egg-jsonp';
|
||||
import 'egg-view';
|
||||
import 'midway-schedule';
|
||||
import 'egg-view-nunjucks';
|
||||
import { EggPluginItem } from 'egg';
|
||||
declare module 'egg' {
|
||||
interface EggPlugin {
|
||||
@ -29,5 +31,6 @@ declare module 'egg' {
|
||||
jsonp?: EggPluginItem;
|
||||
view?: EggPluginItem;
|
||||
schedulePlus?: EggPluginItem;
|
||||
nunjucks?: EggPluginItem;
|
||||
}
|
||||
}
|
||||
3
typings/config/plugin.d.ts
vendored
3
typings/config/plugin.d.ts
vendored
@ -9,9 +9,11 @@ import 'egg-multipart';
|
||||
import 'egg-security';
|
||||
import 'egg-logrotator';
|
||||
import 'egg-schedule';
|
||||
import 'egg-static';
|
||||
import 'egg-jsonp';
|
||||
import 'egg-view';
|
||||
import 'midway-schedule';
|
||||
import 'egg-view-nunjucks';
|
||||
import { EggPluginItem } from 'egg';
|
||||
declare module 'egg' {
|
||||
interface EggPlugin {
|
||||
@ -28,5 +30,6 @@ declare module 'egg' {
|
||||
jsonp?: EggPluginItem;
|
||||
view?: EggPluginItem;
|
||||
schedulePlus?: EggPluginItem;
|
||||
nunjucks?: EggPluginItem;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user