Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

参照Demo里的网站设置新增Action动作类,会导致指定翻译文件名称功能失效 #2095

Closed
444136347 opened this issue Dec 13, 2023 · 1 comment
Labels
wontfix This will not be worked on

Comments

@444136347
Copy link

  • Laravel Version: 8.83.27
  • PHP Version: 7.4
  • Dcat Admin Version: 2.2.3

Description:

参照Demo里的网站设置新增Action动作类,会导致指定翻译文件名称功能失效

image

注释掉bootstrap.php的改行代码:$navbar->$method(App\Admin\Actions\AdminSetting::make()->render());
则指定翻译文件名称功能正常

image
image

一、bootstrap.php

<?php
use Dcat\Admin\Layout\Navbar;

config(['admin' => user_admin_config()]);
Admin::navbar(function (Navbar $navbar) {
    $method = config('admin.layout.horizontal_menu') ? 'left' : 'right';

    )
    // ajax请求不执行
    if (!Dcat\Admin\Support\Helper::isAjaxRequest()) {
        $navbar->$method(App\Admin\Actions\AdminSetting::make()->render());
    }
});

二、Action:

<? php

namespace App\Admin\Actions;

use App\Admin\Forms\AdminSetting as AdminSettingForm;
use Dcat\Admin\Actions\Action;
use Dcat\Admin\Widgets\Modal;

class AdminSetting extends Action
{
    protected $title = '<i class="feather icon-edit" style="font-size: 1.5rem"></i> 网站设置';

    public function render()
    {
        $model = Modal::make()
            ->id('admin-setting-config') // 导航栏显示弹窗,必须固定ID,随机ID会在刷新后失败
            ->title($this->title())
            ->lg()
            ->body(AdminSettingForm::make())
            ->button(
                <<<HTML
<ul class="nav navbar-nav">
     <li class="nav-item"> &nbsp;{$this->title()} &nbsp;</li>
</ul> 
HTML
            );
        return $model->render();
    }
}

三、Forms:

<?php

namespace App\Admin\Forms;

use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Arr;

class AdminSetting extends Form implements LazyRenderable
{
    use LazyWidget;

    /**
     * 主题颜色.
     *
     * @var array
     */
    protected array $colors = [
        'default'    => '深蓝',
        'blue'       => '蓝',
        'green'      => '绿',
    ];

    /**
     * 处理表单请求.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        $input['layout']['horizontal_menu'] = in_array('horizontal_menu', $input['layout']['body_class'], true);

        foreach (Arr::dot($input) as $k => $v) {
            $this->update($k, $v);
        }

        return $this->response()->success('设置成功');
    }

    /**
     * 构建表单.
     */
    public function form()
    {
        $this->text('name')->required()->help('网站名称');
        $this->text('logo')->required()->help('logo设置');
        $this->text('logo-mini', 'Logo mini')->required();
        $this->radio('layout.color', '主题')
            ->required()
            ->help('主题颜色,支持自定义!')
            ->options($this->colors);

        $this->radio('layout.sidebar_style', '菜单样式')
            ->options(['light' => 'Light', 'primary' => 'Primary'])
            ->help('切换菜单栏样式');

        $this->checkbox('layout.body_class', '菜单布局')
            ->options([
                'horizontal_menu' => '水平(Horizontal)',
                'sidebar-separate' => '独立侧边栏(sidebar-separate)',
            ])
            ->help('切换菜单布局');
    }

    /**
     * 设置接口保存成功后的回调JS代码.
     *
     * 1.2秒后刷新整个页面.
     *
     * @return string|void
     */
    public function savedScript()
    {
        return <<<'JS'
    if (data.status) {
        setTimeout(function () {
          location.reload()
        }, 1200);
    }
JS;
    }

    /**
     * 返回表单数据.
     *
     * @return array
     */
    public function default()
    {
        return user_admin_config();
    }

    /**
     * 更新配置.
     *
     * @param string $key
     * @param string $value
     */
    protected function update($key, $value)
    {
        user_admin_config([$key => $value]);
    }
}


Steps To Reproduce:

一、新增Action类
二、新增Form类
三、bootstrap.php新增navbar

Copy link

stale bot commented Jun 14, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jun 14, 2024
@stale stale bot closed this as completed Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant