From 62910e3bf3ca342dc89616628173789fb3d20770 Mon Sep 17 00:00:00 2001 From: Emil Zhai Date: Mon, 5 Dec 2022 08:34:08 +0000 Subject: [PATCH] feat: add content id query logic --- Access_Logs.php | 22 +++++++++++++++ page/routes/logs/index.css | 4 +++ page/routes/logs/index.js | 56 +++++++++++--------------------------- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/Access_Logs.php b/Access_Logs.php index 5a1c5a0..1279e6e 100644 --- a/Access_Logs.php +++ b/Access_Logs.php @@ -11,6 +11,7 @@ class Access_Logs { private static $rpcTypes = [ 'get' => 'GET', 'delete' => 'POST', + 'cids' => 'GET', ]; private $config; @@ -176,6 +177,27 @@ class Access_Logs { return $resp; } + /** + * 获取日志 id 列表 + * + * @access private + * @return ?array + * @throws Exception + */ + public function cids(): ?array + { + $resp = []; + + $list = $this->db->fetchAll($this->db->select('DISTINCT content_id as cid, COUNT(1) as count, table.contents.title') + ->from('table.access_logs') + ->join('table.contents', 'table.access_logs.content_id = table.contents.cid') + ->group('table.access_logs.content_id') + ->order('count', Typecho_Db::SORT_DESC)); + $resp['list'] = $list; + + return $resp; + } + /** * 业务调度入口 * diff --git a/page/routes/logs/index.css b/page/routes/logs/index.css index a6c9969..bed1e05 100644 --- a/page/routes/logs/index.css +++ b/page/routes/logs/index.css @@ -42,6 +42,10 @@ a[data-action="search-anchor"] { flex: 1 1 auto; } +select.typecho-access-logs-filter-item__content { + width: 100%; +} + .typecho-access-logs-filter-apply { padding: 15px 10px 10px; display: flex; diff --git a/page/routes/logs/index.js b/page/routes/logs/index.js index d7f378b..431f301 100644 --- a/page/routes/logs/index.js +++ b/page/routes/logs/index.js @@ -399,46 +399,22 @@ $(document).ready(function () { }); }); - var $form = $("form.search-form"); - var $ipInput = $form.find('input[name="ip"]'); - var $cidSelect = $form.find('select[name="cid"]'); - var $pathInput = $form.find('input[name="path"]'); - var $filterSelect = $form.find('select[name="filter"]'); - var $fuzzySelect = $form.find('select[name="fuzzy"]'); - - $filterSelect.on("change", function () { - $ipInput.removeAttr("placeholder").val("").hide(); - $cidSelect.hide(); - $pathInput.removeAttr("placeholder").val("").hide(); - $fuzzySelect.hide(); - - switch ($filterSelect.val()) { - case "ip": - $ipInput.attr("placeholder", "输入ip").show(); - $fuzzySelect.show(); - break; - case "post": - $cidSelect.show(); - break; - case "path": - $pathInput.attr("placeholder", "输入路由").show(); - $fuzzySelect.show(); - break; - } - }); - - $fuzzySelect.on("change", function (e) { - if (e.target.value === "1") { - $ipInput.val($ipInput.val().replace(/%/u, "\\%")); - $pathInput.val($ipInput.val().replace(/%/u, "\\%")); - } else { - $ipInput.val($ipInput.val().replace(/\\%/u, "%")); - $pathInput.val($ipInput.val().replace(/\\%/u, "%")); - } - }); - - $form.find('button[type="button"]').on("click", function () { - $form.submit(); + $.ajax({ + url: "/access/logs", + method: "get", + dataType: "json", + data: { rpc: 'cids' }, + success: function (res) { + if (res.code === 0) { + var $select = $('select[name="filter-cid"]'); + $.each(res.data.list, function(_, item) { + $select.append( + $('