Browse Source

支持 iview4

xaboy 6 years ago
parent
commit
79333b0c8b
4 changed files with 57 additions and 6 deletions
  1. 15 0
      src/Factory/Iview.php
  2. 14 0
      src/Form.php
  3. 3 1
      src/Handle/IviewFormHandle.php
  4. 25 5
      src/UI/Iview/Bootstrap.php

+ 15 - 0
src/Factory/Iview.php

@@ -126,4 +126,19 @@ abstract class Iview
     {
         return Form::iview($action, $rule, $config);
     }
+
+
+    /**
+     * 创建表单 v4版本
+     *
+     * @param string $action
+     * @param array $rule
+     * @param array $config
+     * @return Form
+     * @throws FormBuilderException
+     */
+    public static function createFormV4($action = '', $rule = [], $config = [])
+    {
+        return Form::iview4($action, $rule, $config);
+    }
 }

+ 14 - 0
src/Form.php

@@ -458,6 +458,20 @@ class Form
     }
 
     /**
+     * Iview v4 版表单生成器
+     *
+     * @param string $action
+     * @param array $rule
+     * @param array|ConfigInterface $config
+     * @return Form
+     * @throws FormBuilderException
+     */
+    public static function iview4($action = '', $rule = [], $config = [])
+    {
+        return new self(new IViewBootstrap(4), $action, $rule, $config);
+    }
+
+    /**
      * element-ui 版表单生成器
      *
      * @param string $action

+ 3 - 1
src/Handle/IviewFormHandle.php

@@ -23,8 +23,10 @@ use FormBuilder\FormHandle;
 abstract class IviewFormHandle extends FormHandle
 {
 
+    protected $version = 3;
+
     protected function ui()
     {
-        return 'iview';
+        return $this->version == 4 ? 'iview4' : 'iview';
     }
 }

+ 25 - 5
src/UI/Iview/Bootstrap.php

@@ -17,15 +17,35 @@ use FormBuilder\Form;
 class Bootstrap implements BootstrapInterface
 {
 
+    protected $version;
+
+    /**
+     * Bootstrap constructor.
+     * @param int $version
+     */
+    public function __construct($version = 3)
+    {
+        $this->version = $version;
+    }
+
     public function init(Form $form)
     {
         $dependScript = $form->getDependScript();
 
-        array_splice($dependScript, 2, 0, [
-            '<link href="https://unpkg.com/iview@3.4.2/dist/styles/iview.css" rel="stylesheet">',
-            '<script src="https://unpkg.com/iview@3.4.2/dist/iview.min.js"></script>',
-            '<script src="https://unpkg.com/@form-create/iview@1.0.3/dist/form-create.min.js"></script>',
-        ]);
+        if ($this->version != 4) {
+            array_splice($dependScript, 2, 0, [
+                '<link href="https://unpkg.com/iview@3.4.2/dist/styles/iview.css" rel="stylesheet">',
+                '<script src="https://unpkg.com/iview@3.4.2/dist/iview.min.js"></script>',
+                '<script src="https://unpkg.com/@form-create/iview@1.0.3/dist/form-create.min.js"></script>',
+            ]);
+        } else {
+            array_splice($dependScript, 2, 0, [
+                '<link href="https://unpkg.com/view-design@4.0.2/dist/styles/iview.css" rel="stylesheet">',
+                '<script src="https://unpkg.com/view-design@4.0.2/dist/iview.min.js"></script>',
+                '<script src="https://unpkg.com/@form-create/iview4@1.0.4/dist/form-create.min.js"></script>',
+            ]);
+        }
+
 
         $form->setDependScript($dependScript);
     }