浏览代码

权限,日志

huwhois 4 年之前
父节点
当前提交
b5982da773

+ 11 - 11
application/admin/controller/Base.php

@ -30,15 +30,15 @@ class Base extends Controller
30 30
        $this->role_id = session('role_id');
31 31
        
32 32
        // //权限检查
33
        // if (!$this->checkAuthor($this->role_id)) {
34
        //     $this->error('你无权限操作');
35
        // }
33
        if (!$this->checkAuthor($this->role_id)) {
34
            $this->error('你无权限操作');
35
        }
36 36
        
37 37
        //记录日志
38 38
        $this->addLog();
39 39
40 40
        //菜单数据
41
        $data_menu = $this->makeMenu($this->role_id);
41
        $data_menu = obj_tree($this->getMenu($this->role_id));
42 42
        //当前活动菜单父id
43 43
        $controller = $request->controller();       
44 44
        $menu_url = strtolower('admin/'.preg_replace('/(?<=[a-z])([A-Z])/', '_$1', $controller)).'/index';
@ -60,10 +60,8 @@ class Base extends Controller
60 60
    /**
61 61
     * 目录获取
62 62
     */
63
    private function makeMenu($rid)
63
    private function getMenu($rid)
64 64
    {
65
        var_dump($this->role_id);
66
        exit;
67 65
        if ($rid === 1) {
68 66
            $data = $this->sysMenuModel
69 67
                ->where('type!=2')
@ -71,7 +69,7 @@ class Base extends Controller
71 69
                ->select();
72 70
        } else {
73 71
            $sysRoleModel = new SysRoleModel();
74
            $permission_ids = $sysRoleModel->where('id', $rid)->value('permission');
72
            $permission_ids = $sysRoleModel->where('id', $rid)->value('permissions');
75 73
            $data = $this->sysMenuModel
76 74
                ->where('type!=2')
77 75
                ->where('id', 'IN', $permission_ids)
@ -79,7 +77,7 @@ class Base extends Controller
79 77
                ->select();
80 78
        }
81 79
82
        return obj_tree($data);
80
        return $data;
83 81
    }
84 82
85 83
    /**
@ -101,12 +99,14 @@ class Base extends Controller
101 99
        if (preg_match('/^public_/', $a)) {
102 100
            return true;
103 101
        }
102
104 103
        if ($c == 'index' && $a == 'index') {
105 104
            return true;
106 105
        }
107
        $permission_ids = model('admin_role')->where('id', $rid)->value('permission');
106
107
        $permission_ids = $this->getMenu($rid);
108 108
        $permissions = $this->sysMenuModel->where('id', 'IN', $permission_ids)->field('id, pid, name, url')->select();
109
        dump($permissions);
109
        // dump($permissions);
110 110
        foreach ($permissions as $v) {
111 111
            if($v->url=='admin/'.$c.'/'.$a) {
112 112
                return true;

+ 1 - 1
application/admin/view/sys_menu/index.html

@ -66,7 +66,7 @@
66 66
						</td>
67 67
					</tr>
68 68
					{notempty name="value.child"} {foreach $value.child as $val}
69
					<tr class="text-c parent_{$value.id}" style="display: none;">
69
					<tr class="text-c parent_{$value.id}">
70 70
						<td>
71 71
							<input type="checkbox" value="{$val.id}" name="checkbox[]">
72 72
						</td>

+ 1 - 3
application/admin/view/sys_role/index.html

@ -12,7 +12,7 @@
12 12
</nav>
13 13
14 14
<div class="Hui-article">
15
	<article class="cl pd-20" style="min-width: 900px;max-width: 80%;">
15
	<article class="cl pd-20" style="min-width: 600px;max-width: 70%;">
16 16
		<div class="cl pd-5 bg-1 bk-gray">
17 17
			<span class="l">
18 18
				<a href="javascript:;" onclick="del_all()" class="btn btn-danger radius">
@ -34,7 +34,6 @@
34 34
						</th>
35 35
						<th width="40px">ID</th>
36 36
						<th width="120px">角色名称</th>
37
						<th>权限id列表</th>
38 37
						<th width="80px">操作</th>
39 38
					</tr>
40 39
				</thead>
@ -46,7 +45,6 @@
46 45
						</td>
47 46
						<td>{$val.id}</td>
48 47
						<td>{$val.name}</td>
49
						<td class="text-l">{$val.permissions}</td>
50 48
						<td class="f-14">
51 49
							<a title="编辑" href="{:url('save?id='.$val.id)}" style="text-decoration:none">
52 50
								<i class="Hui-iconfont">&#xe6df;</i>

+ 84 - 76
application/admin/view/sys_role/save.html

@ -1,96 +1,104 @@
1 1
{layout name="layout" /}
2 2
3 3
<nav class="breadcrumb">
4
    <i class="Hui-iconfont">&#xe67f;</i>
5
    <a href="{:url('index/index')}"> 首页</a>
6
    <span class="c-gray en">&gt;</span>
7
    <a href="{:url('sys_role/index')}">角色管理</a>
8
    <span class="c-gray en">&gt;</span>
9
    <a href="javascprit:;">{$data.id ? '修改' : '新增'}</a>
10
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
11
        title="刷新">
12
        <i class="Hui-iconfont">&#xe68f;</i>
13
    </a>
4
	<i class="Hui-iconfont">&#xe67f;</i>
5
	<a href="{:url('index/index')}"> 首页</a>
6
	<span class="c-gray en">&gt;</span>
7
	<a href="{:url('sys_role/index')}">角色管理</a>
8
	<span class="c-gray en">&gt;</span>
9
	<a href="javascprit:;">{$data.id ? '修改' : '新增'}</a>
10
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
11
		href="javascript:location.replace(location.href);" title="刷新">
12
		<i class="Hui-iconfont">&#xe68f;</i>
13
	</a>
14 14
</nav>
15 15
16 16
<div class="Hui-article">
17
<article class="cl pd-20">
18
	<form action="{:url('save?id='.$data.id)}" method="post" class="form form-horizontal" id="form-admin-role-add">
19
		<div class="row cl">
20
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span> 角色名称:</label>
21
			<div class="formControls col-xs-8 col-sm-4">
22
				<input type="text" class="input-text" value="{$data.name}" placeholder="" id="name" name="name" datatype="*4-16">
17
	<article class="cl pd-20">
18
		<form action="{:url('save?id='.$data.id)}" method="post" class="form form-horizontal" id="form-admin-role-add">
19
			<div class="row cl">
20
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>角色名称:</label>
21
				<div class="formControls col-xs-8 col-sm-9">
22
					<input type="text" class="input-text" value="{$data.name}" placeholder="" id="name" name="name"
23
					datatype="*4-16" nullmsg="角色名称">
24
				</div>
23 25
			</div>
24
		</div>
25
		<div class="row cl">
26
			<label class="form-label col-xs-4 col-sm-2">管理权限选择:</label>
27
			<div class="formControls col-xs-6 col-sm-6">
28
				<dl class="permission-list">
29
					<dd>
26
			<div class="row cl">
27
				<label class="form-label col-xs-4 col-sm-2">备注:</label>
28
				<div class="formControls col-xs-8 col-sm-9">
29
					<input type="text" class="input-text" value="{$data.note}" placeholder="备注" id="note" name="note">
30
				</div>
31
			</div>
32
			<div class="row cl">
33
				<label class="form-label col-xs-4 col-sm-2">权限选择:</label>
34
				<div class="formControls col-xs-8 col-sm-9">
30 35
					{foreach $data_permission as $value}
31
						<dl class="cl permission-list2">
32
							<dt>
33
								<label>
34
									<input type="checkbox" class="parent" value="{$value.id}" name="perm_check[]" id="check_{$value.id}" 
35
										{if condition="in_array($value.id, $role_powers)"}checked{/if}>
36
									{$value.name}
37
								</label>
36
					<dl class="permission-list">
37
						<dt>
38
							<label>
39
								<input type="checkbox" value="" name="{$value.id}" id="check_{$value.id}"  name="perm_check[]" {if condition="in_array($value.id, $role_powers)"}checked{/if}>
40
							{$value.name}</label>
41
						</dt>
42
						{notempty name='value.child'}
43
							{foreach $value.child as $val}
44
						<dd>
45
							<dl class="cl permission-list2">
46
								<dt>
47
									<label class="">
48
										<input type="checkbox" value="{$val.id}" name="perm_check[]" id="check_{$val.id}"{if condition="in_array($val.id, $role_powers)"}checked{/if}>
49
										{$val.name}</label>
50
								</dt>
51
								{notempty name='val.child'}
38 52
								<dd>
39
									{notempty name='value.child'}
40
									{foreach $value.child as $val}
41
									<label>
42
										<input type="checkbox" class="child pid_{$val.pid}" data-pid="{$val.pid}" value="{$val.id}" name="perm_check[]"
43
											{if condition="in_array($val.id, $role_powers)"}checked{/if} id="check_{$val.id}">
44
										{$val.name}
45
									</label>
53
									{foreach $val.child as $vo}
54
									<label class="">
55
										<input type="checkbox" value="{$vo.id}" name="perm_check[]" id="check_{$val.id}" {if condition="in_array($vo.id, $role_powers)"}checked{/if}>
56
										{$vo.name}</label>
46 57
									{/foreach}
47
									{/notempty}
48 58
								</dd>
49
							</dt>
50
						</dl>
59
								{/notempty}
60
							</dl>
61
						</dd>
62
						{/foreach}
63
						{/notempty}
64
					</dl>
51 65
					{/foreach}
52
					</dd>
53
				</dl>
54
			</div>
55
		</div>
56
		<div class="row cl">
57
			<label class="form-label col-xs-4 col-sm-2">备注:</label>
58
			<div class="formControls col-xs-8 col-sm-4">
59
				<textarea id="note" name="note" cols="" rows="" class="textarea" placeholder="备注...200个字符以内" dragonfly="true"
60
					onKeyUp="textarealength(this,200)">{$data.note}</textarea>
61
				<p class="textarea-numberbar">
62
					<em class="textarea-length">0</em>/200</p>
66
				</div>
63 67
			</div>
68
			<div class="row cl">
69
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
70
					<button type="submit" class="btn btn-success radius" id="admin-role-save"><i
71
							class="icon-ok"></i> 确定</button>
72
					<button type="button" class="btn btn-default radius" onClick="window.history.back();"><i
73
						class="Hui-iconfont">&#xe66b;</i>取消</button>
74
				</div>
64 75
			</div>
65
		<div class="row cl">
66
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
67
				<button type="submit" class="btn btn-success radius" id="admin-role-save" name=""><i class="Hui-iconfont">&#xe632;</i>&nbsp;确&nbsp;定&nbsp;</button>
68
				<button type="button" class="btn btn-default radius" onClick="window.history.back();"><i class="Hui-iconfont">&#xe66b;</i>&nbsp;取&nbsp;消&nbsp;</button>
69
			</div>
70
		</div>
71
	</form>
72
</article>
76
		</form>
77
	</article>
73 78
</div>
74 79
75
<!--请在下方写此页面业务相关的脚本--> 
80
<!--请在下方写此页面业务相关的脚本-->
76 81
<script type="text/javascript">
77
$(function(){
78
	$(".child").click(function(){
79
		var pid = $(this).data('pid');
80
81
		$("#check_"+pid).prop('checked', true);
82
	})
83
84
	$(".parent").click(function(){
85
		var id = $(this).val();
86
		var status = $(this).prop('checked');
87
88
		if (status) {
89
			$(".pid_"+id).prop('checked', !$(".pid_"+id).prop('checked'));
90
		} else {
91
			$(".pid_"+id).prop('checked', false);
92
		}		
82
	$(function () {
83
		$(".permission-list dt input:checkbox").click(function(){
84
			$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
85
		});
86
		$(".permission-list2 dd input:checkbox").click(function(){
87
			var l =$(this).parent().parent().find("input:checked").length;
88
			var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
89
			if($(this).prop("checked")){
90
				$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
91
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
92
			}
93
			else{
94
				if(l==0){
95
					$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
96
				}
97
				if(l2==0){
98
					$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
99
				}
100
			}
101
		});
93 102
	})
94
			})
95 103
</script>
96 104
<!--请在上方写此页面业务相关的脚本-->

+ 3 - 1
public/.gitignore

@ -1,2 +1,4 @@
1 1
test.php
2
static/index/*
2
static/index/*
3
start.bat
4
start.sh