Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
dc3e66dc
Commit
dc3e66dc
authored
Jan 26, 2018
by
zfc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
权限管理
parent
910e8364
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
158 additions
and
33 deletions
+158
-33
common.php
application/index/common.php
+36
-0
Auth.php
application/index/controller/Auth.php
+38
-14
access.html
application/index/view/auth/access.html
+5
-4
AuthRule.php
application/model/AuthRule.php
+35
-5
route.php
application/route.php
+14
-6
access.js
public/resource/js/access.js
+26
-0
auth_rule_box.js
public/resource/js/auth_rule_box.js
+2
-2
access_template_tpl.html
public/resource/template/access_template_tpl.html
+2
-2
No files found.
application/index/common.php
View file @
dc3e66dc
...
...
@@ -3,4 +3,39 @@
function
prt
(
$arr
){
echo
'<pre/>'
;
print_r
(
$arr
);
}
/**
* 把返回的数据集转换成Tree
* @access public
* @param array $list 要转换的数据集
* @param string $pid parent标记字段
* @param string $level level标记字段
* @return array
*/
function
list_to_tree
(
$list
,
$pk
=
'id'
,
$pid
=
'pid'
,
$child
=
'_child'
,
$root
=
0
,
$is_count
=
false
)
{
// 创建Tree
$tree
=
[];
if
(
is_array
(
$list
))
{
// 创建基于主键的数组引用
$refer
=
[];
foreach
(
$list
as
$key
=>
$data
)
{
$refer
[
$data
[
$pk
]]
=&
$list
[
$key
];
}
foreach
(
$list
as
$key
=>
$data
)
{
// 判断是否存在parent
$parentId
=
$data
[
$pid
];
if
(
$root
==
$parentId
)
{
$tree
[]
=&
$list
[
$key
];
}
else
{
if
(
isset
(
$refer
[
$parentId
]))
{
$parent
=&
$refer
[
$parentId
];
$parent
[
$child
][]
=&
$list
[
$key
];
if
(
$is_count
==
true
)
$parent
[
'_count'
]
=
count
(
$parent
[
$child
]);
}
}
}
}
return
$tree
;
}
\ No newline at end of file
application/index/controller/Auth.php
View file @
dc3e66dc
...
...
@@ -132,15 +132,21 @@ class Auth extends Basic
}
}
public
function
test
(){
// $this->authRuleModel = new AuthRule();
// dump($this->authRuleModel);die;
// $list= $this->authRuleModel->find();
// return $this->response(200, '', $list);
}
//权限表list
public
function
classList
(
$type
=
1
){
$table
=
new
authRule
;
$menus
=
db
(
'auth_rule'
)
->
select
();
// exit;
$menus
=
$table
->
toFormatTree
(
$menus
,
'title'
);
// prt($menus);
if
(
$type
==
1
)
{
return
$this
->
response
(
200
,
'成功'
,
$menus
);
}
else
{
return
$menus
;
}
}
/**
...
...
@@ -152,7 +158,7 @@ class Auth extends Basic
*/
public
function
accessLook
(
$group_id
=
0
){
$table
=
New
AuthGroup
;
$table2
=
New
A
uthRule
;
$table2
=
new
a
uthRule
;
$data
[
'title'
]
=
'权限分配'
;
// echo $group_id;
// exit;
...
...
@@ -176,12 +182,14 @@ class Auth extends Basic
//查看
$role_auth_rule
=
$table
->
where
([
'id'
=>
intval
(
$group_id
)])
->
value
(
'rules'
);
$data
[
'rules'
]
=
explode
(
','
,
$role_auth_rule
);
//获取指定获取到的权限
$data
[
'class'
]
=
$this
->
AuthClass
(
1
);
foreach
(
$data
[
'class'
]
as
$v
){
$data
[
'class'
]
=
$this
->
classList
(
2
);
//设置选中
foreach
(
$data
[
'class'
]
as
$k
=>
$v
){
if
(
in_array
(
$v
[
'id'
],
$data
[
'rules'
])){
$v
[
'is'
]
=
'1'
;
$data
[
'class'
][
$k
][
'is'
]
=
'1'
;
}
else
{
$
v
[
'is'
]
=
'0'
;
$
data
[
'class'
][
$k
]
[
'is'
]
=
'0'
;
}
...
...
@@ -189,7 +197,23 @@ class Auth extends Basic
}
return
$this
->
response
(
200
,
'可以查看'
,
$data
);
}
//编辑角色权限
public
function
updateAccess
(){
$table
=
New
AuthGroup
;
$data
=
input
(
'post.'
);
// prt($data);
$data
[
'rules'
]
=
trim
(
$data
[
'rules'
],
','
);
//提交数据
if
(
$table
->
editData
(
$data
,
$data
[
'id'
]))
{
return
$this
->
response
(
200
,
'成功'
);
}
else
{
return
$this
->
response
(
100
,
'失败'
);
}
}
/**
* 设置角色的状态
...
...
application/index/view/auth/access.html
View file @
dc3e66dc
...
...
@@ -5,9 +5,8 @@
<div
class=
"col-lg-10 col-lg-offset-0"
>
<div
class=
"builder-tabs builder-form-tabs"
>
<ul
class=
"nav nav-tabs"
>
<li
class=
""
><a
href=
"/admin.php/index/roleedit/1.html"
>
角色信息
</a></li>
<li
class=
"active"
><a
href=
"/admin.php/index/access/1.html"
>
权限分配
</a></li>
<li
class=
""
><a
href=
"/admin.php/index/accessUser/1.html"
>
成员授权
</a></li>
<li
class=
""
><a
id=
"href1"
href=
""
>
角色信息
</a></li>
<li
class=
"active"
><a
id=
"href2"
href=
""
>
权限分配
</a></li>
</ul>
<div
class=
"form-group"
></div>
</div>
...
...
@@ -25,7 +24,9 @@
</div>
<div
class=
"form-group"
>
<div
class=
"col-md-offset-2 tc"
>
<div
class=
"col-md-3"
><button
class=
"btn btn-block btn-primary submit ajax-post"
type=
"submit"
target-form=
"form-builder"
>
确认
</button></div>
<div
class=
"col-md-3"
>
<a
class=
"btn btn-block btn-primary submit ajax-post"
id=
"submit"
>
确认
</a>
</div>
<div
class=
"col-md-3"
><button
class=
"btn bg-aqua btn-block return"
onclick=
"javascript:history.back(-1);return false;"
><i
class=
"fa fa-mail-reply"
></i>
返回
</button></div>
</div>
</div>
...
...
application/model/AuthRule.php
View file @
dc3e66dc
...
...
@@ -18,15 +18,45 @@ class AuthRule extends BaseModel
// 'birthday' => 'timestamp',
// ];
// 定义时间戳字段名
protected
$createTime
=
''
;
//protected $updateTime = '';
/**
*返回功能权限列表
*
* 将格式数组转换为树
*
* @param array $list
* @param integer $level 进行递归时传递用的参数
*/
private
$formatTree
;
//用于树型数组完成递归格式的全局变量
private
function
_toFormatTree
(
$list
,
$level
=
0
,
$title
=
'title'
)
{
foreach
(
$list
as
$key
=>
$val
){
$tmp_str
=
str_repeat
(
" "
,
$level
*
2
);
$tmp_str
.=
"└"
;
$val
[
'level'
]
=
$level
;
$val
[
'title_show'
]
=
$level
==
0
?
$val
[
$title
]
.
" "
:
$tmp_str
.
$val
[
$title
]
.
" "
;
// $val['title_show'] = $val['id'].'|'.$level.'级|'.$val['title_show'];
if
(
!
array_key_exists
(
'_child'
,
$val
)){
array_push
(
$this
->
formatTree
,
$val
);
}
else
{
$tmp_ary
=
$val
[
'_child'
];
unset
(
$val
[
'_child'
]);
array_push
(
$this
->
formatTree
,
$val
);
$this
->
_toFormatTree
(
$tmp_ary
,
$level
+
1
,
$title
);
//进行下一层递归
}
}
return
;
}
public
function
toFormatTree
(
$list
,
$title
=
'title'
,
$pk
=
'id'
,
$pid
=
'pid'
,
$root
=
0
){
$list
=
list_to_tree
(
$list
,
$pk
,
$pid
,
'_child'
,
$root
);
$this
->
formatTree
=
array
();
$this
->
_toFormatTree
(
$list
,
0
,
$title
);
return
$this
->
formatTree
;
}
/**
* 记录总数
*
...
...
application/route.php
View file @
dc3e66dc
...
...
@@ -76,18 +76,26 @@ 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'
]],
//角色列表
'roleedit'
=>
[
'index/auth/roleEdit'
,
[
'method'
=>
'get'
]],
//--编辑角色页面
'access'
=>
[
'index/auth/access'
,
[
'method'
=>
'get'
]],
//--权限分配角色
'addAuth'
=>
[
'index/auth/addAuth'
,
[
'method'
=>
'post'
]],
//--添加角色
'accessLook'
=>
[
'index/auth/accessLook'
,
[
'method'
=>
'post'
]],
//--查看编辑角色权限
'setStatus'
=>
[
'index/auth/setStatus'
,
[
'method'
=>
'post'
]],
//--设置角色的状态
//权限管理
'classList'
=>
[
'index/auth/classList'
,[
'method'
=>
'get'
]],
//分类列表
'getAuth'
=>
[
'index/auth/getAuth'
,
[
'method'
=>
'get'
]],
//角色列表
'roleedit'
=>
[
'index/auth/roleEdit'
,
[
'method'
=>
'get'
]],
//--编辑角色页面
'access'
=>
[
'index/auth/access'
,
[
'method'
=>
'get'
]],
//--权限分配角色页面
'updateAccess'
=>
[
'index/auth/updateAccess'
,
[
'method'
=>
'post'
]],
//--编辑角色权限【接口】
'addAuth'
=>
[
'index/auth/addAuth'
,
[
'method'
=>
'post'
]],
//--添加角色【接口】
'accessLook'
=>
[
'index/auth/accessLook'
,
[
'method'
=>
'post'
]],
//--查看编辑角色权限【接口】
'setStatus'
=>
[
'index/auth/setStatus'
,
[
'method'
=>
'post'
]],
//--设置角色的状态【接口】
'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'
]],
//商圈列表
'editBusinessDistrict'
=>
[
'index/BusinessDistrict/edit'
,
[
'method'
=>
'get | post'
]],
//编辑商圈
'delBusinessDistrict'
=>
[
'index/BusinessDistrict/del'
,
[
'method'
=>
'post'
]],
//删除商圈列表
...
...
public/resource/js/access.js
View file @
dc3e66dc
...
...
@@ -10,6 +10,30 @@ define (['doT', 'text!temp/access_template_tpl.html', 'css!style/home.css','pagi
},
event
:
function
()
{
var
id
=
getUrlParam
(
'id'
);
$
(
"#submit"
).
click
(
function
()
{
var
par
=
{}
var
v
=
''
;
$
(
"input[name=rules]:checked"
).
each
(
function
(
i
)
{
v
+=
$
(
this
).
val
()
+
','
;
})
console
.
log
(
v
);
$
.
ajax
({
url
:
'/index/updateAccess'
,
data
:{
'rules'
:
v
,
'id'
:
id
},
type
:
'post'
,
async
:
true
,
dataType
:
'json'
,
success
:
function
(
data
)
{
alert
(
data
.
msg
);
console
.
log
(
data
);
}
});
})
},
getList
:
function
(){
//ajax
...
...
@@ -23,6 +47,8 @@ define (['doT', 'text!temp/access_template_tpl.html', 'css!style/home.css','pagi
var
temp
=
document
.
getElementById
(
'access_tpl'
).
innerHTML
;
var
doTempl
=
doT
.
template
(
temp
);
$
(
"#access_box"
).
html
(
doTempl
(
data
.
data
.
class
));
$
(
"#href2"
).
attr
(
'href'
,
'/index/access?id='
+
id
);
$
(
"#href1"
).
attr
(
'href'
,
'/index/roleedit?id='
+
id
);
}
})
...
...
public/resource/js/auth_rule_box.js
View file @
dc3e66dc
...
...
@@ -35,14 +35,14 @@ define (['doT', 'text!temp/auth_rule_box_template_tpl.html', 'css!style/home.css
},
getList
:
function
(){
$
.
ajax
({
url
:
'/index/
AuthClass.html
'
,
url
:
'/index/
classList/type/1
'
,
type
:
'GET'
,
async
:
true
,
dataType
:
'json'
,
success
:
function
(
data
)
{
var
temp
=
document
.
getElementById
(
'auth_class_tpl'
).
innerHTML
;
var
doTempl
=
doT
.
template
(
temp
);
$
(
"#pid"
).
html
(
doTempl
(
data
.
data
.
list
));
//赋值
$
(
"#pid"
).
html
(
doTempl
(
data
.
data
));
//赋值
}
});
var
id
=
getUrlParam
(
'id'
);
...
...
public/resource/template/access_template_tpl.html
View file @
dc3e66dc
...
...
@@ -7,10 +7,10 @@
[
%
}
%
]
[
%
if
(
it
[
item
][
'is'
]
!=
0
){
%
]
<
input
type
=
"checkbox"
name
=
"rules
[]"
checked
=
"checked"
>
<
input
type
=
"checkbox"
name
=
"rules
"
value
=
"[%= it[item]['id'] %]"
checked
=
"checked"
>
[
%=
it
[
item
][
"title"
]
%
]
<
br
>
[
%
}
else
{
%
]
<
input
type
=
"checkbox"
name
=
"rules
[]"
>
<
input
type
=
"checkbox"
name
=
"rules
"
value
=
"[%= it[item]['id'] %]"
>
[
%=
it
[
item
][
"title"
]
%
]
<
br
>
[
%
}
%
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment