完善路由标签CoolTag可以单独使用

This commit is contained in:
COOL 2025-01-02 15:16:04 +08:00
parent b670e8ead7
commit 0623782867
3 changed files with 37 additions and 14 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/core",
"version": "7.1.24",
"version": "7.1.25",
"description": "",
"main": "dist/index.js",
"typings": "index.d.ts",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/core",
"version": "7.1.24",
"version": "7.1.25",
"description": "",
"main": "index.js",
"typings": "index.d.ts",

View File

@ -20,7 +20,20 @@ import * as _ from 'lodash';
export class CoolUrlTagData {
data = {};
/**
*
*/
async init() {
// 类标记
await this.classTag();
// 方法标记
await this.methodTag();
}
/**
*
*/
async classTag() {
const tags = listModule(COOL_URL_TAG_KEY);
for (const controller of tags) {
// class的标记
@ -37,18 +50,28 @@ export class CoolUrlTagData {
}))
);
}
// 方法标记
const listPropertyMetas = listPropertyDataFromClass(COOL_METHOD_TAG_KEY, controller);
const requestMetas = getClassMetadata(WEB_ROUTER_KEY, controller);
for (const propertyMeta of listPropertyMetas) {
const _data = this.data[propertyMeta.tag] || [];
const requestMeta = _.find(requestMetas, { method: propertyMeta.key })
if(requestMeta){
this.data[propertyMeta.tag] = _.uniq(_data.concat(
controllerOption.prefix + requestMeta.path
))
}
}
}
}
/**
*
*/
async methodTag() {
const controllers = listModule(CONTROLLER_KEY);
for (const controller of controllers) {
const controllerOption = getClassMetadata(CONTROLLER_KEY, controller);
// 方法标记
const listPropertyMetas = listPropertyDataFromClass(COOL_METHOD_TAG_KEY, controller);
const requestMetas = getClassMetadata(WEB_ROUTER_KEY, controller);
for (const propertyMeta of listPropertyMetas) {
const _data = this.data[propertyMeta.tag] || [];
const requestMeta = _.find(requestMetas, { method: propertyMeta.key })
if(requestMeta){
this.data[propertyMeta.tag] = _.uniq(_data.concat(
controllerOption.prefix + requestMeta.path
))
}
}
}
}