Browse Source

权限设置

master
林一峰 8 years ago
parent
commit
f4f838622f
  1. 13
      app/Http/Controllers/Admin/IndexController.php
  2. 3
      app/Http/Controllers/Admin/MenuController.php
  3. 62
      app/Http/Controllers/Admin/UserRoleController.php
  4. 82
      lqycms.sql
  5. 2
      resources/views/admin/article/add.blade.php
  6. 5
      resources/views/admin/menu/add.blade.php
  7. 2
      resources/views/admin/menu/index.blade.php
  8. 2
      resources/views/admin/userrole/index.blade.php
  9. 67
      resources/views/admin/userrole/permissions.blade.php
  10. 2
      routes/web.php

13
app/Http/Controllers/Admin/IndexController.php

@ -12,7 +12,18 @@ class IndexController extends CommonController
public function index()
{
return view('admin.index.index');
$data['menus'] = category_tree(get_category('menu',0));
if($_SESSION['admin_user_info']['role_id']==1)
{
}
else
{
}
return view('admin.index.index', $data);
}
//更新配置

3
app/Http/Controllers/Admin/MenuController.php

@ -22,6 +22,9 @@ class MenuController extends CommonController
public function add()
{
if(!empty($_GET["pid"])){$pid = $_GET["pid"];}else{$pid=0;}
$data['pid'] = $pid;
$data['menu'] = category_tree(get_category('menu',0));
return view('admin.menu.add', $data);

62
app/Http/Controllers/Admin/UserRoleController.php

@ -77,4 +77,66 @@ class UserRoleController extends CommonController
error_jump('删除失败!请重新提交');
}
}
//角色权限设置视图
public function permissions()
{
if(!empty($_GET["id"])){$data['role_id'] = $_GET["id"];}else{error_jump('您访问的页面不存在或已被删除!');}
$menu = [];
$access = DB::table('access')->where('role_id', $data['role_id'])->get();
if($access)
{
foreach($access as $k=>$v)
{
$menu[] = $v->menu_id;
}
}
$data['menus'] = category_tree(get_category('menu',0));
foreach($data['menus'] as $k=>$v)
{
$data['menus'][$k]['is_access'] = 0;
if(!empty($menu) && in_array($v['id'], $menu))
{
$data['menus'][$k]['is_access'] = 1;
}
}
return view('admin.userrole.permissions', $data);
}
//角色权限设置
public function dopermissions()
{
$menus = [];
if($_POST['menuid'] && $_POST['role_id'])
{
foreach($_POST['menuid'] as $row)
{
$menus[] = [
'role_id' => $_POST['role_id'],
'menu_id' => $row
];
}
}
else
{
error_jump('操作失败!');
}
DB::beginTransaction();
DB::table('access')->where('role_id', '=', $_POST['role_id'])->delete();
if(DB::table('access')->insert($menus))
{
DB::commit();
success_jump('操作成功!');
}
else
{
DB::rollBack();
error_jump('操作失败!');
}
}
}

82
lqycms.sql
File diff suppressed because it is too large
View File

2
resources/views/admin/article/add.blade.php

@ -110,7 +110,7 @@ function upImage()
<!-- 实例化编辑器 --><script type="text/javascript">var ue = UE.getEditor('container',{maximumWords:100000,initialFrameHeight:320,enableAutoSave:false});</script></td>
</tr>
<tr>
<td colspan="2"><button type="submit" class="btn btn-success" value="Submit">保存(Submit)</button>&nbsp;&nbsp;<button type="reset" class="btn btn-default" value="Reset">重置(Reset)</button><input type="hidden"></input></td>
<td colspan="2"><button type="submit" class="btn btn-success" value="Submit">保存(Submit)</button>&nbsp;&nbsp;<button type="reset" class="btn btn-default" value="Reset">重置(Reset)</button></td>
</tr>
</tbody></table></form><!-- 表单结束 -->
</div></div><!-- 右边结束 --></div></div>

5
resources/views/admin/menu/add.blade.php

@ -15,8 +15,11 @@
<select name="pid" id="pid">
<option value="0">顶级菜单</option>
<?php if($menu){foreach($menu as $row){ ?>
<?php if($pid<>0 && $row["id"]==$pid){ ?>
<option selected value="<?php echo $row["id"]; ?>"><?php for($i=0;$i<$row["deep"];$i++){echo "";}echo $row["name"]; ?></option>
<?php }else{ ?>
<option value="<?php echo $row["id"]; ?>"><?php for($i=0;$i<$row["deep"];$i++){echo "";}echo $row["name"]; ?></option>
<?php }} ?>
<?php }}} ?>
</select>
</td>
</tr>

2
resources/views/admin/menu/index.blade.php

@ -20,7 +20,7 @@
<td><?php echo $row->name; ?></td>
<td><?php echo $row->action; ?></td>
<td><?php if($row->status==1){echo '显示';}else{echo '隐藏';} ?></td>
<td><a href="/fladmin/menu/edit?id=<?php echo $row->id; ?>">修改</a> | <a onclick="delconfirm('/fladmin/menu/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a></td>
<td><a href="<?php echo route('admin_menu_add',['pid' => $row->id]); ?>">添加子菜单</a> | <a href="/fladmin/menu/edit?id=<?php echo $row->id; ?>">修改</a> | <a onclick="delconfirm('/fladmin/menu/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a></td>
</tr><?php } ?>
</tbody></table></div><!-- 表格结束 --></form><!-- 表单结束 -->

2
resources/views/admin/userrole/index.blade.php

@ -20,7 +20,7 @@
<td><?php echo $row->name; ?></td>
<td><?php echo $row->des; ?></td>
<td><?php if($row->status==0){echo '启用';}else{echo '禁用';} ?></td>
<td><a href="/fladmin/userrole/edit?id=<?php echo $row->id; ?>">权限设置</a> | <a href="/fladmin/userrole/edit?id=<?php echo $row->id; ?>">修改</a> | <a onclick="delconfirm('/fladmin/userrole/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a></td>
<td><?php if($row->id<>1){ ?><a href="/fladmin/userrole/permissions?id=<?php echo $row->id; ?>">权限设置</a> | <?php } ?><a href="/fladmin/userrole/edit?id=<?php echo $row->id; ?>">修改</a> | <a onclick="delconfirm('/fladmin/userrole/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a></td>
</tr><?php } ?>
</tbody></table></div><!-- 表格结束 --></form><!-- 表单结束 -->

67
resources/views/admin/userrole/permissions.blade.php

@ -0,0 +1,67 @@
<!DOCTYPE html><html><head><title>角色权限设置_后台管理</title>@include('admin.common.header')
<div class="container-fluid">
<div class="row">
<!-- 左边开始 --><div class="col-sm-3 col-md-2 sidebar">@include('admin.common.leftmenu')</div><!-- 左边结束 -->
<!-- 右边开始 --><div class="col-sm-9 col-md-10 rightbox"><div id="mainbox">
<h2 class="sub-header">角色权限设置</h2>[ <a href="<?php echo route('admin_userrole'); ?>">角色列表</a> ]<br><br>
<form method="post" action="<?php echo route('admin_userrole_dopermissions'); ?>" role="form" enctype="multipart/form-data" class="table-responsive"><div class="table-responsive">{{ csrf_field() }}
<input style="display:none;" name="role_id" type="text" id="role_id" value="<?php echo $role_id; ?>">
<ul class="list-group">
<?php if($menus){foreach($menus as $row){ ?>
<li class="list-group-item <?php if($row["deep"]==0){echo 'list-group-item-info';} ?>"><?php echo '<span style="padding-left:'.($row["deep"]*30).'px;"></span>'; ?><input type='checkbox' <?php if($row["is_access"]==1){echo "checked='checked'";} ?> name='menuid[]' value='<?php echo $row["id"]; ?>' level='<?php echo $row["deep"]; ?>' onclick='javascript:checknode(this);'> <?php for($i=0;$i<$row["deep"];$i++){echo "—";}echo $row["name"]; ?></li>
<?php }} ?>
</ul>
<button type="submit" class="btn btn-success" value="Submit">保存(Submit)</button><br><br>
</div><!-- 表格结束 --></form><!-- 表单结束 -->
<script>
function checknode(obj)
{
var chk = $("input[type='checkbox']");
var count = chk.length;
var num = chk.index(obj);
var level_top = level_bottom = chk.eq(num).attr('level');
for (var i = num; i >= 0; i--)
{
var le = chk.eq(i).attr('level');
if (le <level_top)
{
chk.eq(i).prop("checked", true);
var level_top = level_top - 1;
}
}
for (var j = num + 1; j < count; j++)
{
var le = chk.eq(j).attr('level');
if (chk.eq(num).prop("checked"))
{
if (le > level_bottom)
{
chk.eq(j).prop("checked", true);
}
else if (le == level_bottom)
{
break;
}
}
else
{
if (le >level_bottom)
{
chk.eq(j).prop("checked", false);
}else if(le == level_bottom)
{
break;
}
}
}
}
</script>
</div></div><!-- 右边结束 --></div></div>
</body></html>

2
routes/web.php

@ -156,6 +156,8 @@ Route::group(['prefix' => 'fladmin', 'namespace' => 'Admin', 'middleware' => ['w
Route::get('/userrole/edit', 'UserRoleController@edit')->name('admin_userrole_edit');
Route::post('/userrole/doedit', 'UserRoleController@doedit')->name('admin_userrole_doedit');
Route::get('/userrole/del', 'UserRoleController@del')->name('admin_userrole_del');
Route::get('/userrole/permissions', 'UserRoleController@permissions')->name('admin_userrole_permissions'); //权限设置
Route::post('/userrole/dopermissions', 'UserRoleController@dopermissions')->name('admin_userrole_dopermissions');
//菜单管理
Route::get('/menu', 'MenuController@index')->name('admin_menu');
Route::get('/menu/add', 'MenuController@add')->name('admin_menu_add');

Loading…
Cancel
Save