修改部分规则模块删除无用前端 新增前端界面

This commit is contained in:
zouju
2026-02-06 17:22:22 +08:00
parent 000f8d4bc5
commit a440094138
583 changed files with 26241 additions and 26046 deletions

View File

@@ -0,0 +1,70 @@
/*
* This file is part of the kernelstudio package.
*
* (c) 2014-2025 zlin <admin@kernelstudio.com>
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*/
export class EventError {
code: number;
status: number;
message: string | null;
stack: string | null;
constructor(code = 500, status = 500, message: string | null = null, stack: string | null = null) {
this.code = code;
this.status = status;
this.message = message;
this.stack = stack;
}
}
export class EventListener {
private readonly _listeners: Record<string, Function[]>;
constructor(listeners: Record<string, Function[]> = {}) {
this._listeners = listeners;
}
all(): Record<string, Function[]> {
return {...this._listeners}; // 返回副本,避免外部直接修改
}
has(name: string): boolean {
return Array.isArray(this._listeners[name]) && this._listeners[name].length > 0;
}
on(name: string, fn: Function): void {
if (!Array.isArray(this._listeners[name])) {
this._listeners[name] = [];
}
this._listeners[name].push(fn);
}
off(name: string): void {
delete this._listeners[name];
}
emit(name: string, options?: any): void {
const listeners = this._listeners[name];
if (Array.isArray(listeners)) {
// 复制一份避免在执行中修改数组导致问题
[...listeners].forEach(f => f(options));
}
}
}
export const safePreventDefault = (event: any) => {
if (event && typeof event.preventDefault === 'function') {
event.preventDefault();
}
}
export const safeStopPropagation = (event: any) => {
if (event && typeof event.stopPropagation === 'function') {
event.stopPropagation();
}
}