Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
wallet
token
Commits
38cd98f1
Commit
38cd98f1
authored
Sep 05, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upadte
parent
28313ef8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
151 additions
and
127 deletions
+151
-127
AuthController.php
backend/controllers/AuthController.php
+4
-3
MenuController.php
backend/controllers/MenuController.php
+147
-124
No files found.
backend/controllers/AuthController.php
View file @
38cd98f1
...
@@ -165,9 +165,9 @@ class AuthController extends BaseController
...
@@ -165,9 +165,9 @@ class AuthController extends BaseController
if
(
!
$role
)
{
if
(
!
$role
)
{
$this
->
error
(
'角色不存在'
);
$this
->
error
(
'角色不存在'
);
}
}
if
(
$role_update
->
name
==
'administrator'
)
{
//
if ($role_update->name == 'administrator') {
$this
->
error
(
'超级管理员权限不允许修改'
);
//
$this->error('超级管理员权限不允许修改');
}
//
}
// 获取操作者角色的所有权限
// 获取操作者角色的所有权限
$role_self
=
current
(
$auth
->
getRolesByUser
(
Yii
::
$app
->
user
->
id
));
$role_self
=
current
(
$auth
->
getRolesByUser
(
Yii
::
$app
->
user
->
id
));
$all_permissions
=
array_keys
(
$auth
->
getPermissionsByRole
(
$role_self
->
name
));
$all_permissions
=
array_keys
(
$auth
->
getPermissionsByRole
(
$role_self
->
name
));
...
@@ -179,6 +179,7 @@ class AuthController extends BaseController
...
@@ -179,6 +179,7 @@ class AuthController extends BaseController
$remove
=
array_intersect
(
array_diff
(
$all_permissions
,
$rules
),
$can_permissions
);
$remove
=
array_intersect
(
array_diff
(
$all_permissions
,
$rules
),
$can_permissions
);
//需要添加的权限
//需要添加的权限
$add
=
array_diff
(
$rules
,
$can_permissions
);
$add
=
array_diff
(
$rules
,
$can_permissions
);
if
(
is_array
(
$add
))
{
if
(
is_array
(
$add
))
{
foreach
(
$add
as
$rule
)
{
foreach
(
$add
as
$rule
)
{
/* 更新auth_item_child表 */
/* 更新auth_item_child表 */
...
...
backend/controllers/MenuController.php
View file @
38cd98f1
...
@@ -2,10 +2,11 @@
...
@@ -2,10 +2,11 @@
namespace
backend\controllers
;
namespace
backend\controllers
;
use
Yii
;
use
common\core\rbac\Rule
;
use
common\models\Menu
;
use
common\helpers\ArrayHelper
;
use
common\helpers\ArrayHelper
;
use
common\models\Menu
;
use
common\models\search\MenuSearch
;
use
common\models\search\MenuSearch
;
use
Yii
;
use
yii\web\NotFoundHttpException
;
use
yii\web\NotFoundHttpException
;
/**
/**
...
@@ -14,137 +15,159 @@ use yii\web\NotFoundHttpException;
...
@@ -14,137 +15,159 @@ use yii\web\NotFoundHttpException;
*/
*/
class
MenuController
extends
BaseController
class
MenuController
extends
BaseController
{
{
/**
/**
* ---------------------------------------
* ---------------------------------------
* 列表页
* 列表页
* ---------------------------------------
* ---------------------------------------
*/
*/
public
function
actionIndex
()
public
function
actionIndex
()
{
{
/* 添加当前位置到cookie供后续跳转调用*/
/* 添加当前位置到cookie供后续跳转调用*/
$this
->
setForward
();
$this
->
setForward
();
$menu
=
new
Menu
();
$menu
=
new
Menu
();
$searchModel
=
new
MenuSearch
();
$searchModel
=
new
MenuSearch
();
$dataProvider
=
$searchModel
->
search
(
Yii
::
$app
->
request
->
queryParams
);
$dataProvider
=
$searchModel
->
search
(
Yii
::
$app
->
request
->
queryParams
);
return
$this
->
render
(
'index'
,
[
return
$this
->
render
(
'index'
,
[
'menu'
=>
$menu
,
'menu'
=>
$menu
,
'searchModel'
=>
$searchModel
,
'searchModel'
=>
$searchModel
,
'dataProvider'
=>
$dataProvider
,
'dataProvider'
=>
$dataProvider
,
]);
]);
}
}
/**
* ---------------------------------------
* 添加
* ---------------------------------------
*/
public
function
actionAdd
()
{
$pid
=
Yii
::
$app
->
request
->
get
(
'pid'
,
0
);
$model
=
$this
->
findModel
(
0
);
/**
if
(
Yii
::
$app
->
request
->
isPost
)
{
* ---------------------------------------
/* 表单验证 */
* 添加
$data
=
Yii
::
$app
->
request
->
post
(
'Menu'
);
* ---------------------------------------
$data
[
'status'
]
=
1
;
*/
public
function
actionAdd
()
{
$pid
=
Yii
::
$app
->
request
->
get
(
'pid'
,
0
);
$model
=
$this
->
findModel
(
0
);
if
(
Yii
::
$app
->
request
->
isPost
)
{
if
(
$this
->
saveRow
(
$model
,
$data
))
{
/* 表单验证 */
//添权限
$data
=
Yii
::
$app
->
request
->
post
(
'Menu'
);
$auth
=
Yii
::
$app
->
authManager
;
$data
[
'status'
]
=
1
;
$rule
=
new
Rule
();
$rule
->
name
=
$data
[
'url'
];
$auth
->
add
(
$rule
);
$permission
=
$auth
->
createPermission
(
$data
[
'url'
]);
$permission
->
ruleName
=
$rule
->
name
;
$auth
->
add
(
$permission
);
$this
->
success
(
'操作成功'
,
$this
->
getForward
());
}
else
{
$this
->
error
(
'操作错误'
);
}
}
if
(
$this
->
saveRow
(
$model
,
$data
))
{
/* 设置默认值 */
$this
->
success
(
'操作成功'
,
$this
->
getForward
());
$model
->
loadDefaultValues
();
}
else
{
$model
->
pid
=
$pid
;
$this
->
error
(
'操作错误'
);
/* 渲染模板 */
}
return
$this
->
render
(
'edit'
,
[
}
'model'
=>
$model
,
]);
}
/* 设置默认值 */
/**
$model
->
loadDefaultValues
();
* ---------------------------------------
$model
->
pid
=
$pid
;
* 编辑
/* 渲染模板 */
* ---------------------------------------
return
$this
->
render
(
'edit'
,
[
*/
'model'
=>
$model
,
public
function
actionEdit
()
]);
{
}
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
0
);
$model
=
$this
->
findModel
(
$id
);
/**
if
(
Yii
::
$app
->
request
->
isPost
)
{
* ---------------------------------------
/* 表单验证 */
* 编辑
$data
=
Yii
::
$app
->
request
->
post
(
'Menu'
);
* ---------------------------------------
//删除原来的权限
*/
$auth
=
Yii
::
$app
->
authManager
;
public
function
actionEdit
()
{
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
0
);
$model
=
$this
->
findModel
(
$id
);
if
(
Yii
::
$app
->
request
->
isPost
)
{
$rule
=
$auth
->
getRule
(
$model
->
url
);
/* 表单验证 */
$permission
=
$auth
->
getPermission
(
$model
->
url
);
$data
=
Yii
::
$app
->
request
->
post
(
'Menu'
);
if
(
$this
->
saveRow
(
$model
,
$data
))
{
if
(
$this
->
saveRow
(
$model
,
$data
))
{
$auth
->
remove
(
$permission
);
$this
->
success
(
'操作成功'
,
$this
->
getForward
());
$auth
->
remove
(
$rule
);
}
else
{
//添权限
$this
->
error
(
'操作错误'
);
$rule
=
new
Rule
();
}
$rule
->
name
=
$data
[
'url'
];
}
$auth
->
add
(
$rule
);
/* 渲染模板 */
$permission
=
$auth
->
createPermission
(
$data
[
'url'
]);
return
$this
->
render
(
'edit'
,
[
$permission
->
ruleName
=
$rule
->
name
;
'model'
=>
$model
,
$auth
->
add
(
$permission
);
]);
$this
->
success
(
'操作成功'
,
$this
->
getForward
());
}
}
else
{
$this
->
error
(
'操作错误'
);
}
}
/* 渲染模板 */
return
$this
->
render
(
'edit'
,
[
'model'
=>
$model
,
]);
}
/**
/**
* ---------------------------------------
* ---------------------------------------
* 删除或批量删除
* 删除或批量删除
* ---------------------------------------
* ---------------------------------------
*/
*/
public
function
actionDelete
()
public
function
actionDelete
()
{
{
$model
=
$this
->
findModel
(
0
);
$model
=
$this
->
findModel
(
0
);
if
(
$this
->
delRow
(
$model
,
'id'
))
{
if
(
$this
->
delRow
(
$model
,
'id'
))
{
$this
->
success
(
'删除成功'
,
$this
->
getForward
());
$this
->
success
(
'删除成功'
,
$this
->
getForward
());
}
else
{
}
else
{
$this
->
error
(
'删除失败!'
);
$this
->
error
(
'删除失败!'
);
}
}
}
}
/**
/**
* Finds the Article model based on its primary key value.
* Finds the Article model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer
$id
* @param integer
$id
* @return Menu the loaded model
* @throws NotFoundHttpException if the model cannot be found
* @throws NotFoundHttpException if the model cannot be found
* @return Menu the loaded model
*/
*/
protected
function
findModel
(
$id
)
protected
function
findModel
(
$id
)
{
{
if
(
$id
==
0
)
{
if
(
$id
==
0
)
{
return
new
Menu
();
return
new
Menu
();
}
}
if
((
$model
=
Menu
::
findOne
(
$id
))
!==
null
)
{
if
((
$model
=
Menu
::
findOne
(
$id
))
!==
null
)
{
return
$model
;
return
$model
;
}
else
{
}
else
{
throw
new
NotFoundHttpException
(
'The requested page does not exist.'
);
throw
new
NotFoundHttpException
(
'The requested page does not exist.'
);
}
}
}
}
/**
/**
* ---------------------------------------
* ---------------------------------------
* 菜单树
* 菜单树
* ---------------------------------------
* ---------------------------------------
*/
*/
public
function
actionTree
()
public
function
actionTree
()
{
{
$lists
=
Menu
::
find
()
->
orderBy
(
'sort asc'
)
->
where
([
'hide'
=>
0
])
->
asArray
()
->
all
();
$lists
=
Menu
::
find
()
->
orderBy
(
'sort asc'
)
->
where
([
'hide'
=>
0
])
->
asArray
()
->
all
();
$lists
=
ArrayHelper
::
list_to_tree
(
$lists
,
'id'
,
'pid'
);
$lists
=
ArrayHelper
::
list_to_tree
(
$lists
,
'id'
,
'pid'
);
$lists
=
ArrayHelper
::
jstree
(
$lists
);
$lists
=
ArrayHelper
::
jstree
(
$lists
);
Yii
::
$app
->
response
->
format
=
'json'
;
Yii
::
$app
->
response
->
format
=
'json'
;
return
$lists
;
return
$lists
;
}
}
/**
/**
* [刷新菜单]
* [刷新菜单]
* @author: libingke
* @author: libingke
*/
*/
public
function
actionFlush
()
public
function
actionFlush
()
{
{
Menu
::
flushMenu
();
Menu
::
flushMenu
();
return
$this
->
goBack
(
Yii
::
$app
->
request
->
getReferrer
());
return
$this
->
goBack
(
Yii
::
$app
->
request
->
getReferrer
());
}
}
}
}
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