Commit 32a5f061 authored by zfc's avatar zfc

权限编辑2

parent 3976c79f
......@@ -10,9 +10,22 @@ namespace app\index\controller;
use app\index\extend\Basic;
use app\model\AuthGroup;
use app\model\AuthRule;
use think\Db;
class Auth extends Basic
{
protected $authGroupModel;
protected $authRuleModel;
function _initialize()
{
}
/**
* 权限列表页
......@@ -59,10 +72,10 @@ class Auth extends Basic
/**
* 角色编辑
*/
public function roleedit() {
public function roleEdit() {
//$this->assign('type','1');
// return $this->display();
return view('roleedit');
return view('role_edit');
}
/**
......@@ -119,6 +132,15 @@ class Auth extends Basic
}
}
public function test(){
// $this->authRuleModel = new AuthRule();
// dump($this->authRuleModel);die;
// $list= $this->authRuleModel->find();
// return $this->response(200, '', $list);
}
/**
* 权限分配
......@@ -127,11 +149,12 @@ class Auth extends Basic
* @date 2018-01-22
* @author zfc
*/
public function access_look($group_id=0){
public function accessLook($group_id=0){
$table= New AuthGroup();
$table2= New AuthRule();
$data['title']='权限分配';
echo $group_id;
exit;
// echo $group_id;
// exit;
if (IS_POST && $group_id=0) {
//添加or修改
$data['id'] = $group_id;
......@@ -157,13 +180,57 @@ class Auth extends Basic
$role_auth_rule = $table->where(['id'=>intval($group_id)])->value('rules');
$data['menu_auth_rules']=explode(',',$role_auth_rule);//获取指定获取到的权限
}
$menu = $table->where(['pid'=>0,'status'=>1])->order('sort asc')->select();
$menu = $table2->where(['pid'=>0,'status'=>1])->order('sort asc')->select();
foreach($menu as $k=>$v){
$menu[$k]['_child']=$this->authRuleModel->where(['pid'=>$v['id']])->order('sort asc')->select();
$menu[$k]['_child']=$table2->where(['pid'=>$v['id']])->order('sort asc')->select();
}
$data['all_auth_rules']=$menu;//所以规则
return $this->response(200,'可以查看',$data);
}
/**
* 设置角色的状态
*/
public function setStatus($model ='auth_rule',$script = false){
$ids = input('request.ids/a');
if ($model =='AuthGroup') {
if (is_array($ids)) {
if(in_array(1, $ids)) {
$this->error('超级管理员不允许操作');
}
} else{
if($ids === 1) {
$this->error('超级管理员不允许操作');
}
}
} else{
//cache('admin_sidebar_menus_'.$this->currentUser['uid'],null);//清空后台菜单缓存
}
parent::setStatus($model);
}
//权限列表
public function authList(){
$data['status'] = 200;
$data['msg'] = '';
$params = $this->request->param();
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 20 : $params['pageSize'];
$table= new authRule;
//条件
$field='a.id,a.name,a.title,a.depend_flag,a.type,a.pid,a.icon,a.sort,a.is_menu,a.status,b.name as name2';
$where='a.status=1';
$order='a.pid asc,a.sort asc';
$join=[['auth_rule b', ' a.pid=b.id','left']];
$list=$table->authList($pageNo, $pageSize,$order,$field,$join, $where);
// prt($list);//转化arr
//prt(collection($list)->toArray());//转化arr
return $this->response(200,'成功',$list);
}
}
\ No newline at end of file
......@@ -127,6 +127,97 @@ class Basic extends Controller
}
/**
* 设置一条或者多条数据的状态
* @param $script 严格模式要求处理的纪录的uid等于当前登陆用户UID
*/
public function setStatus($model = CONTROLLER_NAME, $script = false) {
$ids = $this->request->param('ids/a');
$status = $this->request->param('status');
if (empty($ids)) {
$this->error('请选择要操作的数据');
}
$model_primary_key = model($model)->getPk();
$map[$model_primary_key] = ['in',$ids];
if ($script) {
$map['uid'] = ['eq', is_login()];
}
switch ($status) {
case 'forbid' : // 禁用条目
$data = ['status' => 0];
$this->editRow(
$model,
$data,
$map,
['success'=>'禁用成功','error'=>'禁用失败']
);
break;
case 'resume' : // 启用条目
$data = ['status' => 1];
$map = array_merge(['status' => 0], $map);
$this->editRow(
$model,
$data,
$map,
array('success'=>'启用成功','error'=>'启用失败')
);
break;
case 'hide' : // 隐藏条目
$data = array('status' => 1);
$map = array_merge(array('status' => 2), $map);
$this->editRow(
$model,
$data,
$map,
array('success'=>'隐藏成功','error'=>'隐藏失败')
);
break;
case 'show' : // 显示条目
$data = array('status' => 2);
$map = array_merge(array('status' => 1), $map);
$this->editRow(
$model,
$data,
$map,
array('success'=>'显示成功','error'=>'显示失败')
);
break;
case 'recycle' : // 移动至回收站
$data['status'] = -1;
$this->editRow(
$model,
$data,
$map,
array('success'=>'成功移至回收站','error'=>'删除失败')
);
break;
case 'restore' : // 从回收站还原
$data = array('status' => 1);
$map = array_merge(array('status' => -1), $map);
$this->editRow(
$model,
$data,
$map,
array('success'=>'恢复成功','error'=>'恢复失败')
);
break;
case 'delete' : // 删除条目
action_log(0, is_login(), ['param'=>$this->param],'删除操作');
$result = model($model)->where($map)->delete();
if ($result) {
$this->success('删除成功,不可恢复!');
} else {
$this->error('删除失败');
}
break;
default :
$this->error('参数错误');
break;
}
}
}
{layout name="global/frame_tpl" /}
<input type="hidden" class="page-load" id="role_edit"/>
<div id="page-content-wrapper">
<div class="container">
<div class="col-lg-10 col-lg-offset-0">
......@@ -13,9 +14,9 @@
<div class="builder formbuilder-box panel-body bg-color-fff">
<div class="row">
<div class="col-md-7">
<form action="" method="post" class="form-builder form-horizontal">
<form action="/index/addAUth" method="post" class="form-builder form-horizontal">
<fieldset>
<input type="hidden" name="id" value="3">
<!-- <input type="hidden" name="id" value="3">-->
<div class="form-group">
<label for="title" class="col-md-2 control-label">名称:</label>
<div class="col-md-10">
......
......@@ -34,7 +34,10 @@
<a href="/admin.php/index/version.html"> 版本号管理</a>
</li>
<li role="presentation">
<a href="/admin.php/index/auth.html">权限管理</a>
<a href="/admin.php/index/auth.html">角色管理</a>
</li>
<li role="presentation">
<a href="/admin.php/index/authList.html">权限管理</a>
</li>
<li role="presentation">
<a href="/admin.php/index/houseList.html">商铺列表</a>
......
......@@ -166,8 +166,10 @@ class AuthGroup extends BaseModel
return $this->checkId('AuthGroup',$gid, '以下用户组id不存在:');
}
/**
* 返回权限分组
* 返回角色分组
*
* @param type $pageNo
* @param type $pageSize
......
......@@ -22,4 +22,20 @@ class AuthRule extends Model
protected $createTime = '';
//protected $updateTime = '';
/**
*返回功能权限列表
*
*
*/
public function authList($p = 1, $pageSize = 20, $order_ = '', $field = '',$join='', $where = ''){
$data = $this->field($field)
->alias('a')
->join($join)
->where($where)
->order($order_)
->limit($pageSize)
->page($p)
->select();
return $data;
}
}
\ No newline at end of file
......@@ -73,11 +73,13 @@ Route::group('index', [
'getVersionNo' => ['index/version/getVersionNo',['method'=>'post']],
'getVersionList' => ['index/version/getVersionList',['method'=>'post']],
'addVersion' => ['index/version/addVersion',['method'=>'post']],
'getAuth' => ['index/auth/getAuth', ['method' => 'get']], //权限列表
'access' => ['index/auth/access', ['method' => 'get']], //权限分配
'getAuth' => ['index/auth/getAuth', ['method' => 'get']], //角色列表
'roleedit' => ['index/auth/roleEdit', ['method' => 'get']], //编辑角色页面
'access' => ['index/auth/access', ['method' => 'get']], //权限分配角色
'addAuth' => ['index/auth/addAuth', ['method' => 'post']], //添加角色
'access_look'=>['index/auth/access_look', ['method' => 'post']], //查看编辑角色权限
'roleedit' => ['index/auth/roleedit', ['method' => 'get']], //编辑角色
'accessLook'=>['index/auth/accessLook', ['method' => 'post']], //查看编辑角色权限
'setStatus'=>['index/auth/setStatus', ['method' => 'post']], //设置角色的状态
'authList'=>['index/auth/authList', ['method' => 'get']], //权限列表
'accessUser' => ['index/auth/accessUser', ['method' => 'get']], //成员授权
'BusinessDistrict' => ['index/BusinessDistrict/index', ['method' => 'get']], //商圈列表
'editBusinessDistrict' => ['index/BusinessDistrict/edit', ['method' => 'get | post']], //编辑商圈
......
/* auth 2018/01/23 by dafei
*/
define (['doT', 'text!temp/user_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 () {
$("#sss").click(function(){
});
},
getList: function(){
//ajax
$("input[name = title]").val("1111");
}
}
return Role;
});
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