Browse Source

补充说明文档

xaboy 7 years ago
parent
commit
52bfe250b9
6 changed files with 100 additions and 10 deletions
  1. 83 3
      README.md
  2. BIN
      images/components.png
  3. BIN
      images/demo02.jpg
  4. BIN
      images/demo03.jpg
  5. 1 1
      src/components/Cascader.php
  6. 16 6
      src/traits/form/FormCascaderTrait.php

+ 83 - 3
README.md

@@ -18,8 +18,6 @@ PHP表单生成器,快速生成现代化的form表单。包含复选框、单
 </p>
 </p>
 
 
 
 
-#### 表单是使用[form-create](https://github.com/xaboy/form-create) js表单生成器生成
-
 #### 如果对您有帮助,您可以点右上角 "Star" 支持一下 谢谢!
 #### 如果对您有帮助,您可以点右上角 "Star" 支持一下 谢谢!
  
  
 #### 本项目还在不断开发完善中,如有建议或问题请[在这里提出](https://github.com/xaboy/form-builder/issues/new)
 #### 本项目还在不断开发完善中,如有建议或问题请[在这里提出](https://github.com/xaboy/form-builder/issues/new)
@@ -33,6 +31,78 @@ PHP表单生成器,快速生成现代化的form表单。包含复选框、单
 ![https://raw.githubusercontent.com/xaboy/form-builder/master/demo.jpg](https://raw.githubusercontent.com/xaboy/form-builder/master/demo.jpg)
 ![https://raw.githubusercontent.com/xaboy/form-builder/master/demo.jpg](https://raw.githubusercontent.com/xaboy/form-builder/master/demo.jpg)
 
 
 
 
+### 例子 (TP框架)
+
+#### 版本1 编辑权限
+```php
+$form = Form::create(Url::build('update',array('id'=>$id)),[
+            Form::input('menu_name','按钮名称',$menu['menu_name']),
+            Form::select('pid','父级id',(string)$menu->getData('pid'))->setOptions(function()use($id){
+                $list = (Util::sortListTier(MenusModel::where('id','<>',$id)->select()->toArray(),'顶级','pid','menu_name'));
+                $menus = [['value'=>0,'label'=>'顶级按钮']];
+                foreach ($list as $menu){
+                    $menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['menu_name']];
+                }
+                return $menus;
+            })->filterable(1),
+            Form::select('module','模块名',$menu['module'])->options([['label'=>'总后台','value'=>'admin'],['label'=>'总后台1','value'=>'admin1']]),
+            Form::input('controller','控制器名',$menu['controller']),
+            Form::input('action','方法名',$menu['action']),
+            Form::input('params','参数',MenusModel::paramStr($menu['params']))->placeholder('举例:a/123/b/234'),
+            Form::frameInputOne('icon','图标',Url::build('admin/widget.widgets/icon',array('fodder'=>'icon')),$menu['icon'])->icon('ionic'),
+            Form::number('sort','排序',$menu['sort']),
+            Form::radio('is_show','是否菜单',$menu['is_show'])->options([['value'=>0,'label'=>'隐藏'],['value'=>1,'label'=>'显示(菜单只显示三级)']])
+        ]);
+$form->setMethod('post')->setTitle('编辑权限');
+$this->assign(compact('form'));
+return $this->fetch('public/form-builder');
+
+```
+#### 效果
+![https://raw.githubusercontent.com/xaboy/form-builder/master/images/demo02.jpg](https://raw.githubusercontent.com/xaboy/form-builder/master/images/demo02.jpg)
+
+#### 版本2 添加产品
+```php
+$field = [
+    Form::select('cate_id','产品分类')->setOptions(function(){
+        $list = CategoryModel::getTierList();
+        foreach ($list as $menu){
+            $menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['cate_name'],'disabled'=>$menu['pid']== 0];//,'disabled'=>$menu['pid']== 0];
+        }
+        return $menus;
+    })->filterable(1)->multiple(1),
+    Form::input('store_name','产品名称')->col(Form::col(8)),
+    Form::input('store_info','产品简介')->type('textarea'),
+    Form::input('keyword','产品关键字')->placeholder('多个用英文状态下的逗号隔开'),
+    Form::input('unit_name','产品单位','件'),
+    Form::frameImageOne('image','产品主图片(305*305px)',Url::build('admin/widget.images/index',array('fodder'=>'image')))->icon('image')->width('100%')->height('550px'),
+    Form::frameImages('slider_image','产品轮播图(640*640px)',Url::build('admin/widget.images/index',array('fodder'=>'slider_image')))->maxLength(5)->icon('images')->width('100%')->height('550px')->spin(0),
+    Form::number('price','产品售价')->min(0)->col(8),
+    Form::number('ot_price','产品市场价')->min(0)->col(8),
+    Form::number('give_integral','赠送积分')->min(0)->precision(0)->col(8),
+    Form::number('postage','邮费')->min(0)->col(Form::col(8)),
+    Form::number('sales','销量')->min(0)->precision(0)->col(8),
+    Form::number('ficti','虚拟销量')->min(0)->precision(0)->col(8),
+    Form::number('stock','库存')->min(0)->precision(0)->col(8),
+    Form::number('cost','产品成本价')->min(0)->col(8),
+    Form::number('sort','排序')->col(8),
+    Form::radio('is_show','产品状态',0)->options([['label'=>'上架','value'=>1],['label'=>'下架','value'=>0]])->col(8),
+    Form::radio('is_hot','热卖单品',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
+    Form::radio('is_benefit','促销单品',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
+    Form::radio('is_best','精品推荐',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
+    Form::radio('is_new','首发新品',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
+    Form::radio('is_postage','是否包邮',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8)
+];
+$form = Form::create(Url::build('save'));
+$form->setMethod('post')->setTitle('添加产品')->components($field);
+$this->assign(compact('form'));
+return $this->fetch('public/form-builder');
+
+```
+#### 效果
+![https://raw.githubusercontent.com/xaboy/form-builder/master/images/demo03.jpg](https://raw.githubusercontent.com/xaboy/form-builder/master/images/demo03.jpg)
+
+
 **当form提交成功后会调用`window.formCreate.formSuccess(res,$f,formData)`作为回调方法**
 **当form提交成功后会调用`window.formCreate.formSuccess(res,$f,formData)`作为回调方法**
 
 
 
 
@@ -127,6 +197,7 @@ echo $html;
  * @method $this justify(String $justify) flex 布局下的水平排列方式,可选值为start、end、center、space-around、space-between
  * @method $this justify(String $justify) flex 布局下的水平排列方式,可选值为start、end、center、space-around、space-between
  * @method $this className(String $className) 自定义的class名称
  * @method $this className(String $className) 自定义的class名称
 ```
 ```
+参考: [view col栅格布局](http://v2.iviewui.com/components/grid#API)
 
 
 ## Col栅格规则
 ## Col栅格规则
 * **Form::col**
 * **Form::col**
@@ -143,6 +214,7 @@ echo $html;
  * @method $this md(Number|Col $span) ≥992px 响应式栅格,可为栅格数或一个包含其他属性的对象
  * @method $this md(Number|Col $span) ≥992px 响应式栅格,可为栅格数或一个包含其他属性的对象
  * @method $this lg(Number|Col $span) ≥1200px 响应式栅格,可为栅格数或一个包含其他属性的对象
  * @method $this lg(Number|Col $span) ≥1200px 响应式栅格,可为栅格数或一个包含其他属性的对象
 ```
 ```
+参考: [view col栅格布局](http://v2.iviewui.com/components/grid#API)
 
 
 
 
 ## select,checkbox,radio组件配置options专用方法
 ## select,checkbox,radio组件配置options专用方法
@@ -416,4 +488,12 @@ echo $html;
  * @method $this checked(Boolean $bool) 是否勾选(如果勾选,子节点也会全部勾选)
  * @method $this checked(Boolean $bool) 是否勾选(如果勾选,子节点也会全部勾选)
  * @method $this children(array $children) 批量设置子集
  * @method $this children(array $children) 批量设置子集
  * @method $this child(TreeData $child) 设置子集
  * @method $this child(TreeData $child) 设置子集
-```
+```
+
+##所有组件生成效果
+![https://raw.githubusercontent.com/xaboy/form-builder/master/images/components.png](https://raw.githubusercontent.com/xaboy/form-builder/master/images/components.png)
+
+## 参考
+
+ui框架: [iview2.x](http://v2.iviewui.com/docs/guide/install)
+js表单生成器生成: [form-create](https://github.com/xaboy/form-create)

BIN
images/components.png


BIN
images/demo02.jpg


BIN
images/demo03.jpg


+ 1 - 1
src/components/Cascader.php

@@ -94,7 +94,7 @@ class Cascader extends FormComponentDriver
     }
     }
 
 
     /**
     /**
-     * @param $value
+     * @param array $value
      * @return $this
      * @return $this
      */
      */
     public function value($value)
     public function value($value)

+ 16 - 6
src/traits/form/FormCascaderTrait.php

@@ -36,13 +36,18 @@ trait FormCascaderTrait
      * 省市二级联动
      * 省市二级联动
      * @param $field
      * @param $field
      * @param $title
      * @param $title
-     * @param string $province
+     * @param array|string $province
      * @param string $city
      * @param string $city
      * @return Cascader
      * @return Cascader
      */
      */
-    public static function city($field, $title, $province = '', $city = '')
+    public static function city($field, $title, $province = [], $city = '')
     {
     {
-        $cascader = self::cascader($field, $title, [(string)$province, (string)$city], Cascader::TYPE_CITY);
+        if(is_array($province))
+            $value = $province;
+        else
+            $value = [(string)$province, (string)$city];
+
+        $cascader = self::cascader($field, $title, $value, Cascader::TYPE_CITY);
         $cascader->jsData('province_city');
         $cascader->jsData('province_city');
         return $cascader;
         return $cascader;
     }
     }
@@ -52,14 +57,19 @@ trait FormCascaderTrait
      * 省市区三级联动
      * 省市区三级联动
      * @param $field
      * @param $field
      * @param $title
      * @param $title
-     * @param string $province
+     * @param array|string $province
      * @param string $city
      * @param string $city
      * @param string $area
      * @param string $area
      * @return Cascader
      * @return Cascader
      */
      */
-    public static function cityArea($field, $title, $province = '', $city = '', $area = '')
+    public static function cityArea($field, $title, $province = [], $city = '', $area = '')
     {
     {
-        $cascader = self::cascader($field, $title, [(string)$province, (string)$city, (string)$area], Cascader::TYPE_CITY_AREA);
+        if(is_array($province))
+            $value = $province;
+        else
+            $value = [(string)$province, (string)$city, (string)$area];
+
+        $cascader = self::cascader($field, $title, $value, Cascader::TYPE_CITY_AREA);
         $cascader->jsData('province_city_area');
         $cascader->jsData('province_city_area');
         return $cascader;
         return $cascader;
     }
     }