Skip to content

Commit

Permalink
增加路由日志
Browse files Browse the repository at this point in the history
Signed-off-by: hanhyu <[email protected]>
  • Loading branch information
hanhyu committed Feb 16, 2021
1 parent 41afbbf commit 2979c75
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .php_cs.cache

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions application/domain/System/LogDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,9 @@ public function getRouterList(array $data): ?array
return $res;
}

public function getRouterInfo(string $id): array|bool
{
return RouterLogMysql::getInstance()->getInfoById($id);
}

}
4 changes: 4 additions & 0 deletions application/models/Forms/SystemLogForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ class SystemLogForms
'req_ip' => ['StrLenGeLe:2,20|Alias:请求IP', 'StrIn:'],
];

public static array $getRouterInfo = [
'id' => 'Required|Str',
];

}
20 changes: 20 additions & 0 deletions application/models/Mysql/RouterLogMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,25 @@ public function getListCount(array $data): int
return self::getDb($this->db)->from($this->table)->where($wheres)->count();
}

/**
* User: hanhyu
* Date: 2021/2/15
* Time: 下午9:49
*
* @param string $id
*
* @return array|bool
* @throws Exception
* @throws ProgramException
*/
public function getInfoById(string $id): array|bool
{
return self::getDb($this->db)
->from($this->table)
->where('id', $id)
->select('id, req_data, resp_data', true)
->fetch();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ public function getListAction(): string
return http_response(data: $this->log->getRouterList($data));
}

#[Router(method: 'GET', auth: true)]
public function getInfoAction(): string
{
$data = $this->validator(SystemLogForms::$getRouterInfo);
return http_response(data: $this->log->getRouterInfo($data['id']));
}

}
49 changes: 49 additions & 0 deletions html/controller/log/router_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
new Vue({
el: ".all",
data: {
info: []
},
beforeCreate: function () {
checkLogin();
},
created: function () {
axiosConfig();
},
beforeMount: function () {
},
mounted: function () {
this.axios = axios;
this.getRouterInfo();
},
methods: {
getRouterInfo() {
let self = this;
this.axios({
method: 'get',
url: 'system/logRouter/getInfo',
params: {
id: getUrlParam('id')
}
})
.then(function (response) {
switch (response.data.code) {
case 200:
self.info = response.data.data;
break;
case 300:
location.href = 'login.html';
break;
default:
layer.msg(response.data.msg);
}
})
.catch(function (error) {
console.log(error);
});
},
},
watch: {},
updated: function () {
},
filters: {}
});
5 changes: 2 additions & 3 deletions html/controller/log/router_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ new Vue({
});
},
//显示详细信息
getInfo(item) {
let info = encodeURIComponent(JSON.stringify(item));
x_admin_show('详细信息', "router_info.html?info=" + info, 800, 700);
getInfo(id) {
x_admin_show('详细信息', "router_info.html?id=" + id, 800, 700);
},
//清空查询条件
cleanSearch() {
Expand Down
56 changes: 56 additions & 0 deletions html/view/log/router_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title></title>
<!--<link rel="import" href="../head_js.html">-->
<meta content="webkit|ie-comp|ie-stand" name="renderer">
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"
name="viewport"/>
<meta content="no-siteapp" http-equiv="Cache-Control"/>

<link href="../../favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<link href="../../static/css/font.css" rel="stylesheet">
<link href="../../static/css/xadmin.css" rel="stylesheet">
<script charset="utf-8" src="../../static/lib/layui/layui.js" type="text/javascript"></script>
<script src="../../static/js/xadmin.js" type="text/javascript"></script>

<script src="../../static/js/axios.js" type="text/javascript"></script>
<script src="../../conf/axiosConfig.js" type="text/javascript"></script>
<script src="../../static/js/vue.js" type="text/javascript"></script>
<link href="../../static/css/jquery.jsonview.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="layui-fluid all">
<table class="layui-table layui-form" lay-size="lg">
<colgroup>
<col width="50">
<col width="300">
<col>
</colgroup>
<tbody>
<tr>
<td>ID</td>
<td>{{info.id}}</td>
</tr>
<tr>
<td>请求内容</td>
<td>
<div id="req_json">{{info.req_data}}</div>
</td>
</tr>
<tr>
<td>响应内容</td>
<td>
<div id="resp_json">{{info.resp_data}}</div>
</td>
</tr>
</tbody>
</table>
</div>
</body>
<script src="../../controller/log/router_info.js"></script>
</html>
2 changes: 1 addition & 1 deletion html/view/log/router_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<td width="80px">{{formatDate(item.resp_time)}}</td>
<td width="80px">{{item.create_time}}</td>
<td class="td-manage">
<button @click.prevent="getInfo(item)" class="layui-btn layui-btn-sm"><i
<button @click.prevent="getInfo(item.id)" class="layui-btn layui-btn-sm"><i
class="layui-icon">&#xe642;</i>详情
</button>
</td>
Expand Down

0 comments on commit 2979c75

Please sign in to comment.