mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
实现后台操作日志记录;
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\Admin as AppAdmin;
|
||||
use app\model\AdminLog;
|
||||
use app\UploadFiles as AppUploadFiles;
|
||||
use think\facade\View;
|
||||
|
||||
@@ -86,4 +87,14 @@ class Admin extends Common
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function adminLog()
|
||||
{
|
||||
|
||||
$list = AdminLog::order('id desc')->paginate(10);
|
||||
|
||||
View::assign('list',$list);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\AdminPermission as AppAdminPermission;
|
||||
use think\facade\Cache;
|
||||
use think\facade\View;
|
||||
use think\Request;
|
||||
|
||||
@@ -17,7 +18,7 @@ class AdminPermission extends Common
|
||||
{
|
||||
//
|
||||
|
||||
$list = AppAdminPermission::paginate();
|
||||
$list = AppAdminPermission::order('app,controller,action')->paginate();
|
||||
|
||||
View::assign('list',$list);
|
||||
|
||||
@@ -51,6 +52,8 @@ class AdminPermission extends Common
|
||||
|
||||
$model_permission->save();
|
||||
|
||||
Cache::delete('logged_admin_permission');
|
||||
|
||||
return json_message();
|
||||
}
|
||||
|
||||
@@ -63,5 +66,8 @@ class AdminPermission extends Common
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
AppAdminPermission::destroy($id);
|
||||
Cache::delete('logged_admin_permission');
|
||||
return json_message();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'\app\middleware\PermissionRecord'
|
||||
'\app\middleware\PermissionRecord',
|
||||
'\app\middleware\AdminLog',
|
||||
];
|
||||
41
app/middleware/AdminLog.php
Normal file
41
app/middleware/AdminLog.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
use app\model\AdminLog as AppAdminLog;
|
||||
use app\model\AdminPermission;
|
||||
use app\Request;
|
||||
use think\Collection;
|
||||
use think\facade\Cache;
|
||||
|
||||
class AdminLog
|
||||
{
|
||||
public function handle(Request $request, \Closure $next)
|
||||
{
|
||||
$logged_admin_permission = Cache::get('logged_admin_permission');
|
||||
|
||||
if(empty($logged_admin_permission)){
|
||||
$logged_admin_permission = new Collection(AdminPermission::where('is_log',1)->select());
|
||||
}
|
||||
|
||||
|
||||
$is_exit = $logged_admin_permission->where('app',$request->app())
|
||||
->where('controller',$request->controller())
|
||||
->where('action',$request->action());
|
||||
|
||||
if(!$is_exit->isEmpty()){
|
||||
AppAdminLog::create([
|
||||
'app'=>$request->app(),
|
||||
'controller'=>$request->controller(),
|
||||
'action'=>$request->action(),
|
||||
'param'=>$request->param(),
|
||||
'create_time'=>time(),
|
||||
'admin_id'=>$request->session('admin_id','0'),
|
||||
'ip'=>$request->ip()
|
||||
]);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
}
|
||||
}
|
||||
40
app/model/AdminLog.php
Normal file
40
app/model/AdminLog.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class AdminLog extends Model
|
||||
{
|
||||
//
|
||||
use SoftDelete;
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->belongsTo('Admin','admin_id');
|
||||
}
|
||||
|
||||
public function getUrlAttr()
|
||||
{
|
||||
return AdminPermission::where([
|
||||
'app'=>$this->getData('app'),
|
||||
'controller'=>$this->getData('controller'),
|
||||
'action'=>$this->getData('action'),
|
||||
])->find();
|
||||
}
|
||||
|
||||
public function setParamAttr($value)
|
||||
{
|
||||
return json_encode($value,JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
public function getParamAttr($value)
|
||||
{
|
||||
return \mb_substr($value,0,30);
|
||||
}
|
||||
}
|
||||
@@ -11,4 +11,14 @@ use think\Model;
|
||||
class AdminPermission extends Model
|
||||
{
|
||||
//
|
||||
|
||||
public function getIsLogAttr($value)
|
||||
{
|
||||
$status = [
|
||||
0=>'不记录',
|
||||
1=>'记录',
|
||||
];
|
||||
|
||||
return $status[intval($value)];
|
||||
}
|
||||
}
|
||||
|
||||
100
view/admin/admin/admin_log.html
Normal file
100
view/admin/admin/admin_log.html
Normal file
@@ -0,0 +1,100 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>应用管理</title>
|
||||
{include file="common/_require"}
|
||||
</head>
|
||||
|
||||
<body class="layui-layout-body">
|
||||
|
||||
<div class="layui-layout layui-layout-admin">
|
||||
{include file="common/_header"}
|
||||
|
||||
{include file="common/left_admin_manage"}
|
||||
|
||||
<div class="layui-body">
|
||||
|
||||
<div style="padding:15px">
|
||||
<div class="main-header">
|
||||
<span class="layui-breadcrumb">
|
||||
<a>首页</a>
|
||||
<a><cite>系统信息</cite></a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="main-container">
|
||||
<div>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<table class="layui-table">
|
||||
<colgroup>
|
||||
<col width="150">
|
||||
<col width="200">
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>访问地址</th>
|
||||
<th>访问信息</th>
|
||||
<th>携带参数</th>
|
||||
<th>操作管理员</th>
|
||||
<!-- <th>操作</th> -->
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{volist name='list' id='vo'}
|
||||
|
||||
<tr data-id="{$vo.id}" data-param="{$vo->getData('param')}">
|
||||
<td>{$vo.id}</td>
|
||||
<td>
|
||||
<p>{$vo.url.name}</p>
|
||||
<p>{$vo.app}/{$vo.controller}/{$vo.action}</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>访问时间:{$vo.create_time}</p>
|
||||
<p>访问IP:{$vo.ip}</p>
|
||||
</td>
|
||||
<td>
|
||||
<div class="layui-btn layui-btn-sm" onclick="layer.open({type:1,area:['400px','600px'],content:$(this).parents('tr').data('param')})">查看详情</div>
|
||||
<br>
|
||||
{$vo.param}
|
||||
</td>
|
||||
<td>
|
||||
<img src="{$vo.admin.avatar}" alt="" style="width: 50px;">
|
||||
{$vo.admin_id}/{$vo.admin.nickname}
|
||||
</td>
|
||||
<!-- <td>
|
||||
<div class="layui-btn-container">
|
||||
<div class="layui-btn layui-btn-sm delete">删除</div>
|
||||
</div>
|
||||
</td> -->
|
||||
</tr>
|
||||
{/volist}
|
||||
{if condition="count($list) eq 0" }
|
||||
<tr>
|
||||
<td colspan="6">暂无操作记录</td>
|
||||
</tr>
|
||||
{/if}
|
||||
</tbody>
|
||||
</table>
|
||||
<div>
|
||||
{$list->render()|raw}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{include file="common/_footer"}
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -44,7 +44,7 @@
|
||||
<tbody>
|
||||
{volist name='list' id='vo'}
|
||||
|
||||
<tr class="item" data-id="{$vo.id}">
|
||||
<tr class="item" data-id="{$vo.id}" data-is-log="{$vo->getData('is_log')}">
|
||||
<td>{$vo.id}</td>
|
||||
<td>
|
||||
<span>{$vo.name}</span>
|
||||
@@ -56,6 +56,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<div class="layui-btn-container">
|
||||
<div class="layui-btn layui-btn-sm is-log" >{$vo.is_log}</div>
|
||||
<div class="layui-btn layui-btn-sm delete">删除</div>
|
||||
</div>
|
||||
</td>
|
||||
@@ -68,6 +69,9 @@
|
||||
{/if}
|
||||
</tbody>
|
||||
</table>
|
||||
<div>
|
||||
{$list->render()|raw}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -109,7 +113,40 @@
|
||||
})
|
||||
|
||||
$('.delete').click(function(){
|
||||
|
||||
var item = this;
|
||||
layer.confirm('确定要删除吗?',function(){
|
||||
$.get('{:url("AdminPermission/delete")}',{
|
||||
id:$(item).parents('tr').data('id')
|
||||
},function(result){
|
||||
if(result.code == 0){
|
||||
layer.msg('删除成功');
|
||||
$(item).parents('tr').remove();
|
||||
}else{
|
||||
layer.msg(result.msg)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
$('.is-log').click(function(){
|
||||
var item = this;
|
||||
var isLog = $(item).parents('tr').data('is-log')
|
||||
if(isLog == 0){
|
||||
isLog = 1
|
||||
}else{
|
||||
isLog = 0
|
||||
}
|
||||
$.post('{:url("AdminPermission/update")}',{
|
||||
id:$(item).parents('tr').data('id'),
|
||||
is_log:isLog
|
||||
},function(){
|
||||
if(isLog == 1){
|
||||
$(item).text('记录')
|
||||
}else{
|
||||
$(item).text('不记录')
|
||||
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
<li class="layui-nav-item layui-nav-itemed">
|
||||
<a class="" href="{:url('admin/AdminPermission/index')}">权限管理</a>
|
||||
</li>
|
||||
<li class="layui-nav-item layui-nav-itemed">
|
||||
<a class="" href="{:url('Admin/adminLog')}">操作日志</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user