Repository navigation
fix: 修复权限/角色表单菜单树不渲染及 flushMenuCache 未定义错误 - #31
Merged
Merged
Conversation
问题 1:multipleselect 模板新增的脚本使用 `$('.{{$selector}}')`,而 `$selector`
本身已是 `#form-id .field_xxx`,拼接后变为 `$('.#form-id .field_xxx')`,jQuery 抛出
选择器语法错误,导致同一批合并执行的脚本中断,其后的 tags、tree 等字段全部未初始化
(表现为“菜单”树为空、HTTP 路径显示为原生多选框)。
- 移除该独立脚本,将“有选中值时禁用占位隐藏 input”的逻辑并入 select-script 的
Dcat.init 回调(通过 `multiple` 参数开启),按 name 查找兄弟隐藏 input,
不再使用 `?.`,并避免 `off('change.select2')` 误删 select2 内部监听。
- 同一选择器不能重复 Dcat.init,否则会被 `initialized` 标记跳过,故不能单独注册。
问题 2:Form 的 saved 回调会被 `bindTo($model)` 重新绑定到模型实例,
回调内 `$this->flushMenuCache()` 实际调用的是 Permission/Role 模型上的方法,
抛出 `Call to undefined method ...::flushMenuCache()`。
- HasMenuTreeField 改为提供 `flushMenuCacheOnSaved(Form $form)`,回调内不依赖 `$this`。
- PermissionController、RoleController 统一改用该方法注册。
Closed
- Composer >= 2.10 默认开启 policy.advisories.block,Laravel 10/11 全部版本带安全公告 被拒绝加载,PHP 8.1 下无可安装版本。仅在 CI 安装前关闭该阻断。 - 新版 PHPStan 不再报告 Zip.php 的 `$folders might not be defined`, baseline 条目变为未匹配错误。显式初始化 `$folders = []` 并移除该条目。
Owner
Author
|
CI 两处失败均为环境漂移,与本次代码改动无关,已在本 PR 中一并修复并通过全部 PHP 8.1–8.5 矩阵:
|
PrintNow
added a commit
that referenced
this pull request
Nov 13, 2026
fix: 修复权限/角色表单菜单树不渲染及 flushMenuCache 未定义错误
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #30
问题
Call to undefined method Dcat\Admin\Models\Permission::flushMenuCache(),但数据已保存。根因
两处均由近期提交引入:
问题 1(
195435ce/af0d4db2):multipleselect.blade.php新增的脚本写成$('.{{$selector}}'),而$selector本身已是带前缀的#form-id .field_xxx,渲染后变成:jQuery 抛出选择器语法错误。Dcat 会把页面内所有
<script>合并后一次执行,这段报错后其后的 tags、tree 等字段初始化全部中断,于是菜单树为空、HTTP 路径未初始化。此外off('change.select2')会误删 select2 自身绑定的内部监听。问题 2(
f676ac3c):Form::saved()的回调在HasEvents::makeListener中会被bindTo($model)重新绑定到模型实例,回调里的$this->flushMenuCache()实际调用的是 Permission / Role 模型的方法。RoleController同样受影响。修改
select-script.blade.php:新增multiple开关,在同一个Dcat.init回调中按name查找兄弟隐藏 input,有选中值时禁用,并移除?.以兼容旧浏览器。multipleselect.blade.php:删除独立脚本,改为@include('admin::form.select-script', ['multiple' => true])。同一选择器不能重复Dcat.init,否则会被initialized标记跳过,所以不能单独注册。HasMenuTreeField:flushMenuCache()改为flushMenuCacheOnSaved(Form $form),回调内不依赖$this。PermissionController/RoleController:改用flushMenuCacheOnSaved()注册。验证
php -l与 PHPStan(--memory-limit=1G)通过,仅剩与本次无关的Zip.phpignore 规则不匹配提示。$('.#form-1 .field_...'),修复后生成的脚本经node --check语法检查通过。