w-web-sso 1.0.13 → 1.0.15
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/db/wsso/ips/data.mdb +0 -0
- package/db/wsso/ips/lock.mdb +0 -0
- package/db/wsso/tokens/data.mdb +0 -0
- package/db/wsso/tokens/lock.mdb +0 -0
- package/db/wsso/users/data.mdb +0 -0
- package/db/wsso/users/lock.mdb +0 -0
- package/dist/css/{app.03a2f95c.css → app.e4367a2b.css} +1 -1
- package/dist/index.tmp +6 -2
- package/dist/js/app-legacy.4ebeee34.js +2 -0
- package/dist/js/app-legacy.4ebeee34.js.map +1 -0
- package/dist/js/app.d1707f92.js +2 -0
- package/dist/js/app.d1707f92.js.map +1 -0
- package/dist/js/chunk-vendors-legacy.7380957a.js +15 -0
- package/dist/js/chunk-vendors-legacy.7380957a.js.map +1 -0
- package/dist/js/chunk-vendors.7380957a.js +15 -0
- package/dist/js/chunk-vendors.7380957a.js.map +1 -0
- package/dist/w-web-sso.umd.js +2 -2
- package/dist/w-web-sso.umd.js.map +1 -1
- package/docs/WWebSso.html +4 -112
- package/docs/WWebSso.mjs.html +460 -111
- package/docs/index.html +1 -1
- package/g.getSettings.mjs +0 -1
- package/g.initialData.mjs +8 -10
- package/g.mjs +0 -0
- package/package.json +7 -6
- package/public/index.html +13 -0
- package/server/WWebSso.mjs +459 -110
- package/server/procCore.mjs +871 -277
- package/server/procProtect.mjs +746 -0
- package/server/procStaInfor.mjs +393 -0
- package/server/provideUsers.mjs +0 -1
- package/server/srlog.mjs +12 -0
- package/server/staLogs/staIp.callWorker.mjs +35 -0
- package/server/staLogs/staIp.mjs +118 -0
- package/server/staLogs/staIp.shellWorker.mjs +18 -0
- package/server/staLogs/staToken.callWorker.mjs +35 -0
- package/server/staLogs/staToken.mjs +118 -0
- package/server/staLogs/staToken.shellWorker.mjs +18 -0
- package/server/staLogs/staUserAccountLogin.callWorker.mjs +35 -0
- package/server/staLogs/staUserAccountLogin.mjs +136 -0
- package/server/staLogs/staUserAccountLogin.shellWorker.mjs +18 -0
- package/server/staLogs/test_staIp.mjs +27 -0
- package/server/staLogs/test_staToken.mjs +27 -0
- package/server/staLogs/test_staUserAccountLogin.mjs +30 -0
- package/settings.json +15 -1
- package/src/components/Layout.vue +70 -15
- package/src/components/LayoutContent.vue +35 -33
- package/src/components/LayoutContentIps.vue +757 -0
- package/src/components/LayoutContentStaInfor.vue +917 -0
- package/src/components/LayoutContentTokens.vue +961 -0
- package/src/components/{LayoutContentInfor.vue → LayoutContentUserInfor.vue} +366 -73
- package/src/components/LayoutContentUsers.vue +21 -34
- package/src/components/PageLogin.vue +1 -1
- package/src/components/VeUser.vue.txt +9 -10
- package/src/components/ruleGroup.vue.txt +5 -6
- package/src/main.js +7 -13
- package/src/plugins/mLang.mjs +853 -520
- package/src/plugins/mShare.mjs +141 -3
- package/src/plugins/mUI.mjs +30 -21
- package/src/schema/index.mjs +2 -0
- package/src/schema/tables/ips.mjs +0 -9
- package/src/schema/tables/tokens.mjs +5 -1
- package/src/schema/tables/users.mjs +2 -14
- package/src/store/mutations.mjs +3 -3
- package/src/store/types.mjs +1 -1
- package/srv.mjs +55 -38
- package/_/350/246/217/345/212/203.md +0 -275
- package/dist/js/app-legacy.d468ef7f.js +0 -2
- package/dist/js/app-legacy.d468ef7f.js.map +0 -1
- package/dist/js/app.d468ef7f.js +0 -2
- package/dist/js/app.d468ef7f.js.map +0 -1
- package/dist/js/chunk-vendors-legacy.f51f58bb.js +0 -13
- package/dist/js/chunk-vendors-legacy.f51f58bb.js.map +0 -1
- package/dist/js/chunk-vendors.f51f58bb.js +0 -13
- package/dist/js/chunk-vendors.f51f58bb.js.map +0 -1
- package/src/components/LayoutContentSettings.vue +0 -1248
|
@@ -0,0 +1,917 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
style="height:100%;"
|
|
4
|
+
v-domresize
|
|
5
|
+
@domresize="resizePanel"
|
|
6
|
+
:changeLang="changeLang"
|
|
7
|
+
>
|
|
8
|
+
|
|
9
|
+
<div
|
|
10
|
+
style="height:100%; background:#f9fafb; overflow-y:auto;"
|
|
11
|
+
v-if="!isLoading"
|
|
12
|
+
>
|
|
13
|
+
|
|
14
|
+
<div style="padding:20px 30px;">
|
|
15
|
+
|
|
16
|
+
<!-- 頁面標題 -->
|
|
17
|
+
<div class="mb-8">
|
|
18
|
+
<div style="font-size:1.5rem; font-weight:600;">{{$t('statisticsInformation')}}</div>
|
|
19
|
+
<div style="font-size:0.9rem; color:#6b7280;">{{$t('statisticsInformationDescription')}}</div>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<div class="space-y-8">
|
|
23
|
+
|
|
24
|
+
<!-- 使用者資訊區區塊 -->
|
|
25
|
+
<div>
|
|
26
|
+
<div class="pb-1 text-gray-500 flex items-center">
|
|
27
|
+
<i class="text-2xl mdi mdi-shield-account-outline mr-2"></i>
|
|
28
|
+
<span class="text-sm">{{$t('userGroupInfor')}}</span>
|
|
29
|
+
</div>
|
|
30
|
+
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-5">
|
|
31
|
+
|
|
32
|
+
<div class="bg-white p-5 rounded-lg shadow-sm border border-gray-200 flex items-center">
|
|
33
|
+
<div class="bg-blue-100 p-3 rounded-full">
|
|
34
|
+
<i class="mdi mdi-account-group-outline mdi-24px text-blue-600"></i>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="ml-4">
|
|
37
|
+
<div class="text-gray-500 text-sm">{{$t('totalUsers')}}</div>
|
|
38
|
+
<div class="text-2xl font-bold text-gray-900">{{ userOverview.total || 0 }}</div>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div class="bg-white p-5 rounded-lg shadow-sm border border-gray-200 flex items-center">
|
|
43
|
+
<div class="bg-green-100 p-3 rounded-full">
|
|
44
|
+
<i class="mdi mdi-account-check-outline mdi-24px text-green-600"></i>
|
|
45
|
+
</div>
|
|
46
|
+
<div class="ml-4">
|
|
47
|
+
<div class="text-gray-500 text-sm">{{$t('activeUsers')}}</div>
|
|
48
|
+
<div class="text-2xl font-bold text-gray-900">{{ userOverview.active || 0 }}</div>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<div class="bg-white p-5 rounded-lg shadow-sm border border-gray-200 flex items-center">
|
|
53
|
+
<div class="bg-red-100 p-3 rounded-full">
|
|
54
|
+
<i class="mdi mdi-account-lock-outline mdi-24px text-red-600"></i>
|
|
55
|
+
</div>
|
|
56
|
+
<div class="ml-4">
|
|
57
|
+
<div class="text-gray-500 text-sm">{{$t('blockedUsers')}}</div>
|
|
58
|
+
<div class="text-2xl font-bold text-gray-900">{{ userOverview.locked || 0 }}</div>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<div class="bg-white p-5 rounded-lg shadow-sm border border-gray-200 flex items-center">
|
|
63
|
+
<div class="bg-yellow-100 p-3 rounded-full">
|
|
64
|
+
<i class="mdi mdi-account-clock-outline mdi-24px text-yellow-600"></i>
|
|
65
|
+
</div>
|
|
66
|
+
<div class="ml-4">
|
|
67
|
+
<div class="text-gray-500 text-sm">{{$t('expiredUsers')}}</div>
|
|
68
|
+
<div class="text-2xl font-bold text-gray-900">{{ userOverview.expired || 0 }}</div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
<!-- 存取活動監測區塊 -->
|
|
77
|
+
<div>
|
|
78
|
+
<div class="pb-1 text-gray-500 flex items-center">
|
|
79
|
+
<i class="text-2xl mdi mdi-chart-box-outline mr-2"></i>
|
|
80
|
+
<span class="text-sm">{{$t('accessActivityMonitoring')}}</span>
|
|
81
|
+
</div>
|
|
82
|
+
<div class="grid grid-cols-1 lg:grid-cols-1 gap-6">
|
|
83
|
+
|
|
84
|
+
<!-- 使用者登入頻率區塊 -->
|
|
85
|
+
<div class="bg-white p-5 rounded-lg shadow-sm border border-gray-200">
|
|
86
|
+
<div class="pb-2 flex items-center font-semibold text-gray-700">
|
|
87
|
+
<i class="text-4xl mdi mdi-login-variant mr-2 text-purple-600"></i>
|
|
88
|
+
<span class="text-lg">{{$t('userLoginFrequency')}}</span>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="flex justify-between items-center">
|
|
91
|
+
<div class="text-xs text-gray-500 mb-4">{{$t('last7Days')}}</div>
|
|
92
|
+
<select v-model="timeGroupLogin" @change="updateChartsDebounce" class="border rounded px-2 py-1 text-sm">
|
|
93
|
+
<option v-for="v in timeGroupOptions" :key="v" :value="v">{{$t(`selectItem${v}`)}}</option>
|
|
94
|
+
</select>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<WEchartsVueDyn
|
|
98
|
+
style="width:100%; height:300px;"
|
|
99
|
+
:options="optLogin"
|
|
100
|
+
v-if="optLogin"
|
|
101
|
+
></WEchartsVueDyn>
|
|
102
|
+
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<!-- 金鑰使用頻率區塊 -->
|
|
106
|
+
<div class="bg-white p-5 rounded-lg shadow-sm border border-gray-200">
|
|
107
|
+
<div class="pb-2 flex items-center font-semibold text-gray-700">
|
|
108
|
+
<i class="text-2xl mdi mdi-ticket-confirmation-outline mr-2 text-purple-600"></i>
|
|
109
|
+
<span class="text-lg">{{$t('tokenUsageFrequency')}}</span>
|
|
110
|
+
</div>
|
|
111
|
+
<div class="flex justify-between items-center">
|
|
112
|
+
<div class="text-xs text-gray-500 mb-4">{{$t('last7Days')}}</div>
|
|
113
|
+
<div class="flex items-center space-x-4">
|
|
114
|
+
<div class="flex items-center">
|
|
115
|
+
<input id="showIndividuallyToken" type="checkbox" v-model="showIndividuallyToken" @change="updateChartsDebounce" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500">
|
|
116
|
+
<label for="showIndividuallyToken" class="ml-2 text-sm font-medium text-gray-900">{{$t('showIndividually')}}</label>
|
|
117
|
+
</div>
|
|
118
|
+
<select v-model="timeGroupToken" @change="updateChartsDebounce" class="border rounded px-2 py-1 text-sm">
|
|
119
|
+
<option v-for="v in timeGroupOptions" :key="v" :value="v">{{$t(`selectItem${v}`)}}</option>
|
|
120
|
+
</select>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
<WEchartsVueDyn
|
|
125
|
+
style="width:100%; height:300px;"
|
|
126
|
+
:options="optToken"
|
|
127
|
+
v-if="optToken"
|
|
128
|
+
></WEchartsVueDyn>
|
|
129
|
+
|
|
130
|
+
<!-- 金鑰對應使用者用量統計 -->
|
|
131
|
+
<div v-if="tokenUsageSummary.length > 0" class="mt-4">
|
|
132
|
+
<div class="overflow-x-auto relative shadow-md">
|
|
133
|
+
<div :style="`${showAllTokenUsers ? 'max-height:400px; overflow-y:auto;' : ''}`">
|
|
134
|
+
<table class="w-full text-sm text-left text-gray-500 border-collapse">
|
|
135
|
+
<thead class="text-xs text-gray-700 bg-gray-50 sticky top-0 z-10 shadow-sm">
|
|
136
|
+
<tr>
|
|
137
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200 w-7">{{$t('numberOrder')}}</th>
|
|
138
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('username')}}</th>
|
|
139
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('total')}}</th>
|
|
140
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('last1Day')}}</th>
|
|
141
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('last8Hour')}}</th>
|
|
142
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('last4Hour')}}</th>
|
|
143
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('last1Hour')}}</th>
|
|
144
|
+
</tr>
|
|
145
|
+
</thead>
|
|
146
|
+
<tbody>
|
|
147
|
+
<tr v-for="(item, index) in displayTokenUsageSummary" :key="index" class="hover:bg-gray-50 transition-colors">
|
|
148
|
+
<td class="py-4 px-6 border border-solid border-gray-200 w-7">{{ item.number }}</td>
|
|
149
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ item.username }}</td>
|
|
150
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ formatNumber(item.total) }}</td>
|
|
151
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ formatNumber(item.last1d) }}</td>
|
|
152
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ formatNumber(item.last8h) }}</td>
|
|
153
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ formatNumber(item.last4h) }}</td>
|
|
154
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ formatNumber(item.last1h) }}</td>
|
|
155
|
+
</tr>
|
|
156
|
+
</tbody>
|
|
157
|
+
</table>
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
<div class="text-right mt-2">
|
|
161
|
+
<span @click="toggleShowAllTokenUsers" class="text-blue-600 hover:underline text-sm cursor-pointer">
|
|
162
|
+
{{ showAllTokenUsers ? $t('showMax5') : $t('showAll') }}
|
|
163
|
+
</span>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<!-- IP連線頻率區塊 -->
|
|
170
|
+
<div class="bg-white p-5 rounded-lg shadow-sm border border-gray-200">
|
|
171
|
+
<div class="pb-2 flex items-center font-semibold text-gray-700">
|
|
172
|
+
<i class="text-2xl mdi mdi-access-point-network mr-2 text-purple-600"></i>
|
|
173
|
+
<span class="text-lg">{{$t('ipConnectionFrequency')}}</span>
|
|
174
|
+
</div>
|
|
175
|
+
<div class="flex justify-between items-center">
|
|
176
|
+
<div class="text-xs text-gray-500 mb-4">{{$t('last7Days')}}</div>
|
|
177
|
+
<div class="flex items-center space-x-4">
|
|
178
|
+
<div class="flex items-center">
|
|
179
|
+
<input id="showIndividuallyIp" type="checkbox" v-model="showIndividuallyIp" @change="updateChartsDebounce" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500">
|
|
180
|
+
<label for="showIndividuallyIp" class="ml-2 text-sm font-medium text-gray-900">{{$t('showIndividually')}}</label>
|
|
181
|
+
</div>
|
|
182
|
+
<select v-model="timeGroupIp" @change="updateChartsDebounce" class="border rounded px-2 py-1 text-sm">
|
|
183
|
+
<option v-for="v in timeGroupOptions" :key="v" :value="v">{{$t(`selectItem${v}`)}}</option>
|
|
184
|
+
</select>
|
|
185
|
+
</div>
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
<WEchartsVueDyn
|
|
189
|
+
style="width:100%; height:300px;"
|
|
190
|
+
:options="optIp"
|
|
191
|
+
v-if="optIp"
|
|
192
|
+
></WEchartsVueDyn>
|
|
193
|
+
|
|
194
|
+
<!-- IP 使用量統計 -->
|
|
195
|
+
<div v-if="ipUsageSummary.length > 0" class="mt-4">
|
|
196
|
+
<div class="overflow-x-auto relative shadow-md">
|
|
197
|
+
<div :style="`${showAllIpUsers ? 'max-height:400px; overflow-y:auto;' : ''}`">
|
|
198
|
+
<table class="w-full text-sm text-left text-gray-500 border-collapse">
|
|
199
|
+
<thead class="text-xs text-gray-700 bg-gray-50 sticky top-0 z-10 shadow-sm">
|
|
200
|
+
<tr>
|
|
201
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200 w-7">{{$t('numberOrder')}}</th>
|
|
202
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('ip')}}</th>
|
|
203
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('total')}}</th>
|
|
204
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('last1Day')}}</th>
|
|
205
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('last8Hour')}}</th>
|
|
206
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('last4Hour')}}</th>
|
|
207
|
+
<th scope="col" class="py-3 px-6 border border-solid border-gray-200">{{$t('last1Hour')}}</th>
|
|
208
|
+
</tr>
|
|
209
|
+
</thead>
|
|
210
|
+
<tbody>
|
|
211
|
+
<tr v-for="(item, index) in displayIpUsageSummary" :key="index" class="hover:bg-gray-50 transition-colors">
|
|
212
|
+
<td class="py-4 px-6 border border-solid border-gray-200 w-7">{{ item.number }}</td>
|
|
213
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ item.ip }}</td>
|
|
214
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ formatNumber(item.total) }}</td>
|
|
215
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ formatNumber(item.last1d) }}</td>
|
|
216
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ formatNumber(item.last8h) }}</td>
|
|
217
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ formatNumber(item.last4h) }}</td>
|
|
218
|
+
<td class="py-4 px-6 border border-solid border-gray-200">{{ formatNumber(item.last1h) }}</td>
|
|
219
|
+
</tr>
|
|
220
|
+
</tbody>
|
|
221
|
+
</table>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
<div class="text-right mt-2">
|
|
225
|
+
<span @click="toggleShowAllIpUsers" class="text-blue-600 hover:underline text-sm cursor-pointer">
|
|
226
|
+
{{ showAllIpUsers ? $t('showMax5') : $t('showAll') }}
|
|
227
|
+
</span>
|
|
228
|
+
</div>
|
|
229
|
+
</div>
|
|
230
|
+
|
|
231
|
+
</div>
|
|
232
|
+
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
<!-- 管控狀態區塊 -->
|
|
238
|
+
<div>
|
|
239
|
+
<div class="pb-1 text-gray-500 flex items-center">
|
|
240
|
+
<i class="text-2xl mdi mdi-monitor-account mr-2"></i>
|
|
241
|
+
<span class="text-sm">{{$t('controlStatus')}}</span>
|
|
242
|
+
</div>
|
|
243
|
+
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-5">
|
|
244
|
+
|
|
245
|
+
<!-- 活躍 Token -->
|
|
246
|
+
<div class="bg-white p-5 rounded-lg shadow-sm border border-gray-200">
|
|
247
|
+
<div class="pb-3 flex items-center mb-2">
|
|
248
|
+
<i class="text-2xl mdi mdi-folder-key-network-outline text-indigo-600 mr-2"></i>
|
|
249
|
+
<div class="font-semibold text-gray-700">{{$t('tokenCharacteristic')}}</div>
|
|
250
|
+
</div>
|
|
251
|
+
<div class="space-y-2 text-sm">
|
|
252
|
+
<div class="flex justify-between"><span>{{$t('activeTokens')}}:</span> <span class="font-bold">{{ tokenStatus.active || 0 }}</span></div>
|
|
253
|
+
<div class="flex justify-between"><span>{{$t('createdLast24h')}}:</span> <span class="font-bold">{{ tokenStatus.created24h || 0 }}</span></div>
|
|
254
|
+
<div class="flex justify-between"><span>{{$t('endingNext24h')}}:</span> <span class="font-bold">{{ tokenStatus.ending24h || 0 }}</span></div>
|
|
255
|
+
<div class="flex justify-between"><span>{{$t('endedTokens')}}:</span> <span class="font-bold">{{ tokenStatus.ended || 0 }}</span></div>
|
|
256
|
+
</div>
|
|
257
|
+
</div>
|
|
258
|
+
|
|
259
|
+
<!-- IP 管控 -->
|
|
260
|
+
<div class="bg-white p-5 rounded-lg shadow-sm border border-gray-200">
|
|
261
|
+
<div class="pb-3 flex items-center mb-2">
|
|
262
|
+
<i class="text-2xl mdi mdi-ip-network-outline text-teal-600 mr-2"></i>
|
|
263
|
+
<div class="font-semibold text-gray-700">{{$t('ipCharacteristic')}}</div>
|
|
264
|
+
</div>
|
|
265
|
+
<div class="space-y-2 text-sm">
|
|
266
|
+
<div class="flex justify-between"><span>{{$t('conn24h')}}:</span> <span class="font-bold">{{ ipCharacteristic.conn24h || 0 }}</span></div>
|
|
267
|
+
<div class="flex justify-between"><span>{{$t('blockedIps')}}:</span> <span class="font-bold">{{ ipCharacteristic.blocked || 0 }}</span></div>
|
|
268
|
+
</div>
|
|
269
|
+
</div>
|
|
270
|
+
|
|
271
|
+
</div>
|
|
272
|
+
</div>
|
|
273
|
+
|
|
274
|
+
</div>
|
|
275
|
+
|
|
276
|
+
</div>
|
|
277
|
+
|
|
278
|
+
</div>
|
|
279
|
+
<template v-else>
|
|
280
|
+
<div
|
|
281
|
+
style="padding:10px 15px; font-size:0.8rem;"
|
|
282
|
+
v-if="isLoading"
|
|
283
|
+
>
|
|
284
|
+
{{$t('waitingData')}}
|
|
285
|
+
</div>
|
|
286
|
+
<div
|
|
287
|
+
style="padding:10px 15px; font-size:0.8rem;"
|
|
288
|
+
v-if="errMsg"
|
|
289
|
+
>
|
|
290
|
+
{{errMsg}}
|
|
291
|
+
</div>
|
|
292
|
+
</template>
|
|
293
|
+
|
|
294
|
+
</div>
|
|
295
|
+
</template>
|
|
296
|
+
|
|
297
|
+
<script>
|
|
298
|
+
import ot from 'dayjs'
|
|
299
|
+
import get from 'lodash-es/get.js'
|
|
300
|
+
import each from 'lodash-es/each.js'
|
|
301
|
+
import map from 'lodash-es/map.js'
|
|
302
|
+
import size from 'lodash-es/size.js'
|
|
303
|
+
import keys from 'lodash-es/keys.js'
|
|
304
|
+
import groupBy from 'lodash-es/groupBy.js'
|
|
305
|
+
import sumBy from 'lodash-es/sumBy.js'
|
|
306
|
+
import cloneDeep from 'lodash-es/cloneDeep.js'
|
|
307
|
+
import omit from 'lodash-es/omit.js'
|
|
308
|
+
import reduce from 'lodash-es/reduce.js'
|
|
309
|
+
import toPairs from 'lodash-es/toPairs.js'
|
|
310
|
+
import sortBy from 'lodash-es/sortBy.js'
|
|
311
|
+
import reverse from 'lodash-es/reverse.js'
|
|
312
|
+
import isearr from 'wsemi/src/isearr.mjs'
|
|
313
|
+
import strright from 'wsemi/src/strright.mjs'
|
|
314
|
+
import haskey from 'wsemi/src/haskey.mjs'
|
|
315
|
+
import debounce from 'wsemi/src/debounce.mjs'
|
|
316
|
+
import WEchartsVueDyn from 'w-component-vue/src/components/WEchartsVueDyn.vue'
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
export default {
|
|
320
|
+
components: {
|
|
321
|
+
WEchartsVueDyn,
|
|
322
|
+
},
|
|
323
|
+
props: {
|
|
324
|
+
},
|
|
325
|
+
data: function() {
|
|
326
|
+
return {
|
|
327
|
+
|
|
328
|
+
dbc: debounce(300),
|
|
329
|
+
|
|
330
|
+
panelWidth: 100,
|
|
331
|
+
panelHeight: 100,
|
|
332
|
+
|
|
333
|
+
isLoading: true,
|
|
334
|
+
errMsg: '',
|
|
335
|
+
|
|
336
|
+
userOverview: {},
|
|
337
|
+
|
|
338
|
+
freqLogin: [],
|
|
339
|
+
freqToken: [],
|
|
340
|
+
freqIp: [],
|
|
341
|
+
|
|
342
|
+
tokenStatus: {},
|
|
343
|
+
ipCharacteristic: {},
|
|
344
|
+
|
|
345
|
+
timeGroupLogin: '1hr',
|
|
346
|
+
timeGroupToken: '1hr',
|
|
347
|
+
timeGroupIp: '1hr',
|
|
348
|
+
timeGroupOptions: ['1hr', '4hr', '8hr', '1day'],
|
|
349
|
+
|
|
350
|
+
optLogin: null,
|
|
351
|
+
optToken: null,
|
|
352
|
+
optIp: null,
|
|
353
|
+
|
|
354
|
+
showIndividuallyToken: false,
|
|
355
|
+
showIndividuallyIp: false,
|
|
356
|
+
|
|
357
|
+
tokenUsageSummary: [],
|
|
358
|
+
showAllTokenUsers: false,
|
|
359
|
+
|
|
360
|
+
ipUsageSummary: [],
|
|
361
|
+
showAllIpUsers: false,
|
|
362
|
+
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
mounted: function() {
|
|
366
|
+
// console.log('mounted')
|
|
367
|
+
|
|
368
|
+
let vo = this
|
|
369
|
+
|
|
370
|
+
//getAndRelaData
|
|
371
|
+
vo.getAndRelaData()
|
|
372
|
+
|
|
373
|
+
},
|
|
374
|
+
computed: {
|
|
375
|
+
|
|
376
|
+
webInfor: function() {
|
|
377
|
+
let wi = get(this, `$store.state.webInfor`)
|
|
378
|
+
return wi
|
|
379
|
+
},
|
|
380
|
+
|
|
381
|
+
userToken: function() {
|
|
382
|
+
let vo = this
|
|
383
|
+
return get(vo, `$store.state.userToken`)
|
|
384
|
+
},
|
|
385
|
+
|
|
386
|
+
lang: function() {
|
|
387
|
+
let vo = this
|
|
388
|
+
return get(vo, `$store.state.lang`, '')
|
|
389
|
+
},
|
|
390
|
+
|
|
391
|
+
changeLang: function() {
|
|
392
|
+
let vo = this
|
|
393
|
+
let lang = vo.lang
|
|
394
|
+
vo.updateChartsDebounce(lang)
|
|
395
|
+
return ''
|
|
396
|
+
},
|
|
397
|
+
|
|
398
|
+
displayTokenUsageSummary: function() {
|
|
399
|
+
let vo = this
|
|
400
|
+
if (vo.showAllTokenUsers) {
|
|
401
|
+
return vo.tokenUsageSummary
|
|
402
|
+
}
|
|
403
|
+
return vo.tokenUsageSummary.slice(0, 5)
|
|
404
|
+
},
|
|
405
|
+
|
|
406
|
+
displayIpUsageSummary: function() {
|
|
407
|
+
let vo = this
|
|
408
|
+
if (vo.showAllIpUsers) {
|
|
409
|
+
return vo.ipUsageSummary
|
|
410
|
+
}
|
|
411
|
+
return vo.ipUsageSummary.slice(0, 5)
|
|
412
|
+
},
|
|
413
|
+
|
|
414
|
+
},
|
|
415
|
+
methods: {
|
|
416
|
+
|
|
417
|
+
resizePanel: function(msg) {
|
|
418
|
+
// console.log('methods resizePanel', msg)
|
|
419
|
+
|
|
420
|
+
let vo = this
|
|
421
|
+
|
|
422
|
+
//panelWidth, panelHeight
|
|
423
|
+
vo.panelWidth = msg.snew.offsetWidth
|
|
424
|
+
vo.panelHeight = msg.snew.offsetHeight
|
|
425
|
+
|
|
426
|
+
},
|
|
427
|
+
|
|
428
|
+
genOpt: function(title, arr, keysPick, timeGroup = '1hr') {
|
|
429
|
+
let vo = this
|
|
430
|
+
|
|
431
|
+
//check
|
|
432
|
+
if (size(arr) === 0) {
|
|
433
|
+
return null
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
//keysPick to array
|
|
437
|
+
if (!isearr(keysPick)) {
|
|
438
|
+
keysPick = [keysPick]
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
//timeGroup
|
|
442
|
+
let dataProc = arr
|
|
443
|
+
if (timeGroup !== '1hr') {
|
|
444
|
+
|
|
445
|
+
//groupHours
|
|
446
|
+
let groupHours = 4
|
|
447
|
+
if (timeGroup === '8hr') {
|
|
448
|
+
groupHours = 8
|
|
449
|
+
}
|
|
450
|
+
else if (timeGroup === '1day') {
|
|
451
|
+
groupHours = 24
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
//gs
|
|
455
|
+
let gs = groupBy(arr, (v) => {
|
|
456
|
+
let t = ot(v.time)
|
|
457
|
+
let h = t.hour()
|
|
458
|
+
let hGroup = Math.floor(h / groupHours)
|
|
459
|
+
let tNew = t.startOf('day').add(hGroup * groupHours, 'hour')
|
|
460
|
+
return tNew.format()
|
|
461
|
+
})
|
|
462
|
+
// console.log('gs', gs)
|
|
463
|
+
|
|
464
|
+
//groupBy
|
|
465
|
+
dataProc = map(gs, (vs, time) => {
|
|
466
|
+
let r = {
|
|
467
|
+
time,
|
|
468
|
+
data: {},
|
|
469
|
+
}
|
|
470
|
+
each(keysPick, (k) => {
|
|
471
|
+
r.data[k] = sumBy(vs, `data.${k}`)
|
|
472
|
+
})
|
|
473
|
+
return r
|
|
474
|
+
})
|
|
475
|
+
// console.log('dataProc', dataProc)
|
|
476
|
+
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
//colors
|
|
480
|
+
let colors = [
|
|
481
|
+
'#3b82f6', // blue-500
|
|
482
|
+
'#ef4444', // red-500
|
|
483
|
+
'#10b981', // emerald-500
|
|
484
|
+
'#f97316', // orange-500
|
|
485
|
+
'#8b5cf6', // violet-500
|
|
486
|
+
'#6366f1', // indigo-500
|
|
487
|
+
'#eab308', // yellow-500
|
|
488
|
+
'#ec4899', // pink-500
|
|
489
|
+
'#14b8a6', // teal-500
|
|
490
|
+
'#a855f7', // purple-500
|
|
491
|
+
]
|
|
492
|
+
function getColor(k) {
|
|
493
|
+
return colors[k % colors.length]
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
//kpKey
|
|
497
|
+
let kpKey = {
|
|
498
|
+
count: 'count',
|
|
499
|
+
attempt: 'countAttempt',
|
|
500
|
+
success: 'countSuccess',
|
|
501
|
+
error: 'countError',
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
//getName
|
|
505
|
+
let getName = (valueKey) => {
|
|
506
|
+
let langKey = ''
|
|
507
|
+
if (haskey(kpKey, valueKey)) {
|
|
508
|
+
langKey = kpKey[valueKey]
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
langKey = valueKey
|
|
512
|
+
}
|
|
513
|
+
let name = vo.$t(langKey)
|
|
514
|
+
// console.log(`langKey[${langKey}]`, `name[${name}]`)
|
|
515
|
+
return name
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
//series
|
|
519
|
+
let totalBarsPerGroup = size(keysPick)
|
|
520
|
+
let barWidthPercent = Math.floor(100 / (totalBarsPerGroup * 1.5)) + '%' // 自動算出適合的 barWidth
|
|
521
|
+
let series = map(keysPick, (valueKey, k) => {
|
|
522
|
+
let name = getName(valueKey)
|
|
523
|
+
// console.log('valueKey', valueKey, 'name', name)
|
|
524
|
+
let color = getColor(k)
|
|
525
|
+
return {
|
|
526
|
+
name,
|
|
527
|
+
type: 'bar',
|
|
528
|
+
barWidth: barWidthPercent, // 改為動態 barWidth
|
|
529
|
+
data: map(dataProc, item => get(item, `data.${valueKey}`, 0)),
|
|
530
|
+
itemStyle: {
|
|
531
|
+
color,
|
|
532
|
+
},
|
|
533
|
+
emphasis: {
|
|
534
|
+
focus: 'series'
|
|
535
|
+
},
|
|
536
|
+
}
|
|
537
|
+
})
|
|
538
|
+
// console.log(title, 'series', series)
|
|
539
|
+
|
|
540
|
+
//formatX
|
|
541
|
+
let formatX = 'MM/DD'
|
|
542
|
+
if (strright(timeGroup, 2) === 'hr') {
|
|
543
|
+
formatX = 'MM/DD\nHH:mm'
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
//opt
|
|
547
|
+
let opt = {
|
|
548
|
+
title: {
|
|
549
|
+
text: title,
|
|
550
|
+
show: false, // 不顯示標題,由組件的HTML提供
|
|
551
|
+
},
|
|
552
|
+
tooltip: {
|
|
553
|
+
trigger: 'axis',
|
|
554
|
+
axisPointer: {
|
|
555
|
+
type: 'shadow'
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
grid: {
|
|
559
|
+
left: '3%',
|
|
560
|
+
right: '4%',
|
|
561
|
+
bottom: '3%',
|
|
562
|
+
containLabel: true
|
|
563
|
+
},
|
|
564
|
+
legend: {
|
|
565
|
+
show: true,
|
|
566
|
+
},
|
|
567
|
+
xAxis: [
|
|
568
|
+
{
|
|
569
|
+
type: 'category',
|
|
570
|
+
data: map(dataProc, item => ot(item.time).format(formatX)),
|
|
571
|
+
axisTick: {
|
|
572
|
+
alignWithLabel: true
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
],
|
|
576
|
+
yAxis: [
|
|
577
|
+
{
|
|
578
|
+
type: 'value'
|
|
579
|
+
}
|
|
580
|
+
],
|
|
581
|
+
series,
|
|
582
|
+
}
|
|
583
|
+
return opt
|
|
584
|
+
},
|
|
585
|
+
|
|
586
|
+
grStaUserSummary: async function() {
|
|
587
|
+
let vo = this
|
|
588
|
+
|
|
589
|
+
//token
|
|
590
|
+
let token = vo.userToken
|
|
591
|
+
|
|
592
|
+
//getStaUserSummary
|
|
593
|
+
await vo.$fapi.getStaUserSummary(token)
|
|
594
|
+
.then((res) => {
|
|
595
|
+
vo.userOverview = res
|
|
596
|
+
})
|
|
597
|
+
.catch((err) => {
|
|
598
|
+
console.log('getStaUserSummary catch', err)
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
},
|
|
602
|
+
|
|
603
|
+
grStaTokenSummary: async function() {
|
|
604
|
+
let vo = this
|
|
605
|
+
|
|
606
|
+
//token
|
|
607
|
+
let token = vo.userToken
|
|
608
|
+
|
|
609
|
+
//getStaTokenSummary
|
|
610
|
+
await vo.$fapi.getStaTokenSummary(token)
|
|
611
|
+
.then((res) => {
|
|
612
|
+
vo.tokenStatus = res
|
|
613
|
+
})
|
|
614
|
+
.catch((err) => {
|
|
615
|
+
console.log('getStaTokenSummary catch', err)
|
|
616
|
+
})
|
|
617
|
+
|
|
618
|
+
},
|
|
619
|
+
|
|
620
|
+
grStaIpSummary: async function() {
|
|
621
|
+
let vo = this
|
|
622
|
+
|
|
623
|
+
//token
|
|
624
|
+
let token = vo.userToken
|
|
625
|
+
|
|
626
|
+
//getStaIpSummary
|
|
627
|
+
await vo.$fapi.getStaIpSummary(token)
|
|
628
|
+
.then((res) => {
|
|
629
|
+
vo.ipCharacteristic = res
|
|
630
|
+
})
|
|
631
|
+
.catch((err) => {
|
|
632
|
+
console.log('getStaIpSummary catch', err)
|
|
633
|
+
})
|
|
634
|
+
|
|
635
|
+
},
|
|
636
|
+
|
|
637
|
+
grStaUserAccountLogin: async function() {
|
|
638
|
+
let vo = this
|
|
639
|
+
|
|
640
|
+
//token
|
|
641
|
+
let token = vo.userToken
|
|
642
|
+
|
|
643
|
+
//getStaUserAccountLogin
|
|
644
|
+
await vo.$fapi.getStaUserAccountLogin(token)
|
|
645
|
+
.then((res) => {
|
|
646
|
+
// console.log('getStaUserAccountLogin(freqLogin)', cloneDeep(res))
|
|
647
|
+
vo.freqLogin = res
|
|
648
|
+
vo.optLogin = vo.genOpt(vo.$t('userLoginFrequency'), vo.freqLogin, ['attempt', 'success', 'error'], vo.timeGroupLogin)
|
|
649
|
+
})
|
|
650
|
+
.catch((err) => {
|
|
651
|
+
console.log('getStaUserAccountLogin catch', err)
|
|
652
|
+
})
|
|
653
|
+
|
|
654
|
+
},
|
|
655
|
+
|
|
656
|
+
grStaToken: async function() {
|
|
657
|
+
let vo = this
|
|
658
|
+
|
|
659
|
+
//token
|
|
660
|
+
let token = vo.userToken
|
|
661
|
+
|
|
662
|
+
//getStaToken
|
|
663
|
+
await vo.$fapi.getStaToken(token)
|
|
664
|
+
.then((res) => {
|
|
665
|
+
// console.log('getStaToken(freqToken)', cloneDeep(res))
|
|
666
|
+
vo.freqToken = res
|
|
667
|
+
vo.updateCharts()
|
|
668
|
+
vo.calculateTokenUsageSummary(res)
|
|
669
|
+
})
|
|
670
|
+
.catch((err) => {
|
|
671
|
+
console.log('getStaToken catch', err)
|
|
672
|
+
})
|
|
673
|
+
|
|
674
|
+
},
|
|
675
|
+
|
|
676
|
+
grStaIp: async function name(params) {
|
|
677
|
+
let vo = this
|
|
678
|
+
|
|
679
|
+
//token
|
|
680
|
+
let token = vo.userToken
|
|
681
|
+
|
|
682
|
+
//getStaIp
|
|
683
|
+
await vo.$fapi.getStaIp(token)
|
|
684
|
+
.then((res) => {
|
|
685
|
+
// console.log('getStaIp(freqIp)', cloneDeep(res))
|
|
686
|
+
vo.freqIp = res
|
|
687
|
+
vo.updateCharts()
|
|
688
|
+
vo.calculateIpUsageSummary(res)
|
|
689
|
+
})
|
|
690
|
+
.catch((err) => {
|
|
691
|
+
console.log('getStaIp catch', err)
|
|
692
|
+
})
|
|
693
|
+
|
|
694
|
+
},
|
|
695
|
+
|
|
696
|
+
getAndRelaData: async function() {
|
|
697
|
+
let vo = this
|
|
698
|
+
|
|
699
|
+
vo.isLoading = true
|
|
700
|
+
vo.errMsg = ''
|
|
701
|
+
vo.grStaUserSummary() //isLoading僅針對grStaUserSummary之取得成功與否做判斷
|
|
702
|
+
.catch((err) => {
|
|
703
|
+
console.log(err)
|
|
704
|
+
vo.errMsg = vo.$t('getDataError')
|
|
705
|
+
})
|
|
706
|
+
.finally(() => {
|
|
707
|
+
vo.isLoading = false
|
|
708
|
+
})
|
|
709
|
+
|
|
710
|
+
vo.grStaTokenSummary()
|
|
711
|
+
.catch(() => { })
|
|
712
|
+
|
|
713
|
+
vo.grStaIpSummary()
|
|
714
|
+
.catch(() => { })
|
|
715
|
+
|
|
716
|
+
vo.grStaUserAccountLogin()
|
|
717
|
+
.catch(() => { })
|
|
718
|
+
|
|
719
|
+
vo.grStaToken()
|
|
720
|
+
.catch(() => { })
|
|
721
|
+
|
|
722
|
+
vo.grStaIp()
|
|
723
|
+
.catch(() => { })
|
|
724
|
+
|
|
725
|
+
},
|
|
726
|
+
|
|
727
|
+
updateCharts: function() {
|
|
728
|
+
let vo = this
|
|
729
|
+
|
|
730
|
+
//optLogin
|
|
731
|
+
vo.optLogin = vo.genOpt(vo.$t('userLoginFrequency'), vo.freqLogin, ['attempt', 'success', 'error'], vo.timeGroupLogin)
|
|
732
|
+
|
|
733
|
+
//optToken
|
|
734
|
+
let dataToken = get(vo.freqToken, '0.data')
|
|
735
|
+
let ksToken = keys(dataToken)
|
|
736
|
+
if (!vo.showIndividuallyToken) {
|
|
737
|
+
ksToken = ['count']
|
|
738
|
+
}
|
|
739
|
+
vo.optToken = vo.genOpt(vo.$t('tokenUsageFrequency'), vo.freqToken, ksToken, vo.timeGroupToken)
|
|
740
|
+
|
|
741
|
+
//optIp
|
|
742
|
+
let dataIp = get(vo.freqIp, '0.data')
|
|
743
|
+
let ksIp = keys(dataIp)
|
|
744
|
+
if (!vo.showIndividuallyIp) {
|
|
745
|
+
ksIp = ['count']
|
|
746
|
+
}
|
|
747
|
+
vo.optIp = vo.genOpt(vo.$t('ipConnectionFrequency'), vo.freqIp, ksIp, vo.timeGroupIp)
|
|
748
|
+
|
|
749
|
+
},
|
|
750
|
+
|
|
751
|
+
updateChartsDebounce: function() {
|
|
752
|
+
let vo = this
|
|
753
|
+
vo.dbc(() => {
|
|
754
|
+
vo.updateCharts()
|
|
755
|
+
})
|
|
756
|
+
},
|
|
757
|
+
|
|
758
|
+
calculateTokenUsageSummary: function(tokenFrequency) {
|
|
759
|
+
let vo = this
|
|
760
|
+
|
|
761
|
+
// 先取得所有使用者
|
|
762
|
+
let users = reduce(tokenFrequency, (acc, entry) => {
|
|
763
|
+
let userData = omit(get(entry, 'data', {}), 'count')
|
|
764
|
+
each(keys(userData), (username) => {
|
|
765
|
+
if (!haskey(acc, username)) {
|
|
766
|
+
acc[username] = {
|
|
767
|
+
username,
|
|
768
|
+
total: 0,
|
|
769
|
+
last1d: 0,
|
|
770
|
+
last8h: 0,
|
|
771
|
+
last4h: 0,
|
|
772
|
+
last1h: 0,
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
})
|
|
776
|
+
return acc
|
|
777
|
+
}, {})
|
|
778
|
+
|
|
779
|
+
// now
|
|
780
|
+
let now = ot()
|
|
781
|
+
|
|
782
|
+
// 迭代 tokenFrequency 進行計算
|
|
783
|
+
each(tokenFrequency, (entry) => {
|
|
784
|
+
let t = ot(entry.time)
|
|
785
|
+
let diff1d = now.diff(t, 'hour') <= 24
|
|
786
|
+
let diff8h = now.diff(t, 'hour') <= 8
|
|
787
|
+
let diff4h = now.diff(t, 'hour') <= 4
|
|
788
|
+
let diff1h = now.diff(t, 'hour') <= 1
|
|
789
|
+
let userData = omit(get(entry, 'data', {}), 'count')
|
|
790
|
+
each(userData, (value, username) => {
|
|
791
|
+
if (haskey(users, username)) {
|
|
792
|
+
users[username].total += value
|
|
793
|
+
if (diff1d) {
|
|
794
|
+
users[username].last1d += value
|
|
795
|
+
}
|
|
796
|
+
if (diff8h) {
|
|
797
|
+
users[username].last8h += value
|
|
798
|
+
}
|
|
799
|
+
if (diff4h) {
|
|
800
|
+
users[username].last4h += value
|
|
801
|
+
}
|
|
802
|
+
if (diff1h) {
|
|
803
|
+
users[username].last1h += value
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
})
|
|
807
|
+
})
|
|
808
|
+
|
|
809
|
+
// 將物件轉換為陣列並排序
|
|
810
|
+
let sortedSummary = toPairs(users)
|
|
811
|
+
sortedSummary = map(sortedSummary, (v) => v[1]) //只取value
|
|
812
|
+
sortedSummary = sortBy(sortedSummary, 'total')
|
|
813
|
+
sortedSummary = reverse(sortedSummary)
|
|
814
|
+
sortedSummary = map(sortedSummary, (v, k) => {
|
|
815
|
+
v.number = k + 1
|
|
816
|
+
return v
|
|
817
|
+
})
|
|
818
|
+
// console.log('sortedSummary', sortedSummary)
|
|
819
|
+
|
|
820
|
+
vo.tokenUsageSummary = sortedSummary
|
|
821
|
+
},
|
|
822
|
+
|
|
823
|
+
toggleShowAllTokenUsers: function() {
|
|
824
|
+
let vo = this
|
|
825
|
+
vo.showAllTokenUsers = !vo.showAllTokenUsers
|
|
826
|
+
},
|
|
827
|
+
|
|
828
|
+
calculateIpUsageSummary: function(ipFrequency) {
|
|
829
|
+
let vo = this
|
|
830
|
+
|
|
831
|
+
// 先取得所有IP
|
|
832
|
+
let ips = reduce(ipFrequency, (acc, entry) => {
|
|
833
|
+
let ipData = omit(get(entry, 'data', {}), 'count')
|
|
834
|
+
each(keys(ipData), (ip) => {
|
|
835
|
+
if (!haskey(acc, ip)) {
|
|
836
|
+
acc[ip] = {
|
|
837
|
+
ip,
|
|
838
|
+
total: 0,
|
|
839
|
+
last1d: 0,
|
|
840
|
+
last8h: 0,
|
|
841
|
+
last4h: 0,
|
|
842
|
+
last1h: 0,
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
})
|
|
846
|
+
return acc
|
|
847
|
+
}, {})
|
|
848
|
+
|
|
849
|
+
// now
|
|
850
|
+
let now = ot()
|
|
851
|
+
|
|
852
|
+
// 迭代 ipFrequency 進行計算
|
|
853
|
+
each(ipFrequency, (entry) => {
|
|
854
|
+
let t = ot(entry.time)
|
|
855
|
+
let diff1d = now.diff(t, 'hour') <= 24
|
|
856
|
+
let diff8h = now.diff(t, 'hour') <= 8
|
|
857
|
+
let diff4h = now.diff(t, 'hour') <= 4
|
|
858
|
+
let diff1h = now.diff(t, 'hour') <= 1
|
|
859
|
+
let ipData = omit(get(entry, 'data', {}), 'count')
|
|
860
|
+
each(ipData, (value, ip) => {
|
|
861
|
+
if (haskey(ips, ip)) {
|
|
862
|
+
ips[ip].total += value
|
|
863
|
+
if (diff1d) {
|
|
864
|
+
ips[ip].last1d += value
|
|
865
|
+
}
|
|
866
|
+
if (diff8h) {
|
|
867
|
+
ips[ip].last8h += value
|
|
868
|
+
}
|
|
869
|
+
if (diff4h) {
|
|
870
|
+
ips[ip].last4h += value
|
|
871
|
+
}
|
|
872
|
+
if (diff1h) {
|
|
873
|
+
ips[ip].last1h += value
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
})
|
|
877
|
+
})
|
|
878
|
+
|
|
879
|
+
// 將物件轉換為陣列並排序
|
|
880
|
+
let sortedSummary = toPairs(ips)
|
|
881
|
+
sortedSummary = map(sortedSummary, (v) => v[1]) //只取value
|
|
882
|
+
sortedSummary = sortBy(sortedSummary, 'total')
|
|
883
|
+
sortedSummary = reverse(sortedSummary)
|
|
884
|
+
sortedSummary = map(sortedSummary, (v, k) => {
|
|
885
|
+
v.number = k + 1
|
|
886
|
+
return v
|
|
887
|
+
})
|
|
888
|
+
// console.log('sortedSummary', sortedSummary)
|
|
889
|
+
|
|
890
|
+
vo.ipUsageSummary = sortedSummary
|
|
891
|
+
},
|
|
892
|
+
|
|
893
|
+
toggleShowAllIpUsers: function() {
|
|
894
|
+
let vo = this
|
|
895
|
+
vo.showAllIpUsers = !vo.showAllIpUsers
|
|
896
|
+
},
|
|
897
|
+
|
|
898
|
+
formatNumber: function(num) {
|
|
899
|
+
if (num === null || num === undefined) {
|
|
900
|
+
return 0
|
|
901
|
+
}
|
|
902
|
+
return num.toLocaleString()
|
|
903
|
+
},
|
|
904
|
+
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
</script>
|
|
908
|
+
|
|
909
|
+
<style scoped>
|
|
910
|
+
@media (min-width: 640px) {
|
|
911
|
+
.sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
912
|
+
}
|
|
913
|
+
@media (min-width: 1024px) {
|
|
914
|
+
.lg\:grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
|
|
915
|
+
.lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
|
916
|
+
}
|
|
917
|
+
</style>
|