hortimagic 1.1.0 → 1.1.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/dist/hortimagic.iife.js +47 -15
- package/dist/hortimagic.js +49 -17
- package/dist/hortimagic.txt +49 -17
- package/dist/hortimagic.user.js +49 -17
- package/package.json +4 -3
- package/src/apps/config-app.ts +172 -0
- package/src/apps/dialog-app.ts +62 -0
- package/src/apps/index.ts +5 -0
- package/src/apps/log-app.ts +251 -0
- package/src/apps/main-app.ts +72 -0
- package/src/apps/script-app.ts +225 -0
- package/src/components/hm-swipe-cell.ts +2 -2
- package/src/core/Emitter.ts +129 -0
- package/src/core/Message.ts +179 -0
- package/src/core/decoder.ts +207 -0
- package/src/core/elements-hooks.ts +168 -0
- package/src/core/encoder.ts +154 -0
- package/src/core/index.ts +10 -0
- package/src/core/log-tools.ts +69 -0
- package/src/core/script-tools.ts +121 -0
- package/src/core/socket-tools.ts +118 -0
- package/src/core/store.ts +151 -0
- package/src/core/tools.ts +318 -0
- package/src/easy-tools.ts +141 -0
- package/src/holders/dialog.ts +9 -0
- package/src/holders/index.ts +4 -0
- package/src/holders/menu.ts +20 -0
- package/src/holders/move-panel.ts +9 -0
- package/src/holders/notification.ts +9 -0
- package/src/main.ts +49 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { movePanelHolder } from '../holders/move-panel';
|
|
2
|
+
import { LitElement, css, html } from 'lit';
|
|
3
|
+
// import { property } from 'lit/decorators.js';
|
|
4
|
+
import { HortimagicStore, saveStore, loadStore, reactive } from '../core/store';
|
|
5
|
+
import { logger } from '../core/log-tools';
|
|
6
|
+
|
|
7
|
+
class HmConfigApp extends LitElement {
|
|
8
|
+
// 返回一个只读的、响应式的快照
|
|
9
|
+
storeSnap = reactive.snapshot(HortimagicStore);
|
|
10
|
+
|
|
11
|
+
static styles = css`
|
|
12
|
+
.config-item {
|
|
13
|
+
margin: 10px 0;
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
render() {
|
|
18
|
+
return html`
|
|
19
|
+
<div class="config-item">
|
|
20
|
+
<hm-cell title-name="自动保存设置" description="修改设置或脚本列表后,将自动保存设置。">
|
|
21
|
+
<hm-switch
|
|
22
|
+
?checked="${this.storeSnap.autoSave}"
|
|
23
|
+
@hm-switch-change="${(e: CustomEvent) => {
|
|
24
|
+
HortimagicStore.autoSave = e.detail.checked;
|
|
25
|
+
saveStore();
|
|
26
|
+
}}"
|
|
27
|
+
></hm-switch>
|
|
28
|
+
</hm-cell>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<div class="config-item">
|
|
32
|
+
<hm-cell title-name="允许LOG输出" description="是否允许LOG级别的日志输出">
|
|
33
|
+
<hm-switch
|
|
34
|
+
?checked="${this.storeSnap.logFlag.log}"
|
|
35
|
+
@hm-switch-change="${(e: CustomEvent) => {
|
|
36
|
+
HortimagicStore.logFlag.log = e.detail.checked;
|
|
37
|
+
}}"
|
|
38
|
+
></hm-switch>
|
|
39
|
+
</hm-cell>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div class="config-item">
|
|
43
|
+
<hm-cell title-name="允许INFO输出" description="是否允许INFO级别的日志输出">
|
|
44
|
+
<hm-switch
|
|
45
|
+
?checked="${this.storeSnap.logFlag.info}"
|
|
46
|
+
@hm-switch-change="${(e: CustomEvent) => {
|
|
47
|
+
HortimagicStore.logFlag.info = e.detail.checked;
|
|
48
|
+
}}"
|
|
49
|
+
></hm-switch>
|
|
50
|
+
</hm-cell>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<div class="config-item">
|
|
54
|
+
<hm-cell title-name="允许DEBUG输出" description="是否允许DEBUG级别的日志输出">
|
|
55
|
+
<hm-switch
|
|
56
|
+
?checked="${this.storeSnap.logFlag.debug}"
|
|
57
|
+
@hm-switch-change="${(e: CustomEvent) => {
|
|
58
|
+
HortimagicStore.logFlag.debug = e.detail.checked;
|
|
59
|
+
}}"
|
|
60
|
+
></hm-switch>
|
|
61
|
+
</hm-cell>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div class="config-item">
|
|
65
|
+
<hm-cell title-name="允许WARN输出" description="是否允许WARN级别的日志输出">
|
|
66
|
+
<hm-switch
|
|
67
|
+
?checked="${this.storeSnap.logFlag.warn}"
|
|
68
|
+
@hm-switch-change="${(e: CustomEvent) => {
|
|
69
|
+
HortimagicStore.logFlag.warn = e.detail.checked;
|
|
70
|
+
}}"
|
|
71
|
+
></hm-switch>
|
|
72
|
+
</hm-cell>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
<div class="config-item">
|
|
76
|
+
<hm-cell title-name="允许ERROR输出" description="是否允许ERROR级别的日志输出">
|
|
77
|
+
<hm-switch
|
|
78
|
+
?checked="${this.storeSnap.logFlag.error}"
|
|
79
|
+
@hm-switch-change="${(e: CustomEvent) => {
|
|
80
|
+
HortimagicStore.logFlag.error = e.detail.checked;
|
|
81
|
+
}}"
|
|
82
|
+
></hm-switch>
|
|
83
|
+
</hm-cell>
|
|
84
|
+
</div>
|
|
85
|
+
<div class="config-item">
|
|
86
|
+
<hm-cell title-name="发送日志" description="打印要发送的消息">
|
|
87
|
+
<hm-switch
|
|
88
|
+
?checked="${this.storeSnap.messageLogFlag.send}"
|
|
89
|
+
@hm-switch-change="${(e: CustomEvent) => {
|
|
90
|
+
HortimagicStore.messageLogFlag.send = e.detail.checked;
|
|
91
|
+
}}"
|
|
92
|
+
></hm-switch>
|
|
93
|
+
</hm-cell>
|
|
94
|
+
</div>
|
|
95
|
+
<div class="config-item">
|
|
96
|
+
<hm-cell title-name="接收日志" description="打印接收到的消息">
|
|
97
|
+
<hm-switch
|
|
98
|
+
?checked="${this.storeSnap.messageLogFlag.receive}"
|
|
99
|
+
@hm-switch-change="${(e: CustomEvent) => {
|
|
100
|
+
HortimagicStore.messageLogFlag.receive = e.detail.checked;
|
|
101
|
+
}}"
|
|
102
|
+
></hm-switch>
|
|
103
|
+
</hm-cell>
|
|
104
|
+
</div>
|
|
105
|
+
<div class="config-item">
|
|
106
|
+
<hm-cell title-name="解码日志" description="打印解码后的消息">
|
|
107
|
+
<hm-switch
|
|
108
|
+
?checked="${this.storeSnap.messageLogFlag.decode}"
|
|
109
|
+
@hm-switch-change="${(e: CustomEvent) => {
|
|
110
|
+
HortimagicStore.messageLogFlag.decode = e.detail.checked;
|
|
111
|
+
}}"
|
|
112
|
+
></hm-switch>
|
|
113
|
+
</hm-cell>
|
|
114
|
+
</div>
|
|
115
|
+
<div class="config-item">
|
|
116
|
+
<hm-cell title-name="触发日志" description="打印要触发的消息">
|
|
117
|
+
<hm-switch
|
|
118
|
+
?checked="${this.storeSnap.messageLogFlag.emit}"
|
|
119
|
+
@hm-switch-change="${(e: CustomEvent) => {
|
|
120
|
+
HortimagicStore.messageLogFlag.emit = e.detail.checked;
|
|
121
|
+
}}"
|
|
122
|
+
></hm-switch>
|
|
123
|
+
</hm-cell>
|
|
124
|
+
</div>
|
|
125
|
+
|
|
126
|
+
<div class="config-item">
|
|
127
|
+
<hm-input
|
|
128
|
+
label="日志列表长度"
|
|
129
|
+
type="number"
|
|
130
|
+
.value="${this.storeSnap.logListLength}"
|
|
131
|
+
@hm-input-change="${(e: CustomEvent) => {
|
|
132
|
+
const value = parseInt(e.detail.value) || 100;
|
|
133
|
+
HortimagicStore.logListLength = value;
|
|
134
|
+
logger.debug('log list length changed:', value);
|
|
135
|
+
}}"
|
|
136
|
+
></hm-input>
|
|
137
|
+
</div>
|
|
138
|
+
`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function initConfigApp() {
|
|
143
|
+
customElements.define('hm-config-app', HmConfigApp);
|
|
144
|
+
let panel = document.createElement('hm-move-panel');
|
|
145
|
+
panel.titleContent = '设置';
|
|
146
|
+
panel.icon = 'config';
|
|
147
|
+
panel.leftButtonText = "读取"
|
|
148
|
+
panel.leftIcon = 'load';
|
|
149
|
+
panel.addEventListener('left-button-click', function () {
|
|
150
|
+
loadStore();
|
|
151
|
+
});
|
|
152
|
+
panel.rightButtonText = "保存"
|
|
153
|
+
panel.rightIcon = 'save';
|
|
154
|
+
panel.addEventListener('right-button-click', function () {
|
|
155
|
+
saveStore();
|
|
156
|
+
});
|
|
157
|
+
// panel.showMovePanel();
|
|
158
|
+
movePanelHolder.appendChild(panel);
|
|
159
|
+
let template = `
|
|
160
|
+
<hm-config-app></hm-config-app>
|
|
161
|
+
`;
|
|
162
|
+
panel.innerHTML = template;
|
|
163
|
+
let menuItem = document.createElement('hm-menu');
|
|
164
|
+
menuItem.content = "设置";
|
|
165
|
+
menuItem.isMenuItem = true;
|
|
166
|
+
menuItem.icon = 'config';
|
|
167
|
+
|
|
168
|
+
menuItem.addEventListener('hm-menu-click', function () {
|
|
169
|
+
panel.putTopToggel();
|
|
170
|
+
});
|
|
171
|
+
return menuItem;
|
|
172
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit';
|
|
2
|
+
import { property } from 'lit/decorators.js';
|
|
3
|
+
import { dialogHolder } from '../holders/dialog';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 对话框模块
|
|
7
|
+
* @slot - 默认slot
|
|
8
|
+
*/
|
|
9
|
+
export class HmDialogApp extends LitElement {
|
|
10
|
+
@property({ type: Boolean })
|
|
11
|
+
dialogOpen = false;
|
|
12
|
+
|
|
13
|
+
@property({ type: String })
|
|
14
|
+
message = '请做出选择';
|
|
15
|
+
|
|
16
|
+
@property({ type: Function })
|
|
17
|
+
closeCallback: Function | null = null;
|
|
18
|
+
@property({ type: Function })
|
|
19
|
+
cancelCallback: Function | null = null;
|
|
20
|
+
@property({ type: Function })
|
|
21
|
+
confirmCallback: Function | null = null;
|
|
22
|
+
/** 触发点击事件 */
|
|
23
|
+
handelClick() {
|
|
24
|
+
this.dispatchEvent(new CustomEvent('hmclick'));
|
|
25
|
+
}
|
|
26
|
+
static styles = css`
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
render() {
|
|
30
|
+
return html`
|
|
31
|
+
<hm-dialog
|
|
32
|
+
?isopen="${this.dialogOpen}"
|
|
33
|
+
@hm-dialog-close="${() => {
|
|
34
|
+
this.dialogOpen =
|
|
35
|
+
false;
|
|
36
|
+
}}"
|
|
37
|
+
@hm-dialog-cancel="${() => {
|
|
38
|
+
if (this.cancelCallback) this.cancelCallback();
|
|
39
|
+
}}"
|
|
40
|
+
@hm-dialog-confirm="${() => {
|
|
41
|
+
if (this.confirmCallback) this.confirmCallback();
|
|
42
|
+
}}"
|
|
43
|
+
>
|
|
44
|
+
<p>${this.message}</p>
|
|
45
|
+
</hm-dialog>
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 默认的对话框模块
|
|
51
|
+
*/
|
|
52
|
+
export const dialogApp: HmDialogApp = document.createElement('hm-dialog-app') as HmDialogApp;;
|
|
53
|
+
/** 初始化对话框模块 */
|
|
54
|
+
export async function initDialogApp() {
|
|
55
|
+
customElements.define('hm-dialog-app', HmDialogApp);
|
|
56
|
+
dialogApp.dialogOpen = false;
|
|
57
|
+
dialogApp.message = '请做出选择';
|
|
58
|
+
dialogApp.closeCallback = null;
|
|
59
|
+
dialogApp.cancelCallback = null;
|
|
60
|
+
dialogApp.confirmCallback = null;
|
|
61
|
+
dialogHolder.append(dialogApp);
|
|
62
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { movePanelHolder } from '../holders/move-panel';
|
|
2
|
+
import { LitElement, css, html } from 'lit';
|
|
3
|
+
import { property } from 'lit/decorators.js';
|
|
4
|
+
import { logEmitter } from '../core/log-tools';
|
|
5
|
+
import { HortimagicStore } from '../core/store';
|
|
6
|
+
|
|
7
|
+
interface LogEntry {
|
|
8
|
+
timestamp: Date;
|
|
9
|
+
level: string;
|
|
10
|
+
tag: string;
|
|
11
|
+
message: any[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class HmLogApp extends LitElement {
|
|
15
|
+
@property({ type: Array })
|
|
16
|
+
logList: LogEntry[] = [];
|
|
17
|
+
|
|
18
|
+
// 新增:记录每条日志的折叠状态
|
|
19
|
+
private foldState = new Map<string, boolean>();
|
|
20
|
+
|
|
21
|
+
constructor() {
|
|
22
|
+
super();
|
|
23
|
+
|
|
24
|
+
// 确保日志列表长度配置存在
|
|
25
|
+
if (HortimagicStore.logListLength < 1) {
|
|
26
|
+
HortimagicStore.logListLength = 50; // 默认保留50条日志
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
logEmitter.on('log', (tag: string, ...args: any[]) => {
|
|
30
|
+
// 从参数中提取日志级别
|
|
31
|
+
let level = 'log';
|
|
32
|
+
if (args.length > 0) {
|
|
33
|
+
// 通过检查console方法来确定日志级别
|
|
34
|
+
const firstArg = args[0];
|
|
35
|
+
if (typeof firstArg === 'string') {
|
|
36
|
+
if (firstArg.startsWith('[DEBUG]')) level = 'debug';
|
|
37
|
+
else if (firstArg.startsWith('[INFO]')) level = 'info';
|
|
38
|
+
else if (firstArg.startsWith('[WARN]')) level = 'warn';
|
|
39
|
+
else if (firstArg.startsWith('[ERROR]')) level = 'error';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 移除可能的级别标记
|
|
44
|
+
const cleanArgs = [...args];
|
|
45
|
+
if (cleanArgs.length > 0 && typeof cleanArgs[0] === 'string' &&
|
|
46
|
+
['[DEBUG]', '[INFO]', '[WARN]', '[ERROR]'].some(marker => cleanArgs[0].startsWith(marker))) {
|
|
47
|
+
cleanArgs.shift();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const logEntry: LogEntry = {
|
|
51
|
+
timestamp: new Date(),
|
|
52
|
+
level,
|
|
53
|
+
tag,
|
|
54
|
+
message: cleanArgs
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** 确保日志列表长度不超过最大长度 */
|
|
58
|
+
while (this.logList.length >= HortimagicStore.logListLength) {
|
|
59
|
+
this.logList.shift();
|
|
60
|
+
}
|
|
61
|
+
this.logList.push(logEntry);
|
|
62
|
+
this.requestUpdate();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static styles = css`
|
|
67
|
+
.log-container {
|
|
68
|
+
height: 400px;
|
|
69
|
+
overflow-y: auto;
|
|
70
|
+
padding: 10px;
|
|
71
|
+
font-family: monospace;
|
|
72
|
+
background-color: #f5f5f5;
|
|
73
|
+
border: 1px solid #ddd;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.log-entry {
|
|
77
|
+
padding: 8px 0;
|
|
78
|
+
border-bottom: 1px solid #eee;
|
|
79
|
+
display: flex;
|
|
80
|
+
flex-direction: column;
|
|
81
|
+
margin-bottom: 10px; /* 增加日志条目之间的间距 */
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.log-header {
|
|
85
|
+
display: flex;
|
|
86
|
+
gap: 10px;
|
|
87
|
+
align-items: center;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.timestamp {
|
|
91
|
+
color: #999;
|
|
92
|
+
min-width: 100px;
|
|
93
|
+
flex-shrink: 0;
|
|
94
|
+
font-size: 12px; /* 调整时间戳字体大小 */
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.level {
|
|
98
|
+
min-width: 50px;
|
|
99
|
+
flex-shrink: 0;
|
|
100
|
+
font-weight: bold;
|
|
101
|
+
font-size: 14px; /* 调整日志级别字体大小 */
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.level.debug { color: #0099cc; }
|
|
105
|
+
.level.info { color: #009900; }
|
|
106
|
+
.level.warn { color: #ff9900; }
|
|
107
|
+
.level.error { color: #ff3333; }
|
|
108
|
+
|
|
109
|
+
.tag {
|
|
110
|
+
color: #666;
|
|
111
|
+
font-weight: bold;
|
|
112
|
+
min-width: 80px;
|
|
113
|
+
flex-shrink: 0;
|
|
114
|
+
font-size: 14px; /* 调整标签字体大小 */
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.message {
|
|
118
|
+
flex: 1;
|
|
119
|
+
word-break: break-word;
|
|
120
|
+
margin-top: 4px;
|
|
121
|
+
max-height: 60px; /* 限制高度,触发折叠 */
|
|
122
|
+
overflow: hidden;
|
|
123
|
+
cursor: pointer;
|
|
124
|
+
position: relative;
|
|
125
|
+
display: block; /* 确保每条消息独占一行 */
|
|
126
|
+
// 强制显示滚动条
|
|
127
|
+
scrollbar-width: auto; /* Firefox */
|
|
128
|
+
-ms-overflow-style: scrollbar; /* IE and Edge */
|
|
129
|
+
overflow-y: scroll; /* 强制显示垂直滚动条 */
|
|
130
|
+
font-size: 14px; /* 调整消息字体大小 */
|
|
131
|
+
line-height: 1.5; /* 调整行高 */
|
|
132
|
+
background-color: #fff; /* 设置背景色 */
|
|
133
|
+
padding: 5px; /* 添加内边距 */
|
|
134
|
+
border-radius: 4px; /* 圆角 */
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.message.collapsed::after {
|
|
138
|
+
content: " ...";
|
|
139
|
+
color: #999;
|
|
140
|
+
position: absolute;
|
|
141
|
+
bottom: 0;
|
|
142
|
+
right: 0;
|
|
143
|
+
background: linear-gradient(to right, transparent, #f5f5f5 70%);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.message.expanded {
|
|
147
|
+
max-height: none;
|
|
148
|
+
overflow: visible;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.controls {
|
|
152
|
+
padding: 10px;
|
|
153
|
+
display: flex;
|
|
154
|
+
gap: 10px;
|
|
155
|
+
background-color: #eaeaea; /* 设置控制区域背景色 */
|
|
156
|
+
border-bottom: 1px solid #ddd; /* 添加下边框 */
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.clear-btn {
|
|
160
|
+
background: #ff3333;
|
|
161
|
+
color: white;
|
|
162
|
+
border: none;
|
|
163
|
+
padding: 5px 10px;
|
|
164
|
+
cursor: pointer;
|
|
165
|
+
border-radius: 3px;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.clear-btn:hover {
|
|
169
|
+
background: #cc0000;
|
|
170
|
+
}
|
|
171
|
+
`;
|
|
172
|
+
|
|
173
|
+
render() {
|
|
174
|
+
return html`
|
|
175
|
+
<div class="controls">
|
|
176
|
+
<button class="clear-btn" @click="${this.clearLogs}">清空日志</button>
|
|
177
|
+
<span>共 ${this.logList.length} 条日志</span>
|
|
178
|
+
</div>
|
|
179
|
+
<div class="log-container">
|
|
180
|
+
${this.logList.map((entry: LogEntry) => {
|
|
181
|
+
const key = `${entry.timestamp.getTime()}-${entry.tag}-${entry.level}`;
|
|
182
|
+
const isExpanded = this.foldState.get(key) ?? false;
|
|
183
|
+
const messageStr = entry.message.map(msg =>
|
|
184
|
+
typeof msg === 'object' ? JSON.stringify(msg) : String(msg)
|
|
185
|
+
).join(' ');
|
|
186
|
+
|
|
187
|
+
// 判断是否需要折叠(例如超过一定字符数)
|
|
188
|
+
const shouldCollapse = messageStr.length > 100;
|
|
189
|
+
|
|
190
|
+
return html`
|
|
191
|
+
<div class="log-entry">
|
|
192
|
+
<div class="log-header">
|
|
193
|
+
<span class="timestamp">${this.formatTime(entry.timestamp)}</span>
|
|
194
|
+
<span class="level ${entry.level}">[${entry.level.toUpperCase()}]</span>
|
|
195
|
+
<span class="tag">${entry.tag}</span>
|
|
196
|
+
</div>
|
|
197
|
+
<div
|
|
198
|
+
class="message ${isExpanded || !shouldCollapse ? 'expanded' : 'collapsed'}"
|
|
199
|
+
@click="${() => this.toggleFold(key)}"
|
|
200
|
+
>
|
|
201
|
+
${isExpanded || !shouldCollapse ? messageStr : messageStr.substring(0, 100)}
|
|
202
|
+
</div>
|
|
203
|
+
</div>
|
|
204
|
+
`;
|
|
205
|
+
})}
|
|
206
|
+
</div>
|
|
207
|
+
`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private formatTime(date: Date): string {
|
|
211
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
|
212
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
213
|
+
const seconds = String(date.getSeconds()).padStart(2, '0');
|
|
214
|
+
const milliseconds = String(date.getMilliseconds()).padStart(3, '0');
|
|
215
|
+
return `${hours}:${minutes}:${seconds}.${milliseconds}`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private clearLogs() {
|
|
219
|
+
this.logList = [];
|
|
220
|
+
this.requestUpdate();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 新增:切换日志消息的折叠状态
|
|
224
|
+
private toggleFold(key: string) {
|
|
225
|
+
const currentState = this.foldState.get(key) ?? false;
|
|
226
|
+
this.foldState.set(key, !currentState);
|
|
227
|
+
this.requestUpdate();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function initLogApp() {
|
|
232
|
+
customElements.define('hm-log-app', HmLogApp);
|
|
233
|
+
let panel = document.createElement('hm-move-panel');
|
|
234
|
+
panel.titleContent = '日志';
|
|
235
|
+
panel.icon = 'log';
|
|
236
|
+
panel.width = 400;
|
|
237
|
+
|
|
238
|
+
// panel.showMovePanel();
|
|
239
|
+
movePanelHolder.appendChild(panel);
|
|
240
|
+
let template = `<hm-log-app></hm-log-app>`;
|
|
241
|
+
panel.innerHTML = template;
|
|
242
|
+
let menuItem = document.createElement('hm-menu');
|
|
243
|
+
menuItem.content = "日志";
|
|
244
|
+
menuItem.isMenuItem = true;
|
|
245
|
+
menuItem.icon = 'log';
|
|
246
|
+
|
|
247
|
+
menuItem.addEventListener('hm-menu-click', function () {
|
|
248
|
+
panel.putTopToggel();
|
|
249
|
+
});
|
|
250
|
+
return menuItem;
|
|
251
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { refreshAll, initHooks } from "../core/elements-hooks";
|
|
2
|
+
import { initSocket } from "../core/socket-tools";
|
|
3
|
+
import { ingecteScriptList } from "../core/script-tools";
|
|
4
|
+
import { initMenuHolder, menuHolder } from "../holders/menu";
|
|
5
|
+
import { initMovePanelHolder } from "../holders/move-panel";
|
|
6
|
+
import { initNotificationHolder } from "../holders/notification";
|
|
7
|
+
import { initDialogHolder } from "../holders/dialog";
|
|
8
|
+
|
|
9
|
+
import { initScriptApp } from "./script-app";
|
|
10
|
+
|
|
11
|
+
import pkg from '../../package.json' with { type: 'json' };
|
|
12
|
+
import { initDialogApp } from "./dialog-app";
|
|
13
|
+
import { notice } from "../easy-tools";
|
|
14
|
+
|
|
15
|
+
import { initStore } from "../core/store";
|
|
16
|
+
import { initConfigApp } from "./config-app";
|
|
17
|
+
import { initLogApp } from "./log-app";
|
|
18
|
+
async function init() {
|
|
19
|
+
try {
|
|
20
|
+
// 初始化配置项
|
|
21
|
+
initStore();
|
|
22
|
+
// 初始化所有容器
|
|
23
|
+
initNotificationHolder(); //先注入通知容器
|
|
24
|
+
initDialogHolder();
|
|
25
|
+
/** 先注弹窗app */
|
|
26
|
+
await initDialogApp();
|
|
27
|
+
initMenuHolder();
|
|
28
|
+
initMovePanelHolder();
|
|
29
|
+
// 初始化网络
|
|
30
|
+
notice.normal(pkg.name, '注入网络钩子函数')
|
|
31
|
+
await initSocket();
|
|
32
|
+
notice.normal(pkg.name, '注入钩子函数')
|
|
33
|
+
// 刷新查找所有元素
|
|
34
|
+
refreshAll();
|
|
35
|
+
// 添加所有钩子函数
|
|
36
|
+
initHooks();
|
|
37
|
+
// 注入脚本
|
|
38
|
+
notice.normal(pkg.name, '注入脚本')
|
|
39
|
+
ingecteScriptList();
|
|
40
|
+
notice.normal(pkg.name, '生成菜单')
|
|
41
|
+
/** 一级菜单 */
|
|
42
|
+
let menu = document.createElement('hm-menu');
|
|
43
|
+
menu.content = "HortiMagic";
|
|
44
|
+
menu.isMenuItem = false;
|
|
45
|
+
|
|
46
|
+
/** 二级菜单 */
|
|
47
|
+
let configMenu = initConfigApp();
|
|
48
|
+
let logMenu = initLogApp();
|
|
49
|
+
let scriptMenu = initScriptApp();
|
|
50
|
+
|
|
51
|
+
/** 菜单点击事件,开关对应的活动窗口 */
|
|
52
|
+
menu.addEventListener('hm-menu-click', function () {
|
|
53
|
+
// menu.flag 会自己改变
|
|
54
|
+
configMenu.flag = menu.flag;
|
|
55
|
+
logMenu.flag = menu.flag;
|
|
56
|
+
scriptMenu.flag = menu.flag;
|
|
57
|
+
});
|
|
58
|
+
menuHolder.append(menu, configMenu, logMenu, scriptMenu,);
|
|
59
|
+
// menuHolder.append(menu, configMenu, scriptMenu,);
|
|
60
|
+
notice.success(pkg.name, `${pkg.version} 已加载`);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(error);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
init
|
|
72
|
+
}
|