feat: 装饰器与装饰器路由注册

This commit is contained in:
手瓜一十雪 committed 2025-11-14 19:49:13 +08:00
1 parent 4f850cd4dc
commit eaa23b4719
13 files changed
+233 -28

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
// 日志装饰器
function log2(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (...args: any[]) {
console.log(`Calling ${propertyKey} with args: ${JSON.stringify(args)}`);
const result = originalMethod.apply(this, args);
console.log(`${propertyKey} returned: ${result}`);
return result;
};
return descriptor;
}
// 示例类
class MathOperations2 {
@log2
add(a: number, b: number): number {
return a + b;
}
@log2
multiply(a: number, b: number): number {
return a * b;
}
}
// 创建实例并调用方法
const math2 = new MathOperations2();
math2.add(1, 2); // 调用加法
math2.multiply(3, 4); // 调用乘法
+31
View File
@@ -0,0 +1,31 @@
// 日志装饰器
function log(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (...args: any[]) {
console.log(`Calling ${propertyKey} with args: ${JSON.stringify(args)}`);
const result = originalMethod.apply(this, args);
console.log(`${propertyKey} returned: ${result}`);
return result;
};
return descriptor;
}
// 示例类
class MathOperations {
@log
add(a: number, b: number): number {
return a + b;
}
@log
multiply(a: number, b: number): number {
return a * b;
}
}
// 创建实例并调用方法
const math = new MathOperations();
math.add(1, 2); // 调用加法
math.multiply(3, 4); // 调用乘法
+9
View File
@@ -4,6 +4,8 @@ import path, { resolve } from 'path';
import nodeResolve from '@rollup/plugin-node-resolve';
import { builtinModules } from 'module';
import napcatVersion from "napcat-vite/vite-plugin-version.js";
import { autoIncludeTSPlugin } from "napcat-vite/vite-auto-include.js";
import react from '@vitejs/plugin-react-swc';
//依赖排除
const external = [
@@ -11,8 +13,15 @@ const external = [
'ws',
'express'
];
const nodeModules = [...builtinModules, builtinModules.map((m) => `node:${m}`)].flat();
const ShellBaseConfigPlugin: PluginOption[] = [
react({ tsDecorators: true }),
autoIncludeTSPlugin({
entries: [
{ entry: 'napcat.ts', dir: path.resolve(__dirname, '../napcat-onebot/action/test') }
]
}),
cp({
targets: [
{ src: '../napcat-native/', dest: 'dist/native', flatten: false },