角色管理完成
This commit is contained in:
1 parent
bd00d57337
commit
9634b6886a
5 files changed
+277
-165
No files matched your search
@@ -13,7 +13,6 @@ class AuthGroup extends Base
|
||||
// 角色列表
|
||||
public function index()
|
||||
{
|
||||
|
||||
// 设置要给模板赋值的信息
|
||||
$list['webtitle'] = '角色列表';
|
||||
|
||||
@@ -134,16 +133,22 @@ class AuthGroup extends Base
|
||||
// 修改角色信息
|
||||
public function edit($id)
|
||||
{
|
||||
// 获取单位信息
|
||||
$list['data'] = AG::field('id,title,miaoshu,rules')
|
||||
->find($id);
|
||||
|
||||
// 获取角色信息
|
||||
$list = AG::field('id,title,miaoshu,rules')
|
||||
->get($id);
|
||||
$list->rules = explode(',',$list->rules);
|
||||
|
||||
// 设置页面标题
|
||||
$list['set'] = array(
|
||||
'webtitle'=>'编辑角色',
|
||||
'butname'=>'修改',
|
||||
'formpost'=>'PUT',
|
||||
'url'=>'/authgroup/'.$id,
|
||||
);
|
||||
|
||||
// 模板赋值
|
||||
$this->assign('list',$list);
|
||||
|
||||
return $this->fetch();
|
||||
// 渲染
|
||||
return $this->fetch('create');
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
<span class="x-red">*</span>角色描述
|
||||
</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" id="title" name="title" lay-verify="required"
|
||||
autocomplete="off" class="layui-input " value="{$list.data.title|default=''}" placeholder="中文2-25个字符">
|
||||
<input type="text" id="miaoshu" name="miaoshu" lay-verify="required"
|
||||
autocomplete="off" class="layui-input " value="{$list.data.miaoshu|default=''}" placeholder="中文2-25个字符">
|
||||
</div>
|
||||
</div>
|
||||
{php}
|
||||
@@ -27,14 +27,26 @@
|
||||
<div class="layui-form-item">
|
||||
{volist name="authrulelist" id="vo"}
|
||||
<div style="background: #eeeeee">
|
||||
<input type="checkbox" name="rules" title="{$vo.title}" value="{$vo.id}" lay-skin="primary" id ="{$vo.id}" pid="0" action="topOnclick">
|
||||
<input type="checkbox" name="rules[]" title="{$vo.title}" value="{$vo.id}" lay-skin="primary" id ="{$vo.id}" pid="0" action="topOnclick" {present name="$list.data.rules"}
|
||||
{in name="vo.id" value="$list['data']['rules']"}
|
||||
checked
|
||||
{/in}
|
||||
{/present}>
|
||||
</div>
|
||||
<div class="layui-form-item" id="{$vo.id}" style="padding-left: 10px;padding-right: 10px;">
|
||||
{volist name="vo.auth_cid" id="vc"}
|
||||
<div>
|
||||
<input type="checkbox" name="rules" title="{$vc.title}" value="{$vc.id}" lay-skin="primary" id ="{$vc.id}" pid="{$vo.id}" action="midOnclick">
|
||||
<input type="checkbox" name="rules[]" title="{$vc.title}" value="{$vc.id}" lay-skin="primary" id ="{$vc.id}" pid="{$vo.id}" action="midOnclick" {present name="$list.data.rules"}
|
||||
{in name="vc.id" value="$list['data']['rules']"}
|
||||
checked
|
||||
{/in}
|
||||
{/present}>
|
||||
{volist name="vc.auth_cid" id="vd"}
|
||||
<input type="checkbox" name="rules" title="{$vd.title}" value="{$vd.id}" lay-skin="primary" id ="{$vd.id}" pid="{$vc.id}" action="btmOnclick">
|
||||
<input type="checkbox" name="rules[]" title="{$vd.title}" value="{$vd.id}" lay-skin="primary" id ="{$vd.id}" pid="{$vc.id}" action="btmOnclick" {present name="$list.data.rules"}
|
||||
{in name="vd.id" value="$list['data']['rules']"}
|
||||
checked
|
||||
{/in}
|
||||
{/present}>
|
||||
{/volist}
|
||||
</div>
|
||||
{/volist}
|
||||
@@ -68,8 +80,8 @@
|
||||
case 'midOnclick':
|
||||
midOnclick(id,pid,ischecked);
|
||||
break;
|
||||
case 'btmClick':
|
||||
cjgl.add('添加单位','/school/create','650','500');
|
||||
case 'btmOnclick':
|
||||
btmOnclick(id,ischecked);
|
||||
break;
|
||||
};
|
||||
});
|
||||
@@ -79,13 +91,23 @@
|
||||
function topOnclick(id,ischecked)
|
||||
{
|
||||
if(ischecked == true){
|
||||
// 更换全部子复选框样式
|
||||
$('#'+id).parent().next().find('div.layui-form-checkbox').each(function(){
|
||||
$(this).attr('class','layui-unselect layui-form-checkbox layui-form-checked')
|
||||
$(this).attr('class','layui-unselect layui-form-checkbox layui-form-checked');
|
||||
});
|
||||
// 全部子复选框
|
||||
$('#'+id).parent().next().find('input').each(function(){
|
||||
$(this).attr('checked',true);
|
||||
});
|
||||
}else{
|
||||
// 更换全部子复选框样式
|
||||
$('#'+id).parent().next().find('div.layui-form-checkbox').each(function(){
|
||||
$(this).attr('class','layui-unselect layui-form-checkbox')
|
||||
});
|
||||
// 取消全部子复选框
|
||||
$('#'+id).parent().next().find('input').each(function(){
|
||||
$(this).attr('checked',false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,31 +115,64 @@
|
||||
function midOnclick(id,pid,ischecked)
|
||||
{
|
||||
if(ischecked == true){
|
||||
|
||||
// 更换上级复选框样式
|
||||
$('#'+id).parent().parent().prev().find('div.layui-form-checkbox').each(function(){
|
||||
$(this).attr('class','layui-unselect layui-form-checkbox layui-form-checked')
|
||||
});
|
||||
// 选中上级复选框
|
||||
$('#'+id).parent().parent().prev().find('input').each(function(){
|
||||
$(this).attr('checked',true);
|
||||
});
|
||||
|
||||
// 更换全部下级复选框样式
|
||||
$('#'+id).siblings('div.layui-form-checkbox').each(function(){
|
||||
$(this).attr('class','layui-unselect layui-form-checkbox layui-form-checked')
|
||||
$(this).attr('class','layui-unselect layui-form-checkbox layui-form-checked');
|
||||
});
|
||||
// 选中全部下级复选框
|
||||
$('#'+id).siblings('input').each(function(){
|
||||
$(this).attr('checked',true);
|
||||
});
|
||||
}else{
|
||||
// $('#'+id).parent().parent().prev().find('div.layui-form-checkbox').each(function(){
|
||||
// $(this).attr('class','layui-unselect layui-form-checkbox layui-form-checked')
|
||||
// });
|
||||
// 更换所有下级复选框样式
|
||||
$('#'+id).siblings('div.layui-form-checkbox').each(function(){
|
||||
$(this).attr('class','llayui-unselect layui-form-checkbox')
|
||||
});
|
||||
var checkboxs = $('#'+id).parent().parent().find('div.layui-form-checkbox').lenght;
|
||||
|
||||
each(function(){
|
||||
$(this).attr('class','layui-unselect layui-form-checkbox layui-form-checked')
|
||||
// 取消选中所有下级复选框
|
||||
$('#'+id).siblings('input').each(function(){
|
||||
$(this).attr('checked',false)
|
||||
});
|
||||
|
||||
// 如果所有属于上级的复框为未状态,则取消选中上级复选框
|
||||
var checkboxs = $('#'+id).parent().parent().find('div.layui-form-checked').length;
|
||||
if(checkboxs == 0){
|
||||
// 更换样式
|
||||
$('#'+id).parent().parent().prev().find('div.layui-form-checkbox').each(function(){
|
||||
$(this).attr('class','layui-unselect layui-form-checkbox')
|
||||
});
|
||||
// 取消选中
|
||||
$('#'+id).parent().parent().prev().find('input').each(function(){
|
||||
$(this).attr('checked',false)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 下层按钮
|
||||
function btmOnclick(id,ischecked)
|
||||
{
|
||||
if(ischecked == true){
|
||||
// 设置上级复选框为状态
|
||||
$('#'+id).parent().children('div.layui-form-checkbox').first().attr('class','layui-unselect layui-form-checkbox layui-form-checked');
|
||||
// 选中上级复选框
|
||||
$('#'+id).parent().children('input').first().attr('checked',true);
|
||||
|
||||
|
||||
|
||||
|
||||
// 设置上级的上级复选框为状态
|
||||
$('#'+id).parent().parent().prev().children('div.layui-form-checkbox').first().attr('class','layui-unselect layui-form-checkbox layui-form-checked');
|
||||
// 选中上级的上级复选框
|
||||
$('#'+id).parent().parent().prev().children('input').first().attr('checked',true);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
{/block}
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
{extend name="common@create" /}
|
||||
{block name="formaa"}
|
||||
<form action="/authgroup/{$list.id}" method="PUT" class="form form-horizontal" id="form-member-add">
|
||||
<div class="row cl">
|
||||
<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称:</label>
|
||||
<div class="formControls col-xs-8 col-sm-9">
|
||||
<input type="text" class="input-text" value="{$list.title}" placeholder="角色名称" id="title" name="title">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row cl">
|
||||
<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色描述:</label>
|
||||
<div class="formControls col-xs-8 col-sm-9">
|
||||
<input type="text" class="input-text" value="{$list.miaoshu}" placeholder="说明角色有哪些权限" id="miaoshu" name="miaoshu">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row cl">
|
||||
<label class="form-label col-xs-4 col-sm-3">网站角色:</label>
|
||||
<div class="formControls col-xs-8 col-sm-9">
|
||||
{php}
|
||||
$rule = new app\admin\model\AuthRule;;
|
||||
$plist = $rule->getRule();
|
||||
{/php}
|
||||
{volist name="plist" id="p"}
|
||||
<dl class="permission-list">
|
||||
<dt>
|
||||
<label>
|
||||
<input type="checkbox" value="{$p.id}" name="rules[]" id="rule{$p.id}" {php}echo in_array($p['id'],$list['rules']) ? 'checked' : '';{/php}>
|
||||
{$p.title}
|
||||
</label>
|
||||
</dt>
|
||||
{php}
|
||||
$clist = $rule->getRule($p['id']);
|
||||
{/php}
|
||||
<dd>
|
||||
|
||||
{volist name = "clist" id = "c"}
|
||||
<dl class="cl permission-list2">
|
||||
<dt>
|
||||
<label class="">
|
||||
<input type="checkbox" value="{$c.id}" name="rules[]" id="rule{$c.id}" {php}echo in_array($c['id'],$list['rules']) ? 'checked' : '';{/php}>
|
||||
{$c.title}
|
||||
</label>
|
||||
</dt>
|
||||
{php}
|
||||
$slist = $rule->getRule($c['id']);
|
||||
{/php}
|
||||
<dd>
|
||||
{volist name="slist" id="s"}
|
||||
<label class="">
|
||||
<input type="checkbox" value="{$s.id}" name="rules[]" id="rule{$s.id}" {php}echo in_array($s['id'],$list['rules']) ? 'checked' : '';{/php}>
|
||||
{$s.title}</label>
|
||||
{/volist}
|
||||
</dd>
|
||||
</dl>
|
||||
{/volist}
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
{/volist}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row cl">
|
||||
<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
|
||||
<input class="btn btn-primary radius" type="submit" value=" 提交 ">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{/block}
|
||||
{block name="yanzheng"}
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$(".permission-list dt input:checkbox").click(function(){
|
||||
$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
|
||||
});
|
||||
$(".permission-list2 dd input:checkbox").click(function(){
|
||||
var l =$(this).parent().parent().find("input:checked").length;
|
||||
var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
|
||||
if($(this).prop("checked")){
|
||||
$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
|
||||
$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
|
||||
}
|
||||
else{
|
||||
if(l==0){
|
||||
$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
|
||||
}
|
||||
if(l2==0){
|
||||
$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#form-admin-role-add").validate({
|
||||
rules:{
|
||||
roleName:{
|
||||
required:true,
|
||||
},
|
||||
},
|
||||
onkeyup:false,
|
||||
focusCleanup:true,
|
||||
success:"valid",
|
||||
submitHandler:function(form){
|
||||
$(form).ajaxSubmit();
|
||||
var index = parent.layer.getFrameIndex(window.name);
|
||||
parent.layer.close(index);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 匹配用户名
|
||||
$.validator.addMethod("zh",function(value,element){
|
||||
var tel = /^[\u4e00-\u9fa5]*$/;
|
||||
return this.optional(element) || tel.test(value);
|
||||
}, "请输入中文");
|
||||
|
||||
// 设置表单验证规则
|
||||
var myrules = {
|
||||
title:{
|
||||
required:true,
|
||||
zh:true,
|
||||
rangelength:[2,6]
|
||||
},
|
||||
miaoshu:{
|
||||
required:true,
|
||||
rangelength:[1,200]
|
||||
},
|
||||
rule:{
|
||||
digits:true,
|
||||
max:999
|
||||
},
|
||||
};
|
||||
|
||||
// 设置表单提交方式
|
||||
var mytype = 'PUT';
|
||||
</script>
|
||||
{/block}
|
||||
Loaded 3 of 5 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user