w-web-api 1.0.74 → 1.0.76
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/README.md +99 -99
- package/dist/css/{app.3a6c6dd2.css → app.ae472c4d.css} +1 -1
- package/dist/index.tmp +1 -1
- package/dist/js/app-legacy.2aa145e5.js +1 -0
- package/dist/js/app.2aa145e5.js +1 -0
- package/dist/js/{chunk-vendors.516b8a46.js → chunk-vendors-legacy.47cf6375.js} +2 -2
- package/dist/js/{chunk-vendors-legacy.516b8a46.js → chunk-vendors.47cf6375.js} +2 -2
- package/dist/w-web-api.umd.js +1 -1
- package/docs/WWebApi.html +76 -2
- package/docs/index.html +1 -1
- package/docs/server_WWebApi.mjs.html +931 -931
- package/docs/src_components_Common_CheckYesNo.vue.html +1 -1
- package/{g.backupDb.mjs → g_backupDb.mjs} +10 -10
- package/{g.initialTestData.mjs → g_initialTestData.mjs} +21 -21
- package/{g.mOrm.mjs → g_mOrm.mjs} +24 -24
- package/{g.provideApis.mjs → g_provideApis.mjs} +53 -53
- package/logs/2026-08-25T20.log +0 -0
- package/logs/2026-08-25T21.log +1891 -0
- package/package.json +12 -12
- package/server/WWebApi.mjs +930 -930
- package/settings.json +1 -1
- package/src/components/LayoutContent.vue +637 -637
- package/src/components/LayoutContentStats.vue +557 -485
- package/srv.mjs +108 -108
- package/tableTags.json +1 -1
- package/dist/js/app-legacy.0999553a.js +0 -1
- package/dist/js/app.0999553a.js +0 -1
- /package/{g.getSettings.mjs → g_getSettings.mjs} +0 -0
|
@@ -1,485 +1,557 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="stats-panel" :style="`height:${height}px; overflow-y:auto; padding:20px 24px; box-sizing:border-box;`">
|
|
3
|
-
|
|
4
|
-
<!--
|
|
5
|
-
<div style="margin-bottom:16px;">
|
|
6
|
-
<div style="font-size:1.4rem; font-weight:600; color:var(--c-1);">{{$t('statisticsInformation')}}</div>
|
|
7
|
-
<div style="font-size:0.875rem; color:var(--c-3); margin-top:4px;">{{$t('statisticsInformationDescription')}}</div>
|
|
8
|
-
</div>
|
|
9
|
-
|
|
10
|
-
<!-- 控制區(事件選擇 + 時間範圍;把各事件分出來、可區分選取,供趨勢辨認 / 危險識別)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
<td>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
</
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
import
|
|
120
|
-
import
|
|
121
|
-
import
|
|
122
|
-
import
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
let
|
|
200
|
-
|
|
201
|
-
let
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
let
|
|
220
|
-
|
|
221
|
-
return
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
let
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
let
|
|
277
|
-
let
|
|
278
|
-
|
|
279
|
-
let
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
},
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
vo
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
.
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
.
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
.
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
border-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
.
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
.
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<div class="stats-panel" :style="`height:${height}px; overflow-y:auto; padding:20px 24px; box-sizing:border-box;`">
|
|
3
|
+
|
|
4
|
+
<!-- 標題列(ref 供 chartHeight 量測上方實佔高度) -->
|
|
5
|
+
<div ref="$hdr" style="margin-bottom:16px;">
|
|
6
|
+
<div style="font-size:1.4rem; font-weight:600; color:var(--c-1);">{{$t('statisticsInformation')}}</div>
|
|
7
|
+
<div style="font-size:0.875rem; color:var(--c-3); margin-top:4px;">{{$t('statisticsInformationDescription')}}</div>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<!-- 控制區(事件選擇 + 時間範圍;把各事件分出來、可區分選取,供趨勢辨認 / 危險識別)
|
|
11
|
+
結構性對齊:.ctrl 為兩欄 grid(label 欄寬 max-content 自動隨語系文字),.ctrl-row 以
|
|
12
|
+
display:contents 使 label 與 field 直接成為 grid 子項,中英文自動對齊,免寫死 label 寬度 -->
|
|
13
|
+
<div ref="$ctrl" class="ctrl">
|
|
14
|
+
|
|
15
|
+
<!-- 第一列:時間範圍 -->
|
|
16
|
+
<div class="ctrl-row">
|
|
17
|
+
<span class="ctrl-label">{{$t('timeRange')}}</span>
|
|
18
|
+
<div class="ctrl-field">
|
|
19
|
+
<select id="timeGroupSel" v-model="timeGroup" class="ctrl-select">
|
|
20
|
+
<option value="1hr">{{$t('selectItem1hr')}}</option>
|
|
21
|
+
<option value="4hr">{{$t('selectItem4hr')}}</option>
|
|
22
|
+
<option value="8hr">{{$t('selectItem8hr')}}</option>
|
|
23
|
+
<option value="1day">{{$t('selectItem1day')}}</option>
|
|
24
|
+
</select>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
<!-- 第二列:選擇事件 標題 + 全選/清除 -->
|
|
29
|
+
<div class="ctrl-row">
|
|
30
|
+
<span class="ctrl-label">{{$t('selectEvents')}}</span>
|
|
31
|
+
<div class="ctrl-field">
|
|
32
|
+
<button class="evt-sel-btn stats-sel-all" @click="selectAllEvents">{{$t('selectAll')}}</button>
|
|
33
|
+
<button class="evt-sel-btn stats-sel-none" @click="selectNoneEvents">{{$t('selectNone')}}</button>
|
|
34
|
+
<span class="evt-count">{{selectedEvents.length}}/{{allEvents.length}}</span>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<!-- 第三列:事件 chip(flex-wrap 內容自然寬;chip 依內容取寬、排滿可用寬才換行) -->
|
|
39
|
+
<div class="evt-grid">
|
|
40
|
+
<label
|
|
41
|
+
v-for="ev in allEvents"
|
|
42
|
+
:key="ev"
|
|
43
|
+
class="evt-chip"
|
|
44
|
+
:class="{on: selectedEvents.includes(ev)}"
|
|
45
|
+
:data-event="ev"
|
|
46
|
+
>
|
|
47
|
+
<input type="checkbox" class="stats-evt-cb" :value="ev" v-model="selectedEvents" />
|
|
48
|
+
<span class="evt-dot" :style="`background:${colorOf(ev)};`"></span>
|
|
49
|
+
<span class="evt-name">{{ev}}</span>
|
|
50
|
+
</label>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<!-- loading -->
|
|
56
|
+
<div v-if="loading" style="padding:12px 0; font-size:0.875rem; color:var(--c-3);">
|
|
57
|
+
{{$t('waitingData')}}
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<!-- 錯誤 -->
|
|
61
|
+
<div v-else-if="errMsg" style="padding:12px 0; font-size:0.875rem; color:var(--danger);">
|
|
62
|
+
{{errMsg}}
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<template v-else>
|
|
66
|
+
|
|
67
|
+
<!-- 圖表區(event 展示區;各選取事件各一系列、各自顏色,可區分趨勢) -->
|
|
68
|
+
<div class="stats-chart-area">
|
|
69
|
+
<div
|
|
70
|
+
v-if="hasNoData"
|
|
71
|
+
style="display:flex; align-items:center; justify-content:center; color:var(--c-3); font-size:0.875rem;"
|
|
72
|
+
:style="`height:${chartHeight}px;`"
|
|
73
|
+
>
|
|
74
|
+
{{$t('noStaData')}}
|
|
75
|
+
</div>
|
|
76
|
+
<WEchartsVue
|
|
77
|
+
v-else
|
|
78
|
+
:options="chartOption"
|
|
79
|
+
:style="`width:100%; height:${chartHeight}px;`"
|
|
80
|
+
></WEchartsVue>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<!-- 事件統計表(各事件為列,依最近1日總數多→少排序;欄位 1日/8時/4時/1時) -->
|
|
84
|
+
<div class="stats-table-area">
|
|
85
|
+
<div style="font-size:1rem; font-weight:600; color:var(--c-1); margin:18px 0 8px;">{{$t('eventStatsTable')}}</div>
|
|
86
|
+
<div v-if="eventRows.length === 0" style="font-size:0.875rem; color:var(--c-3); padding:8px 0;">
|
|
87
|
+
{{$t('noStaData')}}
|
|
88
|
+
</div>
|
|
89
|
+
<table v-else class="stats-table">
|
|
90
|
+
<thead>
|
|
91
|
+
<tr>
|
|
92
|
+
<th style="text-align:left;">{{$t('colEvent')}}</th>
|
|
93
|
+
<th>{{$t('colRecent1day')}}</th>
|
|
94
|
+
<th>{{$t('colRecent8hr')}}</th>
|
|
95
|
+
<th>{{$t('colRecent4hr')}}</th>
|
|
96
|
+
<th>{{$t('colRecent1hr')}}</th>
|
|
97
|
+
</tr>
|
|
98
|
+
</thead>
|
|
99
|
+
<tbody>
|
|
100
|
+
<tr v-for="row in eventRows" :key="row.event" :data-event="row.event">
|
|
101
|
+
<td style="text-align:left;">
|
|
102
|
+
<span class="evt-dot" :style="`background:${colorOf(row.event)};`"></span>{{row.event}}
|
|
103
|
+
</td>
|
|
104
|
+
<td>{{row.d1day}}</td>
|
|
105
|
+
<td>{{row.d8hr}}</td>
|
|
106
|
+
<td>{{row.d4hr}}</td>
|
|
107
|
+
<td>{{row.d1hr}}</td>
|
|
108
|
+
</tr>
|
|
109
|
+
</tbody>
|
|
110
|
+
</table>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
</template>
|
|
114
|
+
|
|
115
|
+
</div>
|
|
116
|
+
</template>
|
|
117
|
+
|
|
118
|
+
<script>
|
|
119
|
+
import ot from 'dayjs'
|
|
120
|
+
import get from 'lodash-es/get.js'
|
|
121
|
+
import map from 'lodash-es/map.js'
|
|
122
|
+
import keys from 'lodash-es/keys.js'
|
|
123
|
+
import groupBy from 'lodash-es/groupBy.js'
|
|
124
|
+
import sumBy from 'lodash-es/sumBy.js'
|
|
125
|
+
import reduce from 'lodash-es/reduce.js'
|
|
126
|
+
import size from 'lodash-es/size.js'
|
|
127
|
+
import isearr from 'wsemi/src/isearr.mjs'
|
|
128
|
+
import WEchartsVue from 'w-echarts-vue/src/components/WEchartsVue.vue'
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
//固定色票(依事件在 allEvents 之索引取色,使同一事件顏色穩定、圖表與表格與 chip 一致)
|
|
132
|
+
let COLORS = [
|
|
133
|
+
'#3b82f6', '#ef4444', '#10b981', '#f97316', '#8b5cf6',
|
|
134
|
+
'#6366f1', '#eab308', '#ec4899', '#14b8a6', '#a855f7',
|
|
135
|
+
'#0ea5e9', '#f43f5e', '#22c55e', '#d97706', '#7c3aed',
|
|
136
|
+
]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
export default {
|
|
140
|
+
components: {
|
|
141
|
+
WEchartsVue,
|
|
142
|
+
},
|
|
143
|
+
props: {
|
|
144
|
+
height: {
|
|
145
|
+
type: Number,
|
|
146
|
+
default: 400,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
data: function() {
|
|
150
|
+
return {
|
|
151
|
+
freq: [],
|
|
152
|
+
selectedEvents: [], //使用者選取要畫的事件(預設載入後全選)
|
|
153
|
+
eventsInited: false, //是否已用實際資料初始化過 selectedEvents
|
|
154
|
+
timeGroup: '1hr',
|
|
155
|
+
loading: false,
|
|
156
|
+
errMsg: '',
|
|
157
|
+
hUpper: 0, //標題列+控制區實佔高度(ResizeObserver 量測,供 chartHeight 計算;chip 換行數/語系皆會使其變化)
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
mounted: function() {
|
|
161
|
+
let vo = this
|
|
162
|
+
|
|
163
|
+
//ResizeObserver 量測標題列+控制區實佔高(含 margin),取代固定扣除值;
|
|
164
|
+
//ro 為瀏覽器原生物件不放 data(避免被深層響應化),掛 this 成非響應式屬性
|
|
165
|
+
let ro = new ResizeObserver(function() {
|
|
166
|
+
vo.updateUpperHeight()
|
|
167
|
+
})
|
|
168
|
+
if (vo.$refs['$hdr']) {
|
|
169
|
+
ro.observe(vo.$refs['$hdr'])
|
|
170
|
+
}
|
|
171
|
+
if (vo.$refs['$ctrl']) {
|
|
172
|
+
ro.observe(vo.$refs['$ctrl'])
|
|
173
|
+
}
|
|
174
|
+
vo.ro = ro
|
|
175
|
+
vo.updateUpperHeight()
|
|
176
|
+
|
|
177
|
+
vo.load()
|
|
178
|
+
},
|
|
179
|
+
beforeDestroy: function() {
|
|
180
|
+
let vo = this
|
|
181
|
+
if (vo.ro) {
|
|
182
|
+
vo.ro.disconnect()
|
|
183
|
+
vo.ro = null
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
computed: {
|
|
187
|
+
|
|
188
|
+
chartHeight: function() {
|
|
189
|
+
let vo = this
|
|
190
|
+
//panel 上下 padding 40 + 上方實佔(hUpper, 量測) + 表格預留 98(既有設計值:舊公式 height−360
|
|
191
|
+
//於 1440 下等價於保留 chart 底至 panel 內容底 98px,沿用該行為,非新設數字)
|
|
192
|
+
let TABLE_RESERVE = 98
|
|
193
|
+
let h = vo.height - 40 - vo.hUpper - TABLE_RESERVE
|
|
194
|
+
return h < 220 ? 220 : h
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
//所有出現過的事件名(union,排除 count),固定排序
|
|
198
|
+
allEvents: function() {
|
|
199
|
+
let vo = this
|
|
200
|
+
let kp = reduce(vo.freq, function(acc, item) {
|
|
201
|
+
let d = get(item, 'data', {})
|
|
202
|
+
keys(d).forEach(function(k) {
|
|
203
|
+
if (k !== 'count') {
|
|
204
|
+
acc[k] = true
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
return acc
|
|
208
|
+
}, {})
|
|
209
|
+
return keys(kp).sort()
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
//時間重採樣(1hr 不變;4hr/8hr/1day 同日合併)— 供圖表 x 軸
|
|
213
|
+
resampledData: function() {
|
|
214
|
+
let vo = this
|
|
215
|
+
let arr = vo.freq
|
|
216
|
+
if (!isearr(arr)) {
|
|
217
|
+
return []
|
|
218
|
+
}
|
|
219
|
+
let tg = vo.timeGroup
|
|
220
|
+
if (tg === '1hr') {
|
|
221
|
+
return arr
|
|
222
|
+
}
|
|
223
|
+
let groupHours = 4
|
|
224
|
+
if (tg === '8hr') {
|
|
225
|
+
groupHours = 8
|
|
226
|
+
}
|
|
227
|
+
else if (tg === '1day') {
|
|
228
|
+
groupHours = 24
|
|
229
|
+
}
|
|
230
|
+
let dataKeyList = vo.allEvents.concat(['count'])
|
|
231
|
+
let gs = groupBy(arr, function(item) {
|
|
232
|
+
let t = ot(item.time)
|
|
233
|
+
let h = t.hour()
|
|
234
|
+
let hGroup = Math.floor(h / groupHours)
|
|
235
|
+
let tNew = t.startOf('day').add(hGroup * groupHours, 'hour')
|
|
236
|
+
return tNew.format()
|
|
237
|
+
})
|
|
238
|
+
return map(gs, function(vs, timeKey) {
|
|
239
|
+
let merged = { time: timeKey, data: {} }
|
|
240
|
+
dataKeyList.forEach(function(k) {
|
|
241
|
+
merged.data[k] = sumBy(vs, function(item) {
|
|
242
|
+
return get(item, `data.${k}`, 0)
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
return merged
|
|
246
|
+
})
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
//實際要畫的系列 = 選取且存在於資料中的事件
|
|
250
|
+
seriesKeys: function() {
|
|
251
|
+
let vo = this
|
|
252
|
+
return vo.selectedEvents.filter(function(e) {
|
|
253
|
+
return vo.allEvents.includes(e)
|
|
254
|
+
})
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
hasNoData: function() {
|
|
258
|
+
let vo = this
|
|
259
|
+
let arr = vo.freq
|
|
260
|
+
if (!isearr(arr) || size(arr) === 0) {
|
|
261
|
+
return true
|
|
262
|
+
}
|
|
263
|
+
let total = reduce(arr, function(sum, item) {
|
|
264
|
+
return sum + get(item, 'data.count', 0)
|
|
265
|
+
}, 0)
|
|
266
|
+
return total === 0
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
chartOption: function() {
|
|
270
|
+
let vo = this
|
|
271
|
+
let data = vo.resampledData
|
|
272
|
+
let tg = vo.timeGroup
|
|
273
|
+
let sKeys = vo.seriesKeys
|
|
274
|
+
|
|
275
|
+
let formatX = tg === '1day' ? 'MM/DD' : 'MM/DD\nHH:mm'
|
|
276
|
+
let totalBars = size(sKeys) || 1
|
|
277
|
+
let barWidthPct = Math.max(3, Math.floor(100 / (totalBars * 1.5))) + '%'
|
|
278
|
+
|
|
279
|
+
let series = map(sKeys, function(valueKey) {
|
|
280
|
+
return {
|
|
281
|
+
name: valueKey,
|
|
282
|
+
type: 'bar',
|
|
283
|
+
barWidth: barWidthPct,
|
|
284
|
+
data: map(data, function(item) {
|
|
285
|
+
return get(item, `data.${valueKey}`, 0)
|
|
286
|
+
}),
|
|
287
|
+
itemStyle: { color: vo.colorOf(valueKey) },
|
|
288
|
+
emphasis: { focus: 'series' },
|
|
289
|
+
}
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
|
|
294
|
+
legend: { show: true, type: 'scroll', top: 0 }, //top須明給: echarts 6 起 legend 預設由 top:0 改為 bottom, 不給會落到底部壓住 x 軸時間標籤
|
|
295
|
+
grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
|
|
296
|
+
xAxis: [{
|
|
297
|
+
type: 'category',
|
|
298
|
+
data: map(data, function(item) { return ot(item.time).format(formatX) }),
|
|
299
|
+
axisTick: { alignWithLabel: true },
|
|
300
|
+
}],
|
|
301
|
+
yAxis: [{ type: 'value' }],
|
|
302
|
+
series: series,
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
|
|
306
|
+
//事件統計表:各事件之最近 1日/8時/4時/1時 計數(由小時 bucket 加總最後 N 桶),依 1日 多→少排序
|
|
307
|
+
eventRows: function() {
|
|
308
|
+
let vo = this
|
|
309
|
+
let arr = isearr(vo.freq) ? vo.freq : []
|
|
310
|
+
//freq 由後端依時間遞增排序;取最後 N 個小時 bucket 對應「最近 N 小時」
|
|
311
|
+
let sumLastN = function(ev, n) {
|
|
312
|
+
let bs = arr.slice(-n)
|
|
313
|
+
return reduce(bs, function(s, item) {
|
|
314
|
+
return s + get(item, `data.${ev}`, 0)
|
|
315
|
+
}, 0)
|
|
316
|
+
}
|
|
317
|
+
let rows = vo.allEvents.map(function(ev) {
|
|
318
|
+
return {
|
|
319
|
+
event: ev,
|
|
320
|
+
d1day: sumLastN(ev, 24),
|
|
321
|
+
d8hr: sumLastN(ev, 8),
|
|
322
|
+
d4hr: sumLastN(ev, 4),
|
|
323
|
+
d1hr: sumLastN(ev, 1),
|
|
324
|
+
}
|
|
325
|
+
})
|
|
326
|
+
//依最近1日總數多→少排序(同數則 8時、4時、1時 依序 tie-break)
|
|
327
|
+
rows.sort(function(a, b) {
|
|
328
|
+
return (b.d1day - a.d1day) || (b.d8hr - a.d8hr) || (b.d4hr - a.d4hr) || (b.d1hr - a.d1hr)
|
|
329
|
+
})
|
|
330
|
+
return rows
|
|
331
|
+
},
|
|
332
|
+
|
|
333
|
+
},
|
|
334
|
+
watch: {
|
|
335
|
+
freq: function() {
|
|
336
|
+
let vo = this
|
|
337
|
+
//首次取得資料時,預設全選所有事件(使各事件一開始即分系列、可區分)
|
|
338
|
+
if (!vo.eventsInited && vo.allEvents.length > 0) {
|
|
339
|
+
vo.selectedEvents = vo.allEvents.slice()
|
|
340
|
+
vo.eventsInited = true
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
methods: {
|
|
345
|
+
|
|
346
|
+
//量測標題列+控制區實佔高(offsetHeight + margin-bottom),存入 hUpper 供 chartHeight 計算
|
|
347
|
+
updateUpperHeight: function() {
|
|
348
|
+
let vo = this
|
|
349
|
+
let mb = function(el) {
|
|
350
|
+
return parseFloat(getComputedStyle(el).marginBottom) || 0
|
|
351
|
+
}
|
|
352
|
+
let h = 0
|
|
353
|
+
let hdr = vo.$refs['$hdr']
|
|
354
|
+
let ctrl = vo.$refs['$ctrl']
|
|
355
|
+
if (hdr) {
|
|
356
|
+
h += hdr.offsetHeight + mb(hdr)
|
|
357
|
+
}
|
|
358
|
+
if (ctrl) {
|
|
359
|
+
h += ctrl.offsetHeight + mb(ctrl)
|
|
360
|
+
}
|
|
361
|
+
vo.hUpper = h
|
|
362
|
+
},
|
|
363
|
+
|
|
364
|
+
colorOf: function(ev) {
|
|
365
|
+
let vo = this
|
|
366
|
+
let idx = vo.allEvents.indexOf(ev)
|
|
367
|
+
if (idx < 0) {
|
|
368
|
+
idx = 0
|
|
369
|
+
}
|
|
370
|
+
return COLORS[idx % COLORS.length]
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
selectAllEvents: function() {
|
|
374
|
+
let vo = this
|
|
375
|
+
vo.selectedEvents = vo.allEvents.slice()
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
selectNoneEvents: function() {
|
|
379
|
+
let vo = this
|
|
380
|
+
vo.selectedEvents = []
|
|
381
|
+
},
|
|
382
|
+
|
|
383
|
+
load: function() {
|
|
384
|
+
let vo = this
|
|
385
|
+
vo.loading = true
|
|
386
|
+
vo.errMsg = ''
|
|
387
|
+
vo.$fapi.getStaEvent(7, 'hr')
|
|
388
|
+
.then(function(rs) {
|
|
389
|
+
vo.freq = isearr(rs) ? rs : []
|
|
390
|
+
})
|
|
391
|
+
.catch(function(err) {
|
|
392
|
+
console.log('getStaEvent catch', err)
|
|
393
|
+
vo.errMsg = vo.$t('getDataError')
|
|
394
|
+
})
|
|
395
|
+
.finally(function() {
|
|
396
|
+
vo.loading = false
|
|
397
|
+
})
|
|
398
|
+
},
|
|
399
|
+
|
|
400
|
+
},
|
|
401
|
+
}
|
|
402
|
+
</script>
|
|
403
|
+
|
|
404
|
+
<style scoped>
|
|
405
|
+
|
|
406
|
+
/* 控制區:兩欄 grid 結構性對齊(label 欄 max-content 隨語系文字自動定寬;
|
|
407
|
+
第二欄 minmax(0,1fr) 防內容撐大),取代先前 label 寫死 64px + evt-grid margin-left 72px 之魔術數字對齊 */
|
|
408
|
+
.ctrl {
|
|
409
|
+
margin-bottom: 16px;
|
|
410
|
+
display: grid;
|
|
411
|
+
grid-template-columns: max-content minmax(0, 1fr);
|
|
412
|
+
gap: 12px 8px;
|
|
413
|
+
align-items: center;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
.ctrl-row {
|
|
417
|
+
display: contents; /* label 與 field 直接成為 .ctrl 之 grid 子項 */
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
.ctrl-label {
|
|
421
|
+
font-size: 0.875rem;
|
|
422
|
+
color: var(--c-2);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
.ctrl-field {
|
|
426
|
+
display: flex;
|
|
427
|
+
align-items: center;
|
|
428
|
+
gap: 8px;
|
|
429
|
+
min-width: 0;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
.ctrl-select {
|
|
433
|
+
border: 1px solid var(--border);
|
|
434
|
+
border-radius: var(--radius);
|
|
435
|
+
background: var(--bg-1);
|
|
436
|
+
color: var(--c-1);
|
|
437
|
+
font-size: 0.875rem;
|
|
438
|
+
padding: 4px 8px;
|
|
439
|
+
outline: none;
|
|
440
|
+
cursor: pointer;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.ctrl-select:focus {
|
|
444
|
+
border-color: var(--accent);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.evt-sel-btn {
|
|
448
|
+
border: 1px solid var(--border);
|
|
449
|
+
border-radius: var(--radius);
|
|
450
|
+
background: var(--bg-1);
|
|
451
|
+
color: var(--c-2);
|
|
452
|
+
font-size: 0.8rem;
|
|
453
|
+
padding: 3px 12px;
|
|
454
|
+
cursor: pointer;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
.evt-sel-btn:hover {
|
|
458
|
+
border-color: var(--accent);
|
|
459
|
+
color: var(--accent);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
.evt-count {
|
|
463
|
+
font-size: 0.78rem;
|
|
464
|
+
color: var(--c-3);
|
|
465
|
+
margin-left: 4px;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/* 事件 chip:flex-wrap 內容自然寬(用滿容器可用寬、排不下才換行),
|
|
469
|
+
置於 .ctrl grid 第二欄與上方控制項對齊;不設 max-width 上限(由容器自然約束) */
|
|
470
|
+
.evt-grid {
|
|
471
|
+
grid-column: 2;
|
|
472
|
+
min-width: 0;
|
|
473
|
+
display: flex;
|
|
474
|
+
flex-wrap: wrap;
|
|
475
|
+
gap: 8px;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
.evt-chip {
|
|
479
|
+
display: flex;
|
|
480
|
+
align-items: center;
|
|
481
|
+
box-sizing: border-box;
|
|
482
|
+
flex: 0 1 auto;
|
|
483
|
+
min-width: 0;
|
|
484
|
+
max-width: 100%; /* 安全閥:極長事件名時 chip 不超過容器寬(此時 .evt-name 之 ellipsis 才生效) */
|
|
485
|
+
border: 1px solid var(--border);
|
|
486
|
+
border-radius: var(--radius);
|
|
487
|
+
background: var(--bg-1);
|
|
488
|
+
padding: 5px 10px;
|
|
489
|
+
font-size: 0.82rem;
|
|
490
|
+
color: var(--c-2);
|
|
491
|
+
cursor: pointer;
|
|
492
|
+
transition: border-color .12s, background .12s, color .12s;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
.evt-chip:hover {
|
|
496
|
+
border-color: var(--accent);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
.evt-chip.on {
|
|
500
|
+
color: var(--c-1);
|
|
501
|
+
border-color: var(--accent);
|
|
502
|
+
background: rgba(0, 153, 255, 0.06);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
.evt-chip .stats-evt-cb {
|
|
506
|
+
cursor: pointer;
|
|
507
|
+
margin: 0 6px 0 0;
|
|
508
|
+
flex-shrink: 0;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
.evt-dot {
|
|
512
|
+
display: inline-block;
|
|
513
|
+
width: 9px;
|
|
514
|
+
height: 9px;
|
|
515
|
+
border-radius: 2px;
|
|
516
|
+
margin-right: 6px;
|
|
517
|
+
flex-shrink: 0;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
.evt-name {
|
|
521
|
+
min-width: 0; /* flex item 預設 min-width:auto 會阻止收縮,明給 0 使安全閥可生效 */
|
|
522
|
+
overflow: hidden;
|
|
523
|
+
text-overflow: ellipsis;
|
|
524
|
+
white-space: nowrap;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
.stats-table-area {
|
|
528
|
+
overflow-x: auto; /* 極端長事件名時表格自帶水平捲動,不外溢撐破 panel */
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
.stats-table {
|
|
532
|
+
width: 100%;
|
|
533
|
+
border-collapse: collapse;
|
|
534
|
+
font-size: 0.85rem;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
.stats-table td:first-child {
|
|
538
|
+
white-space: normal; /* 事件名欄允許換行(數值欄維持 nowrap),與 chip 區同源之防溢出處置 */
|
|
539
|
+
overflow-wrap: anywhere;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
.stats-table th,
|
|
543
|
+
.stats-table td {
|
|
544
|
+
border-bottom: 1px solid var(--border);
|
|
545
|
+
padding: 7px 10px;
|
|
546
|
+
text-align: right;
|
|
547
|
+
color: var(--c-1);
|
|
548
|
+
white-space: nowrap;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
.stats-table th {
|
|
552
|
+
color: var(--c-2);
|
|
553
|
+
font-weight: 600;
|
|
554
|
+
background: var(--bg-2);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
</style>
|