修改系统管理
This commit is contained in:
parent
a4a03857ac
commit
17d30f1cc3
@ -1 +1,84 @@
|
||||
<?php
|
||||
namespace catchAdmin\system\controller;
|
||||
|
||||
use app\Request;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\exceptions\FailedException;
|
||||
use think\facade\Console;
|
||||
use think\facade\Db;
|
||||
use think\Paginator;
|
||||
|
||||
class DataDictionary extends CatchController
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月13日
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月13日
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function tables(Request $request): \think\response\Json
|
||||
{
|
||||
$tables = Db::query('show table status');
|
||||
|
||||
return CatchResponse::paginate(Paginator::make($tables, $request->get('limit') ?? 10, $request->get('page'), count($tables), false, []));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月13日
|
||||
* @param $table
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
public function view($table): string
|
||||
{
|
||||
$this->table = Db::query('show full columns from ' . $table);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月13日
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function optimize(): \think\response\Json
|
||||
{
|
||||
$tables = \request()->post('data');
|
||||
|
||||
foreach ($tables as $table) {
|
||||
Db::query(sprintf('optimize table %s', $table));
|
||||
}
|
||||
|
||||
return CatchResponse::success([], '优化成功');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月13日
|
||||
* @throws FailedException
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function backup(): \think\response\Json
|
||||
{
|
||||
try {
|
||||
Console::call('backup:data', [trim(implode(',', \request()->post('data')), ',')]);
|
||||
}catch (\Exception $e) {
|
||||
throw new FailedException($e->getMessage());
|
||||
}
|
||||
|
||||
return CatchResponse::success([], '备份成功');
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,10 @@ class OperateLog extends Migrator
|
||||
{
|
||||
$table = $this->table('operate_log',['engine'=>'Myisam', 'comment' => '操作日志', 'signed' => false]);
|
||||
$table->addColumn('module', 'string',['limit' => 50,'default'=>'','comment'=>'模块名称'])
|
||||
->addColumn('operate', 'string',['default'=> '', 'limit' => 20, 'comment'=>'操作模块'])
|
||||
->addColumn('route', 'string',['default'=> '','limit' => 20, 'comment'=>'路由'])
|
||||
->addColumn('params', 'string',['default'=> '','limit' => 1000, 'comment'=>'参数'])
|
||||
->addColumn('ip', 'string',['default'=>'', 'limit' => 20,'comment'=>'ip', 'signed' => false])
|
||||
->addColumn('operate', 'string',['default'=> '','comment'=>'操作模块'])
|
||||
->addColumn('creator_id', 'integer',['default'=> 0,'comment'=>'创建人ID', 'signed' => false])
|
||||
->addColumn('method', 'string',['default'=> '','comment'=>'请求方法'])
|
||||
->addColumn('created_at', 'integer', array('default'=>0,'comment'=>'登录时间', 'signed' => false ))
|
||||
|
@ -5,4 +5,11 @@ $router->get('loginLog/index', '\catchAdmin\system\controller\LoginLog@index');
|
||||
// 操作日志
|
||||
$router->get('log/operate', '\catchAdmin\system\controller\OperateLog@list');
|
||||
$router->get('operateLog/index', '\catchAdmin\system\controller\OperateLog@index');
|
||||
// 数据字典
|
||||
$router->get('data/dictionary', '\catchAdmin\system\controller\DataDictionary@index');
|
||||
$router->get('tables', '\catchAdmin\system\controller\DataDictionary@tables');
|
||||
$router->get('table/view/<table>', '\catchAdmin\system\controller\DataDictionary@view');
|
||||
$router->post('table/optimize', '\catchAdmin\system\controller\DataDictionary@optimize');
|
||||
$router->post('table/backup', '\catchAdmin\system\controller\DataDictionary@backup');
|
||||
|
||||
|
||||
|
@ -1,10 +1,113 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
{extend name="../../../view/layout"}
|
||||
{block name="title"}登录日志{/block}
|
||||
{block name="search"}
|
||||
<div class="layui-form toolbar">
|
||||
<div class="layui-form-item">
|
||||
<!--<div class="layui-inline">
|
||||
<div class="layui-input-inline mr0">
|
||||
<input id="edtSearchAuth" class="layui-input" type="text" placeholder="输入角色名称"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<button id="btnSearchAuth" class="layui-btn icon-btn"><i class="layui-icon"></i>搜索
|
||||
</button>-->
|
||||
<button id="optimize" class="layui-btn icon-btn"><i class="layui-icon"></i>优化</button>
|
||||
<button id="backup" class="layui-btn layui-btn-normal icon-btn"><i class="layui-icon"></i>备份</button>
|
||||
<!--</div>-->
|
||||
</div>
|
||||
</div>
|
||||
{/block}
|
||||
{block name="table"}
|
||||
<table class="layui-table" id="database" lay-filter="database"></table>
|
||||
<!-- 表格操作列 -->
|
||||
<script type="text/html" id="operate">
|
||||
{:editButton('查看', 'view')}
|
||||
</script>
|
||||
{/block}
|
||||
{block name="script"}
|
||||
<script>
|
||||
layui.use(['layer', 'table', 'util', 'admin'], function () {
|
||||
var $ = layui.jquery;
|
||||
var table = layui.table;
|
||||
var admin = layui.admin;
|
||||
|
||||
</body>
|
||||
</html>
|
||||
table.render({
|
||||
elem: '#database',
|
||||
url: '{:url("tables")}',
|
||||
page: true,
|
||||
response: {
|
||||
statusCode: 10000,
|
||||
},
|
||||
// toolbar: true,
|
||||
cellMinWidth: 100,
|
||||
cols: [[
|
||||
{type: 'checkbox'},
|
||||
{field: 'Name', title: '表名'},
|
||||
{field: 'Engine', title: '表引擎'},
|
||||
{field: 'Collation', title: '数据集'},
|
||||
{field: 'Rows',title: '数据行数'},
|
||||
{field: 'Index_length', title: '索引大小', templet: function (d) {
|
||||
if (d.Index_length < (1024 * 1024)) {
|
||||
return Math.round(d.Index_length / 1024) + 'KB'
|
||||
} else {
|
||||
return Math.round(d.Index_length/(1024 * 1024)) + 'MB'
|
||||
}
|
||||
}
|
||||
},
|
||||
{field: 'Data_length', title: '数据大小', templet: function (d) {
|
||||
if (d.Data_length < (1024 * 1024)) {
|
||||
return Math.round(d.Data_length / 1024) + 'KB'
|
||||
} else {
|
||||
return Math.round(d.Data_length/(1024 * 1024)) + 'MB'
|
||||
}
|
||||
}
|
||||
},
|
||||
{field: 'Create_time', title: '创建时间'},
|
||||
{field: 'Comment', title: '表注释'},
|
||||
{align: 'center', toolbar: '#operate', title: '操作'}
|
||||
]],
|
||||
});
|
||||
|
||||
// 工具条点击事件
|
||||
table.on('tool(database)', function (obj) {
|
||||
if (obj.event === 'view') { // 查看
|
||||
admin.open({
|
||||
title: '查看表结构',
|
||||
url: '/table/view/'+obj.data.Name,
|
||||
area: '900px',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#optimize').click(function () {
|
||||
var checkRows = table.checkStatus('database');
|
||||
if (checkRows.data.length == 0) {
|
||||
layer.msg('选择需要优化的表', {icon: 2});
|
||||
} else {
|
||||
var name = [];
|
||||
checkRows.data.map(function(item,index){
|
||||
name.push(item.Name)
|
||||
});
|
||||
admin.req("{:url('table/optimize')}", {data:name},function (response) {
|
||||
layer.msg(response.msg, {icon: 1})
|
||||
}, 'post')
|
||||
}
|
||||
})
|
||||
|
||||
$('#backup').click(function () {
|
||||
var checkRows = table.checkStatus('database');
|
||||
if (checkRows.data.length == 0) {
|
||||
layer.msg('选择需要备份的表', {icon: 2});
|
||||
} else {
|
||||
var name = [];
|
||||
checkRows.data.map(function(item,index){
|
||||
name.push(item.Name)
|
||||
});
|
||||
admin.req("{:url('table/backup')}", {data:name},function (response) {
|
||||
layer.msg(response.msg, {icon: response.code === 10000 ? 1 : 2})
|
||||
}, 'post')
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
{/block}
|
@ -5,6 +5,35 @@
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div style="padding: 10px">
|
||||
<table class="layui-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>字段</th>
|
||||
<th>类型</th>
|
||||
<th>字符集</th>
|
||||
<th>Null</th>
|
||||
<th>索引</th>
|
||||
<th>默认值</th>
|
||||
<th>权限</th>
|
||||
<th>注释</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach $table as $field}
|
||||
<tr>
|
||||
<td>{$field['Field']}</td>
|
||||
<td>{$field['Type']}</td>
|
||||
<td>{$field['Collation']}</td>
|
||||
<td>{$field['Null']}</td>
|
||||
<td>{$field['Key']}</td>
|
||||
<td>{$field['Default']}</td>
|
||||
<td>{$field['Privileges']}</td>
|
||||
<td>{$field['Comment']}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -3,16 +3,17 @@
|
||||
{block name="search"}
|
||||
<div class="layui-form toolbar">
|
||||
<div class="layui-form-item">
|
||||
<!--<div class="layui-inline">
|
||||
<div class="layui-inline">
|
||||
<div class="layui-input-inline mr0">
|
||||
<input id="edtSearchAuth" class="layui-input" type="text" placeholder="输入角色名称"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<button id="btnSearchAuth" class="layui-btn icon-btn"><i class="layui-icon"></i>搜索
|
||||
</button>-->
|
||||
<button id="btnAddAuth" class="layui-btn icon-btn"><i class="layui-icon"></i>添加</button>
|
||||
<!--</div>-->
|
||||
</button>
|
||||
<button id="btnAddAuth" class="layui-btn icon-btn"><i class="layui-icon">
|
||||
</i>清空</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/block}
|
||||
@ -36,17 +37,19 @@
|
||||
// toolbar: true,
|
||||
cellMinWidth: 100,
|
||||
cols: [[
|
||||
{type: 'id', title: '#', field: 'id'},
|
||||
{field: 'login_name', sort: true, title: '登录名'},
|
||||
{field: 'login_ip', sort: true, title: '登录IP'},
|
||||
{field: 'browser', sort: true, title: '浏览器'},
|
||||
{field: 'os', sort: true, title: '操作系统'},
|
||||
{field: 'status', sort: true, title: '状态', templet: function (d) {
|
||||
return d.status === 1 ? '成功' : '失败'
|
||||
{type: 'id', title: '序号', field: 'id'},
|
||||
{field: 'login_name', title: '登录名'},
|
||||
{field: 'login_ip', title: '登录IP'},
|
||||
{field: 'browser', title: '浏览器'},
|
||||
{field: 'os', title: '操作系统'},
|
||||
{field: 'status', title: '状态', templet: function (d) {
|
||||
return d.status === 1 ?
|
||||
'<button class="layui-btn layui-btn-xs">成功</button>' :
|
||||
'<button class="layui-btn layui-btn-xs layui-btn-danger">失败</button>'
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'login_at', sort: true, templet: function (d) {
|
||||
field: 'login_at', templet: function (d) {
|
||||
return util.toDateString(d.login_at);
|
||||
}, title: '登录时间'
|
||||
},
|
||||
|
@ -36,15 +36,16 @@
|
||||
// toolbar: true,
|
||||
cellMinWidth: 100,
|
||||
cols: [[
|
||||
{type: 'id', title: '#', field: 'id'},
|
||||
{field: 'module', sort: true, title: '模块'},
|
||||
{field: 'ip', sort: true, title: 'IP'},
|
||||
{field: 'operate', sort: true, title: 'operate'},
|
||||
{field: 'creator', sort: true, title: '操作者'},
|
||||
{field: 'method', sort: true, title: '请求方法'},
|
||||
{field: 'created_at', sort: true, title: '创建时间', templet: function (d) {
|
||||
return d.status === 1 ? '成功' : '失败'
|
||||
}
|
||||
{type: 'id', title: '序号', field: 'id'},
|
||||
{field: 'module', title: '模块'},
|
||||
{field: 'ip', title: 'IP'},
|
||||
{field: 'operate', title: 'operate'},
|
||||
{field: 'creator', title: '操作者'},
|
||||
{field: 'method', title: '请求方法'},
|
||||
{
|
||||
field: 'created_at', sort: true, templet: function (d) {
|
||||
return util.toDateString(d.created_at);
|
||||
}, title: '创建时间'
|
||||
},
|
||||
]],
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user