z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.15k stars 2.82k forks source link

复制功能并不能如期执行 #4102

Closed ghost closed 4 years ago

ghost commented 4 years ago

Description:

单行复制的按钮出来了,但点击无效果

Steps To Reproduce:

class Copy extends RowAction
{
    public $name = '复制';

    public function handle(Model $model)
    {
        // 这里调用模型的`replicate`方法复制数据,再调用`save`方法保存
        $model->replicate()->save();

        // 返回一个内容为`复制成功`的成功信息,并且刷新页面
        return $this->response()->success(__('复制成功'))->refresh();
    }

}
ghost commented 4 years ago
$grid->actions(function ($actions) {
            $actions->add(new Copy());
            // 去掉删除
            $actions->disableDelete();
        });
z-song commented 4 years ago

检查一下控制台有什么错误,看看发送请求的参数

ghost commented 4 years ago

image 控制台没有输出

ghost commented 4 years ago

一些使用的扩展。

'extensions' => [
        /*
        $form->tencentMap('latitude', 'longitude', '经纬度');
        // 设置地图高度
        $form->tencentMap('latitude', 'longitude', '经纬度')->height(500);
        // 设置地图缩放
        $form->tencentMap('latitude', 'longitude', '经纬度')->zoom(13);
        // 设置默认值
        $form->tencentMap('latitude', 'longitude', '经纬度')->default(['lat' => 90, 'lng' => 90]);
         */
        'tencent-map' => [
            'enable' => true,
            'api_key' => env('TENCENT_MAP_API_KEY')
        ],
        'env-manager' => [
            // If the value is set to false, this extension will be disabled
            'enable' => true
        ],
        'admin-config' => [
            'title'=>'AdminConfig',
            'description'=>'Manage your profiles as profiles',
            'action'=>' ',
        ],
        'multi-language' => [
            'enable' => true,
            // the key should be same as var locale in config/app.php
            // the value is used to show
            'languages' => [
                'en' => 'English',
                'zh-CN' => '简体中文',
            ],
            // default locale
            'default' => 'zh-CN',
        ],
        'china-distpicker' => [

            // 如果要关掉这个扩展,设置为false
            'enable' => true,
        ],
        'json-editor' => [
            // set to false if you want to disable this extension
            'enable' => true,
            'config' =>
                [
                    'mode' => 'tree',
                    'modes' => ['code', 'form', 'text', 'tree', 'view'], // allowed modes
                ],
        ],
        'cropper' => [

            // 如果要关掉这个扩展,设置为false
            'enable' => true,
        ],
        'echarts' => [
            // Set to `false` if you want to disable this extension
            'enable' => true,
        ],
        'material-ui' => [
            // 如果要关掉这个扩展,设置为false
            'enable' => true
        ],
        'media-manager' => [ 
            // Select a local disk that you configured in `config/filesystem.php`
            'disk' => 'local'
        ],
        //https://github.com/laravel-admin-extensions/wangEditor
        'wang-editor' => [ 
            // 如果要关掉这个扩展,设置为false
            'enable' => true, 
            // 编辑器的配置
            'config' => [
                'uploadImgServer' => '/upload'
            ]
        ],
        'iframe-tabs' => [
            'enable' => true,
            'home_action' => App\Admin\Controllers\HomeController::class . '@index',
            'home_title' => 'Home',
            'home_icon' => 'fa-home',
            'use_icon' => true,
            'tabs_css' =>'vendor/laravel-admin-ext/iframe-tabs/dashboard.css',
            'layer_path' => 'vendor/laravel-admin-ext/iframe-tabs/layer/layer.js',

            'pass_urls' => ['/auth/logout', '/auth/lock'],
            'force_login_in_top' => true,
            'tabs_left'  => 42,
            'bind_urls' => 'popup', //[ popup / new_tab / none] 
            'bind_selecter' => '.box-body table.table tbody a.grid-row-view,.box-body table.table tbody a.grid-row-edit,.box-header .pull-right .btn-success',

        ]
    ],
ghost commented 4 years ago
<?php

namespace App\Admin\Controllers;

use App\Models\Goods;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

use App\Admin\Actions\Goods\Up;
use App\Admin\Actions\Goods\Down;
use App\Admin\Actions\Goods\Wms;
use App\Admin\Actions\Goods\Copy;

class GoodsController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'App\Models\Goods';

    /**
     * 商品列表
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Goods);

        $grid->column('id', __('Id'));
        $grid->column('title', __('Title'))->editable();
        $grid->column('sub_title', __('Sub title')); 
        $grid->column('shop_id', __('Shop')); 
        $grid->column('price', __('Price'));  
        $grid->column('created_at', __('Created at')); 
        $list_status = $this->getStatus();
        //状态字段显示
        $grid->column('status', __('Status'))->display(function ($status) use($list_status) {
            switch ($status) {
                case 1:
                    $color = "blue";
                    break;
                case 2:
                    $color = "red";
                    break;
                case 3:
                    $color = "green";
                    break;
                default:
                    # code...
                    break;
            }
            return "<span style='color:".$color."'>".$list_status[$status]."</span>";

        });

        $grid->actions(function ($actions) {
            $actions->add(new Copy());
            // 去掉删除
            $actions->disableDelete();
        });

        // 去掉批量删除操作
        $grid->tools(function ($tools) {
            $tools->batch(function ($batch) {
                $batch->disableDelete();
            });
        });
        //批量上下架,加入仓库
        $grid->batchActions(function ($batch) {
            $batch->add(new Up());
            $batch->add(new Down());
            $batch->add(new Wms());
        });
        //$grid->disableBatchActions();
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Goods::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('title', __('Title'));
        $show->field('sub_title', __('Sub title'));
        $show->field('body', __('Body'));
        $show->field('shop_id', __('Shop'));
        $show->field('order', __('Order'));
        $show->field('price', __('Price'));
        $show->field('cost_price', __('Cost price'));
        $show->field('ori_price', __('Ori price'));
        $show->field('market_price', __('Market price'));
        $show->field('active_id', __('Active id'));
        $show->field('pars', __('Pars'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    protected function getStatus(){
        return [
            1 => __('上架'), 
            2 =>  __('下架'), 
            3 =>  __('放入仓库')
        ];
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Goods);

        $form->text('title', __('Title'))->rules('required');
        $form->text('sub_title', __('Sub title'))->rules('required');
        $form->editor('body', __('Body'))->rules('required'); 

        $form->number('price', __('Price'))->rules('required');
        $form->number('cost_price', __('Cost price'))->rules('required');
        $form->number('ori_price', __('Ori price'));
        $form->number('market_price', __('Market price'))->rules('required'); 
        $form->text('pars', __('Pars'));

        $form->select('status', __('Status'))->options($this->getStatus())->rules('required');

        $form->number('order', __('Order'));

        // 在表单提交前调用
        $form->saving(function (Form $form) {
           $form->order  = 0; 
           $form->model()->shop_id  = 0; 
        });

        return $form;
    }
}
ghost commented 4 years ago
<?php

namespace App\Admin\Actions\Goods;

use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;

class Copy extends RowAction
{
    public $name = '复制';

    public function handle(Model $model)
    {
        // 这里调用模型的`replicate`方法复制数据,再调用`save`方法保存
        $model->replicate()->save();

        // 返回一个内容为`复制成功`的成功信息,并且刷新页面
        return $this->response()->success(__('复制成功'))->refresh();
    }

}
ghost commented 4 years ago

完整的代码。

jsonlove-cc commented 4 years ago

$grid->actions(function ($actions) { $actions->add(new Copy);//这里你把括号去掉像我这样 // 去掉删除 $actions->disableDelete(); });

ghost commented 4 years ago

试了没反应。一样的。

jsonlove-cc commented 4 years ago

你看下报什么错啊,或者在你的handle里面打印以下看一下有没有进入哪个方法里面

ghost commented 4 years ago

我重装了,现在好了。 就是没错,估计可能是哪个插件导致的。安装的都是官方扩展里面的。

ghost commented 4 years ago

发现是主题的原因。

https://github.com/laravel-admin-extensions/material-ui/issues/12

DreamSeekerKaiser commented 4 years ago

我没有更改主题 也出现了跟你一样的情况 操作后 能弹出交互页面就是确认后没有数据交互

DreamSeekerKaiser commented 4 years ago

image 这个函数似乎不触发导致前台没有发送网络请求到handle函数