diff --git a/application/admin/controller/Menu.php b/application/admin/controller/Menu.php index 4503ae494..73fc1d024 100644 --- a/application/admin/controller/Menu.php +++ b/application/admin/controller/Menu.php @@ -8,7 +8,13 @@ use library\Node; use library\Tools; use think\Db; - +/** + * 系统后台管理管理 + * + * @package app\admin\controller + * @author Anyon + * @date 2017/02/15 + */ class Menu extends BasicAdmin { /** @@ -23,29 +29,22 @@ class Menu extends BasicAdmin { */ protected $table = 'SystemMenu'; - /** - * 关闭分页 - * @var bool - */ - protected $_page_on = false; - /** * 定义菜单链接打开方式 * @var array */ - protected $targetList = array( + protected $targetList = [ '_self' => '本窗口打开', '_blank' => '新窗口打开', '_parent' => '父窗口打开', '_top' => '顶级窗口打开', - ); + ]; /** * 菜单列表 */ public function index() { - $db = Db::name($this->table); - parent::_list($db, false); + parent::_list($this->table, false); } /** diff --git a/application/extra/view/admin.main.html b/application/extra/view/admin.main.html index 69691483e..eef906c73 100644 --- a/application/extra/view/admin.main.html +++ b/application/extra/view/admin.main.html @@ -10,6 +10,7 @@ {block name="style"}{/block} + diff --git a/extend/controller/BasicAdmin.php b/extend/controller/BasicAdmin.php index 008720833..d8a7794fe 100644 --- a/extend/controller/BasicAdmin.php +++ b/extend/controller/BasicAdmin.php @@ -3,6 +3,7 @@ namespace controller; use think\Controller; +use think\Db; use think\db\Query; /** @@ -14,17 +15,47 @@ use think\db\Query; */ class BasicAdmin extends Controller { + /** + * 默认操作数据表 + * @var string + */ + protected $table; + + /** + * 默认检查用户登录状态 + * @var bool + */ + protected $checkLogin = true; + + /** + * 默认检查节点访问权限 + * @var bool + */ + protected $checkAuth = true; + /** * 后台权限控制初始化方法 */ public function _initialize() { - if (!$this->isLogin()) { - $this->redirect('@admin/login'); + # 用户登录状态检查 + if ($this->checkLogin || $this->checkAuth) { + if (!$this->isLogin()) { + $this->redirect('@admin/login'); + } } - // 初始化赋值常用变量 + # 节点访问权限检查 + if ($this->checkLogin && $this->checkAuth) { + $node = strtolower($this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action()); + if (!auth($node)) { + $this->error('抱歉,您没有访问该模块的权限!'); + } + } + # 初始化赋值常用变量 if ($this->request->isGet()) { - $this->assign('classuri', strtolower($this->request->module() . '/' . $this->request->controller())); + $class_uri = strtolower($this->request->module() . '/' . $this->request->controller()); + $this->assign('classuri', $class_uri); } + } /** @@ -48,9 +79,8 @@ class BasicAdmin extends Controller { * @return array|string */ protected function _list($db = null, $is_page = true, $is_display = true, $total = false) { - is_null($db) && $db = db($this->table); - is_string($db) && $db = db($db); - !$db->getTable() && $db->setTable($this->table); + is_null($db) && $db = Db::name($this->table); + is_string($db) && $db = Db::name($db); # 列表排序默认处理 if ($this->request->isPost() && $this->request->post('action') === 'resort') { $data = $this->request->post(); @@ -67,7 +97,7 @@ class BasicAdmin extends Controller { if ($is_page) { $row_page = $this->request->get('rows', cookie('rows'), 'intval'); cookie('rows', $row_page >= 10 ? $row_page : 10); - $page = $db->paginate($row_page, $total, ['query' => input('get.')]); + $page = $db->paginate($row_page, $total, ['query' => $this->request->get()]); $result['list'] = $page->all(); $result['page'] = preg_replace(['|href="(.*?)"|', '|pagination|'], ['data-open="$1" href="javascript:void(0);"', 'pagination pull-right'], $page->render()); } else { @@ -101,8 +131,7 @@ class BasicAdmin extends Controller { $this->_callback('_form_filter', $vo); $result = Data::save($db, $vo, $pk, $where); if (false !== $this->_callback('_form_result', $result)) { - $back = $pk_value === '' ? 'javascript:history.back();' : 'javascript:$.form.reload();'; - $result !== false ? $this->success('恭喜,保存成功哦!', $back) : $this->error('保存失败,请稍候再试!'); + $result !== false ? $this->success('恭喜,保存成功哦!', ($pk_value === '' ? null : '')) : $this->error('保存失败,请稍候再试!'); } return $result; } diff --git a/public/static/admin/app.js b/public/static/admin/app.js index a59f58295..99da2d9a5 100644 --- a/public/static/admin/app.js +++ b/public/static/admin/app.js @@ -37,7 +37,7 @@ require.config({ 'admin.listen': {deps: ['jquery', 'jquery.cookies', 'admin.plugs']}, }, deps: ['css!//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css'], - // urlArgs: "t=" + (new Date()).getTime() + urlArgs: "t=" + (new Date()).getTime() }); window.WEB_SOCKET_SWF_LOCATION = "//cdn.bootcss.com/web-socket-js/1.0.0/WebSocketMain.swf"; diff --git a/public/static/admin/plugs.js b/public/static/admin/plugs.js index 3909f936b..131ffd3c6 100644 --- a/public/static/admin/plugs.js +++ b/public/static/admin/plugs.js @@ -166,7 +166,7 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) { !!data.url ? (window.location.href = data.url) : $.form.reload(); }); } - self.error(data.msg, 3000, function () { + self.error(data.msg, 3, function () { !!data.url && (window.location.href = data.url); }); }; @@ -179,7 +179,7 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) { /** * 表单构造函数 - * @returns {common_L11._form} + * @private */ function _form() { this.version = '2.0'; @@ -189,13 +189,13 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) { /** * 异步加载的数据 - * @param {type} url 请求的地址 - * @param {json|form|$form} data 额外请求数据 - * @param {type} type 提交的类型 GET|POST - * @param {type} callback 成功后的回调方法 - * @param {type} loading 是否显示加载层 - * @param {type} tips 提示消息 - * @param {type} time 消息提示时间 + * @param url 请求的地址 + * @param data 额外请求数据 + * @param type 提交的类型 GET|POST + * @param callback 成功后的回调方法 + * @param loading 是否显示加载层 + * @param tips 提示消息 + * @param time 消息提示时间 */ _form.prototype.load = function (url, data, type, callback, loading, tips, time) { var self = this; @@ -244,10 +244,10 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) { }); }); }; + /** * 动态HTML事件重载 - * @param {type} $container - * @returns {undefined} + * @param $container */ _form.prototype.reInit = function ($container) { $.validate.listen.call(this); @@ -266,15 +266,15 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) { /* 自动给必填字符加上样式 @zoujingli @by 2016-05-11 */ $container.find('[required]').parent().prevAll('label').addClass('label-required'); }; + /** * 加载HTML到目标位置 - * @param {type} url - * @param {type} data - * @param {type} target - * @param {type} callback - * @param {type} loading - * @param {type} tips - * @returns {undefined} + * @param url + * @param data + * @param target + * @param callback + * @param loading + * @param tips */ _form.prototype.open = function (url, data, target, callback, loading, tips) { data && (typeof (data) === 'object') && (data = $.param(data)); @@ -284,25 +284,21 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) { return $.msg.auto(res); } var $container = $('.layer-main-container').html(res); - - function reinit() { - /* 事件重载 */ - $.form.reInit($container); - } - reinit.call(this), setTimeout(reinit, 500), setTimeout(reinit, 1000); return (typeof callback === 'function') && callback.call(this); + function reinit() { + $.form.reInit($container); + } }, loading, tips); }; /** * 加载HTML到弹出层 - * @param {type} url - * @param {type} data - * @param {type} callback - * @param {type} loading - * @param {type} tips - * @returns {undefined} + * @param url + * @param data + * @param callback + * @param loading + * @param tips */ _form.prototype.modal = function (url, data, callback, loading, tips) { data && (typeof (data) === 'object') && (data = $.param(data)); @@ -333,24 +329,21 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) { /** * 显示HTML到中主内容区 - * @param {type} html - * @returns {undefined} + * @param html */ _form.prototype.show = function (html) { var $container = $('.layer-main-container').html(html); - + reinit.call(this), setTimeout(reinit, 500), setTimeout(reinit, 1000); function reinit() { $.validate.listen.call(this); $container.find('h3').addClass('animated fadeIn container-animated'); } - - reinit.call(this), setTimeout(reinit, 500), setTimeout(reinit, 1000); }; /** * 打开一个iframe窗口 - * @param {type} url - * @returns {unresolved} + * @param url + * @param title */ _form.prototype.iframe = function (url, title) { return layer.open({ @@ -365,13 +358,15 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) { /** * 关闭FORM框 - * @returns {undefined} + * @return {*|jQuery} */ _form.prototype.close = function () { return $(this._modal).modal('hide'); }; - /*刷新当前页面*/ + /** + * 刷新当前页面 + */ _form.prototype.reload = function () { window.onhashchange.call(this); };