Skip to content

Commit

Permalink
修复 前端 v-action 失效
Browse files Browse the repository at this point in the history
  • Loading branch information
edenleung committed Feb 4, 2020
1 parent 793d314 commit c990b69
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions app/service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@
use app\BaseService;
use app\event\UserLogin;
use app\model\Dept;
use app\model\Permission;
use app\model\Role;
use app\model\User;
use think\facade\Db;
use app\service\PermissionService;

class UserService extends BaseService
{
/**
* @var User
* @param User $user
*/
public $model;

public $permission;

public function __construct(User $user, PermissionService $permission)
public function __construct(User $user)
{
$this->model = $user;
$this->permission = $permission;
}

/**
Expand Down Expand Up @@ -76,15 +75,18 @@ public function makeToken(User $user)
return app('jwt')->token(['uid' => $user->id]);
}

/**
* 获取用户信息与菜单列表.
*
* @return User
*/
/**
* 获取用户信息与菜单列表.
*
* @param User $user
* @return User
*/
public function info(User $user)
{
$permission = new PermissionService(new Permission());

// 获取所有菜单
$menus = $this->permission->getMenu();
$menus = $permission->getMenu();

// 过滤当前用户有权限的菜单及操作按钮
$permissions = $this->filterPermissionMenu($menus, $user);
Expand All @@ -93,8 +95,8 @@ public function info(User $user)

$user->role = ['permissions' => $permissions];

$routes = $this->permission->getTree();
$user->menus = $this->formatRoute($routes, $user);
$routes = $permission->getTree();
$user->menus = $this->formatRoute($routes);

return $user;
}
Expand Down Expand Up @@ -379,21 +381,23 @@ protected function filterPermissionMenu($data, $user)
if ($menu['type'] == 'menu' && $user->can($menu['name'])) {
$permission = [];
$permission['permissionId'] = $menu['name'];
$permission['actionList'] = null;
$permission['actionList'] = [];
$permission['dataAccess'] = null;
$actionEntity = [];
if (! empty($menu['children'])) {
foreach ($menu['children'] as $action) {
if ($user->can($action['name'])) {
$permission['actions'][] = ['action' => $action['name'], 'describe' => $action['title']];
$actionEntity[] = ['action' => $action['name'], 'describe' => $action['title'], 'defaultCheck' => false];
$permission['actionList'][] = $action['name'];
}
}

$permission['actionEntitySet'] = $actionEntity;
}

$permission['actionEntitySet'] = $actionEntity;
$permissions[] = $permission;
}

if (! empty($menu['children'])) {
$permissions = array_merge($permissions, $this->filterPermissionMenu($menu['children'], $user));
}
Expand Down

0 comments on commit c990b69

Please sign in to comment.