mirror of
https://github.com/cool-team-official/cool-admin-midway-packages.git
synced 2025-12-10 21:32:48 +00:00
v8.x
This commit is contained in:
parent
5638c19434
commit
b612d7eaf8
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cool-midway/core",
|
||||
"version": "8.0.0-beta.2",
|
||||
"version": "8.0.0",
|
||||
"description": "cool-admin midway core",
|
||||
"main": "dist/index.js",
|
||||
"typings": "index.d.ts",
|
||||
|
||||
@ -8,7 +8,6 @@ import {
|
||||
} from '@midwayjs/core';
|
||||
import { GlobalConfig } from '../constant/global';
|
||||
import { ControllerOption, CurdOption } from '../decorator/controller';
|
||||
import { BaseService } from '../service/base';
|
||||
import { IMidwayApplication } from '@midwayjs/core';
|
||||
import { Context } from '@midwayjs/koa';
|
||||
import { TypeORMDataSourceManager } from '@midwayjs/typeorm';
|
||||
@ -22,8 +21,7 @@ export abstract class BaseController {
|
||||
@Inject('ctx')
|
||||
baseCtx: Context;
|
||||
|
||||
@Inject()
|
||||
service: BaseService;
|
||||
service: any;
|
||||
|
||||
@App()
|
||||
baseApp: IMidwayApplication;
|
||||
@ -38,6 +36,7 @@ export abstract class BaseController {
|
||||
@Init()
|
||||
async init() {
|
||||
const option: ControllerOption = getClassMetadata(CONTROLLER_KEY, this);
|
||||
this.service = await this.baseCtx.requestContext.getAsync('baseService');
|
||||
const curdOption: CurdOption = option.curdOption;
|
||||
this.curdOption = curdOption;
|
||||
if (!this.curdOption) {
|
||||
@ -53,6 +52,17 @@ export abstract class BaseController {
|
||||
await this.createDynamicMethods(curdOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户ID
|
||||
* @param type 类型
|
||||
* @returns
|
||||
*/
|
||||
protected getUserId(type: 'admin' | 'app' = 'admin') {
|
||||
return type === 'admin'
|
||||
? this.baseCtx.admin?.userId
|
||||
: this.baseCtx.user?.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建动态方法
|
||||
* @param curdOption 配置
|
||||
|
||||
@ -8,6 +8,7 @@ import {
|
||||
MiddlewareParamArray,
|
||||
WEB_ROUTER_KEY,
|
||||
attachClassMetadata,
|
||||
getClassMetadata,
|
||||
} from '@midwayjs/core';
|
||||
import * as fs from 'fs';
|
||||
import * as _ from 'lodash';
|
||||
@ -74,7 +75,7 @@ export interface QueryOp {
|
||||
// 需要模糊查询的字段
|
||||
keyWordLikeFields?: string[];
|
||||
// 查询条件
|
||||
where?: Function;
|
||||
where?: Function | any[][];
|
||||
// 查询字段
|
||||
select?: string[];
|
||||
// 字段模糊查询
|
||||
@ -209,34 +210,50 @@ function saveMetadata(prefix, routerOptions, target, curdOption, module) {
|
||||
);
|
||||
// 追加CRUD路由
|
||||
if (!_.isEmpty(curdOption?.api)) {
|
||||
// 获取已存在的路由
|
||||
const existingRoutes = getClassMetadata(WEB_ROUTER_KEY, target) || [];
|
||||
const existingPaths = existingRoutes.map(route => route.path);
|
||||
|
||||
curdOption?.api.forEach(path => {
|
||||
attachClassMetadata(
|
||||
WEB_ROUTER_KEY,
|
||||
{
|
||||
path: `/${path}`,
|
||||
requestMethod: path == 'info' ? 'get' : 'post',
|
||||
method: path,
|
||||
summary: apiDesc[path] || path,
|
||||
description: '',
|
||||
},
|
||||
target
|
||||
);
|
||||
const routePath = `/${path}`;
|
||||
// 检查路由是否已存在
|
||||
if (!existingPaths.includes(routePath)) {
|
||||
attachClassMetadata(
|
||||
WEB_ROUTER_KEY,
|
||||
{
|
||||
path: routePath,
|
||||
requestMethod: path == 'info' ? 'get' : 'post',
|
||||
method: path,
|
||||
summary: apiDesc[path] || path,
|
||||
description: '',
|
||||
},
|
||||
target
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!_.isEmpty(curdOption?.serviceApis)) {
|
||||
// 获取已存在的路由
|
||||
const existingRoutes = getClassMetadata(WEB_ROUTER_KEY, target) || [];
|
||||
const existingPaths = existingRoutes.map(route => route.path);
|
||||
|
||||
curdOption.serviceApis.forEach(api => {
|
||||
const methodName = typeof api === 'string' ? api : api.method;
|
||||
attachClassMetadata(
|
||||
WEB_ROUTER_KEY,
|
||||
{
|
||||
path: `/${methodName}`,
|
||||
requestMethod: 'post',
|
||||
method: methodName,
|
||||
summary: typeof api === 'string' ? api : api.summary,
|
||||
description: '',
|
||||
},
|
||||
target
|
||||
);
|
||||
const routePath = `/${methodName}`;
|
||||
// 检查路由是否已存在
|
||||
if (!existingPaths.includes(routePath)) {
|
||||
attachClassMetadata(
|
||||
WEB_ROUTER_KEY,
|
||||
{
|
||||
path: routePath,
|
||||
requestMethod: 'post',
|
||||
method: methodName,
|
||||
summary: typeof api === 'string' ? api : api.summary,
|
||||
description: '',
|
||||
},
|
||||
target
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
Scope(ScopeEnum.Request)(target);
|
||||
|
||||
@ -69,6 +69,22 @@ export abstract class BaseService {
|
||||
await this.service.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户ID
|
||||
* @param type 类型
|
||||
* @returns
|
||||
*/
|
||||
/**
|
||||
* 获取用户ID
|
||||
* @param type 类型
|
||||
* @returns
|
||||
*/
|
||||
protected getUserId(type: 'admin' | 'app' = 'admin') {
|
||||
return type === 'admin'
|
||||
? this.baseCtx.admin?.userId
|
||||
: this.baseCtx.user?.id;
|
||||
}
|
||||
|
||||
// 设置模型
|
||||
setEntity(entity: any) {
|
||||
this.entity = entity;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cool-midway/rpc",
|
||||
"version": "8.0.0-beta.2",
|
||||
"version": "8.0.0",
|
||||
"description": "cool-admin midway rpc",
|
||||
"main": "dist/index.js",
|
||||
"typings": "index.d.ts",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cool-midway/task",
|
||||
"version": "8.0.0-beta.2",
|
||||
"version": "8.0.0",
|
||||
"description": "cool-admin midway task",
|
||||
"main": "dist/index.js",
|
||||
"typings": "index.d.ts",
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@cool-midway/typeorm",
|
||||
"private": false,
|
||||
"version": "8.0.0-beta.1",
|
||||
"version": "8.0.0",
|
||||
"description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.",
|
||||
"license": "MIT",
|
||||
"readmeFilename": "README.md",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user