From 7e831339c8e0f2ee35a0daf27ac9f5eb6f1400d1 Mon Sep 17 00:00:00 2001 From: Karson Date: Sat, 1 Dec 2018 22:02:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=B3=BB=E7=BB=9F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BC=9A=E5=91=98=E5=88=86=E7=BB=84=E8=A7=84=E5=88=99?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/general/Config.php | 21 +++++++++++++++++-- application/admin/model/UserRule.php | 11 +++++++++- .../admin/view/general/config/index.html | 13 ++++++++++-- public/assets/js/backend/general/config.js | 15 +++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) 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; + }
@@ -32,8 +38,9 @@ {:__('Title')} - {:__('Value')} + {:__('Value')} {:__('Name')} + @@ -121,6 +128,7 @@ {php}echo "{\$site.". $item['name'] . "}";{/php} + {/foreach} @@ -132,6 +140,7 @@ + diff --git a/public/assets/js/backend/general/config.js b/public/assets/js/backend/general/config.js index 3e584b67..d56d000d 100644 --- a/public/assets/js/backend/general/config.js +++ b/public/assets/js/backend/general/config.js @@ -73,6 +73,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin }); }); + + //删除配置 + $(document).on("click", ".btn-delcfg", function () { + var that = this; + Layer.confirm(__('Are you sure you want to delete this item?'), {icon: 3, title:'提示'}, function (index) { + Backend.api.ajax({ + url: "general/config/del?receiver=" + value, + data: {name: $(that).data("name")} + }, function () { + $(that).closest("tr").remove(); + Layer.close(index); + }); + }); + + }); }, add: function () { Controller.api.bindevent();