Sfoglia il codice sorgente

Merge branch 'dev'

jqh 5 anni fa
parent
commit
24b4878630

+ 46 - 0
resources/views/form/done-step.blade.php

@@ -0,0 +1,46 @@
+<style>
+    .la-done-step {
+        max-width: 560px;
+        margin: 0 auto;
+        padding: 24px 0 8px;
+    }
+    .la-done-step .st-icon {
+        color: var(--success);
+        font-size: 72px;
+        text-align:center;
+    }
+    .la-done-step .st-content {
+        text-align:center;
+    }
+    .la-done-step .st-title {
+        font-size: 24px;
+    }
+    .la-done-step .st-desc {
+        color: rgba(0,0,0,.5);
+        font-size: 14px;
+        line-height: 1.6;
+    }
+    .la-done-step .st-btn {
+        margin: 30px 0 10px;
+    }
+</style>
+<div style="margin: 0 auto">
+    <div class="st-icon">
+        <svg viewBox="64 64 896 896" focusable="false" class="" data-icon="check-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 0 1-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"></path></svg>
+    </div>
+
+    <div class="st-content">
+        <div class="st-title">
+            {{ $title }}
+        </div>
+        <div class="st-desc">
+            {{ $description }}
+        </div>
+
+        <div class="st-btn">
+            <a class="btn btn-success" href="{{ $createUrl }}" >{{ trans('admin.continue_creating') }}</a>
+            &nbsp;
+            <a class="btn btn-default" href="{{ $backUrl }}"><i class="fa fa-long-arrow-left"></i> {{ trans('admin.back') }}</a>
+        </div>
+    </div>
+</div>

+ 15 - 8
resources/views/form/steps.blade.php

@@ -38,10 +38,13 @@
                     </a>
                 </li>
             </ul>
-            <div>
+            <div class="la-step-form">
                 @foreach($steps as $step)
                     {!! $step->render() !!}
                 @endforeach
+
+                <div id="{{ $doneStep->getElementId() }}" class="la-done-step" style="display: none;">
+                </div>
             </div>
         </div>
     @endif
@@ -89,11 +92,15 @@ LA.ready(function () {
             isSubmitting = 1;
 
             // 提交完整表单
-            submit(function (result) {
+            submit(function (state, data) {
                 $t.button('reset');
                 isSubmitting = 0;
 
-                if (result) {
+                if (state) {
+                    if (data) {
+                        form.find('.la-done-step').html(data);
+                    }
+
                     smartWizard.next();
 
                     toggle_btn();
@@ -153,11 +160,11 @@ LA.ready(function () {
 
         // 发送表单到服务器进行验证
         stepInput.val(smartWizard.current_index);
-        submit(function (result) {
+        submit(function (state) {
             $(self).button('reset');
             isSubmitting = 0;
 
-            if (result) {
+            if (state) {
                 // 表单验证成功
                 if (smartWizard.steps.index(self) !== smartWizard.current_index) {
                     smartWizard.next();
@@ -172,10 +179,10 @@ LA.ready(function () {
     function submit(after) {
         LA.Form({
             $form: form,
-            after: function (success, b, c, d) {
-                after(success, b, c, d);
+            after: function (state, b, c, d) {
+                after(state, b, c, d);
 
-                if (success) {
+                if (state) {
                     return false;
                 }
 

+ 20 - 2
src/Form.php

@@ -617,6 +617,10 @@ class Form implements Renderable
             return $response;
         }
 
+        if ($response = $this->responseDoneStep()) {
+            return $response;
+        }
+
         return $this->redirect(
             $this->getRedirectUrl($id, $redirectTo),
             trans('admin.save_succeeded')
@@ -676,7 +680,7 @@ class Form implements Renderable
      * @param array $data
      * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
      */
-    protected function  validateStepForm(array $data)
+    protected function validateStepForm(array $data)
     {
         // Handle validation errors.
         if ($validationMessages = $this->validationMessages($data)) {
@@ -686,6 +690,20 @@ class Form implements Renderable
         return $this->ajaxResponse('Success');
     }
 
+    /**
+     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response|void
+     */
+    protected function responseDoneStep()
+    {
+        if (! $done = $this->builder->getDoneStep()) {
+            return;
+        }
+
+        $done->finish();
+
+        return response($done->render());
+    }
+
     /**
      * Get ajax response.
      *
@@ -1620,7 +1638,7 @@ class Form implements Renderable
      */
     public function getResource($slice = -2)
     {
-        $path = $this->resource ?: app('request')->getUri();
+        $path = $this->resource ?: $this->request->getUri();
 
         $segments = explode('/', trim($path, '/'));
 

+ 36 - 7
src/Form/Builder.php

@@ -272,7 +272,6 @@ class Builder
         return $this;
     }
 
-
     /**
      * @return StepForm[]
      */
@@ -281,6 +280,41 @@ class Builder
         return $this->stepForms;
     }
 
+    /**
+     * @return DoneStep|null
+     */
+    public function getDoneStep()
+    {
+        if (! $this->stepForms) {
+            return;
+        }
+
+        if (! $this->doneStep) {
+            $this->setDefaultDonePage();
+        }
+
+        return $this->doneStep;
+    }
+
+    /**
+     * @return void
+     */
+    protected function setDefaultDonePage()
+    {
+        $this->done(function () {
+            $resource = $this->form->getResource(0);
+
+            $data = [
+                'title'       => trans('admin.save_succeeded'),
+                'description' => '',
+                'createUrl'   => $resource.'/create',
+                'backUrl'     => $resource,
+            ];
+
+            return view('admin::form.done-step', $data);
+        });
+    }
+
     /**
      * Set the builder mode.
      *
@@ -784,11 +818,6 @@ class Builder
             $this->setupSubmitScript();
         }
 
-        if ($this->stepForms && !$this->doneStep) {
-            $this->done(function () {
-            });
-        }
-
         $open = $this->open(['class' => 'form-horizontal']);
 
         $data = [
@@ -798,7 +827,7 @@ class Builder
             'formId'     => $this->getFormId(),
             'showHeader' => $this->showHeader,
             'steps'      => $this->stepForms,
-            'doneStep'   => $this->doneStep,
+            'doneStep'   => $this->getDoneStep(),
         ];
 
         $this->layout->prepend(

+ 40 - 3
src/Form/DoneStep.php

@@ -5,6 +5,7 @@ namespace Dcat\Admin\Form;
 use Dcat\Admin\Form;
 use Dcat\Admin\Support\Helper;
 use Illuminate\Contracts\Support\Renderable;
+use Illuminate\Support\Arr;
 use Illuminate\Support\Str;
 
 class DoneStep
@@ -68,7 +69,7 @@ class DoneStep
      * @param string|\Closure|Renderable $contents
      * @return void
      */
-    public function contents($contents)
+    public function content($contents)
     {
         $this->contents = $contents;
     }
@@ -81,12 +82,48 @@ class DoneStep
         return $this->elementId;
     }
 
+    /**
+     * @return array
+     */
+    public function getNewId()
+    {
+        return $this->form->getKey();
+    }
+
+    /**
+     * @param string|null $key
+     * @param mixed|null $default
+     * @return array|mixed
+     */
+    public function input($key = null, $default = null)
+    {
+        $input = $this->form->getUpdates();
+
+        if ($key === null) {
+            return $input;
+        }
+
+        return Arr::get($input, $key, $default);
+    }
+
+    /**
+     * @return void
+     */
+    public function finish()
+    {
+        $value = call_user_func($this->builder, $this);
+
+        if ($value) {
+            $this->content($value);
+        }
+    }
+
     /**
      * @return string
      */
-    public function build()
+    public function render()
     {
-        call_user_func($this->builder, $this);
+        return Helper::render($this->contents);
     }
 
 }

+ 11 - 2
src/Form/StepForm.php

@@ -107,8 +107,11 @@ class StepForm extends WidgetForm
      */
     protected function open()
     {
-        Admin::js('vendor/dcat-admin/SmartWizard/dist/js/jquery.smartWizard.min.js');
-        Admin::css('vendor/dcat-admin/SmartWizard/dist/css/step.min.css');
+        $this->collectAssets();
+
+        if ($this->index > 0) {
+            $this->setHtmlAttribute('style', 'display:none');
+        }
 
         $this->setHtmlAttribute('data-toggle', 'validator');
         $this->setHtmlAttribute('role', 'form');
@@ -126,4 +129,10 @@ HTML;
         return '</div>';
     }
 
+    protected function collectAssets()
+    {
+        Admin::js('vendor/dcat-admin/SmartWizard/dist/js/jquery.smartWizard.min.js');
+        Admin::css('vendor/dcat-admin/SmartWizard/dist/css/step.min.css');
+    }
+
 }