Commit 02940855 by 杨昕

控制用户权限

parent 069ed4f3
Pipeline #13693 passed with stages
in 40 seconds
...@@ -258,6 +258,31 @@ function getAdmin(){ ...@@ -258,6 +258,31 @@ function getAdmin(){
return $user; return $user;
} }
/**
* 控制页面显示
* @param string $keyName
* @param string $subKey
* @return bool
*/
function permissionExist($keyName = "manager_media",$subKey="media_model_list"){
$user = \Illuminate\Support\Facades\Auth::user();
$permissions = $user->permission;
if ($user->name == 'offcn'){
return true;
}
foreach ($permissions as $key => $val) {
if ($val['key_name'] === $keyName) {
$flag = array_search($subKey,array_column($val['son'],'key_name'));
if ($flag !== false){
return true;
}
return false;
}
}
return false;
}
function parse_custom_str($str, $handle = '/') function parse_custom_str($str, $handle = '/')
{ {
$str = substr($str, strpos($str, $handle) + 1); $str = substr($str, strpos($str, $handle) + 1);
......
...@@ -15,9 +15,40 @@ class ModuleModel extends Eloquent ...@@ -15,9 +15,40 @@ class ModuleModel extends Eloquent
if ($user['name'] == 'offcn' ){ if ($user['name'] == 'offcn' ){
$module = file_get_contents(public_path('module.json')); $module = file_get_contents(public_path('module.json'));
}else{ }else{
$module = file_get_contents(public_path('media_category.json'));
}
if ($user['media_show']){
$module = file_get_contents(public_path('sub_admin.json'));
}else{
$module = file_get_contents(public_path('media_category.json'));
}
$tmp = json_decode($module,true);
$result = [];
/**
* 控制大类显示
*/
foreach ($tmp as $key => &$value){
if ($value['show'] ){
/**
* 控制子类显示
*/
$res = [];
foreach ($value['son'] as $item){
if ($item['have']){
$res[] = $item;
}
}
$value['son'] = $res;
$result[] = $value;
}
}
if (Auth::user()){
Auth::user()->permission = $result;
}
$module = json_encode($result);
}
return json_decode($module,true); return json_decode($module,true);
} }
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
} }
} }
// loadStyles(baseurl+"/xadmin/extra/toast/css/animate.css"); loadStyles("/xadmin/extra/toast/css/animate.css");
//显示提示信息 toast //显示提示信息 toast
$.fn.toast = function(options){ $.fn.toast = function(options){
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<meta name="robots" content="all,follow"> <meta name="robots" content="all,follow">
<title>后台管理系统</title> <title>后台管理系统</title>
<link rel="shortcut icon" href="img/test.ico"> <link rel="shortcut icon" >
<script src="{{ asset('xadmin/js/jquery.min.js')}}"></script> <script src="{{ asset('xadmin/js/jquery.min.js')}}"></script>
<script src="{{ asset('xadmin/js/jquery.cookie.js')}}"></script> <script src="{{ asset('xadmin/js/jquery.cookie.js')}}"></script>
......
...@@ -31,11 +31,11 @@ ...@@ -31,11 +31,11 @@
<!--***** CONTENT *****--> <!--***** CONTENT *****-->
<div class="row ml20"> <div class="row ml20">
<div class="xblock"> <div class="xblock">
@if(permissionExist("manager_media","media_create"))
<button class="btn btn-primary" onclick="x_admin_show('/web/media_model/create')"> <button class="btn btn-primary" onclick="x_admin_show('/web/media_model/create')">
添加 添加
</button> </button>
@endif
<form> <form>
<input type="text" name="media_name" class="form-input" placeholder="请输入媒资名称" value="{{$media_name}}" autocomplete="off"> <input type="text" name="media_name" class="form-input" placeholder="请输入媒资名称" value="{{$media_name}}" autocomplete="off">
<input type="text" name="username" class="form-input" placeholder="请输入创建人" value="{{$username}}" autocomplete="off"> <input type="text" name="username" class="form-input" placeholder="请输入创建人" value="{{$username}}" autocomplete="off">
...@@ -74,17 +74,26 @@ ...@@ -74,17 +74,26 @@
<td style="max-width: 100px;">{{$media['create_time']}}</td> <td style="max-width: 100px;">{{$media['create_time']}}</td>
<td class="td-manage"> <td class="td-manage">
@if(permissionExist("manager_media","media_edit"))
<a title="编辑" href="/web/media_model/{{$media['_id']}}/edit"> <a title="编辑" href="/web/media_model/{{$media['_id']}}/edit">
<i class="iconfont">&#xe609;</i> <i class="iconfont">&#xe609;</i>
</a> </a>
@endif
{{--<a onclick="x_admin_show('修改密码','/web/password/{{$user->id}}',500,300)" title="修改密码"--}} {{--<a onclick="x_admin_show('修改密码','/web/password/{{$user->id}}',500,300)" title="修改密码"--}}
{{--href="javascript:;">--}} {{--href="javascript:;">--}}
{{--<i class="iconfont">&#xe61a;</i>--}} {{--<i class="iconfont">&#xe61a;</i>--}}
{{--</a>--}} {{--</a>--}}
<a title="删除" onclick="member_del(this,'{{$media["_id"]}}')" href="javascript:;">
<i class="iconfont">&#xe695;</i> @if(permissionExist("manager_media","media_model_destroy"))
<a title="删除" onclick="member_del(this,'{{$media["_id"]}}')" href="javascript:;">
<i class="iconfont">&#xe695;</i>
</a>
@endif
<a title="生成" onclick="member_del(this,'{{$media["_id"]}}')" href="javascript:;">
<i class="iconfont">&#xe61a;</i>
</a> </a>
</td> </td>
</tr> </tr>
@endforeach @endforeach
...@@ -130,17 +139,13 @@ ...@@ -130,17 +139,13 @@
function member_del(row,id){ function member_del(row,id){
$.confirm({ $.confirm({
// confirmButtonClass: 'btn-info',
// cancelButtonClass: 'btn-info',
cancelButtonClass: 'btn-info', cancelButtonClass: 'btn-info',
confirmButtonClass: 'btn-danger', confirmButtonClass: 'btn-danger',
content:'确认要刪除吗?', content:'确认要刪除吗?',
confirmButton:'确认', confirmButton:'确认',
cancelButton:'取消', cancelButton:'取消',
confirm: function () { confirm: function () {
fetch_response('DELETE',"/web/media_model/"+id).then(function (res) { fetch_response('DELETE',"/web/media_model/"+id).then(function (res) {
if (res.code==200) { if (res.code==200) {
...@@ -162,7 +167,6 @@ ...@@ -162,7 +167,6 @@
}); });
} }
}) })
}, },
cancel: function () { cancel: function () {
$('body').toast({ $('body').toast({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment