Commit 02940855 by 杨昕

控制用户权限

parent 069ed4f3
Pipeline #13693 passed with stages
in 40 seconds
......@@ -258,6 +258,31 @@ function getAdmin(){
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 = '/')
{
$str = substr($str, strpos($str, $handle) + 1);
......
......@@ -15,9 +15,40 @@ class ModuleModel extends Eloquent
if ($user['name'] == 'offcn' ){
$module = file_get_contents(public_path('module.json'));
}else{
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);
}
......
......@@ -20,7 +20,7 @@
}
}
// loadStyles(baseurl+"/xadmin/extra/toast/css/animate.css");
loadStyles("/xadmin/extra/toast/css/animate.css");
//显示提示信息 toast
$.fn.toast = function(options){
......
......@@ -6,7 +6,7 @@
<meta name="robots" content="all,follow">
<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.cookie.js')}}"></script>
......
......@@ -31,11 +31,11 @@
<!--***** CONTENT *****-->
<div class="row ml20">
<div class="xblock">
@if(permissionExist("manager_media","media_create"))
<button class="btn btn-primary" onclick="x_admin_show('/web/media_model/create')">
添加
</button>
@endif
<form>
<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">
......@@ -74,17 +74,26 @@
<td style="max-width: 100px;">{{$media['create_time']}}</td>
<td class="td-manage">
@if(permissionExist("manager_media","media_edit"))
<a title="编辑" href="/web/media_model/{{$media['_id']}}/edit">
<i class="iconfont">&#xe609;</i>
</a>
@endif
{{--<a onclick="x_admin_show('修改密码','/web/password/{{$user->id}}',500,300)" title="修改密码"--}}
{{--href="javascript:;">--}}
{{--<i class="iconfont">&#xe61a;</i>--}}
{{--</a>--}}
@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>
</td>
</tr>
@endforeach
......@@ -130,17 +139,13 @@
function member_del(row,id){
$.confirm({
// confirmButtonClass: 'btn-info',
// cancelButtonClass: 'btn-info',
cancelButtonClass: 'btn-info',
confirmButtonClass: 'btn-danger',
content:'确认要刪除吗?',
confirmButton:'确认',
cancelButton:'取消',
confirm: function () {
fetch_response('DELETE',"/web/media_model/"+id).then(function (res) {
if (res.code==200) {
......@@ -162,7 +167,6 @@
});
}
})
},
cancel: function () {
$('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