mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-16 04:42:49 +00:00
整理代码, 新增方法缓存支持
This commit is contained in:
parent
e8b7bafa67
commit
23af1a379c
@ -8,4 +8,4 @@ end_of_line = lf
|
|||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
"@typescript-eslint/no-unused-vars": "off",
|
"@typescript-eslint/no-unused-vars": "off",
|
||||||
"node/no-extraneous-import": "off",
|
"node/no-extraneous-import": "off",
|
||||||
"no-empty": "off",
|
"no-empty": "off",
|
||||||
"node/no-extraneous-require": "off"
|
"node/no-extraneous-require": "off",
|
||||||
|
"eqeqeq": "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,8 +13,9 @@
|
|||||||
"ipip-ipdb": "^0.3.0",
|
"ipip-ipdb": "^0.3.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"md5": "^2.3.0",
|
"md5": "^2.3.0",
|
||||||
"midwayjs-cool-core": "^3.0.8",
|
"midwayjs-cool-core": "/Users/ap/Documents/srcs/cool-admin/midway-core/core/dist",
|
||||||
"midwayjs-cool-oss": "^1.0.0",
|
"midwayjs-cool-oss": "^1.0.0",
|
||||||
|
"midwayjs-cool-redis": "/Users/ap/Documents/srcs/cool-admin/midway-core/redis/dist",
|
||||||
"mysql2": "^2.2.5",
|
"mysql2": "^2.2.5",
|
||||||
"svg-captcha": "^1.4.0",
|
"svg-captcha": "^1.4.0",
|
||||||
"svg-to-dataurl": "^1.0.0"
|
"svg-to-dataurl": "^1.0.0"
|
||||||
|
|||||||
@ -11,6 +11,6 @@ export default (app: Application) => {
|
|||||||
// 模块描述
|
// 模块描述
|
||||||
description: '基础的权限管理功能,包括登录,权限校验',
|
description: '基础的权限管理功能,包括登录,权限校验',
|
||||||
// 中间件
|
// 中间件
|
||||||
middlewares: ['baseAuthorityMiddleware', 'baseLogMiddleware'],
|
//middlewares: ['baseAuthorityMiddleware', 'baseLogMiddleware'],
|
||||||
} as ModuleConfig;
|
} as ModuleConfig;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
import { Config, Inject, Provide } from '@midwayjs/decorator';
|
import { App, Config, Provide } from '@midwayjs/decorator';
|
||||||
import { IWebMiddleware, IMidwayWebNext } from '@midwayjs/web';
|
import {
|
||||||
|
IWebMiddleware,
|
||||||
|
IMidwayWebNext,
|
||||||
|
IMidwayWebApplication,
|
||||||
|
} from '@midwayjs/web';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { CoolCache, CoolConfig, RESCODE } from 'midwayjs-cool-core';
|
import { CoolConfig, RESCODE } from 'midwayjs-cool-core';
|
||||||
import * as jwt from 'jsonwebtoken';
|
import * as jwt from 'jsonwebtoken';
|
||||||
import { Context } from 'egg';
|
import { Context } from 'egg';
|
||||||
|
|
||||||
@ -13,8 +17,10 @@ export class BaseAuthorityMiddleware implements IWebMiddleware {
|
|||||||
@Config('cool')
|
@Config('cool')
|
||||||
coolConfig: CoolConfig;
|
coolConfig: CoolConfig;
|
||||||
|
|
||||||
@Inject('cool:cache')
|
coolCache;
|
||||||
coolCache: CoolCache;
|
|
||||||
|
@App()
|
||||||
|
app: IMidwayWebApplication;
|
||||||
|
|
||||||
resolve() {
|
resolve() {
|
||||||
return async (ctx: Context, next: IMidwayWebNext) => {
|
return async (ctx: Context, next: IMidwayWebNext) => {
|
||||||
@ -48,12 +54,15 @@ export class BaseAuthorityMiddleware implements IWebMiddleware {
|
|||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 需要动态获得缓存
|
||||||
|
this.coolCache = await this.app
|
||||||
|
.getApplicationContext()
|
||||||
|
.getAsync('cool:cache');
|
||||||
// 判断密码版本是否正确
|
// 判断密码版本是否正确
|
||||||
const passwordV = await this.coolCache.get(
|
const passwordV = await this.coolCache.get(
|
||||||
`admin:passwordVersion:${ctx.admin.userId}`
|
`admin:passwordVersion:${ctx.admin.userId}`
|
||||||
);
|
);
|
||||||
console.log(6666666666, '密码版本', passwordV);
|
if (passwordV != ctx.admin.passwordVersion) {
|
||||||
if (passwordV !== ctx.admin.passwordVersion) {
|
|
||||||
ctx.status = 401;
|
ctx.status = 401;
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
code: RESCODE.COMMFAIL,
|
code: RESCODE.COMMFAIL,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Inject, Provide } from '@midwayjs/decorator';
|
import { Inject, Provide } from '@midwayjs/decorator';
|
||||||
import { BaseService, CoolPlugin } from 'midwayjs-cool-core';
|
import { BaseService, CoolPlugin, Cache } from 'midwayjs-cool-core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件
|
* 插件
|
||||||
@ -12,6 +12,7 @@ export class BasePluginInfoService extends BaseService {
|
|||||||
/**
|
/**
|
||||||
* 列表
|
* 列表
|
||||||
*/
|
*/
|
||||||
|
@Cache(3000)
|
||||||
async list(keyWord) {
|
async list(keyWord) {
|
||||||
return this.coolPlugin.list(keyWord);
|
return this.coolPlugin.list(keyWord);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ export class BaseSysDepartmentService extends BaseService {
|
|||||||
departments.forEach(e => {
|
departments.forEach(e => {
|
||||||
const parentMenu = departments.filter(m => {
|
const parentMenu = departments.filter(m => {
|
||||||
e.parentId = parseInt(e.parentId + '');
|
e.parentId = parseInt(e.parentId + '');
|
||||||
if (e.parentId === m.id) {
|
if (e.parentId == m.id) {
|
||||||
return m.name;
|
return m.name;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -33,7 +33,7 @@ export class BaseSysMenuService extends BaseService {
|
|||||||
menus.forEach(e => {
|
menus.forEach(e => {
|
||||||
const parentMenu = menus.filter(m => {
|
const parentMenu = menus.filter(m => {
|
||||||
e.parentId = parseInt(e.parentId);
|
e.parentId = parseInt(e.parentId);
|
||||||
if (e.parentId === m.id) {
|
if (e.parentId == m.id) {
|
||||||
return m.name;
|
return m.name;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -63,12 +63,11 @@ export class BaseSysMenuService extends BaseService {
|
|||||||
let perms = [];
|
let perms = [];
|
||||||
if (!_.isEmpty(roleIds)) {
|
if (!_.isEmpty(roleIds)) {
|
||||||
const result = await this.nativeQuery(
|
const result = await this.nativeQuery(
|
||||||
`
|
`SELECT a.perms FROM base_sys_menu a ${this.setSql(
|
||||||
SELECT a.perms FROM base_sys_menu a ${this.setSql(
|
!roleIds.includes('1'),
|
||||||
!roleIds.includes('1'),
|
'JOIN base_sys_role_menu b on a.id = b.menuId AND b.roleId in (?)',
|
||||||
'JOIN base_sys_role_menu b on a.id = b.menuId AND b.roleId in (?)',
|
[roleIds]
|
||||||
[roleIds]
|
)}
|
||||||
)}
|
|
||||||
where 1=1 and a.perms is not NULL
|
where 1=1 and a.perms is not NULL
|
||||||
`,
|
`,
|
||||||
[roleIds]
|
[roleIds]
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { Application } from 'egg';
|
|||||||
import * as orm from '@midwayjs/orm';
|
import * as orm from '@midwayjs/orm';
|
||||||
import * as cool from 'midwayjs-cool-core';
|
import * as cool from 'midwayjs-cool-core';
|
||||||
import * as oss from 'midwayjs-cool-oss';
|
import * as oss from 'midwayjs-cool-oss';
|
||||||
|
import * as redis from 'midwayjs-cool-redis';
|
||||||
|
|
||||||
@Configuration({
|
@Configuration({
|
||||||
// 注意组件顺序 cool 有依赖orm组件, 所以必须放在,orm组件之后 cool的其他组件必须放在cool 核心组件之后
|
// 注意组件顺序 cool 有依赖orm组件, 所以必须放在,orm组件之后 cool的其他组件必须放在cool 核心组件之后
|
||||||
@ -14,6 +15,8 @@ import * as oss from 'midwayjs-cool-oss';
|
|||||||
cool,
|
cool,
|
||||||
// oss插件,需要到后台配置之后才有用,默认是本地上传
|
// oss插件,需要到后台配置之后才有用,默认是本地上传
|
||||||
oss,
|
oss,
|
||||||
|
// 将缓存替换成redis
|
||||||
|
redis,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class ContainerLifeCycle implements ILifeCycle {
|
export class ContainerLifeCycle implements ILifeCycle {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user