diff --git a/application/admin/controller/general/Config.php b/application/admin/controller/general/Config.php index 035d8a9c..0d6d9c26 100644 --- a/application/admin/controller/general/Config.php +++ b/application/admin/controller/general/Config.php @@ -85,10 +85,10 @@ class Config extends Backend if ($result !== false) { try { $this->refreshFile(); - $this->success(); } catch (Exception $e) { $this->error($e->getMessage()); } + $this->success(); } else { $this->error($this->model->getError()); } @@ -126,15 +126,32 @@ class Config extends Backend $this->model->allowField(true)->saveAll($configList); try { $this->refreshFile(); - $this->success(); } catch (Exception $e) { $this->error($e->getMessage()); } + $this->success(); } $this->error(__('Parameter %s can not be empty', '')); } } + public function del($ids = "") + { + $name = $this->request->request('name'); + $config = ConfigModel::getByName($name); + if ($config) { + try { + $config->delete(); + $this->refreshFile(); + } catch (Exception $e) { + $this->error($e->getMessage()); + } + $this->success(); + } else { + $this->error(__('Invalid parameters')); + } + } + /** * 刷新配置文件 */ diff --git a/application/admin/model/UserRule.php b/application/admin/model/UserRule.php index 641d65b0..51391c1d 100644 --- a/application/admin/model/UserRule.php +++ b/application/admin/model/UserRule.php @@ -2,6 +2,7 @@ namespace app\admin\model; +use fast\Tree; use think\Model; class UserRule extends Model @@ -43,8 +44,16 @@ class UserRule extends Model { $ruleList = collection(self::where('status', 'normal')->order('weigh desc,id desc')->select())->toArray(); $nodeList = []; + Tree::instance()->init($ruleList); + $ruleList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name'); + $hasChildrens = []; + foreach ($ruleList as $k => $v) + { + if ($v['haschild']) + $hasChildrens[] = $v['id']; + } foreach ($ruleList as $k => $v) { - $state = array('selected' => $v['ismenu'] ? false : in_array($v['id'], $selected)); + $state = array('selected' => in_array($v['id'], $selected) && !in_array($v['id'], $hasChildrens)); $nodeList[] = array('id' => $v['id'], 'parent' => $v['pid'] ? $v['pid'] : '#', 'text' => __($v['title']), 'type' => 'menu', 'state' => $state); } return $nodeList; diff --git a/application/admin/view/general/config/index.html b/application/admin/view/general/config/index.html index 78fdccd7..6b8036bd 100644 --- a/application/admin/view/general/config/index.html +++ b/application/admin/view/general/config/index.html @@ -4,10 +4,16 @@ .edit-form tr th:first-child,.edit-form tr td:first-child{ width:20%; } - .edit-form tr th:last-child,.edit-form tr td:last-child{ + .edit-form tr th:nth-last-of-type(-n+2),.edit-form tr td:nth-last-of-type(-n+2){ display: none; } } + .edit-form table > tbody > tr td a.btn-delcfg{ + visibility: hidden; + } + .edit-form table > tbody > tr:hover td a.btn-delcfg{ + visibility: visible; + }