@pisell/core 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/app/app.d.ts +83 -0
- package/es/app/app.js +151 -0
- package/es/app/const.d.ts +4 -0
- package/es/app/const.js +6 -0
- package/es/app/index.d.ts +14 -0
- package/es/app/index.js +52 -0
- package/es/applicationManager/application.d.ts +50 -0
- package/es/applicationManager/application.js +223 -0
- package/es/applicationManager/index.d.ts +13 -0
- package/es/applicationManager/index.js +190 -0
- package/es/config.d.ts +3 -3
- package/es/config.js +5 -5
- package/es/cookie/index.d.ts +13 -0
- package/es/cookie/index.js +47 -0
- package/es/css/global.less +73 -0
- package/es/css/index.less +31 -0
- package/es/css/variables.css +84 -0
- package/es/data/index.d.ts +8 -0
- package/es/data/index.js +16 -0
- package/es/{locales → history}/config.d.ts +5 -5
- package/es/history/config.js +43 -0
- package/es/history/index.d.ts +20 -0
- package/es/history/index.js +41 -0
- package/es/history/type.d.ts +2 -0
- package/es/hooks/index.d.ts +12 -0
- package/es/hooks/index.js +13 -0
- package/es/hooks/useDelayedValue/index.d.ts +2 -0
- package/es/hooks/useDelayedValue/index.js +26 -0
- package/es/hooks/useDispatch/index.d.ts +2 -0
- package/es/hooks/useDispatch/index.js +2 -0
- package/es/hooks/useLowCode/index.d.ts +13 -0
- package/es/hooks/useLowCode/index.js +74 -0
- package/es/hooks/useStore/index.d.ts +6 -0
- package/es/hooks/useStore/index.js +11 -0
- package/es/index.d.ts +1 -2
- package/es/index.js +9 -2
- package/es/indexDB/index.d.ts +178 -0
- package/es/indexDB/index.js +542 -0
- package/es/locales/en.d.ts +2 -1
- package/es/locales/en.js +5 -1
- package/es/locales/index.d.ts +37 -53
- package/es/locales/index.js +213 -70
- package/es/locales/original.d.ts +3 -0
- package/es/locales/original.js +7 -0
- package/es/locales/type.d.ts +15 -5
- package/es/locales/zh-CN.d.ts +2 -1
- package/es/locales/zh-CN.js +5 -1
- package/es/locales/zh-HK.d.ts +2 -1
- package/es/locales/zh-HK.js +5 -1
- package/es/logger/feishu.d.ts +11 -0
- package/es/logger/feishu.js +50 -0
- package/es/logger/index.d.ts +122 -0
- package/es/logger/index.js +539 -0
- package/es/menuManager/hooks.d.ts +17 -0
- package/es/menuManager/hooks.js +136 -0
- package/es/menuManager/index.d.ts +28 -0
- package/es/menuManager/index.js +142 -0
- package/es/models/global.d.ts +32 -0
- package/es/models/global.js +66 -0
- package/es/models/index.d.ts +45 -0
- package/es/models/index.js +65 -0
- package/es/models/type.d.ts +2 -0
- package/es/models/type.js +1 -0
- package/es/plugin/index.d.ts +0 -0
- package/es/plugin/index.js +0 -0
- package/es/pubsub/example.d.ts +5 -0
- package/es/pubsub/example.js +92 -0
- package/es/pubsub/index.d.ts +63 -0
- package/es/pubsub/index.js +144 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/cache.js +311 -0
- package/es/request/cancelToken.d.ts +38 -0
- package/es/request/cancelToken.js +59 -0
- package/es/request/config.d.ts +3 -0
- package/es/request/config.js +58 -0
- package/es/request/constants.d.ts +2 -0
- package/es/request/constants.js +6 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/index.js +176 -0
- package/es/request/pisell2Request.d.ts +6 -0
- package/es/request/pisell2Request.js +62 -0
- package/es/request/type.d.ts +41 -0
- package/es/request/type.js +1 -0
- package/es/request/utils.d.ts +46 -0
- package/es/request/utils.js +147 -0
- package/es/routes/config.d.ts +7 -0
- package/es/routes/config.js +17 -0
- package/es/routes/index.d.ts +28 -0
- package/es/routes/index.js +148 -0
- package/es/socket/components/SocketMonitorPage.d.ts +6 -0
- package/es/socket/components/SocketMonitorPage.js +485 -0
- package/es/socket/components/index.d.ts +2 -0
- package/es/socket/components/index.js +2 -0
- package/es/socket/constants.d.ts +33 -0
- package/es/socket/constants.js +39 -0
- package/es/socket/events.d.ts +31 -0
- package/es/socket/events.js +19 -0
- package/es/socket/heartbeat.d.ts +66 -0
- package/es/socket/heartbeat.js +184 -0
- package/es/socket/index.d.ts +61 -0
- package/es/socket/index.js +246 -0
- package/es/socket/monitor.d.ts +169 -0
- package/es/socket/monitor.js +447 -0
- package/es/socket/reconnect.d.ts +61 -0
- package/es/socket/reconnect.js +199 -0
- package/es/socket/socket.d.ts +129 -0
- package/es/socket/socket.js +595 -0
- package/es/socket/types.d.ts +85 -0
- package/es/socket/types.js +35 -0
- package/es/storage/index.d.ts +17 -0
- package/es/storage/index.js +56 -0
- package/es/tasks/index.d.ts +77 -0
- package/es/tasks/index.js +743 -0
- package/es/tasks/type.d.ts +62 -0
- package/es/tasks/type.js +1 -0
- package/es/tasks/useTasks.d.ts +5 -0
- package/es/tasks/useTasks.js +25 -0
- package/es/type.d.ts +1 -1
- package/es/variables/VariablesProvider.d.ts +7 -0
- package/es/variables/VariablesProvider.js +12 -0
- package/es/variables/config.d.ts +3 -0
- package/es/variables/config.js +16 -0
- package/es/variables/index.d.ts +6 -0
- package/es/variables/index.js +5 -0
- package/es/variables/type.d.ts +2 -0
- package/es/variables/type.js +1 -0
- package/es/website/index.d.ts +6 -0
- package/es/website/index.js +65 -0
- package/lib/app/app.d.ts +83 -0
- package/lib/app/app.js +125 -0
- package/lib/app/const.d.ts +4 -0
- package/lib/app/const.js +33 -0
- package/lib/app/index.d.ts +14 -0
- package/lib/app/index.js +76 -0
- package/lib/applicationManager/application.d.ts +50 -0
- package/lib/applicationManager/application.js +110 -0
- package/lib/applicationManager/index.d.ts +13 -0
- package/lib/applicationManager/index.js +76 -0
- package/lib/config.d.ts +3 -3
- package/lib/cookie/index.d.ts +13 -0
- package/lib/cookie/index.js +64 -0
- package/lib/css/global.less +73 -0
- package/lib/css/index.less +31 -0
- package/lib/css/variables.css +84 -0
- package/lib/data/index.d.ts +8 -0
- package/lib/data/index.js +35 -0
- package/lib/{locales → history}/config.d.ts +5 -5
- package/lib/history/config.js +41 -0
- package/lib/history/index.d.ts +20 -0
- package/lib/history/index.js +58 -0
- package/lib/history/type.d.ts +2 -0
- package/lib/history/type.js +17 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/{date → hooks}/index.js +14 -20
- package/lib/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/hooks/useDelayedValue/index.js +36 -0
- package/lib/hooks/useDispatch/index.d.ts +2 -0
- package/lib/hooks/useDispatch/index.js +26 -0
- package/lib/hooks/useLowCode/index.d.ts +13 -0
- package/lib/hooks/useLowCode/index.js +75 -0
- package/lib/hooks/useStore/index.d.ts +6 -0
- package/lib/hooks/useStore/index.js +33 -0
- package/lib/index.d.ts +1 -2
- package/lib/index.js +3 -22
- package/lib/indexDB/index.d.ts +178 -0
- package/lib/indexDB/index.js +277 -0
- package/lib/locales/en.d.ts +2 -1
- package/lib/locales/en.js +5 -1
- package/lib/locales/index.d.ts +37 -53
- package/lib/locales/index.js +130 -41
- package/lib/locales/original.d.ts +3 -0
- package/lib/locales/original.js +31 -0
- package/lib/locales/type.d.ts +15 -5
- package/lib/locales/zh-CN.d.ts +2 -1
- package/lib/locales/zh-CN.js +5 -1
- package/lib/locales/zh-HK.d.ts +2 -1
- package/lib/locales/zh-HK.js +5 -1
- package/lib/logger/feishu.d.ts +11 -0
- package/lib/logger/feishu.js +52 -0
- package/lib/logger/index.d.ts +122 -0
- package/lib/logger/index.js +288 -0
- package/lib/menuManager/hooks.d.ts +17 -0
- package/lib/menuManager/hooks.js +135 -0
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/menuManager/index.js +110 -0
- package/lib/models/global.d.ts +32 -0
- package/lib/models/global.js +62 -0
- package/lib/models/index.d.ts +45 -0
- package/lib/models/index.js +69 -0
- package/lib/models/type.d.ts +2 -0
- package/lib/models/type.js +17 -0
- package/lib/plugin/index.d.ts +0 -0
- package/lib/plugin/index.js +0 -0
- package/lib/pubsub/example.d.ts +5 -0
- package/lib/pubsub/example.js +61 -0
- package/lib/pubsub/index.d.ts +63 -0
- package/lib/pubsub/index.js +129 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/cache.js +159 -0
- package/lib/request/cancelToken.d.ts +38 -0
- package/lib/request/cancelToken.js +59 -0
- package/lib/request/config.d.ts +3 -0
- package/lib/request/config.js +64 -0
- package/lib/request/constants.d.ts +2 -0
- package/lib/request/constants.js +34 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/index.js +147 -0
- package/lib/request/pisell2Request.d.ts +6 -0
- package/lib/request/pisell2Request.js +75 -0
- package/lib/request/type.d.ts +41 -0
- package/lib/request/type.js +17 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/request/utils.js +113 -0
- package/lib/routes/config.d.ts +7 -0
- package/lib/routes/config.js +50 -0
- package/lib/routes/index.d.ts +28 -0
- package/lib/routes/index.js +118 -0
- package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/socket/components/SocketMonitorPage.js +346 -0
- package/lib/socket/components/index.d.ts +2 -0
- package/lib/socket/components/index.js +39 -0
- package/lib/socket/constants.d.ts +33 -0
- package/lib/socket/constants.js +62 -0
- package/lib/socket/events.d.ts +31 -0
- package/lib/socket/events.js +44 -0
- package/lib/socket/heartbeat.d.ts +66 -0
- package/lib/socket/heartbeat.js +152 -0
- package/lib/socket/index.d.ts +61 -0
- package/lib/socket/index.js +200 -0
- package/lib/socket/monitor.d.ts +169 -0
- package/lib/socket/monitor.js +346 -0
- package/lib/socket/reconnect.d.ts +61 -0
- package/lib/socket/reconnect.js +153 -0
- package/lib/socket/socket.d.ts +129 -0
- package/lib/socket/socket.js +410 -0
- package/lib/socket/types.d.ts +85 -0
- package/lib/socket/types.js +36 -0
- package/lib/storage/index.d.ts +17 -0
- package/lib/storage/index.js +63 -0
- package/lib/tasks/index.d.ts +77 -0
- package/lib/tasks/index.js +438 -0
- package/lib/tasks/type.d.ts +62 -0
- package/lib/{date → tasks}/type.js +1 -1
- package/lib/tasks/useTasks.d.ts +5 -0
- package/lib/tasks/useTasks.js +37 -0
- package/lib/type.d.ts +1 -1
- package/lib/variables/VariablesProvider.d.ts +7 -0
- package/lib/{locales/config.js → variables/VariablesProvider.js} +17 -29
- package/lib/variables/config.d.ts +3 -0
- package/lib/{date → variables}/config.js +2 -7
- package/lib/variables/index.d.ts +6 -0
- package/lib/variables/index.js +29 -0
- package/lib/variables/type.d.ts +2 -0
- package/lib/variables/type.js +17 -0
- package/lib/website/index.d.ts +6 -0
- package/lib/website/index.js +75 -0
- package/package.json +22 -5
- package/es/date/config.d.ts +0 -3
- package/es/date/config.js +0 -21
- package/es/date/index.d.ts +0 -7
- package/es/date/index.js +0 -22
- package/es/date/type.d.ts +0 -7
- package/es/locales/config.js +0 -57
- package/lib/date/config.d.ts +0 -3
- package/lib/date/index.d.ts +0 -7
- package/lib/date/type.d.ts +0 -7
- /package/es/{date → history}/type.js +0 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/logger/feishu.ts
|
|
20
|
+
var feishu_exports = {};
|
|
21
|
+
__export(feishu_exports, {
|
|
22
|
+
sendWarningLog: () => sendWarningLog
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(feishu_exports);
|
|
25
|
+
var createFeishuMessageContent = (contentArr) => {
|
|
26
|
+
return JSON.stringify(
|
|
27
|
+
contentArr.map((item) => {
|
|
28
|
+
return [
|
|
29
|
+
{ tag: "text", text: `${item.key}: ` },
|
|
30
|
+
{ tag: "text", text: `${item.value}` }
|
|
31
|
+
];
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
var sendWarningLog = async ({ title, content, webhook }) => {
|
|
36
|
+
const contentStr = createFeishuMessageContent(content);
|
|
37
|
+
const response = await fetch(webhook, {
|
|
38
|
+
headers: {
|
|
39
|
+
"Content-Type": "application/json"
|
|
40
|
+
},
|
|
41
|
+
method: "POST",
|
|
42
|
+
body: JSON.stringify({
|
|
43
|
+
msg_type: "post",
|
|
44
|
+
content: `{"post":{"zh_cn":{"title":"${title}","content":${contentStr}}}}`
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
return await response.json();
|
|
48
|
+
};
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
sendWarningLog
|
|
52
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import App from "../app";
|
|
2
|
+
export type LogConsoleType = "info" | "warning" | "error" | "debug";
|
|
3
|
+
/**
|
|
4
|
+
* 日志项接口
|
|
5
|
+
*/
|
|
6
|
+
interface LogItem {
|
|
7
|
+
type: LogConsoleType;
|
|
8
|
+
title: string;
|
|
9
|
+
date?: string;
|
|
10
|
+
metadata?: any;
|
|
11
|
+
}
|
|
12
|
+
interface LogFile {
|
|
13
|
+
fileName: string;
|
|
14
|
+
date: string;
|
|
15
|
+
fileContent: LogFileContent;
|
|
16
|
+
}
|
|
17
|
+
interface LogFileContent {
|
|
18
|
+
metadata: any;
|
|
19
|
+
logs: LogItem[];
|
|
20
|
+
}
|
|
21
|
+
export interface LoggerOptions {
|
|
22
|
+
prefix?: string;
|
|
23
|
+
checkInterval?: number;
|
|
24
|
+
feishuConfig?: any;
|
|
25
|
+
retentionDays?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 日志管理器类
|
|
29
|
+
*/
|
|
30
|
+
declare class LoggerManager {
|
|
31
|
+
private logBuffer;
|
|
32
|
+
private timer;
|
|
33
|
+
private checkInterval;
|
|
34
|
+
private prefix;
|
|
35
|
+
private metadata;
|
|
36
|
+
private db;
|
|
37
|
+
private app;
|
|
38
|
+
private feishuConfig;
|
|
39
|
+
private retentionDays;
|
|
40
|
+
private metadataFunction;
|
|
41
|
+
/**
|
|
42
|
+
* 构造函数
|
|
43
|
+
* @param prefix 日志前缀
|
|
44
|
+
* @param checkInterval 检查间隔时间,默认5分钟
|
|
45
|
+
*/
|
|
46
|
+
constructor(app: App, options?: LoggerOptions);
|
|
47
|
+
init(): void;
|
|
48
|
+
/**
|
|
49
|
+
* 初始化 IndexDB
|
|
50
|
+
*/
|
|
51
|
+
private initDB;
|
|
52
|
+
/**
|
|
53
|
+
* 设置元数据
|
|
54
|
+
* @param metadata 元数据
|
|
55
|
+
*/
|
|
56
|
+
setMetadata(metadata: any): void;
|
|
57
|
+
setMetadataFunction(metadataFunction: () => any): void;
|
|
58
|
+
/**
|
|
59
|
+
* 初始化定时器
|
|
60
|
+
*/
|
|
61
|
+
initTimer(): void;
|
|
62
|
+
/**
|
|
63
|
+
* 添加日志
|
|
64
|
+
* @param log 日志项
|
|
65
|
+
*/
|
|
66
|
+
addLog(log: LogItem): void;
|
|
67
|
+
/**
|
|
68
|
+
* 发送飞书通知
|
|
69
|
+
* @param log 日志项
|
|
70
|
+
*/
|
|
71
|
+
private sendFeishuNotification;
|
|
72
|
+
/**
|
|
73
|
+
* 创建日志文件名
|
|
74
|
+
* @returns 日志文件名
|
|
75
|
+
*/
|
|
76
|
+
private createFileName;
|
|
77
|
+
/**
|
|
78
|
+
* 创建日志文件
|
|
79
|
+
* @param _fileName 文件名
|
|
80
|
+
* @returns 日志文件对象
|
|
81
|
+
*/
|
|
82
|
+
private createFile;
|
|
83
|
+
/**
|
|
84
|
+
* 存储日志到持久化存储
|
|
85
|
+
*/
|
|
86
|
+
private storeLog;
|
|
87
|
+
/**
|
|
88
|
+
* 清理旧日志,只保留最近指定天数的日志
|
|
89
|
+
*/
|
|
90
|
+
private cleanupOldLogs;
|
|
91
|
+
/**
|
|
92
|
+
* 获取日志文件列表
|
|
93
|
+
* @returns 日志文件列表
|
|
94
|
+
*/
|
|
95
|
+
getLogFiles(): Promise<LogFile[]>;
|
|
96
|
+
/**
|
|
97
|
+
* 获取指定日志文件的内容
|
|
98
|
+
* @param fileName 日志文件名
|
|
99
|
+
* @returns 日志文件内容
|
|
100
|
+
*/
|
|
101
|
+
getLogFile(fileName: string): Promise<LogFile | null>;
|
|
102
|
+
/**
|
|
103
|
+
* 清空指定日志文件
|
|
104
|
+
* @param fileName 日志文件名,不指定则清空所有日志
|
|
105
|
+
* @returns 是否成功
|
|
106
|
+
*/
|
|
107
|
+
clearLogs(fileName?: string): Promise<boolean>;
|
|
108
|
+
/**
|
|
109
|
+
* 设置日志保留天数
|
|
110
|
+
* @param days 保留天数
|
|
111
|
+
*/
|
|
112
|
+
setRetentionDays(days: number): void;
|
|
113
|
+
/**
|
|
114
|
+
* 手动触发清理旧日志
|
|
115
|
+
*/
|
|
116
|
+
manualCleanup(): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* 销毁实例
|
|
119
|
+
*/
|
|
120
|
+
destroy(): void;
|
|
121
|
+
}
|
|
122
|
+
export default LoggerManager;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/logger/index.ts
|
|
30
|
+
var logger_exports = {};
|
|
31
|
+
__export(logger_exports, {
|
|
32
|
+
default: () => logger_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(logger_exports);
|
|
35
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
36
|
+
var import_feishu = require("./feishu");
|
|
37
|
+
var LoggerManager = class {
|
|
38
|
+
/**
|
|
39
|
+
* 构造函数
|
|
40
|
+
* @param prefix 日志前缀
|
|
41
|
+
* @param checkInterval 检查间隔时间,默认5分钟
|
|
42
|
+
*/
|
|
43
|
+
constructor(app, options) {
|
|
44
|
+
// 私有属性
|
|
45
|
+
this.logBuffer = [];
|
|
46
|
+
// 日志缓冲区
|
|
47
|
+
this.timer = null;
|
|
48
|
+
// 检查间隔时间(毫秒)
|
|
49
|
+
this.prefix = "app";
|
|
50
|
+
this.db = null;
|
|
51
|
+
this.prefix = (options == null ? void 0 : options.prefix) || "app";
|
|
52
|
+
this.checkInterval = (options == null ? void 0 : options.checkInterval) || 5 * 60 * 1e3;
|
|
53
|
+
this.app = app;
|
|
54
|
+
this.feishuConfig = options == null ? void 0 : options.feishuConfig;
|
|
55
|
+
this.retentionDays = (options == null ? void 0 : options.retentionDays) || 7;
|
|
56
|
+
this.initDB();
|
|
57
|
+
}
|
|
58
|
+
init() {
|
|
59
|
+
this.initTimer();
|
|
60
|
+
this.cleanupOldLogs();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 初始化 IndexDB
|
|
64
|
+
*/
|
|
65
|
+
async initDB() {
|
|
66
|
+
if (this.app.dbManager) {
|
|
67
|
+
this.db = this.app.dbManager;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 设置元数据
|
|
72
|
+
* @param metadata 元数据
|
|
73
|
+
*/
|
|
74
|
+
setMetadata(metadata) {
|
|
75
|
+
this.metadata = metadata;
|
|
76
|
+
}
|
|
77
|
+
setMetadataFunction(metadataFunction) {
|
|
78
|
+
this.metadataFunction = metadataFunction;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 初始化定时器
|
|
82
|
+
*/
|
|
83
|
+
initTimer() {
|
|
84
|
+
this.timer = setInterval(() => {
|
|
85
|
+
if (this.logBuffer.length > 0) {
|
|
86
|
+
this.storeLog();
|
|
87
|
+
}
|
|
88
|
+
}, this.checkInterval);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 添加日志
|
|
92
|
+
* @param log 日志项
|
|
93
|
+
*/
|
|
94
|
+
addLog(log) {
|
|
95
|
+
const logItem = {
|
|
96
|
+
...log,
|
|
97
|
+
date: log.date || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss"),
|
|
98
|
+
metadata: JSON.stringify(log.metadata || "{}")
|
|
99
|
+
};
|
|
100
|
+
console.log("---- 行为日志", logItem);
|
|
101
|
+
if (log.type === "error") {
|
|
102
|
+
this.sendFeishuNotification(logItem);
|
|
103
|
+
}
|
|
104
|
+
this.logBuffer.push(logItem);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 发送飞书通知
|
|
108
|
+
* @param log 日志项
|
|
109
|
+
*/
|
|
110
|
+
sendFeishuNotification(log) {
|
|
111
|
+
var _a;
|
|
112
|
+
if (this.feishuConfig) {
|
|
113
|
+
const _metadata = ((_a = this.metadataFunction) == null ? void 0 : _a.call(this)) || {};
|
|
114
|
+
(0, import_feishu.sendWarningLog)({
|
|
115
|
+
title: log.title,
|
|
116
|
+
content: [
|
|
117
|
+
{ key: "日志类型", value: log.type },
|
|
118
|
+
{ key: "日志时间", value: log.date || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss") },
|
|
119
|
+
{ key: "日志来源", value: JSON.stringify({ ...this.metadata || {}, ..._metadata }) },
|
|
120
|
+
{ key: "日志内容", value: JSON.stringify(log.metadata) }
|
|
121
|
+
],
|
|
122
|
+
webhook: this.feishuConfig.webhook
|
|
123
|
+
});
|
|
124
|
+
console.log("-------- 发送飞书通知", log);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 创建日志文件名
|
|
129
|
+
* @returns 日志文件名
|
|
130
|
+
*/
|
|
131
|
+
createFileName(date) {
|
|
132
|
+
const _date = date || (0, import_dayjs.default)().format("YYYY-MM-DD-HH");
|
|
133
|
+
const fileName = `${this.prefix}_${_date}.log`;
|
|
134
|
+
return fileName;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 创建日志文件
|
|
138
|
+
* @param _fileName 文件名
|
|
139
|
+
* @returns 日志文件对象
|
|
140
|
+
*/
|
|
141
|
+
createFile(_fileName) {
|
|
142
|
+
const _date = (0, import_dayjs.default)().format("YYYY-MM-DD-HH");
|
|
143
|
+
const fileName = _fileName || this.createFileName(_date);
|
|
144
|
+
return {
|
|
145
|
+
fileName,
|
|
146
|
+
date: _date,
|
|
147
|
+
fileContent: {
|
|
148
|
+
metadata: this.metadata,
|
|
149
|
+
logs: []
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 存储日志到持久化存储
|
|
155
|
+
*/
|
|
156
|
+
async storeLog() {
|
|
157
|
+
if (this.logBuffer.length === 0 || !this.db) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const fileName = this.createFileName();
|
|
161
|
+
try {
|
|
162
|
+
let logFile = await this.db.get("logs", fileName);
|
|
163
|
+
if (!logFile) {
|
|
164
|
+
logFile = this.createFile(fileName);
|
|
165
|
+
await this.db.add("logs", logFile);
|
|
166
|
+
}
|
|
167
|
+
logFile.fileContent.logs = [...logFile.fileContent.logs, ...this.logBuffer];
|
|
168
|
+
await this.db.update("logs", logFile);
|
|
169
|
+
console.log("-------- 存储日志", {
|
|
170
|
+
fileName,
|
|
171
|
+
logFile
|
|
172
|
+
});
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error("存储日志到IndexDB失败:", error);
|
|
175
|
+
}
|
|
176
|
+
this.logBuffer = [];
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 清理旧日志,只保留最近指定天数的日志
|
|
180
|
+
*/
|
|
181
|
+
async cleanupOldLogs() {
|
|
182
|
+
if (!this.db) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
const logFiles = await this.getLogFiles();
|
|
187
|
+
const cutoffDate = (0, import_dayjs.default)().subtract(this.retentionDays, "day").format("YYYY-MM-DD");
|
|
188
|
+
const filesToDelete = logFiles.filter((file) => file.date < cutoffDate);
|
|
189
|
+
console.log(`-------- 清理旧日志,保留 ${this.retentionDays} 天内的日志,截止日期: ${cutoffDate}`);
|
|
190
|
+
for (const file of filesToDelete) {
|
|
191
|
+
await this.db.delete("logs", file.fileName);
|
|
192
|
+
console.log(`-------- 删除旧日志文件: ${file.fileName}, 日期: ${file.date}`);
|
|
193
|
+
}
|
|
194
|
+
if (filesToDelete.length > 0) {
|
|
195
|
+
console.log(`-------- 共清理 ${filesToDelete.length} 个旧日志文件`);
|
|
196
|
+
}
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.error("清理旧日志失败:", error);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* 获取日志文件列表
|
|
203
|
+
* @returns 日志文件列表
|
|
204
|
+
*/
|
|
205
|
+
async getLogFiles() {
|
|
206
|
+
if (!this.db) {
|
|
207
|
+
return [];
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
return await this.db.getAll("logs");
|
|
211
|
+
} catch (error) {
|
|
212
|
+
console.error("获取日志文件列表失败:", error);
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* 获取指定日志文件的内容
|
|
218
|
+
* @param fileName 日志文件名
|
|
219
|
+
* @returns 日志文件内容
|
|
220
|
+
*/
|
|
221
|
+
async getLogFile(fileName) {
|
|
222
|
+
if (!this.db) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
return await this.db.get("logs", fileName);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
console.error("获取日志文件内容失败:", error);
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* 清空指定日志文件
|
|
234
|
+
* @param fileName 日志文件名,不指定则清空所有日志
|
|
235
|
+
* @returns 是否成功
|
|
236
|
+
*/
|
|
237
|
+
async clearLogs(fileName) {
|
|
238
|
+
if (!this.db) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
if (fileName) {
|
|
243
|
+
await this.db.delete("logs", fileName);
|
|
244
|
+
} else {
|
|
245
|
+
await this.db.clear("logs");
|
|
246
|
+
}
|
|
247
|
+
return true;
|
|
248
|
+
} catch (error) {
|
|
249
|
+
console.error("清空日志失败:", error);
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* 设置日志保留天数
|
|
255
|
+
* @param days 保留天数
|
|
256
|
+
*/
|
|
257
|
+
setRetentionDays(days) {
|
|
258
|
+
if (days > 0) {
|
|
259
|
+
this.retentionDays = days;
|
|
260
|
+
console.log(`-------- 设置日志保留天数为 ${days} 天`);
|
|
261
|
+
} else {
|
|
262
|
+
console.error("日志保留天数必须大于0");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* 手动触发清理旧日志
|
|
267
|
+
*/
|
|
268
|
+
async manualCleanup() {
|
|
269
|
+
await this.cleanupOldLogs();
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* 销毁实例
|
|
273
|
+
*/
|
|
274
|
+
destroy() {
|
|
275
|
+
if (this.timer) {
|
|
276
|
+
clearInterval(this.timer);
|
|
277
|
+
this.timer = null;
|
|
278
|
+
}
|
|
279
|
+
if (this.logBuffer.length > 0) {
|
|
280
|
+
this.storeLog();
|
|
281
|
+
}
|
|
282
|
+
if (this.db) {
|
|
283
|
+
this.db.close();
|
|
284
|
+
this.db = null;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
var logger_default = LoggerManager;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { MenuItem } from "./index";
|
|
3
|
+
export declare const isHttp: (url: string) => boolean;
|
|
4
|
+
export interface MenuContextType {
|
|
5
|
+
selectedKeys: string[];
|
|
6
|
+
openKeys: string[];
|
|
7
|
+
setOpenKeys: (keys: string[]) => void;
|
|
8
|
+
handleClick: (key: string) => void;
|
|
9
|
+
menuItems: MenuItem[];
|
|
10
|
+
getShowChildren: (children: MenuItem[]) => MenuItem[];
|
|
11
|
+
setMenuItems: (items: MenuItem[]) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const MenuProvider: React.FC<{
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
menus: MenuItem[];
|
|
16
|
+
}>;
|
|
17
|
+
export declare const useMenu: () => MenuContextType;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/menuManager/hooks.tsx
|
|
30
|
+
var hooks_exports = {};
|
|
31
|
+
__export(hooks_exports, {
|
|
32
|
+
MenuProvider: () => MenuProvider,
|
|
33
|
+
isHttp: () => isHttp,
|
|
34
|
+
useMenu: () => useMenu
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
37
|
+
var import_react = __toESM(require("react"));
|
|
38
|
+
var import_app = require("../app");
|
|
39
|
+
var isHttp = (url) => {
|
|
40
|
+
return /^http(s)?:\/\//.test(url);
|
|
41
|
+
};
|
|
42
|
+
function handleRouteParams(targetPath, currentPath) {
|
|
43
|
+
if (!targetPath.includes(":")) {
|
|
44
|
+
return targetPath;
|
|
45
|
+
}
|
|
46
|
+
const currentParams = {};
|
|
47
|
+
const pathSegments = currentPath.split("/");
|
|
48
|
+
const targetSegments = targetPath.split("/");
|
|
49
|
+
targetSegments.forEach((segment, index) => {
|
|
50
|
+
if (segment.startsWith(":")) {
|
|
51
|
+
const paramName = segment.slice(1);
|
|
52
|
+
currentParams[paramName] = pathSegments[index] || "";
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return targetPath.replace(/:(\w+)/g, (match, key) => {
|
|
56
|
+
var _a;
|
|
57
|
+
return ((_a = currentParams[key]) == null ? void 0 : _a.toString()) || match;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
var MenuContext = (0, import_react.createContext)(void 0);
|
|
61
|
+
var MenuProvider = ({ children, menus }) => {
|
|
62
|
+
const { app } = (0, import_app.useApp)();
|
|
63
|
+
const menuManager = app.menuManager;
|
|
64
|
+
const location = app.history.useLocation();
|
|
65
|
+
const [selectedKeys, setSelectedKeys] = (0, import_react.useState)([]);
|
|
66
|
+
const [openKeys, setOpenKeys] = (0, import_react.useState)([]);
|
|
67
|
+
const [menuItems, setMenuItems] = (0, import_react.useState)(menus);
|
|
68
|
+
(0, import_react.useEffect)(() => {
|
|
69
|
+
app.menuManager.set(menuItems);
|
|
70
|
+
}, [menuItems]);
|
|
71
|
+
(0, import_react.useEffect)(() => {
|
|
72
|
+
const pathname = location.pathname;
|
|
73
|
+
if (!pathname) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const currentMenuItem = menuManager.findMenuItemByPath(menuItems, pathname);
|
|
77
|
+
if (currentMenuItem) {
|
|
78
|
+
setSelectedKeys([currentMenuItem.key]);
|
|
79
|
+
const parent = menuManager.findParent(menuItems, currentMenuItem.key);
|
|
80
|
+
if (parent) {
|
|
81
|
+
const _children = menuManager.getShowChildren(parent.children || []);
|
|
82
|
+
if (_children == null ? void 0 : _children.length) {
|
|
83
|
+
setOpenKeys((prevKeys) => [.../* @__PURE__ */ new Set([...prevKeys, parent.key])]);
|
|
84
|
+
} else {
|
|
85
|
+
setSelectedKeys([parent.key]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, [location, menuItems]);
|
|
90
|
+
const handleClick = (key) => {
|
|
91
|
+
try {
|
|
92
|
+
if (!key) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (isHttp(key)) {
|
|
96
|
+
window.open(key, "_blank");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const newPath = handleRouteParams(key, location.pathname);
|
|
100
|
+
if (newPath !== location.pathname) {
|
|
101
|
+
app.history.push(newPath);
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error("Menu navigation error:", error);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
108
|
+
MenuContext.Provider,
|
|
109
|
+
{
|
|
110
|
+
value: {
|
|
111
|
+
selectedKeys,
|
|
112
|
+
openKeys,
|
|
113
|
+
setOpenKeys,
|
|
114
|
+
handleClick,
|
|
115
|
+
menuItems,
|
|
116
|
+
getShowChildren: menuManager.getShowChildren,
|
|
117
|
+
setMenuItems
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
children
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
var useMenu = () => {
|
|
124
|
+
const context = (0, import_react.useContext)(MenuContext);
|
|
125
|
+
if (context === void 0) {
|
|
126
|
+
throw new Error("useMenu must be used within a MenuProvider");
|
|
127
|
+
}
|
|
128
|
+
return context;
|
|
129
|
+
};
|
|
130
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
131
|
+
0 && (module.exports = {
|
|
132
|
+
MenuProvider,
|
|
133
|
+
isHttp,
|
|
134
|
+
useMenu
|
|
135
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import App from '../app';
|
|
3
|
+
export interface MenuItem {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
path: string;
|
|
7
|
+
children?: MenuItem[];
|
|
8
|
+
icon?: string | React.ReactNode;
|
|
9
|
+
hide?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class MenuManager {
|
|
12
|
+
private menuItems;
|
|
13
|
+
private menuMaps;
|
|
14
|
+
private app;
|
|
15
|
+
useMenu: () => import("./hooks").MenuContextType;
|
|
16
|
+
MenuProvider: React.FC<{
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
menus: MenuItem[];
|
|
19
|
+
}>;
|
|
20
|
+
constructor(items: MenuItem[], app: App);
|
|
21
|
+
set(items: MenuItem[]): void;
|
|
22
|
+
getMenus(): MenuItem[];
|
|
23
|
+
getMenuMaps(): void;
|
|
24
|
+
findMenuItemByPath(items: MenuItem[], path: string): MenuItem | null;
|
|
25
|
+
findParent(items: MenuItem[], key: string, parent?: MenuItem | null): MenuItem | null;
|
|
26
|
+
getShowChildren(items: MenuItem[]): MenuItem[];
|
|
27
|
+
findMenuItemByKey(items: MenuItem[], key: string): MenuItem | null;
|
|
28
|
+
}
|