parent
5db80290d4
commit
0e67cd22ef
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Wind
|
||||
* Date: 2017/11/25
|
||||
* Time: 13:33
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Controller;
|
||||
use tp5auth\Auth as TAuth;
|
||||
|
||||
class Auth extends Controller
|
||||
{
|
||||
public function _empty($name)
|
||||
{
|
||||
$auth = new TAuth();
|
||||
$auth = $auth->autoload($name);
|
||||
if($auth){
|
||||
if(isset($auth['code'])){
|
||||
return json($auth);
|
||||
}elseif(isset($auth['file'])){
|
||||
return $auth['file'];
|
||||
}
|
||||
$this->view->engine->layout(false);
|
||||
return $this->fetch($auth[0],$auth[1]);
|
||||
}
|
||||
return abort(404,'页面不存在');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,520 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace tp5auth\controller;
|
||||
|
||||
|
||||
use think\Cache;
|
||||
use think\Validate;
|
||||
use tp5auth\Auth;
|
||||
use tp5auth\library\Tree;
|
||||
use tp5auth\model\ActionLog;
|
||||
use tp5auth\model\AuthAccess;
|
||||
use tp5auth\model\AuthRole;
|
||||
use tp5auth\model\AuthRoleUser;
|
||||
use tp5auth\model\Menu;
|
||||
|
||||
class Rbac
|
||||
{
|
||||
|
||||
public $menuValidate = ['name|名称'=>'require' , 'app|应用'=>'require' , 'model|控制器'=>'require' , 'action|方法'=>'require'];
|
||||
public $roleValidate = ['name|角色名称' => 'require'];
|
||||
private $id;
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->param = $this->request->param();
|
||||
$this->post = $this->request->post();
|
||||
$this->id = isset($this->param['id'])?intval($this->param['id']):'';
|
||||
$this->data = ['pach'=>VIEW_PATH];
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单and权限列表
|
||||
*/
|
||||
public function menu(){
|
||||
$result = Menu::where('')->order(["list_order" => "asc",'id'=>'asc'])->column('*','id');
|
||||
$tree = new Tree();
|
||||
$tree->nbsp = ' ';
|
||||
|
||||
foreach ($result as $n=> $r) {
|
||||
$result[$n]['level'] = $tree->get_level($r['id'], $result);
|
||||
$result[$n]['parent_id_node'] = ($r['parent_id']) ? ' class="child-of-node-' . $r['parent_id'] . '"' : '';
|
||||
|
||||
$result[$n]['str_manage'] = checkPath('auth/menuAdd',["parent_id" => $r['id']]) ? '<a href="'.url("auth/menuAdd",["parent_id" => $r['id']]).'">添加子菜单</a> |':'';
|
||||
$result[$n]['str_manage'] .= checkPath('auth/menuEdit',["id" => $r['id']]) ?'<a href="'.url("auth/menuEdit",["id" => $r['id']]).'">编辑</a> |':'';
|
||||
$result[$n]['str_manage'] .= checkPath('auth/menuDelete',["id" => $r['id']]) ?'<a class="a-post" post-msg="你确定要删除吗" post-url="'.url("auth/menuDelete",["id" => $r['id']]).'">删除</a>|':'';
|
||||
$result[$n]['status'] = $r['status'] ? '开启' : '隐藏';
|
||||
}
|
||||
$str = "<tr id='node-\$id' \$parent_id_node>
|
||||
<td style='padding-left:20px;'>
|
||||
<input name='listorders[\$id]' type='text' size='3' value='\$list_order' data='\$id' class='listOrder'>
|
||||
</td>
|
||||
<td>\$id</td>
|
||||
<td>\$spacer \$name</td>
|
||||
<td>\$app</td>
|
||||
<td>\$model</td>
|
||||
<td>\$action</td>
|
||||
<td>\$request</td>
|
||||
<td>\$status</td>
|
||||
<td>\$str_manage</td>
|
||||
</tr>";
|
||||
|
||||
$tree->init($result);
|
||||
$info = $tree->get_tree(0, $str);
|
||||
return [VIEW_PATH.'menu.php',array_merge($this->data,['info'=>$info])];
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单and权限 修改
|
||||
*/
|
||||
public function menuEdit(){
|
||||
|
||||
$post = $this->post;
|
||||
$info = Menu::get($this->id);
|
||||
|
||||
if(empty($info)){
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->request->isPost()){
|
||||
|
||||
$validate = new Validate($this->menuValidate);
|
||||
|
||||
if (!$validate->check($post)) {
|
||||
return ['code'=>0,'msg'=>$validate->getError()];
|
||||
}
|
||||
|
||||
if($info->menuEdit($post)){
|
||||
return ['code'=>1,'msg'=>'修改成功','url'=>url('auth/menu')];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'修改失败'];
|
||||
}
|
||||
}
|
||||
|
||||
$info['selectCategorys'] = menu($info['parent_id']);
|
||||
return [VIEW_PATH.'menuEdit.php',array_merge($this->data,['info'=>$info])];
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单and权限 增加
|
||||
*/
|
||||
public function menuAdd(){
|
||||
$parent_id = isset($this->param['parent_id'])?$this->param['parent_id']:'';
|
||||
|
||||
if($this->request->isPost()){
|
||||
$post = $this->post;
|
||||
$validate = new Validate($this->menuValidate);
|
||||
|
||||
if (!$validate->check($post)) {
|
||||
return ['code'=>0,'msg'=>$validate->getError()];
|
||||
}
|
||||
$menu = new Menu();
|
||||
if($menu->menuAdd($post)){
|
||||
return ['code'=>1,'msg'=>'增加成功','url'=>url('auth/menu')];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'增加失败'];
|
||||
}
|
||||
}
|
||||
|
||||
$info['selectCategorys'] = menu($parent_id);
|
||||
return [VIEW_PATH.'menuAdd.php',array_merge($this->data,['info'=>$info])];
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单and权限 删除
|
||||
*/
|
||||
public function menuDelete(){
|
||||
if($this->request->isPost()){
|
||||
$result = Menu::get($this->id);
|
||||
|
||||
if(empty($result)){
|
||||
return ['code'=>0,'msg'=>'没有数据'];
|
||||
}else if(Menu::where(['parent_id'=>$result['id']])->find()){
|
||||
return ['code'=>0,'msg'=>'有子目录不可删除'];
|
||||
};
|
||||
|
||||
if($result->menuDelete($this->id)){
|
||||
return ['code'=>1,'msg'=>'删除成功','url'=>url('auth/menu')];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'删除失败'];
|
||||
}
|
||||
}
|
||||
return ['code'=>0,'msg'=>'请求方式错误'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单 排序
|
||||
*/
|
||||
public function menuOrder(){
|
||||
if($this->request->isPost()) {
|
||||
$order = isset($this->param['order'])?intval($this->param['order']):'';
|
||||
$result = Menu::get($this->id);
|
||||
|
||||
if(empty($result)){
|
||||
return ['code'=>0,'msg'=>'没有数据'];
|
||||
}else if ($result) {
|
||||
if ($result->save(['list_order' => $order])) {
|
||||
return ['code' => 1, 'msg' => '数据已更新'];
|
||||
}
|
||||
}
|
||||
|
||||
return ['code'=>0,'msg'=>'数据无变化'];
|
||||
}
|
||||
return ['code'=>0,'msg'=>'请求方式错误'];
|
||||
}
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
public function role(){
|
||||
$data = AuthRole::all();
|
||||
return [VIEW_PATH.'role.php',array_merge($this->data,['list'=>$data])];
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色修改
|
||||
*/
|
||||
public function roleEdit(){
|
||||
|
||||
$post = $this->post;
|
||||
$info = AuthRole::get($this->id);
|
||||
if(empty($info)){
|
||||
return false;
|
||||
}
|
||||
//post 数据处理
|
||||
if($this->request->isPost()){
|
||||
|
||||
$validate = new Validate($this->roleValidate);
|
||||
|
||||
if (!$validate->check($post)) {
|
||||
return ['code'=>0,'msg'=>$validate->getError()];
|
||||
}
|
||||
|
||||
if($info->save($post)){
|
||||
return ['code'=>1,'msg'=>'修改成功','url'=>url('auth/role')];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'修改失败'];
|
||||
}
|
||||
}
|
||||
|
||||
return [VIEW_PATH.'roleEdit.php',array_merge($this->data,['info'=>$info])];
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色增加
|
||||
*/
|
||||
public function roleAdd(){
|
||||
|
||||
//post 数据处理
|
||||
if($this->request->isPost()){
|
||||
$post = $this->post;
|
||||
|
||||
//现在数据
|
||||
$validate = new Validate($this->roleValidate);
|
||||
if (!$validate->check($post)) {
|
||||
return ['code'=>0,'msg'=>$validate->getError()];
|
||||
}
|
||||
|
||||
if(AuthRole::create($post)){
|
||||
return ['code'=>1,'msg'=>'增加成功','url'=>url('auth/role')];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'增加失败'];
|
||||
}
|
||||
}
|
||||
return [VIEW_PATH.'roleAdd.php',$this->data];
|
||||
}
|
||||
|
||||
public function roleDelete(){
|
||||
if($this->request->isPost()){
|
||||
$result = AuthRole::get($this->id);
|
||||
|
||||
if($this->id==1){
|
||||
return ['code'=>0,'msg'=>'超级管理员不可删除'];
|
||||
}else if(empty($result)){
|
||||
return ['code'=>0,'msg'=>'没有数据'];
|
||||
}
|
||||
|
||||
if($result->authRoleDelete()){
|
||||
return ['code'=>1,'msg'=>'删除成功','url'=>url('auth/role')];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'删除失败'];
|
||||
}
|
||||
}
|
||||
return ['code'=>0,'msg'=>'请求方式错误'];
|
||||
}
|
||||
/**
|
||||
* 角色授权
|
||||
*/
|
||||
public function authorize(){
|
||||
|
||||
|
||||
$menu = Menu::where('')->order(["list_order" => "asc",'id'=>'asc'])->column('*','id');
|
||||
|
||||
if($this->request->isPost()){//表单处理
|
||||
|
||||
$post = $this->post;
|
||||
$menuid = $post['menuid'];
|
||||
|
||||
if(empty($this->id)){
|
||||
return ['code'=>0,'msg'=>'需要授权的角色不存在'];
|
||||
}
|
||||
|
||||
AuthAccess::where(["role_id" => $this->id,'type'=>'admin_url'])->delete();
|
||||
|
||||
if (is_array($menuid) && count($menuid)>0) {
|
||||
foreach ($menuid as $v) {
|
||||
|
||||
$menus = isset($menu[$v])?$menu[$v]:'';
|
||||
|
||||
if($menus){
|
||||
$name = strtolower("{$menus['app']}/{$menus['model']}/{$menus['action']}");
|
||||
$data[] = [
|
||||
"role_id" => $this->id,
|
||||
"rule_name" => $name,
|
||||
'type' => 'admin_url',
|
||||
'menu_id' => $v
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($data)){
|
||||
$AuthAccess = new AuthAccess();
|
||||
if($AuthAccess->saveAll($data)){
|
||||
return ['code'=>1,'msg'=>'增加成功','url'=>url('auth/role')];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'增加失败'];
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'没有接收到数据,执行清除授权成功!'];
|
||||
}
|
||||
}//表单处理结束
|
||||
|
||||
if(empty($this->id)){
|
||||
return false;
|
||||
}
|
||||
$info = self::authorizeHtml($menu,'admin_url');
|
||||
|
||||
return [VIEW_PATH.'authorize.php',array_merge($this->data,['info'=>$info])];
|
||||
}
|
||||
/**
|
||||
* 管理员授权
|
||||
*/
|
||||
public function adminAuthorize(){
|
||||
|
||||
|
||||
$menu = Menu::where('')->order(["list_order" => "asc",'id'=>'asc'])->column('*','id');
|
||||
|
||||
if($this->request->isPost()){//表单处理
|
||||
|
||||
$post = $this->post;
|
||||
$menuid = $post['menuid'];
|
||||
|
||||
if(empty($this->id)){
|
||||
return ['code'=>0,'msg'=>'需要授权的角色不存在'];
|
||||
}
|
||||
|
||||
AuthAccess::where(["role_id" => $this->id,'type'=>'admin'])->delete();
|
||||
|
||||
if (is_array($menuid) && count($menuid)>0) {
|
||||
foreach ($menuid as $v) {
|
||||
|
||||
$menus = isset($menu[$v])?$menu[$v]:'';
|
||||
|
||||
if($menus){
|
||||
$name = strtolower("{$menus['app']}/{$menus['model']}/{$menus['action']}");
|
||||
$data[] = [
|
||||
"role_id" => $this->id,
|
||||
"rule_name" => $name,
|
||||
'type' => 'admin',
|
||||
'menu_id' => $v
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($data)){
|
||||
$AuthAccess = new AuthAccess();
|
||||
if($AuthAccess->saveAll($data)){
|
||||
return ['code'=>1,'msg'=>'增加成功','url'=>''];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'增加失败'];
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'没有接收到数据,执行清除授权成功!'];
|
||||
}
|
||||
}//表单处理结束
|
||||
|
||||
if(empty($this->id)){
|
||||
return false;
|
||||
}
|
||||
|
||||
//管理员所有角色权限
|
||||
$roleId = AuthRoleUser::hasWhere('authRule')->where(['a.user_id'=>$this->id,'b.status'=>1])->column('role_id');
|
||||
if(in_array(1,$roleId)){
|
||||
$AuthAccess = true;
|
||||
}else if(empty($roleId)){
|
||||
$AuthAccess = [];
|
||||
}else{
|
||||
$AuthAccess = AuthAccess::where(["role_id"=>["in",$roleId]])->column('*','menu_id');
|
||||
}
|
||||
|
||||
|
||||
$info = self::authorizeHtml($menu,'admin',$AuthAccess);
|
||||
|
||||
return [VIEW_PATH.'adminAuthorize.php',array_merge($this->data,['info'=>$info])];
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册样式文件
|
||||
*/
|
||||
public function openFile(){
|
||||
|
||||
$text = '';
|
||||
$file = strtr($this->param['file'], '_', DS);
|
||||
$extension = substr(strrchr($file, '.'), 1);
|
||||
|
||||
switch ($extension)
|
||||
{
|
||||
case 'css':
|
||||
$text = 'text/css';
|
||||
break;
|
||||
case 'js':
|
||||
$text = 'text/js';
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
$pach = VIEW_PATH.'../static/'.$file;
|
||||
$file = file_get_contents($pach);
|
||||
|
||||
return ['file'=>response($file, 200, ['Content-Length' => strlen($file)])->contentType($text)];
|
||||
}
|
||||
|
||||
/**
|
||||
* 日志列表
|
||||
*/
|
||||
public function log(){
|
||||
$where = [];
|
||||
$param = $this->param;
|
||||
if(!empty($param['username'])){
|
||||
$where['username'] = $param['username'];
|
||||
}
|
||||
if(!empty($param['userId'])){
|
||||
$where['user_id'] = $param['userId'];
|
||||
}
|
||||
if(!empty($param['title'])){
|
||||
$where['title'] = ['like','%'.$param['title'].'%'];
|
||||
}
|
||||
|
||||
$list = ActionLog::where($where)->order('id desc')->paginate(20,'',[
|
||||
'query'=>$param
|
||||
]);
|
||||
$page = $list->render();
|
||||
|
||||
return [VIEW_PATH.'log.php',array_merge($this->data,['list'=>$list,'page'=>$page])];
|
||||
}
|
||||
|
||||
/**
|
||||
* 日志详情
|
||||
*/
|
||||
public function viewLog(){
|
||||
$info = ActionLog::get($this->id);
|
||||
return [VIEW_PATH.'viewLog.php',array_merge($this->data,['info'=>$info])];
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空日志
|
||||
*/
|
||||
public function clear(){
|
||||
if(ActionLog::where('1=1')->delete()){
|
||||
return ['code'=>1,'msg'=>'数据已清空','url'=>url('auth/log')];
|
||||
}
|
||||
return ['code'=>0,'msg'=>'操作失败'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除缓存
|
||||
*/
|
||||
public function cache(){
|
||||
Cache::rm('logMenu');
|
||||
return ['code'=>1,'msg'=>'操作成功','url'=>url('auth/menu')];
|
||||
}
|
||||
|
||||
protected function authorizeHtml($menu,$type,$authMenu=[]){
|
||||
$priv_data = AuthAccess::where(['role_id'=>$this->id,'type'=>$type])->field("rule_name")->column('menu_id');
|
||||
$tree = new Tree();
|
||||
foreach ($menu as $n => $t) {
|
||||
$menu[$n]['checked'] = (in_array($t['id'], $priv_data)) ? ' checked' : '';
|
||||
$menu[$n]['level'] = $tree->get_level($t['id'], $menu);
|
||||
$menu[$n]['width'] = 100-$menu[$n]['level'];
|
||||
$menu[$n]['disabled'] = isset($authMenu[$t['id']])||$authMenu===true?[0=>"style='display: none;'disabled=''",1=>'★']:[0=>'',
|
||||
1=>''];
|
||||
|
||||
}
|
||||
|
||||
$tree->init($menu);
|
||||
$tree->text =[
|
||||
'other' => "<label class='checkbox' data-original-title='' data-toggle='' >
|
||||
<input \$checked \$disabled[0] name='menuid[]' value='\$id' level='\$level'
|
||||
onclick='javascript:checknode(this);'type='checkbox'>
|
||||
\$disabled[1] \$name
|
||||
</label>",
|
||||
'0' => [
|
||||
'0' =>"<dl class='checkmod'>
|
||||
<dt class='hd'>
|
||||
<label class='checkbox' data-original-title='' data-toggle='tooltip'>
|
||||
<input \$checked \$disabled[0] name='menuid[]' value='\$id' level='\$level'
|
||||
onclick='javascript:checknode(this);'
|
||||
type='checkbox'>
|
||||
\$disabled[1] \$name
|
||||
</label>
|
||||
</dt>
|
||||
<dd class='bd'>",
|
||||
'1' => "</dd></dl>",
|
||||
],
|
||||
'1' => [
|
||||
'0' => "
|
||||
<div class='menu_parent'>
|
||||
<label class='checkbox' data-original-title='' data-toggle='tooltip'>
|
||||
<input \$checked \$disabled[0] name='menuid[]' value='\$id' level='\$level'
|
||||
onclick='javascript:checknode(this);' type='checkbox'>
|
||||
\$disabled[1] \$name
|
||||
</label>
|
||||
</div>
|
||||
<div class='rule_check' style='width: \$width%;'>",
|
||||
|
||||
'1' => "</div><span class='child_row'></span>",
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
$info['html'] = $tree->get_authTree(0);
|
||||
$info['id'] = $this->id;
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有后台菜单
|
||||
* @param int $selected 默认id
|
||||
* @return mixed
|
||||
*/
|
||||
function menu($selected = 1){
|
||||
$array = '';
|
||||
$result = Menu::where('')->order(["list_order" => "asc",'id'=>'asc'])->column('*','id');
|
||||
|
||||
$tree = new Tree();
|
||||
foreach ($result as $r) {
|
||||
$r['selected'] = $r['id'] == $selected ? 'selected' : '';
|
||||
$array[] = $r;
|
||||
}
|
||||
$str = "<option value='\$id' \$selected>\$spacer \$name</option>";
|
||||
$tree->init($array);
|
||||
$parentid = isset($where['parentid'])?$where['parentid']:0;
|
||||
|
||||
return $tree->get_tree($parentid, $str);
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @param string $path
|
||||
* @param array $param
|
||||
* @return bool
|
||||
*/
|
||||
function checkPath($path,$param=[]){
|
||||
$result = \tp5auth\Auth::checkPath($path,$param);
|
||||
return $result;
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace tp5auth\model;
|
||||
|
||||
|
||||
class ActionLog extends \think\Model
|
||||
{
|
||||
// 设置完整的数据表(包含前缀)
|
||||
protected $name = 'action_log';
|
||||
|
||||
//初始化属性
|
||||
protected function initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 读取器 订单状态
|
||||
protected function getActionIpAttr($reg='',$data='')
|
||||
{
|
||||
return long2ip($data['action_ip']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace tp5auth\model;
|
||||
|
||||
|
||||
class AuthAccess extends \think\Model
|
||||
{
|
||||
// 设置完整的数据表(包含前缀)
|
||||
protected $name = 'auth_access';
|
||||
|
||||
//初始化属性
|
||||
protected function initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//关联一对一 角色
|
||||
public function authRole()
|
||||
{
|
||||
return $this->hasOne('AuthRule','menu_id','menu_id');
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace tp5auth\model;
|
||||
|
||||
|
||||
class AuthRole extends \think\Model
|
||||
{
|
||||
// 设置完整的数据表(包含前缀)
|
||||
protected $name = 'auth_role';
|
||||
|
||||
//初始化属性
|
||||
protected function initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//一对多 权限授权
|
||||
public function authAccess()
|
||||
{
|
||||
return $this->hasMany('AuthAccess','role_id','id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联删除 AuthAccess
|
||||
* @return bool
|
||||
*/
|
||||
public function authRoleDelete(){
|
||||
if($this->delete()){
|
||||
if($this->authAccess){
|
||||
AuthAccess::where(['role_id'=>$this->id,'type'=>'admin_url'])->delete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace tp5auth\model;
|
||||
|
||||
|
||||
class AuthRoleUser extends \think\Model
|
||||
{
|
||||
// 设置完整的数据表(包含前缀)
|
||||
protected $name = 'auth_role_user';
|
||||
|
||||
//初始化属性
|
||||
protected function initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//关联一对一 角色
|
||||
public function authRole()
|
||||
{
|
||||
return $this->hasOne('authRole','id','role_id');
|
||||
}
|
||||
|
||||
//关联一对一 角色
|
||||
public function authAccess()
|
||||
{
|
||||
return $this->hasOne('authAccess','role_id','role_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入角色权限
|
||||
* @param array $role_id 角色ID
|
||||
* @param int $user_id 用户ID
|
||||
* @return bool
|
||||
*/
|
||||
public function authRoleUserAdd($role_id,$user_id){
|
||||
|
||||
$data = [];
|
||||
if(is_array($role_id)){
|
||||
self::where(['user_id'=>$user_id])->delete();
|
||||
foreach($role_id as $v){
|
||||
$data[] = [
|
||||
'role_id' => $v,
|
||||
'user_id' => $user_id
|
||||
];
|
||||
}
|
||||
self::saveAll($data);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除角色权限
|
||||
* @param int $user_id 用户ID
|
||||
* @return bool
|
||||
*/
|
||||
public function authRoleUserDelete($user_id){
|
||||
self::where(['user_id'=>$user_id])->delete();
|
||||
AuthAccess::where(['role_id'=>$user_id,'type'=>'admin'])->delete();
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace tp5auth\model;
|
||||
|
||||
|
||||
class AuthRule extends \think\Model
|
||||
{
|
||||
// 设置完整的数据表(包含前缀)
|
||||
protected $name = 'auth_rule';
|
||||
|
||||
//初始化属性
|
||||
protected function initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//关联一对多 目录
|
||||
public function authAccess()
|
||||
{
|
||||
return $this->hasMany('AuthAccess','menu_id','menu_id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关联 authAccess模型 修改
|
||||
* @param array $param 参数
|
||||
* @return bool
|
||||
*/
|
||||
public function authRuleEdit($param){
|
||||
if($this->save($param)){
|
||||
if($this->authAccess){
|
||||
AuthAccess::where(['menu_id'=>$param['menu_id']])->update(['rule_name'=>$param['name'],'type'=>$param['type']]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @return bool
|
||||
*/
|
||||
public function authRuleDelete(){
|
||||
if($this->delete()){
|
||||
if($this->authAccess){
|
||||
AuthAccess::where(['menu_id'=>$this->menu_id])->delete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
namespace tp5auth\model;
|
||||
|
||||
|
||||
class Menu extends \think\Model
|
||||
{
|
||||
// 设置完整的数据表(包含前缀)
|
||||
protected $name = 'menu';
|
||||
|
||||
//初始化属性
|
||||
protected function initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存后台菜单数据
|
||||
*/
|
||||
public static function actionLogMenu() {
|
||||
$log = [];
|
||||
$men = Menu::where('request <> "" ')->column('*');
|
||||
|
||||
foreach($men as $v){
|
||||
$url = strtolower($v['app'].'/'.$v['model'].'/'.$v['action']);
|
||||
$arr = [
|
||||
'log_rule' => $v['log_rule'],
|
||||
'request' => $v['request'],
|
||||
'rule_param'=> $v['rule_param'],
|
||||
'name' => $v['name'],
|
||||
];
|
||||
if(!isset($log[$url])){
|
||||
$log[$url] = $arr;
|
||||
}else{
|
||||
$log[$url]['child'][] = $arr;
|
||||
}
|
||||
}
|
||||
return $log;
|
||||
}
|
||||
|
||||
//关联一对一 目录
|
||||
public function authRule()
|
||||
{
|
||||
return $this->hasOne('AuthRule','menu_id','id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关联 authRule模型 修改
|
||||
* @param array $param 参数
|
||||
* @return bool
|
||||
*/
|
||||
public function menuEdit($param){
|
||||
|
||||
if($this->save($param)){
|
||||
$authRule = $this->authRule;
|
||||
|
||||
if($this->data['action'] == 'default' ||$this->data['type'] == 0) {//判断他们是否需要加入权限
|
||||
if($authRule){
|
||||
$this->authRule->authRuleDelete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
$name = strtolower("{$this->data['app']}/{$this->data['model']}/{$this->data['action']}");
|
||||
|
||||
$authRuledata = [
|
||||
"name" => $name,
|
||||
"module" => $this->data['app'],
|
||||
"type" => "admin_url",
|
||||
"title" => $this->data['name'],
|
||||
'menu_id' => $this->data['id'],
|
||||
'url_param' => $this->data['url_param'],
|
||||
'rule_param' => $this->data['rule_param'],
|
||||
];
|
||||
if($authRule){
|
||||
$authRule->authRuleEdit($authRuledata);
|
||||
return true;
|
||||
}else{
|
||||
AuthRule::create($authRuledata);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联 authRule模型 增加
|
||||
* @param array $param 参数
|
||||
* @return bool
|
||||
*/
|
||||
public function menuAdd($param){
|
||||
$auth = $this->create($param);
|
||||
if($auth){
|
||||
|
||||
$name = strtolower("{$auth->data['app']}/{$auth->data['model']}/{$auth->data['action']}");
|
||||
$authRule = [
|
||||
"name" => $name,
|
||||
"module" => $auth->data['app'],
|
||||
"type" => "admin_url",
|
||||
"title" => $auth->data['name'],
|
||||
'menu_id' => $auth->data['id'],
|
||||
'url_param' => $auth->data['url_param'],
|
||||
'rule_param' => $auth->data['rule_param'],
|
||||
];
|
||||
|
||||
AuthRule::create($authRule);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联 authRule模型 删除
|
||||
* @param int $id 参数
|
||||
* @return bool
|
||||
*/
|
||||
public function menuDelete(){
|
||||
if($this->delete()){
|
||||
if($this->authRule){
|
||||
$this->authRule->authRuleDelete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 50712
|
||||
Source Host : localhost
|
||||
Source Database : rbac
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 50712
|
||||
File Encoding : utf-8
|
||||
|
||||
Date: 11/17/2016 00:01:38 AM
|
||||
*/
|
||||
|
||||
SET NAMES utf8;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for `tp_action_log`
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tp_action_log`;
|
||||
CREATE TABLE `tp_action_log` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`user_id` int(10) NOT NULL DEFAULT '0' COMMENT '执行用户id',
|
||||
`action_ip` bigint(20) NOT NULL COMMENT '执行行为者ip',
|
||||
`log` longtext NOT NULL COMMENT '日志备注',
|
||||
`log_url` varchar(255) NOT NULL COMMENT '执行的URL',
|
||||
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '执行行为的时间',
|
||||
`username` varchar(255) NOT NULL COMMENT '执行者',
|
||||
`title` varchar(255) NOT NULL COMMENT '标题',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `id` (`id`) USING BTREE
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='行为日志表';
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 50712
|
||||
Source Host : localhost
|
||||
Source Database : rbac
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 50712
|
||||
File Encoding : utf-8
|
||||
|
||||
Date: 11/12/2016 23:25:30 PM
|
||||
*/
|
||||
|
||||
SET NAMES utf8;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for `tp_auth_access`
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tp_auth_access`;
|
||||
CREATE TABLE `tp_auth_access` (
|
||||
`role_id` mediumint(8) unsigned NOT NULL COMMENT '角色',
|
||||
`rule_name` varchar(255) NOT NULL COMMENT '规则唯一英文标识,全小写',
|
||||
`type` varchar(30) DEFAULT NULL COMMENT '权限规则分类,请加应用前缀,如admin_',
|
||||
`menu_id` int(11) DEFAULT NULL COMMENT '后台菜单ID',
|
||||
KEY `role_id` (`role_id`),
|
||||
KEY `rule_name` (`rule_name`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='权限授权表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of `tp_auth_access`
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/default', 'admin_url', '1'), ('2', 'index/auth/default', 'admin_url', '8'), ('2', 'index/auth/menu', 'admin_url', '9'), ('2', 'index/auth/menuadd', 'admin_url', '10'), ('2', 'index/auth/menuedit', 'admin_url', '11'), ('2', 'index/auth/menudelete', 'admin_url', '12'), ('2', 'index/auth/menuorder', 'admin_url', '13');
|
||||
COMMIT;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 50712
|
||||
Source Host : localhost
|
||||
Source Database : rbac
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 50712
|
||||
File Encoding : utf-8
|
||||
|
||||
Date: 11/12/2016 23:25:24 PM
|
||||
*/
|
||||
|
||||
SET NAMES utf8;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for `tp_auth_role`
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tp_auth_role`;
|
||||
CREATE TABLE `tp_auth_role` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(20) NOT NULL COMMENT '角色名称',
|
||||
`pid` smallint(6) DEFAULT '0' COMMENT '父角色ID',
|
||||
`status` tinyint(1) unsigned DEFAULT NULL COMMENT '状态',
|
||||
`remark` varchar(255) DEFAULT NULL COMMENT '备注',
|
||||
`create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
|
||||
`listorder` int(3) NOT NULL DEFAULT '0' COMMENT '排序字段',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `parentId` (`pid`),
|
||||
KEY `status` (`status`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='角色表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of `tp_auth_role`
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `tp_auth_role` VALUES ('1', '超级管理员', '0', '1', '拥有网站最高管理员权限!', '1329633709', '1329633709', '0'), ('2', '文章管理', '0', '1', '', '0', '0', '0');
|
||||
COMMIT;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 50712
|
||||
Source Host : localhost
|
||||
Source Database : rbac
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 50712
|
||||
File Encoding : utf-8
|
||||
|
||||
Date: 11/12/2016 23:25:19 PM
|
||||
*/
|
||||
|
||||
SET NAMES utf8;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for `tp_auth_role_user`
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tp_auth_role_user`;
|
||||
CREATE TABLE `tp_auth_role_user` (
|
||||
`role_id` int(11) unsigned DEFAULT '0' COMMENT '角色 id',
|
||||
`user_id` int(11) DEFAULT '0' COMMENT '用户id',
|
||||
KEY `group_id` (`role_id`),
|
||||
KEY `user_id` (`user_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='用户角色对应表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of `tp_auth_role_user`
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `tp_auth_role_user` VALUES ('2', '16');
|
||||
COMMIT;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 50712
|
||||
Source Host : localhost
|
||||
Source Database : rbac
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 50712
|
||||
File Encoding : utf-8
|
||||
|
||||
Date: 11/12/2016 23:25:13 PM
|
||||
*/
|
||||
|
||||
SET NAMES utf8;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for `tp_auth_rule`
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tp_auth_rule`;
|
||||
CREATE TABLE `tp_auth_rule` (
|
||||
`menu_id` int(11) NOT NULL COMMENT '后台菜单 ID',
|
||||
`module` varchar(20) NOT NULL COMMENT '规则所属module',
|
||||
`type` varchar(30) NOT NULL DEFAULT '1' COMMENT '权限规则分类,请加应用前缀,如admin_',
|
||||
`name` varchar(255) NOT NULL DEFAULT '' COMMENT '规则唯一英文标识,全小写',
|
||||
`url_param` varchar(255) DEFAULT NULL COMMENT '额外url参数',
|
||||
`title` varchar(20) NOT NULL DEFAULT '' COMMENT '规则中文描述',
|
||||
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否有效(0:无效,1:有效)',
|
||||
`rule_param` varchar(300) NOT NULL DEFAULT '' COMMENT '规则附加条件',
|
||||
`nav_id` int(11) DEFAULT '0' COMMENT 'nav id',
|
||||
PRIMARY KEY (`menu_id`),
|
||||
KEY `module` (`module`,`status`,`type`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='权限规则表';
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of `tp_auth_rule`
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `tp_auth_rule` VALUES ('2', 'index', 'admin_url', 'index/auth/default', '', '权限管理', '1', '', '0'), ('3', 'index', 'admin_url', 'index/auth/role', '', '角色管理', '1', '', '0'), ('4', 'index', 'admin_url', 'index/auth/roleadd', '', '角色增加', '1', '', '0'), ('5', 'index', 'admin_url', 'index/auth/roleedit', '', '角色编辑', '1', '', '0'), ('6', 'index', 'admin_url', 'index/auth/roledelete', '', '角色删除', '1', '', '0'), ('7', 'index', 'admin_url', 'index/auth/authorize', '', '角色授权', '1', '', '0'), ('8', 'index', 'admin_url', 'index/auth/menu', '', '菜单管理', '1', '', '0'), ('9', 'index', 'admin_url', 'index/auth/menu', '', '菜单列表', '1', '', '0'), ('10', 'index', 'admin_url', 'index/auth/menuadd', '', '菜单增加', '1', '', '0'), ('11', 'index', 'admin_url', 'index/auth/menuedit', '', '菜单修改', '1', '', '0'), ('12', 'index', 'admin_url', 'index/auth/menudelete', '', '菜单删除', '1', '', '0'), ('13', 'index', 'admin_url', 'index/auth/menuorder', '', '菜单排序', '1', '', '0'), ('14', 'index', 'admin_url', 'index/admin/index', '', '用户管理', '1', '', '0');
|
||||
COMMIT;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,16 @@
|
||||
html,
|
||||
.help-block-error{color: #a94442;}
|
||||
.nav{margin-bottom: 20px;margin-top: 20px;}
|
||||
.table td {font-size: 12px;}
|
||||
a{color: #1abc9c;}
|
||||
.form-actions {padding: 19px 20px 20px;margin-top: 20px;margin-bottom: 20px;background-color: #f5f5f5;border-top: 1px solid #e5e5e5;}
|
||||
.form-required{float: left;padding-top: 6px;padding-left: 4px;font-size: 18px;color: #e74c3c;}
|
||||
.text{float: left;width: 300px;}
|
||||
.width1{width: 100px}
|
||||
.width2{width: 200px}
|
||||
.width3{width: 300px}
|
||||
.listOrder{height: 20px; border: 1px solid rgb(203, 208, 212); text-align: center; width: 40px; background-color: rgb(241, 241, 241);}
|
||||
.toggle {text-align: center;}
|
||||
.toggle img{cursor: pointer }
|
||||
.span-text{float: left;padding-top: 9px;padding-left: 10px;padding-right: 10px;}
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,117 @@
|
||||
<?php require $pach . 'public/top.php';?>
|
||||
|
||||
<style>
|
||||
.checkmod{
|
||||
margin-bottom:20px;
|
||||
border: 1px solid #ebebeb;padding-bottom: 5px;
|
||||
}
|
||||
.checkmod dt{
|
||||
padding-left:10px;
|
||||
height:30px;
|
||||
line-height:30px;
|
||||
font-weight:bold;
|
||||
border-bottom: 1px solid #ebebeb;
|
||||
background-color:#ECECEC;
|
||||
}
|
||||
.checkmod dt{
|
||||
margin-bottom: 5px;
|
||||
border-bottom-color:#ebebeb;
|
||||
background-color:#ECECEC;
|
||||
}
|
||||
.checkbox , .radio{
|
||||
display:inline-block;
|
||||
height:20px;
|
||||
line-height:20px;
|
||||
}
|
||||
.checkmod dd{
|
||||
padding-left:10px;
|
||||
line-height:30px;
|
||||
}
|
||||
.checkmod dd .checkbox{
|
||||
margin:0 10px 0 0;
|
||||
}
|
||||
.checkmod dd .divsion{
|
||||
margin-right:20px;
|
||||
}
|
||||
.checkmod dt{
|
||||
line-height:30px;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.rule_check{border: 1px solid #ebebeb;margin: auto;padding: 5px 10px;}
|
||||
.menu_parent{margin-bottom: 5px;}
|
||||
|
||||
</style>
|
||||
|
||||
<div class="wrap js-check-wrap">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="">{:input('name')}权限</a></li>
|
||||
</ul>
|
||||
<div class="cf well form-search" style="height: 58px;">
|
||||
<p>★已选中的角色权限 <input checked="checked" type="checkbox">已选中的管理员权限</p>
|
||||
</div>
|
||||
|
||||
<form class="form-horizontal" action="{:url('auth/adminAuthorize',['id'=>$info['id']])}" method="post">
|
||||
|
||||
<div class="table_full">
|
||||
<table width="100%" cellspacing="0" id="dnd-example">
|
||||
<tbody>
|
||||
<?php echo $info['html']?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
|
||||
<button type="button" class="btn btn-primary ajax-post " autocomplete="off">
|
||||
保存
|
||||
</button>
|
||||
<a class="btn" href="JavaScript:history.go(-1)">返回</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function checknode(obj) {
|
||||
|
||||
var chk = $("input[type='checkbox']");
|
||||
var count = chk.length;
|
||||
var num = chk.index(obj);
|
||||
var level_top = level_bottom = chk.eq(num).attr('level');
|
||||
|
||||
for (var i = num; i >= 0; i--) {
|
||||
var le = chk.eq(i).attr('level');
|
||||
if (eval(le) < eval(level_top)) {
|
||||
chk.eq(i).prop("checked",true);
|
||||
var level_top = level_top - 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (var j = num + 1; j < count; j++) {
|
||||
var le = chk.eq(j).attr('level');
|
||||
if (chk.eq(num).prop("checked")) {
|
||||
if (eval(le) > eval(level_bottom)){
|
||||
|
||||
chk.eq(j).prop("checked",true);
|
||||
}
|
||||
else if (eval(le) == eval(level_bottom)){
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (eval(le) > eval(level_bottom)){
|
||||
chk.eq(j).prop("checked",false);
|
||||
}else if(eval(le) == eval(level_bottom)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<?php require $pach . 'public/foot.php';?>
|
||||
@ -0,0 +1,119 @@
|
||||
<?php require $pach . 'public/top.php';?>
|
||||
<style>
|
||||
.checkmod{
|
||||
margin-bottom:20px;
|
||||
border: 1px solid #ebebeb;padding-bottom: 5px;
|
||||
}
|
||||
.checkmod dt{
|
||||
padding-left:10px;
|
||||
height:30px;
|
||||
line-height:30px;
|
||||
font-weight:bold;
|
||||
border-bottom: 1px solid #ebebeb;
|
||||
background-color:#ECECEC;
|
||||
}
|
||||
.checkmod dt{
|
||||
margin-bottom: 5px;
|
||||
border-bottom-color:#ebebeb;
|
||||
background-color:#ECECEC;
|
||||
}
|
||||
.checkbox , .radio{
|
||||
display:inline-block;
|
||||
height:20px;
|
||||
line-height:20px;
|
||||
}
|
||||
.checkmod dd{
|
||||
padding-left:10px;
|
||||
line-height:30px;
|
||||
}
|
||||
.checkmod dd .checkbox{
|
||||
margin:0 10px 0 0;
|
||||
}
|
||||
.checkmod dd .divsion{
|
||||
margin-right:20px;
|
||||
}
|
||||
.checkmod dt{
|
||||
line-height:30px;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.rule_check{border: 1px solid #ebebeb;margin: auto;padding: 5px 10px;}
|
||||
.menu_parent{margin-bottom: 5px;}
|
||||
|
||||
</style>
|
||||
|
||||
<div class="wrap js-check-wrap">
|
||||
<ul class="nav nav-tabs">
|
||||
{if condition="checkPath('auth/role')"}
|
||||
<li><a href="<?php echo url('auth/role')?>">角色管理</a></li>
|
||||
{/if}
|
||||
{if condition="checkPath('auth/roleAdd')"}
|
||||
<li><a href="<?php echo url('auth/roleAdd')?>">增加角色</a></li>
|
||||
{/if}
|
||||
<li class="active"><a href="">权限设置</a></li>
|
||||
</ul>
|
||||
|
||||
<form class="form-horizontal" action="{:Url('auth/authorize',['id'=>$info['id']])}" method="post">
|
||||
|
||||
<div class="table_full">
|
||||
<table width="100%" cellspacing="0" id="dnd-example">
|
||||
<tbody>
|
||||
<?php echo $info['html']?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
|
||||
<button type="button" class="btn btn-primary ajax-post " autocomplete="off">
|
||||
保存
|
||||
</button>
|
||||
<a class="btn" href="JavaScript:history.go(-1)">返回</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function checknode(obj) {
|
||||
|
||||
var chk = $("input[type='checkbox']");
|
||||
var count = chk.length;
|
||||
var num = chk.index(obj);
|
||||
var level_top = level_bottom = chk.eq(num).attr('level');
|
||||
|
||||
for (var i = num; i >= 0; i--) {
|
||||
var le = chk.eq(i).attr('level');
|
||||
if (eval(le) < eval(level_top)) {
|
||||
chk.eq(i).prop("checked",true);
|
||||
var level_top = level_top - 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (var j = num + 1; j < count; j++) {
|
||||
var le = chk.eq(j).attr('level');
|
||||
if (chk.eq(num).prop("checked")) {
|
||||
if (eval(le) > eval(level_bottom)){
|
||||
|
||||
chk.eq(j).prop("checked",true);
|
||||
}
|
||||
else if (eval(le) == eval(level_bottom)){
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (eval(le) > eval(level_bottom)){
|
||||
chk.eq(j).prop("checked",false);
|
||||
}else if(eval(le) == eval(level_bottom)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<?php require $pach . 'public/foot.php';?>
|
||||
@ -0,0 +1,37 @@
|
||||
|
||||
|
||||
<div class="form-group ">
|
||||
<label class="col-lg-2 control-label" for="signupform-username">角色名称</label>
|
||||
<div class="col-lg-3">
|
||||
<input type="text" class="form-control" value="<?php echo isset($info['name'])?$info['name']:''?>" name="name" >
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">角色描述</label>
|
||||
<div class="col-lg-3">
|
||||
<textarea name="remark" class="form-control" rows="3"><?php echo isset($info['remark'])?$info['remark']:''?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">状态 </label>
|
||||
<div class="col-lg-3">
|
||||
<?php
|
||||
$status = isset($info['status'])?$info['status']:'';
|
||||
?>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" <?php echo empty($status)|$status==1?'checked':''?> name="status" value="1"> 开启
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" <?php echo $status === 0?'checked':''?> name="status" value="0"> 禁用
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="button" class="btn btn-primary ajax-post " autocomplete="off">
|
||||
保存
|
||||
</button>
|
||||
<a class="btn btn-default active" onclick="history.go(-1)">返回</a>
|
||||
</div>
|
||||
@ -0,0 +1,67 @@
|
||||
<?php require $pach . 'public/top.php';?>
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="{:Url('auth/log')}">日志列表</a></li>
|
||||
</ul>
|
||||
<div>
|
||||
<div class="cf well form-search" style="height: 68px;">
|
||||
<form method="get">
|
||||
<div class="fl">
|
||||
|
||||
<div class="btn-group">
|
||||
<input name="username" class="form-control" value="{:input('username')}" placeholder="用户昵称" type="text">
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<input name="userId" class="form-control" value="{:input('userId')}" placeholder="用户ID" type="text">
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<input name="title" class="form-control" value="{:input('title')}" placeholder="标题" type="text">
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="submit" class="btn btn-success">查询</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="fr">
|
||||
<div class="btn-group">
|
||||
{if condition="checkPath('auth/clear')"}
|
||||
<button type="button" post-url="{:Url('auth/clear')}" class="btn ajax-post
|
||||
btn-success">清空</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table table-hover table-bordered table-list" id="menus-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="100">ID</th>
|
||||
<th>标题</th>
|
||||
<th width="">用户</th>
|
||||
<th width="">执行地址</th>
|
||||
<th width="100">IP</th>
|
||||
<th width="150">执行时间</th>
|
||||
<th width="80">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($list as $v) {?>
|
||||
<tr>
|
||||
<td>{$v.id}</td>
|
||||
<td>{$v.title}</td>
|
||||
<td>{$v.username}</td>
|
||||
<td>{$v.log_url}</td>
|
||||
<td>{$v.action_ip}</td>
|
||||
<th>{:date('Y-m-d H:i:s',$v['create_time'])}</th>
|
||||
<td>
|
||||
{if condition="checkPath('auth/viewlog',['id'=>$v['id']])"}
|
||||
<a href="{:url('auth/viewlog',['id'=>$v['id']])}">详细</a>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
{$page}
|
||||
</div>
|
||||
<?php require $pach . 'public/foot.php';?>
|
||||
@ -0,0 +1,38 @@
|
||||
<?php require $pach . 'public/top.php';?>
|
||||
<ul class="nav nav-tabs">
|
||||
|
||||
<li class="active"><a href="{:url('auth/menu')}">后台菜单</a></li>
|
||||
{if condition="checkPath('auth/menuAdd')"}
|
||||
<li><a href="{:url('auth/menuAdd')}">增加菜单</a></li>
|
||||
{/if}
|
||||
</ul>
|
||||
|
||||
<div class="cf well form-search" style="height: 68px;">
|
||||
<div class="fl ">
|
||||
<div class="btn-group">
|
||||
<button type="button" post-url="{:url('auth/cache')}" class="btn ajax-post btn-success">清除日志缓存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table table-hover table-bordered table-list" id="menus-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="80">排序</th>
|
||||
<th width="50">ID</th>
|
||||
<th>菜单名称</th>
|
||||
<th>应用</th>
|
||||
<th>控制器</th>
|
||||
<th>方法</th>
|
||||
<th>日志请求</th>
|
||||
<th width="80">状态</th>
|
||||
<th width="180">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php echo $info?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<input type="hidden" value="{:url('auth/menuOrder')}" class="listOrderUrl">
|
||||
<?php require $pach . 'public/foot.php';?>
|
||||
@ -0,0 +1,13 @@
|
||||
|
||||
<?php require $pach . 'public/top.php';?>
|
||||
<ul class="nav nav-tabs">
|
||||
{if condition="checkPath('auth/menu')"}
|
||||
<li><a href="{:url('auth/menu')}">后台菜单</a></li>
|
||||
{/if}
|
||||
<li class="active"><a href="{:url('auth/menuAdd')}">增加菜单</a></li>
|
||||
</ul>
|
||||
|
||||
<form class="form-horizontal" action="{:url('auth/menuAdd')}" method="post">
|
||||
<?php require $pach . 'form/form_menu.php';?>
|
||||
</form>
|
||||
<?php require $pach . 'public/foot.php';?>
|
||||
@ -0,0 +1,16 @@
|
||||
|
||||
<?php require $pach . 'public/top.php';?>
|
||||
<ul class="nav nav-tabs">
|
||||
{if condition="checkPath('auth/menu')"}
|
||||
<li><a href="{:url('auth/menu')}">后台菜单</a></li>
|
||||
{/if}
|
||||
{if condition="checkPath('auth/menuAdd')"}
|
||||
<li><a href="{:Url('auth/menuAdd')}">增加菜单</a></li>
|
||||
{/if}
|
||||
<li class="active"><a href="">编辑菜单</a></li>
|
||||
</ul>
|
||||
|
||||
<form class="form-horizontal" action="{:url('auth/menuEdit',['id'=>$info['id']])}" method="post">
|
||||
<?php require $pach . 'form/form_menu.php';?>
|
||||
</form>
|
||||
<?php require $pach . 'public/foot.php';?>
|
||||
@ -0,0 +1,6 @@
|
||||
|
||||
<script src="<?php echo get_file('js_cmsinfo.js')?>"></script>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<?php
|
||||
|
||||
function get_file($file){
|
||||
$directory = \think\Config::get('tp5auth.style_directory');
|
||||
|
||||
if(empty($directory)){
|
||||
return url('auth/openFile',['file'=>$file]);
|
||||
}else{
|
||||
$file = strtr($file, '_', DS);
|
||||
return $directory.$file;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>后台操作系统</title>
|
||||
<link href="<?php echo get_file('css_bootstrap.min.css')?>" rel="stylesheet">
|
||||
<link href="<?php echo get_file('css_site.css')?>" rel="stylesheet">
|
||||
<script src="<?php echo get_file('js_jquery.min.js')?>"></script>
|
||||
<script src="<?php echo get_file('js_bootstrap.min.js')?>"></script>
|
||||
</head>
|
||||
|
||||
|
||||
<body style="min-width:790px;" >
|
||||
<style>
|
||||
.alert{
|
||||
position: fixed !important;z-index: 1000;width: 98%;top: 2%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div id="alert"></div>
|
||||
@ -0,0 +1,19 @@
|
||||
|
||||
<?php require $pach . 'public/top.php';?>
|
||||
|
||||
<ul class="nav nav-tabs">
|
||||
{if condition="checkPath('auth/role')"}
|
||||
<li><a href="<?php echo Url('auth/role')?>">角色管理</a></li>
|
||||
{/if}
|
||||
<li class="active"><a href="<?php echo Url('auth/roleAdd')?>">增加角色</a></li>
|
||||
</ul>
|
||||
<div class="site-signup">
|
||||
<div class="row">
|
||||
<form class="form-horizontal" action="<?php echo Url('auth/roleAdd')?>" method="post" >
|
||||
<?php require $pach . 'form/form_role.php';?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<?php require $pach . 'public/foot.php';?>
|
||||
@ -0,0 +1,19 @@
|
||||
|
||||
<?php include $pach . 'public/top.php';?>
|
||||
<ul class="nav nav-tabs">
|
||||
{if condition="checkPath('auth/role')"}
|
||||
<li><a href="<?php echo Url('auth/role')?>">角色管理</a></li>
|
||||
{/if}
|
||||
{if condition="checkPath('auth/roleAdd')"}
|
||||
<li><a href="<?php echo Url('auth/roleAdd')?>">增加角色</a></li>
|
||||
{/if}
|
||||
<li class="active"><a href="">角色修改</a></li>
|
||||
</ul>
|
||||
<div class="site-signup">
|
||||
<div class="row">
|
||||
<form class="form-horizontal" action="<?php echo Url('auth/roleEdit',['id'=>$info['id']])?>" method="post" >
|
||||
<?php include $pach.'form/form_role.php';?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php include $pach . 'public/foot.php';?>
|
||||
@ -0,0 +1,69 @@
|
||||
<?php require $pach . 'public/top.php';?>
|
||||
<ul class="nav nav-tabs">
|
||||
<li><a href="{:Url('auth/log')}">日志列表</a></li>
|
||||
<li class="active"><a href="">日志详情</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="bs-example">
|
||||
|
||||
<table class="table table-bordered">
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>标题</th>
|
||||
<th>
|
||||
{$info.title}
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>执行地址</th>
|
||||
<th>
|
||||
<a href="{$info.log_url}">{$info.log_url}</a>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th width="150">执行者</th>
|
||||
<td>
|
||||
{$info.username}
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th width="150">执行IP</th>
|
||||
<td>
|
||||
{$info.action_ip}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>执行时间</th>
|
||||
<td>
|
||||
{:date('Y-m-d H:i:s',$info['create_time'])}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th colspan="2" style="text-align: center">日志详情</th>
|
||||
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
{$info.log}
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-actions col-sm-12">
|
||||
|
||||
<a class="btn btn-default active" href="JavaScript:history.go(-1)">返回</a>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<?php require $pach . 'public/foot.php';?>
|
||||
Loading…
Reference in new issue