diff --git a/.vscode/config.code-snippets b/.vscode/config.code-snippets new file mode 100644 index 0000000..0f793eb --- /dev/null +++ b/.vscode/config.code-snippets @@ -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代码片段" + } +} diff --git a/.vscode/controller.code-snippets b/.vscode/controller.code-snippets index 7fae15f..8af3f66 100644 --- a/.vscode/controller.code-snippets +++ b/.vscode/controller.code-snippets @@ -1,31 +1,22 @@ { - "controller": { - "prefix": "controller", - "body": [ - "import { BaseController } from 'egg-cool-controller';", - "import router from 'egg-cool-router';\n", - - "/**", - "* 控制器功能描述", - "*/", - "@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}", - "}" - ], - "description": "cool-admin controller代码片段 node后端" - } + "controller": { + "prefix": "controller", + "body": [ + "import { Provide } from '@midwayjs/decorator';", + "import { CoolController, BaseController } from 'midwayjs-cool-core';", + "", + "/**", + " * 描述", + " */", + "@Provide()", + "@CoolController({", + " api: ['add', 'delete', 'update', 'info', 'list', 'page'],", + " entity: 实体", + "})", + "export class XxxController extends BaseController {", + "", + "}" + ], + "description": "cool-admin controller代码片段" } - \ No newline at end of file +} diff --git a/.vscode/entity.code-snippets b/.vscode/entity.code-snippets new file mode 100644 index 0000000..552b07b --- /dev/null +++ b/.vscode/entity.code-snippets @@ -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代码片段" + } +} diff --git a/.vscode/middleware.code-snippets b/.vscode/middleware.code-snippets new file mode 100644 index 0000000..723ba1b --- /dev/null +++ b/.vscode/middleware.code-snippets @@ -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代码片段" + } +} diff --git a/.vscode/service.code-snippets b/.vscode/service.code-snippets new file mode 100644 index 0000000..7e0ddc3 --- /dev/null +++ b/.vscode/service.code-snippets @@ -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代码片段" + } +} diff --git a/package.json b/package.json index a64d238..a1d0e56 100755 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/app/extend/helper.ts b/src/app/extend/helper.ts new file mode 100644 index 0000000..57d28c6 --- /dev/null +++ b/src/app/extend/helper.ts @@ -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)); + } +} diff --git a/src/app/modules/admin/config.ts b/src/app/modules/admin/config.ts new file mode 100644 index 0000000..82fe14f --- /dev/null +++ b/src/app/modules/admin/config.ts @@ -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; +}; diff --git a/src/app/modules/admin/controller/sys/role.ts b/src/app/modules/admin/controller/sys/role.ts new file mode 100644 index 0000000..a8449f5 --- /dev/null +++ b/src/app/modules/admin/controller/sys/role.ts @@ -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 { + +} \ No newline at end of file diff --git a/src/app/modules/admin/controller/sys/user.ts b/src/app/modules/admin/controller/sys/user.ts new file mode 100644 index 0000000..98509f5 --- /dev/null +++ b/src/app/modules/admin/controller/sys/user.ts @@ -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(); + } + +} \ No newline at end of file diff --git a/src/app/modules/admin/entity/sys/role.ts b/src/app/modules/admin/entity/sys/role.ts new file mode 100644 index 0000000..4d00575 --- /dev/null +++ b/src/app/modules/admin/entity/sys/role.ts @@ -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; + +} \ No newline at end of file diff --git a/src/app/modules/admin/entity/sys/user.ts b/src/app/modules/admin/entity/sys/user.ts new file mode 100644 index 0000000..7e9501d --- /dev/null +++ b/src/app/modules/admin/entity/sys/user.ts @@ -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; +} diff --git a/src/app/modules/admin/middleware/logs.ts b/src/app/modules/admin/middleware/logs.ts new file mode 100644 index 0000000..424c668 --- /dev/null +++ b/src/app/modules/admin/middleware/logs.ts @@ -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); + }; + } + +} \ No newline at end of file diff --git a/src/app/modules/admin/service/sys/user.ts b/src/app/modules/admin/service/sys/user.ts new file mode 100644 index 0000000..eb1f859 --- /dev/null +++ b/src/app/modules/admin/service/sys/user.ts @@ -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; + + /** + * 移动部门 + * @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); + } +} \ No newline at end of file diff --git a/src/app/modules/文件夹说明.md b/src/app/modules/文件夹说明.md new file mode 100644 index 0000000..778d295 --- /dev/null +++ b/src/app/modules/文件夹说明.md @@ -0,0 +1 @@ +这里编写模块代码, 如系统模块、电商的商品模块等 \ No newline at end of file diff --git a/src/app/public/css/welcome.css b/src/app/public/css/welcome.css new file mode 100644 index 0000000..e85c269 --- /dev/null +++ b/src/app/public/css/welcome.css @@ -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); + } +} diff --git a/src/app/public/favicon.ico b/src/app/public/favicon.ico new file mode 100644 index 0000000..da11adc Binary files /dev/null and b/src/app/public/favicon.ico differ diff --git a/src/app/public/js/welcome.js b/src/app/public/js/welcome.js new file mode 100644 index 0000000..1b6f9d3 --- /dev/null +++ b/src/app/public/js/welcome.js @@ -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); +}); diff --git a/src/app/public/uploads/说明.md b/src/app/public/uploads/说明.md new file mode 100644 index 0000000..c741e12 --- /dev/null +++ b/src/app/public/uploads/说明.md @@ -0,0 +1 @@ +文件上传路径 \ No newline at end of file diff --git a/src/app/resource/ipipfree.ipdb b/src/app/resource/ipipfree.ipdb new file mode 100644 index 0000000..911e1ac Binary files /dev/null and b/src/app/resource/ipipfree.ipdb differ diff --git a/src/app/view/welcome.html b/src/app/view/welcome.html new file mode 100644 index 0000000..149af17 --- /dev/null +++ b/src/app/view/welcome.html @@ -0,0 +1,18 @@ + + + + + + + + COOL-AMIND 一个很酷的后台权限管理系统 + + + + + +
{{text}}
+ + + + diff --git a/src/config/config.default.ts b/src/config/config.default.ts index 195f6f4..ccf0b1e 100644 --- a/src/config/config.default.ts +++ b/src/config/config.default.ts @@ -1,4 +1,6 @@ import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg'; +import * as path from 'path'; +import * as fs from 'fs'; export type DefaultConfig = PowerPartial; @@ -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: { diff --git a/src/config/plugin.ts b/src/config/plugin.ts index fabdc59..ef68a09 100755 --- a/src/config/plugin.ts +++ b/src/config/plugin.ts @@ -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; diff --git a/src/controller/home.ts b/src/controller/home.ts deleted file mode 100755 index 6d86ea3..0000000 --- a/src/controller/home.ts +++ /dev/null @@ -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 { - -} diff --git a/src/controller/home1.ts b/src/controller/home1.ts deleted file mode 100755 index 07badb0..0000000 --- a/src/controller/home1.ts +++ /dev/null @@ -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; - } -} diff --git a/src/dto/test.ts b/src/dto/test.ts deleted file mode 100644 index edda77b..0000000 --- a/src/dto/test.ts +++ /dev/null @@ -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; -} \ No newline at end of file diff --git a/src/entity/role.ts b/src/entity/role.ts deleted file mode 100644 index d76de98..0000000 --- a/src/entity/role.ts +++ /dev/null @@ -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; - -} \ No newline at end of file diff --git a/src/entity/user.ts b/src/entity/user.ts deleted file mode 100644 index 19b6077..0000000 --- a/src/entity/user.ts +++ /dev/null @@ -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; - -} \ No newline at end of file diff --git a/src/middleware/report.ts b/src/middleware/report.ts deleted file mode 100644 index 8665486..0000000 --- a/src/middleware/report.ts +++ /dev/null @@ -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); - }; - } - -} \ No newline at end of file diff --git a/src/middleware/report1.ts b/src/middleware/report1.ts deleted file mode 100644 index 788d8df..0000000 --- a/src/middleware/report1.ts +++ /dev/null @@ -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); - }; - } - -} \ No newline at end of file diff --git a/src/service/user.ts b/src/service/user.ts deleted file mode 100644 index 059480a..0000000 --- a/src/service/user.ts +++ /dev/null @@ -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', - }; - } -} diff --git a/src/welcome.ts b/src/welcome.ts new file mode 100644 index 0000000..5fe0263 --- /dev/null +++ b/src/welcome.ts @@ -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' }); + } +} \ No newline at end of file diff --git a/typings/config/index.d.ts b/typings/config/index.d.ts index 71991d0..fdc863b 100644 --- a/typings/config/index.d.ts +++ b/typings/config/index.d.ts @@ -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; } } \ No newline at end of file diff --git a/typings/config/plugin.d.ts b/typings/config/plugin.d.ts index 8adedf3..7722ddf 100644 --- a/typings/config/plugin.d.ts +++ b/typings/config/plugin.d.ts @@ -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; } } \ No newline at end of file