mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
更新节点模块
This commit is contained in:
parent
c4b8e24d56
commit
fdf08b92e8
60
application/admin/controller/Node.php
Normal file
60
application/admin/controller/Node.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use controller\BasicAdmin;
|
||||||
|
use library\Data;
|
||||||
|
use library\Node as ModuleNode;
|
||||||
|
use library\Tools;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统功能节点管理
|
||||||
|
* Class Node
|
||||||
|
* @package app\admin\controller
|
||||||
|
* @author Anyon <zoujingli@qq.com>
|
||||||
|
* @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('访问异常,请重新进入...');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
application/admin/view/node.index.html
Normal file
60
application/admin/view/node.index.html
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
{extend name='extra@admin/content' /}
|
||||||
|
|
||||||
|
{block name="content"}
|
||||||
|
|
||||||
|
<form onsubmit="return false;" action='{:url("$classuri/save")}' data-auto="true" method="POST">
|
||||||
|
|
||||||
|
<div class="text-right" style='margin-bottom:10px'>
|
||||||
|
<button type="submit" class='layui-btn layui-btn-small'><i class='fa fa-save'></i> 保存更改</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class='text-left'>节点代码</th>
|
||||||
|
<th class='text-left'>节点名称</th>
|
||||||
|
<th class='text-left'><input data-none-auto="" data-check-target='.auth-check-box' type='checkbox'/> 权限控制</th>
|
||||||
|
<th class='text-left'><input data-none-auto="" data-check-target='.menu-check-box' type='checkbox'/> 是否菜单</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{foreach $nodes as $key=>$vo}
|
||||||
|
<tr>
|
||||||
|
<td class='text-left'>
|
||||||
|
{$vo.spl}{$vo.node}
|
||||||
|
</td>
|
||||||
|
<td><input name='title.{$vo.node}' value="{$vo.title}"/></td>
|
||||||
|
<td class='text-left'>
|
||||||
|
{if substr_count($vo['node'],'/')==2}
|
||||||
|
{notempty name='vo.is_auth'}
|
||||||
|
<input name='auth.{$vo.node}' checked='checked' class="auth-check-box" type='checkbox' value='1'/>
|
||||||
|
{else /}
|
||||||
|
<input name='auth.{$vo.node}' class="auth-check-box" type='checkbox' value='1'/>
|
||||||
|
{/notempty}
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
<td class='text-left'>
|
||||||
|
{if substr_count($vo['node'],'/')==2}
|
||||||
|
{notempty name='vo.is_menu'}
|
||||||
|
<input name='menu.{$vo.node}' checked='checked' class='menu-check-box' type='checkbox' value='1'/>
|
||||||
|
{else/}
|
||||||
|
<input name='menu.{$vo.node}' class='menu-check-box' type='checkbox' value='1'/>
|
||||||
|
{/notempty}
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/foreach}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<script>
|
||||||
|
$(function () {
|
||||||
|
$('input[type=checkbox]').on('click', function () {
|
||||||
|
var checked = !!this.checked;
|
||||||
|
$('[name^="' + this.name + '"]').map(function () {
|
||||||
|
this.checked = checked;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</form>
|
||||||
|
{/block}
|
@ -44,10 +44,10 @@ class Tools {
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
static public function arr2table($list, $id = 'id', $pid = 'pid', $path = 'path', $ppath = '') {
|
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();
|
$tree = array();
|
||||||
foreach ($_array_tree as $_tree) {
|
foreach ($_array_tree as $_tree) {
|
||||||
$_tree[$path] = $ppath . '-' . $_tree['id'];
|
$_tree[$path] = $ppath . '-' . $_tree[$id];
|
||||||
$_tree['spl'] = str_repeat(" ├ ", substr_count($ppath, '-'));
|
$_tree['spl'] = str_repeat(" ├ ", substr_count($ppath, '-'));
|
||||||
if (!isset($_tree['sub'])) {
|
if (!isset($_tree['sub'])) {
|
||||||
$_tree['sub'] = array();
|
$_tree['sub'] = array();
|
||||||
@ -57,7 +57,7 @@ class Tools {
|
|||||||
$tree[] = $_tree;
|
$tree[] = $_tree;
|
||||||
if (!empty($sub)) {
|
if (!empty($sub)) {
|
||||||
$sub_array = self::arr2table($sub, $id, $pid, $path, $_tree[$path]);
|
$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;
|
return $tree;
|
||||||
@ -103,7 +103,7 @@ class Tools {
|
|||||||
$tree[] = $_tree;
|
$tree[] = $_tree;
|
||||||
if (!empty($sub)) {
|
if (!empty($sub)) {
|
||||||
$sub_array = self::node2table($sub, $node, $pnode, $path, $_tree[$path . "_node"]);
|
$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;
|
return $tree;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user