Commit e315cda8 authored by zfc's avatar zfc

编辑5

parent b0b04bce
......@@ -144,31 +144,27 @@ class Auth extends Basic
/**
* 权限分配
* 角色权限分配or查看
* @param integer $group_id 组ID
* @return [type] [description]
* @date 2018-01-22
* @author zfc
*/
public function accessLook($group_id=0){
$table= New AuthGroup();
$table2= New AuthRule();
$table= New AuthGroup;
$table2= New AuthRule;
$data['title']='权限分配';
// echo $group_id;
// exit;
if (IS_POST && $group_id=0) {
if (IS_POST && $group_id==0) {
//添加or修改
$data['id'] = $group_id;
$menu_auth = input('post.menu_auth/a','');//获取所有授权菜单id
$data['rules'] = implode(',',$menu_auth);//拼接
$id = isset($data['id']) && $data['id']>0 ? $data['id']:false;
//开发过程中先关闭这个限制
//if($group_id==1){
//$this->error('不能修改超级管理员'.$title);
// }else{
//提交数据
if ( $table->editData($data,$id)) {
cache('admin_sidebar_menus_'.$this->currentUser['uid'],null);
return $this->response(200, '成功');
}else{
return $this->response(100, '失败');
......@@ -179,13 +175,18 @@ class Auth extends Basic
} else{
//查看
$role_auth_rule = $table->where(['id'=>intval($group_id)])->value('rules');
$data['menu_auth_rules']=explode(',',$role_auth_rule);//获取指定获取到的权限
$data['rules']=explode(',',$role_auth_rule);//获取指定获取到的权限
$data['class']=$this->AuthClass(1);
foreach($data['class'] as $v){
if(in_array($v['id'],$data['rules'])){
$v['is']='1';
}else{
$v['is']='0';
}
}
$menu = $table2->where(['pid'=>0,'status'=>1])->order('sort asc')->select();
foreach($menu as $k=>$v){
$menu[$k]['_child']=$table2->where(['pid'=>$v['id']])->order('sort asc')->select();
}
$data['all_auth_rules']=$menu;//所以规则
return $this->response(200,'可以查看',$data);
}
......@@ -241,7 +242,7 @@ class Auth extends Basic
return view('auth_rule_box');
}
//分类列表
public function AuthClass(){
public function AuthClass($fu='0'){
$table=new AuthRule;
$data['status'] = 200;
$data['msg'] = '';
......@@ -251,31 +252,52 @@ class Auth extends Basic
$data['list'] = $table->authRuleList2($order,$field,'', $where);
//echo $table->getLastSql();
//prt(collection($data['list'])->toArray());//转化arr
if($fu=='1'){
return $data['list'];
}else{
return $this->response(200,'成功',$data);
}
}
//新增编辑权限
public function updateAuthRule($group_id=0){
$data['status'] = 200;
$data['msg'] = '';
$title = $group_id ? '编辑':'新增';
$table= New AuthGroup();
$table= New AuthRule;
if (IS_POST) {
if (IS_POST && $group_id==0) {
$data = input('post.');
$id = isset($data['id']) && $data['id']>0 ? $data['id']:false;
//判断name是否重复
if($table->repetition('name',$data['name'])&& empty($id)){
return $this->response(100, '存在重复值');
}
//新增或者编辑数据
//prt($data);
if ($table->editData($data,$id)) {
return $this->response(200, '成功');
} else {
return $this->response(101, '失败');
return $this->response(100, '无修改');
}
} else {
$info= $table->findById($group_id);
return $this->response(200, $title, $info);
$where="a.id={$group_id}";
$field="a.*,ifnull(b.title,'顶级菜单') as title2";
$order='';
$join=[['auth_rule b', ' a.pid=b.id','left']];
$info= $table->authRuleList2($order,$field,$join, $where);
//echo $table->getLastSql();
return $this->response(200, $title, $info[0]);
}
......
{layout name="global/frame_tpl" /}
<input type="hidden" class="page-load" id="business_district" /><!--关联js文件-->
<input type="hidden" class="page-load" id="access" /><!--关联js文件-->
<div id="page-content-wrapper">
<div class="container">
<div class="col-lg-10 col-lg-offset-0">
......
......@@ -11,35 +11,26 @@
<div class="row">
<div style="padding: 20px;margin-left:30px;border-radius:3px;" class="col-md-11">
<form class="form-builder form-horizontal" method="post" action="http://me.tp.com/admin.php/admin/auth/ruleedit/id/1.html?_pjax=%23pjax-container">
<form class="form-builder form-horizontal" method="post" action="/index/updateAuthRule">
<fieldset>
<div style="display:none;" class="form-group item_id ">
<label class="col-md-2 control-label" for="id">ID</label>
<div class="col-md-4">
<input type="hidden" value="1" name="id" id="id" class="form-control">
<input type="hidden" value="" name="id" id="id" class="form-control">
</div>
<div class="col-md-5 help-block"><i class="fa fa-info-circle color-info1"></i> ID</div></div>
<div class="form-group item_title ">
<label class="col-md-2 control-label" for="title">标题</label>
<label class="col-md-2 control-label" >标题</label>
<div class="col-md-4">
<input type="text" value="" name="title" class="form-control">
</div>
<div class="col-md-5 help-block"><i class="fa fa-info-circle color-info1"></i> 用于后台显示的配置标题</div></div>
<div class="form-group item_depend_flag ">
<!--<label class="col-md-2 control-label" for="depend_flag">所属模块</label>-->
<!--<div class="col-md-4">-->
<!--<select class="form-control" id="depend_flag" name="depend_flag">-->
<!--<option value="">请选择</option> <option selected="" value="admin">后台模块</option>-->
<!--<option value="home">前台模块</option>-->
<!--<option value="user">用户中心</option>-->
<!--</select>-->
<!--</div>-->
<!--<div class="col-md-6 help-block"><i class="fa fa-info-circle color-info1"></i> 所属的模块,模块菜单必须选择,否则无法导出</div></div>-->
<div class="form-group item_pid ">
<label class="col-md-2 control-label">上级菜单</label>
<div class="col-md-4">
......@@ -50,28 +41,8 @@
</div>
</div>
<!--<div class="form-group item_icon ">-->
<!--<label class="col-md-2 control-label" for="icon">字体图标</label>-->
<!--<div class="col-md-6">-->
<!--<div id="icon-picker" class="input-group input">-->
<!--<span class="input-group-btn">-->
<!--<button onclick="filter_icon(this);" type="button" class="btn btn-raised btn-default btn-sm"><i class="fa fa-info-circle"></i> 选择图标</button>-->
<!--</span>-->
<!--<input type="text" value="fa-tachometer" id="icon" name="icon" class="form-control iconpicker">-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<script type="text/javascript">
// function setIconFilter(filter) {
// $('#icon').val(filter);
// layer.closeAll('iframe');
// }
</script>
<div class="form-group item_name ">
<label class="col-md-2 control-label" for="name">链接</label>
<label class="col-md-2 control-label" >链接</label>
<div class="col-md-4">
<input type="text" value="" name="name" class="form-control">
</div>
......@@ -84,20 +55,20 @@
$option = array('title' => 标题, 'data-id' => 1);
-->
<div class="form-group item_is_menu ">
<label class="col-md-2 control-label" for="is_menu">后台菜单</label>
<label class="col-md-2 control-label" >后台菜单</label>
<div class="col-md-8">
<div class="oh mb-10 pl-5">
<div class="radio radio-primary fl mr-10">
<label class="radio-label1" for="is_menu1">
<div class="iradio_minimal-blue checked" style="position: relative;" aria-checked="false" aria-disabled="false">
<input type="radio" checked="" value="1" id="is_menu1" name="is_menu" style="">
<input type="radio" value="1" id="is_menu1" name="is_menu" style="">
</div></label>
</div>
<div class="radio radio-primary fl mr-10">
<label class="radio-label2" for="is_menu0">
<label class="radio-label2" >
<div class="iradio_minimal-blue" style="position: relative;" aria-checked="false" aria-disabled="false">
<input type="radio" checked="" value="1" id="is_menu1" name="is_menu" style="">
<input type="radio" value="0" id="is_menu2" name="is_menu" style="">
</div></label>
</div>
......@@ -108,16 +79,8 @@
</div>
<!--
如果选项的值是自定义数组(必须定义key为title的元素)需要解析,如果选项的值是常规字符串直接显示
此处主要是用来给option定义更多的属性,比如data-ia=1,那么option应为
$option = array('title' => 标题, 'data-id' => 1);
-->
<div class="form-group item_sort ">
<label class="col-md-2 control-label" for="sort">排序</label>
<label class="col-md-2 control-label" >排序</label>
<div class="col-md-4">
<input type="number" value="1" name="sort" class="form-control">
</div>
......@@ -126,7 +89,7 @@
<div class="form-group">
<div class="col-md-10 col-xs-offset-2 mt-10 tc">
<div class="col-md-3 col-xs-6">
<button target-form="form-builder" type="submit" class="btn btn-block btn-primary submit ajax-post ">确定</button>
<a target-form="form-builder" id="submit" class="btn btn-block btn-primary submit ajax-post ">确定</a>
</div>
<div class="col-md-3 col-xs-6">
<button class="btn btn-block btn-default return" onclick="javascript:history.back(-1);return false;">返回</button>
......
......@@ -35,9 +35,9 @@
<!-- 工具栏按钮 -->
<!--<div class="form-group">-->
<a href="/index/authRuleBox.html" class="btn btn-primary btn-sm" title="新增">新增</a>&nbsp;
<a href="/setstatus/status/resume/model/auth_rule.html" model="auth_rule" class="btn btn-success ajax-post confirm btn-sm" target-form="ids" title="启用">启用</a>&nbsp;
<a href="/setstatus/status/forbid/model/auth_rule.html" model="auth_rule" class="btn btn-warning ajax-post confirm btn-sm" target-form="ids" title="禁用">禁用</a>&nbsp;
<a href="/status/delete/model/auth_rule.html" model="auth_rule" class="btn btn-danger ajax-post confirm btn-sm" target-form="ids" title="删除">删除</a>&nbsp;
<!--<a href="/setstatus/status/resume/model/auth_rule.html" model="auth_rule" class="btn btn-success ajax-post confirm btn-sm" target-form="ids" title="启用">启用</a>&nbsp;-->
<!--<a href="/setstatus/status/forbid/model/auth_rule.html" model="auth_rule" class="btn btn-warning ajax-post confirm btn-sm" target-form="ids" title="禁用">禁用</a>&nbsp;-->
<!--<a href="/status/delete/model/auth_rule.html" model="auth_rule" class="btn btn-danger ajax-post confirm btn-sm" target-form="ids" title="删除">删除</a>&nbsp;-->
<!--<a onclick="move_menuparent()" title="&lt;i class=&quot;fa fa-exchange&quot;&gt;&lt;/i&gt; 移动位置" class="btn btn-info btn-sm" target-form="ids"><i class="fa fa-exchange"></i> 移动位置</a>&nbsp;-->
<!--<a model="auth_rule" href="/admin.php/admin/auth/rule_sort/pid/0.html" class="btn btn-info btn-sm" name="排序" title="&lt;i class=&quot;fa fa-sort&quot;&gt;&lt;/i&gt; 排序"><i class="fa fa-sort"></i> 排序</a>&nbsp;-->
<!--&lt;!&ndash; </div>&ndash;&gt;-->
......
......@@ -186,4 +186,19 @@ class AuthGroup extends BaseModel
->page($pageNo)
->select();
}
/**
*检查重复
*
*/
public function repetition($key,$name){
$r=$this->field($name)
->where($key,$name)
->select();
if($r){
return true;
}else{
return false;
}
}
}
......@@ -5,7 +5,7 @@ namespace app\model;
use think\Model;
class AuthRule extends Model
class AuthRule extends BaseModel
{
// 设置完整的数据表(包含前缀)
// protected $table = 'think_access';
......@@ -61,4 +61,20 @@ class AuthRule extends Model
->select();
return $data;
}
/**
*检查重复
*
*/
public function repetition($name,$key){
$r=$this->field($name)
->where($name,'=',$key)
->select();
//$this->getLastSql();
if($r){
return true;
}else{
return false;
}
}
}
\ No newline at end of file
......@@ -36,14 +36,21 @@ class BaseModel extends Model
$this->allowField(true);
if ($confirm) {//是否验证
$this->validate($confirm);
}
if($kv){//编辑
$res=$this->save($data,[$key=>$kv]);
}else{
$res=$this->data($data)->save();
}
return $res;
}
......
......@@ -85,6 +85,7 @@ Route::group('index', [
'authRuleIndex'=>['index/auth/authRuleIndex', ['method' => 'get']], //权限列表界面
'authRuleList'=>['index/auth/authRuleList', ['method' => 'get']], //--规则列表
'authRuleBox'=>['index/auth/authRuleBox', ['method' => 'get']], //--编辑规则
'updateAuthRule'=>['index/auth/updateAuthRule', ['method' => 'post']],//--编辑规则接口
'authClass'=>['index/auth/authClass', ['method' => 'get']], //--规则分类列表
'accessUser' => ['index/auth/accessUser', ['method' => 'get']], //成员授权
'BusinessDistrict' => ['index/BusinessDistrict/index', ['method' => 'get']], //商圈列表
......
/* auth 2018/01/23 by dafei
*/
define (['doT', 'text!temp/access_template_tpl.html', 'css!style/home.css','pagination','bootstrapJs'], function (doT, template) {
var Role = {
init: function () {
//初始化dot
$ ("body").append (template);
Role.getList ();
Role.event ();
},
event: function () {
},
getList: function(){
//ajax
var id= getUrlParam('id');
$.ajax({
url: '/index/accessLook/group_id/'+id,
type: 'post',
async: true,
dataType: 'json',
success: function (data) {
var temp=document.getElementById('access_tpl').innerHTML;
var doTempl=doT.template(temp);
$("#access_box").html(doTempl(data.data.class));
}
})
}
}
return Role;
});
......@@ -8,6 +8,30 @@ define (['doT', 'text!temp/auth_rule_box_template_tpl.html', 'css!style/home.css
},
event:function () {
$ ("#submit").click(function () {
var par={}
par.id= $("input[name = id]").val();
par.title= $("input[name = title]").val();
par.name= $("input[name = name]").val();
par.sort= $("input[name = sort]").val();
par.pid=$("#pid").val();
par.is_menu=$("input[name =is_menu]:checked").val();
$.ajax({
url: '/index/updateAuthRule',
data:par,
type: 'post',
async: true,
dataType: 'json',
success: function (data) {
alert(data.msg);
console.log(data);
}
});
})
},
getList:function(){
$.ajax({
......@@ -20,7 +44,28 @@ define (['doT', 'text!temp/auth_rule_box_template_tpl.html', 'css!style/home.css
var doTempl=doT.template(temp);
$("#pid").html(doTempl(data.data.list));//赋值
}
});
var id= getUrlParam('id');
$.ajax({
url: '/index/updateAuthRule/group_id/'+id,
type: 'post',
async: true,
dataType: 'json',
success: function (data) {
$("input[name = id]").val(data.data.id);
$("input[name = title]").val(data.data.title);
$("input[name = name]").val(data.data.name);
$("input[name = sort]").val(data.data.sort);
$("#pid").val(data.data.pid);
if(data.data.is_menu==0){
$("#is_menu2").attr('checked',true);
}else{
$("#is_menu1").attr('checked',true);
}
}
})
}
}
......
......@@ -26,6 +26,12 @@ define(['doT', 'jquery'], function (doT, $) {
}
});
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = decodeURI(window.location.search).substr(1).match(reg);
if(r != null) return unescape(r[2]);
return null;
}
/* auth 2018/01/23 by dafei
*/
define (['doT', 'text!temp/user_template_tpl.html', 'css!style/home.css','pagination','bootstrapJs'], function (doT, template) {
define (['doT', 'css!style/home.css','pagination','bootstrapJs'], function (doT, template) {
var Role = {
init: function () {
//初始化dot
$ ("body").append (template);
Role.getList ();
Role.event ();
},
event: function () {
$("#sss").click(function(){
......@@ -32,11 +33,6 @@ define (['doT', 'text!temp/user_template_tpl.html', 'css!style/home.css','pagina
return Role;
});
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = decodeURI(window.location.search).substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
<script id="access_tpl" type="text/template">
[% if(it) { %]
[% for(var item in it){ %]
[% if(it[item]['pid']!=0){ %]
--
[% } %]
[% if(it[item]['is']!=0){ %]
<input type="checkbox" name="rules[]" checked="checked">
[%= it[item]["title"] %]<br>
[% }else{ %]
<input type="checkbox" name="rules[]">
[%= it[item]["title"] %]<br>
[% } %]
[% } %]
[% } %]
</script>
\ No newline at end of file
......@@ -4,9 +4,9 @@
[% for(var item in it){ %]
[% if(it[item]['pid']!=0){ %]
<option value="45">&nbsp;&nbsp;[%= it[item]["title"] %]&nbsp;</option>
<option value="[%= it[item]['id'] %]">&nbsp;&nbsp;[%= it[item]["title"] %]&nbsp;</option>
[% }else{ %]
<option value="1">[%= it[item]["title"] %]&nbsp;</option>
<option value="[%= it[item]['id'] %]">[%= it[item]["title"] %]&nbsp;</option>
[% } %]
[% } %]
......
......@@ -15,7 +15,7 @@
<td>[%= it[item]["status"] %]</td>
<!--<td><span class="fa fa-check text-success"></span></td>-->
<td>
<a style="margin-right:6px;" href="/index/authRuleBox/group_id/[%= it[item]['id'] %]" class="btn btn-primary btn-xs" title="编辑">编辑</a>
<a style="margin-right:6px;" href="/index/authRuleBox.html?id=[%= it[item]['id'] %]" class="btn btn-primary btn-xs" title="编辑">编辑</a>
<a style="margin-right:6px;" href="" class="btn btn-warning btn-xs ajax-get confirm" title="禁用">禁用</a>
</td>
</tr>
......
......@@ -298,6 +298,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
*/
public function data($data, $value = null)
{
if (is_string($data)) {
$this->data[$data] = $value;
} else {
......
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