优化网站

This commit is contained in:
MasonLiu committed 2026-09-14 22:06:21 +08:00
1 parent 9bb6e6a41e
commit 0e7265481f
22 files changed
+1071 -238

No files matched your search

+11 -7
View File
@@ -36,9 +36,8 @@ function vis_query_access(string $mode, string $ipF, string $q, int $page, int $
$entries = visitors_entries();
$all = [];
if ($mode === 'compact') {
// 精简模式:按 IP 聚合(最近访问时间 / IP / 访问次数),首次出现即该 IP 最新一条
// 精简模式:按 IP 聚合(最近访问时间 / IP / 访问次数),并默认按访问次数从多到少排序
$grp = [];
$order = [];
foreach ($entries as $e) {
if ($ipF !== '' && stripos($e['ip'], $ipF) === false) {
continue;
@@ -48,13 +47,18 @@ function vis_query_access(string $mode, string $ipF, string $q, int $page, int $
}
if (!isset($grp[$e['ip']])) {
$grp[$e['ip']] = ['ip' => $e['ip'], 'last_at' => $e['created_at'], 'cnt' => 0];
$order[] = $e['ip'];
}
$grp[$e['ip']]['cnt']++;
}
foreach ($order as $ip) {
$all[] = $grp[$ip];
}
$all = array_values($grp);
// 访问次数多的在前;次数相同按最近访问时间倒序;再相同按 IP 升序
usort($all, static function (array $a, array $b): int {
if ($a['cnt'] !== $b['cnt']) {
return $b['cnt'] <=> $a['cnt'];
}
$d = strcmp((string) $b['last_at'], (string) $a['last_at']);
return $d !== 0 ? $d : strcmp((string) $a['ip'], (string) $b['ip']);
});
} else {
// 完整模式:逐条明细
foreach ($entries as $e) {
@@ -117,7 +121,7 @@ function vis_render_access(array $d): string
if ($logs) {
?>
<div class="tip" style="margin:10px 0 6px">
共命中 <?= (int) $d['total'] ?> <?= $mode === 'compact' ? '个 IP' : '条记录' ?>;
共命中 <?= (int) $d['total'] ?> <?= $mode === 'compact' ? '个 IP(按访问次数从多到少)' : '条记录' ?>;
当前第 <?= $page ?> / <?= $totalPages ?> 页,每页 <?= (int) $d['perPage'] ?> 条。
</div>
<div class="v-scroll">