diff --git a/app/home/common.php b/app/home/common.php index e37e75c..dd9d86a 100644 --- a/app/home/common.php +++ b/app/home/common.php @@ -86,14 +86,14 @@ function get_login_admin($key = '') //读取后台菜单列表 function get_admin_menu() { - $menu = Db::name('AdminMenu')->order('sort asc')->select()->toArray(); + $menu = Db::name('AdminMenu')->order('sort asc,id asc')->select()->toArray(); return $menu; } //读取权限节点列表 function get_admin_rule() { - $rule = Db::name('AdminRule')->order('id desc')->select()->toArray(); + $rule = Db::name('AdminRule')->order('sort asc,id asc')->select()->toArray(); return $rule; } diff --git a/app/home/controller/Menu.php b/app/home/controller/Menu.php index a75062a..a8b1e08 100644 --- a/app/home/controller/Menu.php +++ b/app/home/controller/Menu.php @@ -33,18 +33,15 @@ class Menu extends BaseController $param = get_params(); if (request()->isAjax()) { if ($param['id'] > 0) { - $data[$param['field']] = $param['value']; - $data['id'] = $param['id']; - if (!empty($data['title'])) { - try { - validate(MenuCheck::class)->scene('edit')->check($data); - } catch (ValidateException $e) { - // 验证失败 输出错误信息 - return to_assign(1, $e->getError()); - } + try { + validate(MenuCheck::class)->scene('edit')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); } - Db::name('AdminMenu')->strict(false)->field(true)->update($data); - add_log('edit', $param['id'], $data); + $param['update_time'] = time(); + Db::name('AdminMenu')->strict(false)->field(true)->update($param); + add_log('edit', $param['id'], $param); } else { try { validate(MenuCheck::class)->scene('add')->check($param); @@ -52,6 +49,7 @@ class Menu extends BaseController // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } + $param['create_time'] = time(); $mid = Db::name('AdminMenu')->strict(false)->field(true)->insertGetId($param); //自动为系统所有者管理组分配新增的菜单 $group = Db::name('AdminGroup')->find(1); @@ -67,6 +65,12 @@ class Menu extends BaseController return to_assign(); } else { $id = isset($param['id']) ? $param['id'] : 0; + $pid = isset($param['pid']) ? $param['pid'] : 0; + if($id>0){ + $detail = Db::name('AdminMenu')->where('id',$id)->find(); + View::assign('detail', $detail); + } + View::assign('id', $id); View::assign('pid', $pid); return view(); } diff --git a/app/home/controller/Rule.php b/app/home/controller/Rule.php index 9a5fdae..c58785e 100644 --- a/app/home/controller/Rule.php +++ b/app/home/controller/Rule.php @@ -33,26 +33,14 @@ class Rule extends BaseController $param = get_params(); if (request()->isAjax()) { if ($param['id'] > 0) { - $data[$param['field']] = $param['value']; - $data['id'] = $param['id']; - if (!empty($data['title'])) { - try { - validate(RuleCheck::class)->scene('edit_title')->check($data); - } catch (ValidateException $e) { - // 验证失败 输出错误信息 - return to_assign(1, $e->getError()); - } + try { + validate(RuleCheck::class)->scene('edit')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); } - if (!empty($data['src'])) { - try { - validate(RuleCheck::class)->scene('edit_src')->check($data); - } catch (ValidateException $e) { - // 验证失败 输出错误信息 - return to_assign(1, $e->getError()); - } - } - Db::name('AdminRule')->strict(false)->field(true)->update($data); - add_log('edit', $param['id'], $data); + Db::name('AdminRule')->strict(false)->field(true)->update($param); + add_log('edit', $param['id'], $param); } else { try { validate(RuleCheck::class)->scene('add')->check($param); @@ -60,6 +48,7 @@ class Rule extends BaseController // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } + $param['create_time'] = time(); $rid = Db::name('AdminRule')->strict(false)->field(true)->insertGetId($param); //自动为系统所有者管理组分配新增的节点 $group = Db::name('AdminGroup')->find(1); @@ -74,7 +63,13 @@ class Rule extends BaseController clear_cache('adminRules'); return to_assign(); } else { + $id = isset($param['id']) ? $param['id'] : 0; $pid = isset($param['pid']) ? $param['pid'] : 0; + if($id>0){ + $detail = Db::name('AdminRule')->where('id',$id)->find(); + View::assign('detail', $detail); + } + View::assign('id', $id); View::assign('pid', $pid); return view(); } diff --git a/app/home/validate/RuleCheck.php b/app/home/validate/RuleCheck.php index 9a33090..c837a2b 100644 --- a/app/home/validate/RuleCheck.php +++ b/app/home/validate/RuleCheck.php @@ -13,6 +13,7 @@ class RuleCheck extends Validate { protected $rule = [ 'title' => 'require|unique:admin_rule', + 'name' => 'require', 'src' => 'unique:admin_rule', 'id' => 'require', ]; @@ -21,13 +22,13 @@ class RuleCheck extends Validate 'title.require' => '节点名称不能为空', 'title.unique' => '同样的节点名称已经存在', 'src.unique' => '同样的节点规则已经存在', + 'name.require' => '节点日志操作名称不能为空', 'id.require' => '缺少更新条件', 'filed.require' => '缺少要更新的字段名', ]; protected $scene = [ - 'add' => ['title','src'], - 'edit_title' => ['id', 'title'], - 'edit_src' => ['id', 'src'], + 'add' => ['title','src','name'], + 'edit' => ['id', 'title','src','name'] ]; } diff --git a/app/home/view/admin/log.html b/app/home/view/admin/log.html index 9438556..2dce31b 100644 --- a/app/home/view/admin/log.html +++ b/app/home/view/admin/log.html @@ -62,7 +62,7 @@ field: 'param', title: '操作数据' }, { - field: 'nickname', + field: 'name', title: '操作用户', align: 'center', width: 100 diff --git a/app/home/view/conf/add.html b/app/home/view/conf/add.html index ede337f..4fa6bf0 100644 --- a/app/home/view/conf/add.html +++ b/app/home/view/conf/add.html @@ -2,7 +2,8 @@ {block name="body"}