jqhph / dcat-admin

🔥 基于 Laravel 的后台系统构建工具 (Laravel Admin),使用很少的代码快速构建一个功能完善的高颜值后台系统,内置丰富的后台常用组件,开箱即用,让开发者告别冗杂的HTML代码
http://www.dcatadmin.com
MIT License
3.89k stars 711 forks source link

FormTab使用image提交获取字段值为null #1086

Closed taobali32 closed 3 years ago

taobali32 commented 3 years ago

Description:

v2.0.18-beta

Steps To Reproduce:

89行image字段(form1.help_wechat_qrcode),29行打印提交的数据(dd($data);)

<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Config;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Widgets\Form;
use Dcat\Admin\Widgets\Tab;
use Dcat\Admin\Http\JsonResponse;

class SettingController extends Controller
{
    protected $f = [
      'form1'   =>  'base_config'
    ];

    public function index(Content $content)
    {
        if (request()->getMethod() == 'POST') {
            $post = request()->all();

//            dd($post);
            if (isset($post['form1'])){
                $data = $post['form1'];

                dd($data);
                $f = Config::query()->where('type',$this->f['form1'])->first();
                if ($f){
                    Config::query()->where('type',$this->f['form1'])->update(['config' => $data]);
                }else{
                    Config::create([
                       'type'   =>  $this->f['form1'],
                       'remark' =>  '基础设置',
                       'config' =>  $data
                    ]);
                }
            }

            return JsonResponse::make()->success('操作成功');
        }

        $content->row(function (Row $row) {
            $type = request('_t', 1);

            $tab = new Tab();

            if ($type == 1) {
                $tab->add('基本设置', $this->form1());
//                $tab->addLink('Form-2', request()->fullUrlWithQuery(['_t' => 2]));
            } else {
                $tab->addLink('基本设置', request()->fullUrlWithQuery(['_t' => 1]));
//                $tab->add('Form-2', $this->form2(), true);
            }

            $row->column(12, $tab->withCard());
        });

        return $content->header('系统设置');
    }

    protected function form1()
    {
        $form = new Form();

        $form->action(request()->fullUrl());

        $config = Config::query()->where('type',$this->f['form1'])->first();
        if ($config){
            $body = $config->config;

            if (!isset($body['help_wechat_qrcode'])){
                $body['help_wechat_qrcode'] = '';
            }
        }else{
            $body = [
//                'day_price' =>  0,
//                'max_rise'  =>  0,
                'cny_price' => 0,
                'help_wechat_qrcode' => ''
            ];
        }

        $form->decimal('form1.cny_price', '人民币价格')->required()->default($body['cny_price'] ?? 0)->help('美元对人民币价格');

//        $form->image('form1.image', '客服帮助中心二维码');
        $form->image('form1.help_wechat_qrcode','客服帮助中心二维码')->default($body['help_wechat_qrcode']);

        $form->disableResetButton();

        return "<div style='padding:10px 8px'>{$form->render()}</div>";
    }

    protected function form2()
    {
        $form = new Form();

        $form->action(request()->fullUrl());

        return "<div style='padding:9px 8px'>{$form->render()}</div>";
    }
}

结果

image

jqhph commented 3 years ago

未看出问题,不过这种功能建议使用工具表单,参考 https://github.com/jqhph/dcat-admin-demo/blob/2.0/app/Admin/Forms/AdminSetting.php