Home  >  Article  >  PHP Framework  >  The new expansion system is online! Release Dcat Admin v2.0.0-BETA version~

The new expansion system is online! Release Dcat Admin v2.0.0-BETA version~

藏色散人
藏色散人forward
2020-10-20 13:53:034048browse

The following is the tutorial column of Laravel to introduce the release of Dcat Admin v2.0.0-BETA. I hope it will be helpful to friends in need!

The new expansion system is online! Release Dcat Admin v2.0.0-BETA version~

PrefaceHi, hello classmates! After many days, Dcat Admin

finally ushered in the first version of

2.0. Here is a brief introduction to the main changes. Everyone is welcome to install and experience it. If there are any problems, they will be fixed immediately~Installation

The v2.0.1-beta version has been released

composer require dcat/laravel-admin:v2.0.1-beta -vvv

What are the changes?

1. Extension We have focused on optimizing the extension

function in this version, mainly simplifying The extension usage process allows users to install, uninstall, and upgrade extensions through the page, and supports both page compression and

composer installation methods. The App Market function will be launched when the official version is released, so stay tuned~The detailed usage documentation will be gradually updated this week~

2. Enhance form layout capabilitiesIn 2.0

, we have

The block layout function has been refactored to support more complex layouts. Example

$form->block(8, function (Form\BlockForm $form) {
    $form->title('基本设置');
    $form->showFooter();
    $form->width(9, 2);

    $form->column(6, function (Form\BlockForm $form) {
        $form->display('id');
        $form->text('name');
        $form->email('email');
        $form->image('avatar');
        $form->password('password');
    });

    $form->column(6, function (Form\BlockForm $form) {
        $form->text('username');
        $form->email('mobile');
        $form->textarea('description');
    });
});
$form->block(4, function (Form\BlockForm $form) {
    $form->title('分块2');

    $form->text('nickname');
    $form->number('age');
    $form->radio('status')->options(['1' => '默认', 2 => '冻结'])->default(1);

    $form->next(function (Form\BlockForm $form) {
        $form->title('分块3');

        $form->date('birthday');
        $form->date('created_at');
    });
});

##2.0 is also supported in

tab

Nested layouts use column and rows layouts, such as This function supports both data forms

and
Tool form

$form->tab('标题', function (Form $form) {
    $form->column(6, function (Form $form) {
        ...
    });

    $form->column(6, function (Form $form) {
        ...
    });});
3. Refactor the form response method

in version1.0 The response methods of the form are only

success

, error and redirect, which cannot meet some more complex scenarios. In 2.0 we let the form The response methods of action are unified to support more functions and reduce the learning cost of developers. In the data form<pre class="brush:php;toolbar:false">$form-&gt;saving(function (Form $form) {     return $form         -&gt;response()         -&gt;success('保存成功')         -&gt;script('console.log(&quot;执行JS代码&quot;)')         -&gt;redirect('auth/users');});</pre>In the tool form

public function handle(array $input){
    ...

    return $this
        ->response()
        ->alert()
        ->success('成功')
        ->detail('详细内容');}

4. Separation of JS code and PHP code

This function is a follow-up to the new features of laravel-admin2.0 version. In 2.0, it is recommended to put the

JS

code into the view file, example The code in <pre class="brush:php;toolbar:false">&lt;style&gt; .popover{z-index:29891015} &lt;/style&gt; &lt;div class=&quot;{{$viewClass[&amp;#39;form-group&amp;#39;]}}&quot;&gt; &lt;div for=&quot;{{ $id }}&quot; class=&quot;{{$viewClass[&amp;#39;label&amp;#39;]}} control-label&quot;&gt; &lt;span&gt;{!! $label !!}&lt;/span&gt; &lt;/div&gt; &lt;div class=&quot;{{$viewClass[&amp;#39;field&amp;#39;]}}&quot;&gt; @include(&amp;#39;admin::form.error&amp;#39;) &lt;div class=&quot;input-group&quot;&gt; &lt;span class=&quot;input-group-prepend&quot;&gt;&lt;span class=&quot;input-group-text bg-white&quot; style=&quot;padding: 4px&quot;&gt;&lt;i style=&quot;width: 24px;height: 100%;background: {!! $value !!}&quot;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt; &lt;input {!! $attributes !!} /&gt; @if ($append) &lt;span class=&quot;input-group-append&quot;&gt;{!! $append !!}&lt;/span&gt; @endif &lt;/div&gt; @include(&amp;#39;admin::form.help-block&amp;#39;) &lt;/div&gt; &lt;/div&gt; &lt;script require=&quot;@color&quot;&gt; $(&amp;#39;{{ $selector }}&amp;#39;).colorpicker({!! json_encode($options) !!}).on(&amp;#39;colorpickerChange&amp;#39;, function(event) { $(this).parents(&amp;#39;.input-group&amp;#39;).find(&amp;#39;.input-group-prepend i&amp;#39;).css(&amp;#39;background-color&amp;#39;, event.color.toString()); }); &lt;/script&gt;</pre>3f1c4e4b6b16bbbd69b2ee476dc4f83a and

c9ccee2e6ea535a969eb3f532ad9fe89

tags will be extracted and compiled, and Admin::script() will be implemented. The same processing effect as Admin::style(). It should be noted that 3f1c4e4b6b16bbbd69b2ee476dc4f83a and c9ccee2e6ea535a969eb3f532ad9fe89 must be root tags and cannot be Wrap it in other tags, otherwise the extraction will fail!

5. Refactor the table column selector function

There are some column selectors in 1.x Due to compatibility issues, some special types of tables are not compatible, so in

2.0

we reconstructed the column selector function and abandoned the old API (responsive). The new column selector function is perfectly compatible with the fixed column and

combined header

functions, and supports the remember user operation function, which will automatically remember the user's selection , the effect is as follows

6. Reconstruct the table event

in1.0 The design of table events is relatively random and non-standard, so we reconstructed the table events in

2.0

and added some events. The usage of the new table events is as follows<pre class="brush:php;toolbar:false">use Dcat\Admin\Grid; Grid::make(new Model(), function (Grid $grid) { $grid-&gt;listen(Grid\Events\Fetching::class, function (Grid $grid) { ... }); });</pre>If You want to listen to allGrid

use Dcat\Admin\Grid;
use Illuminate\Support\Facades\Event;

Event::listen(Grid\Events\Fetching::class, function (Grid $grid) {
    ...
});

// 或者

Grid::resolving(function (Grid $grid) {
    $grid->listen(Grid\Events\Fetching::class, function (Grid $grid) {
        ...
    });
});

For more usage of events, please refer to the relevant documentation

7. Table row support Use Model

2.0中如果Grid表格使用的是model渲染数据,则可以在数据行相关回调中直接使用model的对象,如

$grid->clolumn(&#39;avatar&#39;)->display(function () {
    // getAvatar是model中的自定义方法,这里可以直接调用
    return $this->getAvatar();
});

8.重构模型树行操作

2.0中我们对模型树的行操作功能进行了重构,新的行操作功能和数据表格的行操作功能用法一致

use Dcat\Admin\Tree;

$tree->actions(function (Tree\Actions $actions) {
    if ($actions->row->id > 5) {
        $actions->disableDelete(); // 禁用删除按钮
    }

    // 添加新的action
    $actions->append(...);
});

// 批量添加action
$tree->actions([
    new Action1(),
    "<div>...</div>",
    ...
]);

9.增加settings配置表

在新版本中增加了settings配置表,目前主要用于保存扩展的启用和禁用配置数据,可以通过以下方式读写配置

// 读取
admin_settings(&#39;key1&#39;, &#39;默认值&#39;);
admin_settings(&#39;arr.k1&#39;, &#39;默认值&#39;);

// 保存配置
admin_settings([
    &#39;key1&#39; => [&#39;v1&#39;],
    &#39;arr.k1&#39; => &#39;v1&#39;,
]);

10.数据仓库接口重命名

2.0中我们对数据仓库的接口命名做了简化处理,新的interface如下

interface Repository{
    /**
     * 获取主键名称.
     *
     * @return string
     */
    public function getKeyName();

    /**
     * 获取创建时间字段.
     *
     * @return string
     */
    public function getCreatedAtColumn();

    /**
     * 获取更新时间字段.
     *
     * @return string
     */
    public function getUpdatedAtColumn();

    /**
     * 是否使用软删除.
     *
     * @return bool
     */
    public function isSoftDeletes();

    /**
     * 获取Grid表格数据.
     *
     * @param Grid\Model $model
     *
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|Collection|array
     */
    public function get(Grid\Model $model);

    /**
     * 获取编辑页面数据.
     *
     * @param Form $form
     *
     * @return array|\Illuminate\Contracts\Support\Arrayable
     */
    public function edit(Form $form);

    /**
     * 获取详情页面数据.
     *
     * @param Show $show
     *
     * @return array|\Illuminate\Contracts\Support\Arrayable
     */
    public function detail(Show $show);

    /**
     * 新增记录.
     *
     * @param Form $form
     *
     * @return mixed
     */
    public function store(Form $form);

    /**
     * 查询更新前的行数据.
     *
     * @param Form $form
     *
     * @return array|\Illuminate\Contracts\Support\Arrayable
     */
    public function updating(Form $form);

    /**
     * 更新数据.
     *
     * @param Form $form
     *
     * @return bool
     */
    public function update(Form $form);

    /**
     * 删除数据.
     *
     * @param Form  $form
     * @param array $deletingData
     *
     * @return mixed
     */
    public function delete(Form $form, array $deletingData);

    /**
     * 查询删除前的行数据.
     *
     * @param Form $form
     *
     * @return array|\Illuminate\Contracts\Support\Arrayable
     */
    public function deleting(Form $form);}

更多变动

  • 控制器命名空间更新为Dcat\Admin\Http\Controllers
  • 废弃操作日志
  • 废弃分步表单(已开发成扩展 dcat-admin/form-step)
  • 语言包目录重命名(zh-CN更新为zh_CN
  • google字体本地化
  • 异常处理功能重构
  • 表单事件重构
  • UI优化
  • 静态资源目录由vendors更改为vendor

我们在2.0中做了大量的细节改进,对许多功能接口都做了调整和代码优化,限于篇幅这里不再一一列出,详细说明会放在1.x升级指导文档中(文档即将在这几天内发布)。

关于应用市场和新主题

应用市场会在正式版发布时同步上线;
新主题会开发成插件,也会在正式版发布时同步上线~                                        

The above is the detailed content of The new expansion system is online! Release Dcat Admin v2.0.0-BETA version~. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete