set_permission.php 4.21 KB
<?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 . '&nbsp;&nbsp;&nbsp;&nbsp;'; ?>
                                <?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 . '&nbsp;&nbsp;&nbsp;&nbsp;'; ?>
                                   <?php endforeach; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endforeach; ?>

                    <tr>
                        <td></td>
                        <td colspan="2">
                            <button type="submit" class="btn btn-primary" id="save">保存</button>&nbsp;&nbsp;&nbsp;&nbsp;
                            <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>