From 98060d5128c41c5eedd1ef1a05d66be561f5c2cf Mon Sep 17 00:00:00 2001 From: Karson <karsonzhang@163.com> Date: Wed, 12 Jul 2017 13:28:20 +0800 Subject: [PATCH] 修复CRUD时使用带前缀表时的BUG 修复安卓下快捷搜索菜单的BUG --- application/admin/command/Crud.php | 23 +++++++++-------------- public/assets/js/backend/index.js | 9 ++++++++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php index 6645e3e..7f81d96 100644 --- a/application/admin/command/Crud.php +++ b/application/admin/command/Crud.php @@ -201,7 +201,8 @@ class Crud extends Command $prefix = Config::get('database.prefix'); //检查主表 - $tableName = $table; + $table = stripos($table, $prefix) === 0 ? substr($table, strlen($prefix)) : $table; + $modelTableName = $tableName = $table; $modelTableType = 'table'; $tableInfo = Db::query("SHOW TABLE STATUS LIKE '{$tableName}'", [], TRUE); if (!$tableInfo) @@ -214,21 +215,19 @@ class Crud extends Command throw new Exception("table not found"); } } - else - { - $table = stripos($table, $prefix) === 0 ? substr($table, strlen($prefix)) : $table; - } $tableInfo = $tableInfo[0]; + $relationModelTableName = $relationTableName = $relation; $relationModelTableType = 'table'; //检查关联表 if ($relation) { - $relationTableName = $prefix . $relation; + $relation = stripos($relation, $prefix) === 0 ? substr($relation, strlen($prefix)) : $relation; + $relationModelTableName = $relationTableName = $relation; $relationTableInfo = Db::query("SHOW TABLE STATUS LIKE '{$relationTableName}'", [], TRUE); if (!$relationTableInfo) { - $relationTableName = $relation; + $relationTableName = $prefix . $relation; $relationModelTableType = 'name'; $relationTableInfo = Db::query("SHOW TABLE STATUS LIKE '{$relationTableName}'", [], TRUE); if (!$relationTableInfo) @@ -236,10 +235,6 @@ class Crud extends Command throw new Exception("relation table not found"); } } - else - { - $relation = stripos($relation, $prefix) === 0 ? substr($relation, strlen($prefix)) : $relation; - } } //根据表名匹配对应的Fontawesome图标 @@ -247,6 +242,7 @@ class Crud extends Command $iconName = is_file($iconPath) && stripos(file_get_contents($iconPath), '@fa-var-' . $table . ':') ? $table : 'fa fa-circle-o'; //控制器默认以表名进行处理,以下划线进行分隔,如果需要自定义则需要传入controller,格式为目录层级 + $controller = str_replace('_', '', $controller); $controllerArr = !$controller ? explode('_', strtolower($table)) : explode('/', strtolower($controller)); $controllerUrl = implode('/', $controllerArr); $controllerName = ucfirst(array_pop($controllerArr)); @@ -670,7 +666,6 @@ class Crud extends Command } } - //JS最后一列加上操作列 $javascriptList[] = str_repeat(" ", 24) . "{field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}"; $addList = implode("\n", array_filter($addList)); @@ -718,9 +713,9 @@ class Crud extends Command 'modelAutoWriteTimestamp' => in_array('createtime', $fieldArr) || in_array('updatetime', $fieldArr) ? "'int'" : 'false', 'createTime' => in_array('createtime', $fieldArr) ? "'createtime'" : 'false', 'updateTime' => in_array('updatetime', $fieldArr) ? "'updatetime'" : 'false', - 'modelTableName' => $table, + 'modelTableName' => $modelTableName, 'modelTableType' => $modelTableType, - 'relationModelTableName' => $relation, + 'relationModelTableName' => $relationModelTableName, 'relationModelTableType' => $relationModelTableType, 'relationModelName' => $relationModelName, 'relationWith' => '', diff --git a/public/assets/js/backend/index.js b/public/assets/js/backend/index.js index 6ad7a9e..39fc7ae 100755 --- a/public/assets/js/backend/index.js +++ b/public/assets/js/backend/index.js @@ -13,13 +13,20 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'adminlte', 'form'], functi }); e.stopPropagation(); }); - + //快捷搜索 $(".menuresult").width($("form.sidebar-form > .input-group").width()); + var isAndroid = /(android)/i.test(navigator.userAgent); var searchResult = $(".menuresult"); $("form.sidebar-form").on("blur", "input[name=q]", function () { searchResult.addClass("hide"); + if (isAndroid) { + $.AdminLTE.options.sidebarSlimScroll = true; + } }).on("focus", "input[name=q]", function () { + if (isAndroid) { + $.AdminLTE.options.sidebarSlimScroll = false; + } if ($("a", searchResult).size() > 0) { searchResult.removeClass("hide"); } -- libgit2 0.24.0