diff --git a/CHANGELOG-2.0.md b/CHANGELOG-2.0.md deleted file mode 100644 index ed05ec9b..00000000 --- a/CHANGELOG-2.0.md +++ /dev/null @@ -1,28 +0,0 @@ -# v2.0 - TBD - -## v2.0-RC - -### Added - - -## v2.0.1-beta.7 - -- [#225](https://github.com/mineadmin/MineAdmin/pull/225) Optimising ws amqp processing logic -- [#250](https://github.com/mineadmin/MineAdmin/pull/250) Optimise user filtering logic - -## v2.0.0-beta.6 - -- [#178](https://github.com/mineadmin/MineAdmin/pull/178) Code generator add preview page -- [#184](https://github.com/mineadmin/MineAdmin/pull/184) remove global http middleware -- [#205](https://github.com/mineadmin/MineAdmin/pull/205) specify swagger component version -- [#213](https://github.com/mineadmin/MineAdmin/pull/213) Optimise `common/common.php` loading logic -- [#215](https://github.com/mineadmin/MineAdmin/pull/215) Add generator migration file preview field -- [#217](https://github.com/mineadmin/MineAdmin/pull/217) Remove `redis->flushAll` to avoid misbehaviour when performing `mine:update` updates -- [#218](https://github.com/mineadmin/MineAdmin/pull/218) Fix some files generated with table prefixes when table prefix is not null. -- [#219](https://github.com/mineadmin/MineAdmin/pull/219) Add interface testing process under sql server environment, optimise existing unit test, change data structure of some migration files. - -## v2.0.0-beta.5 - -- [#134](https://github.com/mineadmin/MineAdmin/pull/134) Fix data migration filling failure due to file name not found class error. -- [#116](https://github.com/mineadmin/MineAdmin/pull/116) Optimise online user statistics interface. -- [#111](https://github.com/mineadmin/MineAdmin/pull/111) Modify handleSearch condition check function and adjust primary key to support snowflake ID and UUID diff --git a/CHANGELOG-2.0.zh_CN.md b/CHANGELOG-2.0.zh_CN.md deleted file mode 100644 index 78a86d02..00000000 --- a/CHANGELOG-2.0.zh_CN.md +++ /dev/null @@ -1,22 +0,0 @@ -# v2.0 - TBD - -## v2.0.1-beta.7 TDB - -- [#225](https://github.com/mineadmin/MineAdmin/pull/225) 优化 ws amqp 处理逻辑 -- [#250](https://github.com/mineadmin/MineAdmin/pull/250) 优化 用户管理筛选逻辑 -## v2.0.0-beta.6 - -- [#178](https://github.com/mineadmin/MineAdmin/pull/178) 代码生成器增加预览页面 -- [#184](https://github.com/mineadmin/MineAdmin/pull/184) 移除全局 http 中间件 -- [#205](https://github.com/mineadmin/MineAdmin/pull/205) 指定 swagger 组件版本 -- [#213](https://github.com/mineadmin/MineAdmin/pull/213) 优化 `common/common.php` 加载逻辑 -- [#215](https://github.com/mineadmin/MineAdmin/pull/215) 添加生成器迁移文件预览字段 -- [#217](https://github.com/mineadmin/MineAdmin/pull/217) 删除 `redis->flushAll`,避免执行 `mine:update`更新时误操作 -- [#218](https://github.com/mineadmin/MineAdmin/pull/218) 修复表前缀不为空时生成的某些文件自动带上了表前缀 -- [#219](https://github.com/mineadmin/MineAdmin/pull/219) 增加 sql server 环境下的接口测试流程、优化现有单元测试,部分迁移文件数据结构变更 - -## v2.0.0-beta.5 - -- [#134](https://github.com/mineadmin/MineAdmin/pull/134) 修复因文件名未找到类错误而导致的数据迁移填充失败 -- [#116](https://github.com/mineadmin/MineAdmin/pull/116) 优化在线用户统计界面。 -- [#111](https://github.com/mineadmin/MineAdmin/pull/111) 修改 handleSearch 条件检查函数,并调整主键支持雪花 ID 和 UUID diff --git a/app/System/Mapper/SystemMenuMapper.php b/app/System/Mapper/SystemMenuMapper.php index 33707c9e..abd20352 100644 --- a/app/System/Mapper/SystemMenuMapper.php +++ b/app/System/Mapper/SystemMenuMapper.php @@ -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; + } + /** * 逻辑删除菜单. */ @@ -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(); + } + /** * 搜索处理器. */ @@ -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'] . '%'); } diff --git a/app/System/Service/SystemMenuService.php b/app/System/Service/SystemMenuService.php index 64fa28f2..d2161967 100644 --- a/app/System/Service/SystemMenuService.php +++ b/app/System/Service/SystemMenuService.php @@ -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); } /** @@ -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); + } } diff --git a/plugin/mine-admin/app-store/.gitignore b/plugin/mine-admin/app-store/.gitignore new file mode 100644 index 00000000..cfe16b32 --- /dev/null +++ b/plugin/mine-admin/app-store/.gitignore @@ -0,0 +1 @@ +!install.lock \ No newline at end of file diff --git a/plugin/mine-admin/app-store/install.lock b/plugin/mine-admin/app-store/install.lock new file mode 100644 index 00000000..56a6051c --- /dev/null +++ b/plugin/mine-admin/app-store/install.lock @@ -0,0 +1 @@ +1 \ No newline at end of file