set_permission.php
4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
use yii\helpers\Url;
$this->title = '分配权限';
$this->params['breadcrumbs'][] = '系统管理';
$this->params['breadcrumbs'][] = ['label' => '角色管理', 'url' => ['/system/role/index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<form action="<?=Url::toRoute(["/system/role/do-set-permission", 'id' => $role->roleId])?>" name="roleForm" id="roleForm" method="post">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?= $role->name ?></h3>
</div>
<div class="panel-body">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th style="width:10%;">模块</th>
<th style="width:15%;">菜单</th>
<th style="width:75%;">功能权限</th>
</tr>
</thead>
<tbody
<?php foreach ($permission as $k => $p) : ?>
<?php
$count = count($p['items']);
$p1 = array_shift($p['items']) ;
?>
<tr>
<td rowspan="<?= $count ?>"><input type="checkbox" class="check-1" data-group="<?= $k ?>" /><?= $p['label'] ?></td>
<td><input type="checkbox" class="check-2 check-<?= $k ?>-2" data-group="<?= $k ?>" /><?= $p1['label'] ?></td>
<td>
<?php foreach ($p1['items'] as $k1 => $p1) : ?>
<input type="checkbox" class="check-3 check-<?= $k ?>-3" name="permission[]" value="<?= $k1 ?>" <?php if (array_key_exists($k1, $selected)) echo 'checked' ?> /><?php echo $p1 . ' '; ?>
<?php endforeach; ?>
</td>
</tr>
<?php foreach ($p['items'] as $p2) : ?>
<tr>
<td><input type="checkbox" class="check-2 check-<?= $k ?>-2" data-group="<?= $k ?>" /><?= $p2['label'] ?></td>
<td>
<?php foreach ($p2['items'] as $k3 => $p3) : ?>
<input type="checkbox" class="check-3 check-<?= $k ?>-3" name="permission[]" value="<?= $k3 ?>" <?php if (array_key_exists($k3, $selected)) echo 'checked' ?> /> <?php echo $p3 . ' '; ?>
<?php endforeach; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
<tr>
<td></td>
<td colspan="2">
<button type="submit" class="btn btn-primary" id="save">保存</button>
<a class="btn btn-default" href="<?=Url::toRoute(["/system/role/set-permission", 'id' => $role->roleId])?>">重置</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
<script>
// 表单提交验证
seajs.use("base/1.0.0/unit/validate/custom-1.0.0",function () {
var validator = $("#roleForm").validate({
});
});
$(document).ready(function() {
$('.check-1').change(function(){
var o = $(this);
var group = o.data('group');
var check2 = '.check-' + group + '-2';
if (o.prop('checked')) {
$(check2).prop('checked', true)
} else {
$(check2).prop('checked', false)
}
$(check2).change()
});
$('.check-2').change(function(){
var o = $(this);
var group = o.data('group');
var check3 = '.check-' + group + '-3';
if (o.prop('checked')) {
o.parent().parent().find(check3).prop('checked', true)
} else {
o.parent().parent().find(check3).prop('checked', false)
}
});
});
</script>