增加数据字典

This commit is contained in:
JaguarJack 2019-01-18 14:33:54 +08:00
parent a17f53f967
commit 8a98d585a2
4 changed files with 158 additions and 2 deletions

View File

@ -0,0 +1,63 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/1/18
* Time: 10:36
*/
namespace app\admin\controller;
use think\Db;
class Database extends Base
{
/**
* 数据字典列表
*
* @time at 2019年01月18日
* @return mixed
*/
public function index()
{
$this->tables = Db::query('SHOW TABLE STATUS');
return $this->fetch();
}
/**
* 优化表
*
* @time at 2019年01月18日
* @return void
*/
public function optimize()
{
$table = $this->request->post('table');
if (!$table) {
$this->error('参数错误, 未指定表');
}
Db::query(sprintf('optimize table %s', $table)) ? $this->success('优化成功') : $this->error('优化失败');
}
/**
*
*
* @time at 2019年01月18日
* @return void
*/
public function view()
{
$table = $this->request->param('table');
if (!$table) {
$this->error('参数错误', '未指定表');
}
$this->table = Db::query('show full columns from ' . $table);
return $this->fetch();
}
}

View File

@ -24,13 +24,13 @@ class LogRecordModel extends BaseModel
public function getAll(array $params, $limit = self::LIMIT) public function getAll(array $params, $limit = self::LIMIT)
{ {
if (!count($params)) { if (!count($params)) {
return $this->paginate($limit, false, ['query' => request()->param()]); return $this->order('created_at', 'desc')->paginate($limit, false, ['query' => request()->param()]);
} }
if (isset($params['name'])) { if (isset($params['name'])) {
$list = $this->whereLike('user_name', '%'.$params['name'].'%'); $list = $this->whereLike('user_name', '%'.$params['name'].'%');
} }
return $list->paginate($limit, false, ['query' => request()->param()]); return $list->order('created_at', 'desc')->paginate($limit, false, ['query' => request()->param()]);
} }
} }

View File

@ -0,0 +1,63 @@
{extend name="public:base" /}
{block name="menu"}数据字段{/block}
{block name="table-head"}
<tr>
<th>表名</th>
<th>引擎</th>
<th>字符集</th>
<th>索引大小</th>
<th>数据大小</th>
<th>行数</th>
<th>备注</th>
<th>创建时间</th>
<th>操作</th>
</tr>
{/block}
{block name="table-body"}
{if condition="!count($tables)"}
<tr>
<td colspan="7" class="text-center">没有数据</td>
</tr>
{else/}
{foreach $tables as $key => $table}
<tr>
<td>{$table['Name']}</td>
<td>{$table['Engine']}</td>
<td>{$table['Collation']}</td>
<td>{$table['Index_length']}</td>
<td>{$table['Data_length']}</td>
<td>{$table['Rows']}</td>
<td>{$table['Comment']}</td>
<td>{$table['Create_time']}</td>
<td>
<button class="btn btn-info btn-xs" type="button" data="{$table['Name']}" onclick="optimize($(this).attr('data'));">优化</button>
<button class="btn btn-primary btn-xs" type="button" data="{:url('database/view', ['table' => $table['Name']])}" onclick="view($(this).attr('data'));">查看</button>
</td>
</tr>
{/foreach}
{/if}
{/block}
{block name="js"}
<script>
// 优化
function optimize(table) {
$.post("{:url('database/optimize')}", {table: table}, function (response) {
if (!response.code) {
error(response.msg);
} else {
success(response.msg);
}
})
}
// 查看数据表结构
function view(url) {
layer.open({
type: 2,
title: '数据表结构',
closeBtn: 1, //不显示关闭按钮
area: ['800px', '600px'],
content: url, //iframe的urlno代表不显示滚动条
});
}
</script>
{/block}

View File

@ -0,0 +1,30 @@
{extend name="public:base" /}
{block name="menu"}数据表结构{/block}
{block name="table-head"}
<tr>
<th>字段名</th>
<th>类型</th>
<th>是否为NULL</th>
<th>默认值</th>
<th>备注</th>
<th>权限</th>
</tr>
{/block}
{block name="table-body"}
{if condition="!count($table)"}
<tr>
<td colspan="7" class="text-center">没有数据</td>
</tr>
{else/}
{foreach $table as $key => $t}
<tr>
<td>{$t['Field']}</td>
<td>{$t['Type']}</td>
<td>{$t['Null']}</td>
<td>{$t['Default']}</td>
<td>{$t['Comment']}</td>
<td>{$t['Privileges']}</td>
</tr>
{/foreach}
{/if}
{/block}