Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
restore-keys: |
${{ runner.os }}-php-${{ matrix.php }}-composer-

# Laravel 10/11 已停止安全维护,Composer >= 2.10 默认拒绝加载带安全公告的版本,
# 会导致 PHP 8.1 无可安装版本;仅在 CI 中关闭该阻断以保留低版本矩阵。
- run: composer config policy.advisories.block false

- run: composer install --no-interaction --prefer-dist

- run: vendor/bin/phpstan analyse --no-progress --memory-limit=512M --error-format=github
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,6 @@ parameters:
count: 1
path: src/Support/Setting.php

-
message: '#^Variable \$folders might not be defined\.$#'
identifier: variable.undefined
count: 1
path: src/Support/Zip.php

-
message: '#^Result of method Dcat\\Admin\\Tree\:\:disableCreateButton\(\) \(void\) is used\.$#'
identifier: method.void
Expand Down
8 changes: 1 addition & 7 deletions resources/views/form/multipleselect.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,4 @@
</div>
</div>

@include('admin::form.select-script')

<script>
$('.{{$selector}}').off('change.select2').on('change.select2', function () {
$(this).closest('.field').find('input[type="hidden"][name="{{$name}}[]"]').prop('disabled', $(this).val()?.length > 0);
});
</script>
@include('admin::form.select-script', ['multiple' => true])
17 changes: 17 additions & 0 deletions resources/views/form/select-script.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
<script require="@select2?lang={{ config('app.locale') === 'en' ? '' : str_replace('_', '-', config('app.locale')) }}" init="{!! $selector !!}">
var configs = {!! admin_javascript_json($configs) !!};

@if(! empty($multiple))
// 多选:有选中值时禁用占位的隐藏 input,避免额外提交空值。
// 不能再单独用 Dcat.init 注册同一选择器,否则会被 initialized 标记跳过。
$this.each(function () {
var $select = $(this),
$hidden = $select.siblings('input[type="hidden"][name="' + $select.attr('name') + '"]'),
toggle = function () {
var val = $select.val();

$hidden.prop('disabled', !!(val && val.length > 0));
};

$select.on('change', toggle);
toggle();
});
@endif

@yield('admin.select-ajax')

@if(isset($remoteOptions))
Expand Down
12 changes: 9 additions & 3 deletions src/Http/Controllers/HasMenuTreeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ protected function addMenuTreeField(Form $form)

/**
* Flush menu cache after form saved.
*
* 注意:Form 的事件回调会被重新绑定到模型实例(见 HasEvents::makeListener),
* 回调内的 $this 不再是控制器,因此这里不能依赖 $this,统一通过本方法注册。
*/
protected function flushMenuCache()
protected function flushMenuCacheOnSaved(Form $form)
{
$model = config('admin.database.menu_model');
(new $model())->flushCache();
$form->saved(function () {
$model = config('admin.database.menu_model');

(new $model())->flushCache();
});
}
}
8 changes: 5 additions & 3 deletions src/Http/Controllers/PermissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function form()
$with[] = 'menus';
}

return Form::make(Permission::with($with), function (Form $form) use ($bindMenu) {
$form = Form::make(Permission::with($with), function (Form $form) use ($bindMenu) {
$permissionTable = config('admin.database.permissions_table');
$connection = config('admin.database.connection');
$permissionModel = config('admin.database.permissions_model');
Expand Down Expand Up @@ -125,9 +125,11 @@ public function form()

$form->disableViewButton();
$form->disableViewCheck();
})->saved(function () {
$this->flushMenuCache();
});

$this->flushMenuCacheOnSaved($form);

return $form;
}

public function getRoutes()
Expand Down
8 changes: 5 additions & 3 deletions src/Http/Controllers/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function form()
$with[] = 'menus';
}

return Form::make(Role::with($with), function (Form $form) use ($bindMenu) {
$form = Form::make(Role::with($with), function (Form $form) use ($bindMenu) {
$roleTable = config('admin.database.roles_table');
$connection = config('admin.database.connection');

Expand Down Expand Up @@ -125,9 +125,11 @@ public function form()
if ($id == $roleModel::ADMINISTRATOR_ID) {
$form->disableDeleteButton();
}
})->saved(function () {
$this->flushMenuCache();
});

$this->flushMenuCacheOnSaved($form);

return $form;
}

public function destroy($id)
Expand Down
2 changes: 2 additions & 0 deletions src/Support/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public function add($source, $options = [])
$basedir = $options['basedir'];
$baseglob = $options['baseglob'];

$folders = [];

if (is_file($source)) {
$files = [$source];
$recursive = false;
Expand Down
Loading