Skip to content

Commit

Permalink
Release v2.0.2 (#304)
Browse files Browse the repository at this point in the history
* Add App Store .gitignore Entry and Include install.lock in Repository

* fix [BUG] 后台菜单的level字段出错 #244

* Apply cs-fix

---------

Co-authored-by: wlfpanda <[email protected]>
  • Loading branch information
zds-s and ShaBaoFa authored Jul 9, 2024
1 parent d129ec7 commit d431f1a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 51 deletions.
28 changes: 0 additions & 28 deletions CHANGELOG-2.0.md

This file was deleted.

22 changes: 0 additions & 22 deletions CHANGELOG-2.0.zh_CN.md

This file was deleted.

28 changes: 28 additions & 0 deletions app/System/Mapper/SystemMenuMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ public function update(mixed $id, array $data): bool
return parent::update($id, $data);
}

/**
* 批量更新菜单.
*/
#[DeleteCache('loginInfo:*'), Transaction]
public function batchUpdate(array $update): bool
{
foreach ($update as $item) {
$result = parent::update($item['id'], $item['data']);
if (! $result) {
return false;
}
}
return true;
}

/**
* 逻辑删除菜单.
*/
Expand Down Expand Up @@ -189,6 +204,15 @@ public function checkChildrenExists(int $id): bool
return $this->model::withTrashed()->where('parent_id', $id)->exists();
}

/**
* 获取子孙menus.
*/
public function getDescendantsMenus(int $parentId): array
{
$params = ['level' => $parentId];
return $this->handleSearch($this->model::query(), $params)->get()->toArray();
}

/**
* 搜索处理器.
*/
Expand All @@ -198,6 +222,10 @@ public function handleSearch(Builder $query, array $params): Builder
$query->where('status', $params['status']);
}

if (isset($params['level']) && filled($params['level'])) {
$query->where('level', 'like', '%' . $params['level'] . '%');
}

if (isset($params['name']) && filled($params['name'])) {
$query->where('name', 'like', '%' . $params['name'] . '%');
}
Expand Down
27 changes: 26 additions & 1 deletion app/System/Service/SystemMenuService.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,23 @@ public function genButtonMenu(SystemMenu $model): bool
*/
public function update(mixed $id, array $data): bool
{
return $this->mapper->update($id, $this->handleData($data));
$handleData = $this->handleData($data);
if (! $this->checkChildrenExists($id)) {
return $this->mapper->update($id, $handleData);
}
$update[] = [
'id' => $id,
'data' => $handleData,
];
$descendants = $this->mapper->getDescendantsMenus((int) $id);
foreach ($descendants as $descendant) {
$handleDescendantMenuLevelData = $this->handleDescendantMenuLevels($descendant['level'], $handleData['level'], $id);
$update[] = [
'id' => $descendant['id'],
'data' => ['level' => $handleDescendantMenuLevelData],
];
}
return $this->mapper->batchUpdate($update);
}

/**
Expand Down Expand Up @@ -166,4 +182,13 @@ protected function handleData(array $data): array
}
return $data;
}

protected function handleDescendantMenuLevels(string $descendantLevel, string $handleDataLevel, int $id): string
{
$descendantLevelArr = explode(',', $descendantLevel);
$handleDataLevelArr = explode(',', $handleDataLevel);
$position = array_search($id, $descendantLevelArr);
array_splice($descendantLevelArr, 0, $position, $handleDataLevelArr);
return implode(',', $descendantLevelArr);
}
}
1 change: 1 addition & 0 deletions plugin/mine-admin/app-store/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!install.lock
1 change: 1 addition & 0 deletions plugin/mine-admin/app-store/install.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1

0 comments on commit d431f1a

Please sign in to comment.