Skip to content

Commit

Permalink
修复插件菜单授权显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyan74 committed Nov 15, 2019
1 parent 285af53 commit da86176
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/modules/common/controllers/AddonsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function actionInstall($data = true)
}
}

Yii::$app->services->authItem->createByAddons($allAuthItem, $allMenu, $name);
Yii::$app->services->authItem->createByAddons($allAuthItem, $allMenu, $removeAppIds, $name);
// 移除
foreach ($removeAppIds as $removeAppId) {
unset($allMenu[$removeAppId]);
Expand Down
16 changes: 11 additions & 5 deletions services/common/AuthItemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AuthItemService extends Service
* @throws UnprocessableEntityHttpException
* @throws \yii\db\Exception
*/
public function createByAddons($allAuthItem, $allMenu, $name)
public function createByAddons($allAuthItem, $allMenu, $removeAppIds, $name)
{
// 卸载权限
$this->uninstallAddonsByName($name);
Expand Down Expand Up @@ -97,7 +97,13 @@ public function createByAddons($allAuthItem, $allMenu, $name)
$menu = ArrayHelper::getColumn(ArrayHelper::getRowsByItemsMerge($menu, 'child'), 'route');
}

$allAuth = ArrayHelper::merge($allAuth, $this->regroupByAddonsData($item, $menu, $name, $key));
$is_menu = 1;
// 是否菜单被移除
if (in_array($key, $removeAppIds)) {
$is_menu = 2;
}

$allAuth = ArrayHelper::merge($allAuth, $this->regroupByAddonsData($item, $menu, $is_menu, $name, $key));
}

// 创建权限
Expand Down Expand Up @@ -193,7 +199,7 @@ public function findAllByAppId($app_id = AppEnum::BACKEND, $ids = [])
* @param $app_id
* @return array
*/
protected function regroupByAddonsData($item, $menu, $name, $app_id)
protected function regroupByAddonsData($item, $menu, $is_menu, $name, $app_id)
{
foreach ($item as &$value) {
$value['app_id'] = $app_id;
Expand All @@ -202,11 +208,11 @@ protected function regroupByAddonsData($item, $menu, $name, $app_id)

// 判断是否是菜单
if (in_array($app_id, [AppEnum::BACKEND, AppEnum::MERCHANT]) && in_array($value['name'], $menu)) {
$value['is_menu'] = 1;
$value['is_menu'] = $is_menu;
}
// 组合子级
if (isset($value['child']) && !empty($value['child'])) {
$value['child'] = $this->regroupByAddonsData($value['child'], $menu, $name, $app_id);
$value['child'] = $this->regroupByAddonsData($value['child'], $menu, $is_menu, $name, $app_id);
}
}

Expand Down

0 comments on commit da86176

Please sign in to comment.