Browse Source

增加分步表单默认选中步骤功能

jqh 5 years ago
parent
commit
11b7d3ee79

+ 2 - 1
resources/assets/SmartWizard/dist/js/jquery.smartWizard.js

@@ -98,7 +98,8 @@
 
             if (idx > 0 && this.options.anchorSettings.markDoneStep && this.options.anchorSettings.markAllPreviousStepsAsDone) {
                 // Mark previous steps of the active step as done
-                this.steps.eq(idx).parent('li').prevAll().addClass("done");
+                // this.steps.eq(idx).parent('li').prevAll().addClass("done");
+                this._setDone(this.steps.eq(idx).parent('li').prevAll());
             }
 
             // Show the initial step

File diff suppressed because it is too large
+ 0 - 0
resources/assets/SmartWizard/dist/js/jquery.smartWizard.min.js


+ 3 - 3
resources/views/form/steps.blade.php

@@ -39,9 +39,7 @@
                 </li>
             </ul>
             <div class="la-step-form">
-                @foreach($steps->all() as $step)
-                    {!! $step->render() !!}
-                @endforeach
+                {!! $steps->build() !!}
 
                 <div id="{{ $steps->getDoneStep()->getElementId() }}" class="la-done-step" style="display: none;">
                 </div>
@@ -112,6 +110,7 @@ LA.ready(function () {
         });
 
     smartWizard = box.smartWizard({
+        selected: {{ $steps->getOption('selected') }},
         transitionEffect: 'fade',
         useURLhash: false,
         lang: {
@@ -124,6 +123,7 @@ LA.ready(function () {
             toolbarButtonPosition: 'left'
         },
         anchorSettings: {
+            removeDoneStepOnNavigateBack: true,
             enableAnchorOnDoneStep: false,
         },
     });

+ 53 - 0
src/Form/StepBuilder.php

@@ -30,6 +30,7 @@ class StepBuilder
      * @var array
      */
     protected $options = [
+        'selected' => 0,
         'width'    => '1000px',
         'remember' => false,
     ];
@@ -105,6 +106,15 @@ class StepBuilder
         return $this->options[$key] ?? $default;
     }
 
+    /**
+     * @param int $index
+     * @return $this
+     */
+    public function select(int $index)
+    {
+        return $this->option('selected', $index);
+    }
+
     /**
      * @param string $width
      * @return $this
@@ -229,4 +239,47 @@ class StepBuilder
         Admin::css('vendor/dcat-admin/SmartWizard/dist/css/step.min.css');
     }
 
+    /**
+     * @return void
+     */
+    protected function selectStep()
+    {
+        if (! $this->options['remember'] || ! $input = $this->fetchStash()) {
+            return;
+        }
+
+        $current = $input[static::CURRENT_VALIDATION_STEP] ?? null;
+        if ($current !== null && $current !== '') {
+            $this->select((int) ($input[static::CURRENT_VALIDATION_STEP] + 1));
+        }
+
+        if (! empty($input[static::ALL_STEPS])) {
+            $this->select($this->count() - 1);
+        }
+    }
+
+    /**
+     * @return string
+     */
+    public function build()
+    {
+        $this->selectStep();
+
+        return $this->renderFields();
+    }
+
+    /**
+     * @return string
+     */
+    public function renderFields()
+    {
+        $html = '';
+
+        foreach($this->stepForms as $step) {
+            $html .= (string) $step->render();
+        }
+
+        return $html;
+    }
+
 }

Some files were not shown because too many files changed in this diff