mirror of
https://github.com/kokororin/typecho-plugin-Access.git
synced 2024-12-26 21:00:17 +08:00
feat: add content id query logic
This commit is contained in:
parent
f8900b1fdc
commit
62910e3bf3
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务调度入口
|
||||
*
|
||||
|
@ -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;
|
||||
|
@ -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(
|
||||
$('<option />', { value: item.cid })
|
||||
.text(item.title + ' (' + item.count + ')')
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
fetchLogs();
|
||||
|
Loading…
Reference in New Issue
Block a user