From fdf08b92e841b36bbca6047d4b5a7bb672da6fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Thu, 23 Feb 2017 16:19:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=8A=82=E7=82=B9=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Node.php | 60 ++++++++++++++++++++++++++ application/admin/view/node.index.html | 60 ++++++++++++++++++++++++++ extend/library/Tools.php | 8 ++-- 3 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 application/admin/controller/Node.php create mode 100644 application/admin/view/node.index.html diff --git a/application/admin/controller/Node.php b/application/admin/controller/Node.php new file mode 100644 index 000000000..11879d326 --- /dev/null +++ b/application/admin/controller/Node.php @@ -0,0 +1,60 @@ + + * @date 2017/02/15 18:13 + */ +class Node extends BasicAdmin { + + protected $table = 'SystemNode'; + + public function index() { + $this->title = '系统节点管理'; + parent::_list($this->table); + } + + protected function _index_data_filter($data) { + $nodes = []; + $alias = []; + foreach ($data as $vo) { + $alias["{$vo['node']}"] = $vo; + } + foreach (ModuleNode::getNodeTree(APP_PATH) as $thr) { + $tmp = explode('/', $thr); + $one = $tmp[0]; + $two = "{$tmp[0]}/{$tmp[1]}"; + $nodes[$one] = array_merge(isset($alias[$one]) ? $alias[$one] : ['node' => $one, 'title' => $thr, 'is_menu' => 0, 'is_auth' => 0], ['pnode' => '']); + $nodes[$two] = array_merge(isset($alias[$two]) ? $alias[$two] : ['node' => $two, 'title' => $thr, 'is_menu' => 0, 'is_auth' => 0], ['pnode' => $one]); + $nodes[$thr] = array_merge(isset($alias[$thr]) ? $alias[$thr] : ['node' => $thr, 'title' => $thr, 'is_menu' => 1, 'is_auth' => 1], ['pnode' => $two]); + } + $this->assign('nodes', Tools::arr2table($nodes, 'node', 'pnode')); + } + + public function save() { + if ($this->request->isPost()) { + $post = $this->request->post(); + foreach ($post as $key => $vo) { + if (stripos($key, 'title_') !== 0) { + continue; + } + $node = substr($key, strlen('title_')); + $data = ['node' => $node, 'title' => $vo, 'is_menu' => intval(!empty($post["menu_{$node}"])), 'is_auth' => intval(!empty($post["auth_{$node}"]))]; + Data::save($this->table, $data, 'node'); + } + $this->success('参数保存成功!', ''); + } else { + $this->error('访问异常,请重新进入...'); + } + } + +} diff --git a/application/admin/view/node.index.html b/application/admin/view/node.index.html new file mode 100644 index 000000000..15b0ffa35 --- /dev/null +++ b/application/admin/view/node.index.html @@ -0,0 +1,60 @@ +{extend name='extra@admin/content' /} + +{block name="content"} + +
+ +
+ +
+ + + + + + + + + + + + {foreach $nodes as $key=>$vo} + + + + + + + {/foreach} + +
节点代码节点名称 权限控制 是否菜单
+ {$vo.spl}{$vo.node} + + {if substr_count($vo['node'],'/')==2} + {notempty name='vo.is_auth'} + + {else /} + + {/notempty} + {/if} + + {if substr_count($vo['node'],'/')==2} + {notempty name='vo.is_menu'} + + {else/} + + {/notempty} + {/if} +
+ +
+{/block} \ No newline at end of file diff --git a/extend/library/Tools.php b/extend/library/Tools.php index 91663a4ce..5b7d79e9f 100644 --- a/extend/library/Tools.php +++ b/extend/library/Tools.php @@ -44,10 +44,10 @@ class Tools { * @return array */ static public function arr2table($list, $id = 'id', $pid = 'pid', $path = 'path', $ppath = '') { - $_array_tree = self::arr2tree($list); + $_array_tree = self::arr2tree($list, $id, $pid); $tree = array(); foreach ($_array_tree as $_tree) { - $_tree[$path] = $ppath . '-' . $_tree['id']; + $_tree[$path] = $ppath . '-' . $_tree[$id]; $_tree['spl'] = str_repeat("   ├ ", substr_count($ppath, '-')); if (!isset($_tree['sub'])) { $_tree['sub'] = array(); @@ -57,7 +57,7 @@ class Tools { $tree[] = $_tree; if (!empty($sub)) { $sub_array = self::arr2table($sub, $id, $pid, $path, $_tree[$path]); - $tree = array_merge($tree, (Array)$sub_array); + $tree = array_merge($tree, (Array) $sub_array); } } return $tree; @@ -103,7 +103,7 @@ class Tools { $tree[] = $_tree; if (!empty($sub)) { $sub_array = self::node2table($sub, $node, $pnode, $path, $_tree[$path . "_node"]); - $tree = array_merge($tree, (Array)$sub_array); + $tree = array_merge($tree, (Array) $sub_array); } } return $tree;