mirror of
https://github.com/crmeb/CRMEB.git
synced 2025-12-15 04:52:50 +00:00
更新
This commit is contained in:
parent
c0f815c523
commit
26f3daba97
@ -131,6 +131,8 @@ class Article extends AuthController
|
||||
['visit',0],
|
||||
['sort',0],
|
||||
'url',
|
||||
['is_banner',0],
|
||||
['is_hot',0],
|
||||
['status',1],],$request);
|
||||
$data['cid'] = implode(',',$data['cid']);
|
||||
$content = $data['content'];
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
<?php
namespace app\admin\controller\setting;
use think\Url;
use service\FormBuilder as Form;
use think\Request;
use service\UtilService as Util;
use service\JsonService as Json;
use app\admin\controller\AuthController;
use app\admin\model\system\SystemConfigTab as ConfigTabModel;
use app\admin\model\system\SystemConfig as ConfigModel;
/**
* 配置分类控制器
* Class SystemConfigTab
* @package app\admin\controller\system
*/
class SystemConfigTab extends AuthController
{
/**
* 子子段
* @return mixed|\think\response\Json
*/
public function sonconfigtab(){
$tab_id = input('tab_id');
if(!$tab_id) return Json::fail('参数错误');
$this->assign('tab_id',$tab_id);
$list = ConfigModel::getAll($tab_id);
foreach ($list as $k=>$v){
$list[$k]['value'] = json_decode($v['value'],true);
if($v['type'] == 'radio' || $v['type'] == 'checkbox'){
$list[$k]['value'] = ConfigTabModel::getRadioOrCheckboxValueInfo($v['menu_name'],$v['value']);
}
if($v['type'] == 'upload' && !empty($v['value'])){
if($v['upload_type'] == 1 || $v['upload_type'] == 3) $list[$k]['value'] = explode(',',$v['value']);
}
}
$this->assign('list',$list);
return $this->fetch();
}
/**
* 基础配置
* @return mixed
*/
public function index(){
$where = Util::getMore([
['status',''],
['title',''],
],$this->request);
$this->assign('where',$where);
$this->assign(ConfigTabModel::getSystemConfigTabPage($where));
return $this->fetch();
}
/**
* 添加配置分类
* @return mixed
*/
public function create(){
$form = Form::create(Url::build('save'),[
Form::input('title','分类昵称'),
Form::input('eng_title','分类字段'),
Form::frameInputOne('icon','图标',Url::build('admin/widget.widgets/icon',array('fodder'=>'icon')))->icon('ionic'),
Form::radio('type','类型',0)->options([['value'=>0,'label'=>'系统'],['value'=>1,'label'=>'公众号'],['value'=>2,'label'=>'小程序'],['value'=>3,'label'=>'其它']]),
Form::radio('status','状态',1)->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']])
]);
$form->setMethod('post')->setTitle('添加分类配置');
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
/**
* 保存分类名称
* @param Request $request
* @return \think\response\Json
*/
public function save(Request $request){
$data = Util::postMore([
'eng_title',
'status',
'title',
'icon',
'type'],$request);
if(!$data['title']) return Json::fail('请输入按钮名称');
ConfigTabModel::set($data);
return Json::successful('添加菜单成功!');
}
/**
* 修改分类
* @param $id
* @return mixed
*/
public function edit($id){
$menu = ConfigTabModel::get($id)->getData();
if(!$menu) return Json::fail('数据不存在!');
$form = Form::create(Url::build('update',array('id'=>$id)),[
Form::input('title','分类昵称',$menu['title']),
Form::input('eng_title','分类字段',$menu['eng_title']),
Form::frameInputOne('icon','图标',Url::build('admin/widget.widgets/icon',array('fodder'=>'icon')),$menu['icon'])->icon('ionic'),
Form::radio('type','类型',$menu['type'])->options([['value'=>0,'label'=>'系统'],['value'=>1,'label'=>'公众号'],['value'=>2,'label'=>'小程序'],['value'=>3,'label'=>'其它']]),
Form::radio('status','状态',$menu['status'])->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']])
]);
$form->setMethod('post')->setTitle('添加分类配置');
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
/**
* @param Request $request
* @param $id
* @return \think\response\Json
*/
public function update(Request $request, $id)
{
$data = Util::postMore(['title','status','eng_title','icon','type'],$request);
if(!$data['title']) return Json::fail('请输入分类昵称');
if(!$data['eng_title']) return Json::fail('请输入分类字段');
if(!ConfigTabModel::get($id)) return Json::fail('编辑的记录不存在!');
ConfigTabModel::edit($data,$id);
return Json::successful('修改成功!');
}
/**
* @param $id
* @return \think\response\Json
*/
public function delete($id){
if(!ConfigTabModel::del($id))
return Json::fail(ConfigTabModel::getErrorInfo('删除失败,请稍候再试!'));
else
return Json::successful('删除成功!');
}
}
|
||||
<?php
namespace app\admin\controller\setting;
use think\Url;
use service\FormBuilder as Form;
use think\Request;
use service\UtilService as Util;
use service\JsonService as Json;
use app\admin\controller\AuthController;
use app\admin\model\system\SystemConfigTab as ConfigTabModel;
use app\admin\model\system\SystemConfig as ConfigModel;
/**
* 配置分类控制器
* Class SystemConfigTab
* @package app\admin\controller\system
*/
class SystemConfigTab extends AuthController
{
/**
* 子子段
* @return mixed|\think\response\Json
*/
public function sonconfigtab(){
$tab_id = input('tab_id');
if(!$tab_id) return Json::fail('参数错误');
$this->assign('tab_id',$tab_id);
$list = ConfigModel::getAll($tab_id);
foreach ($list as $k=>$v){
$list[$k]['value'] = json_decode($v['value'],true)?:'';
if($v['type'] == 'radio' || $v['type'] == 'checkbox'){
$list[$k]['value'] = ConfigTabModel::getRadioOrCheckboxValueInfo($v['menu_name'],$v['value']);
}
if($v['type'] == 'upload' && !empty($v['value'])){
// if($v['upload_type'] == 1 || $v['upload_type'] == 3) $list[$k]['value'] = explode(',',$v['value']);
}
}
$this->assign('list',$list);
return $this->fetch();
}
/**
* 基础配置
* @return mixed
*/
public function index(){
$where = Util::getMore([
['status',''],
['title',''],
],$this->request);
$this->assign('where',$where);
$this->assign(ConfigTabModel::getSystemConfigTabPage($where));
return $this->fetch();
}
/**
* 添加配置分类
* @return mixed
*/
public function create(){
$form = Form::create(Url::build('save'),[
Form::input('title','分类昵称'),
Form::input('eng_title','分类字段'),
Form::frameInputOne('icon','图标',Url::build('admin/widget.widgets/icon',array('fodder'=>'icon')))->icon('ionic'),
Form::radio('type','类型',0)->options([['value'=>0,'label'=>'系统'],['value'=>1,'label'=>'公众号'],['value'=>2,'label'=>'小程序'],['value'=>3,'label'=>'其它']]),
Form::radio('status','状态',1)->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']])
]);
$form->setMethod('post')->setTitle('添加分类配置');
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
/**
* 保存分类名称
* @param Request $request
* @return \think\response\Json
*/
public function save(Request $request){
$data = Util::postMore([
'eng_title',
'status',
'title',
'icon',
'type'],$request);
if(!$data['title']) return Json::fail('请输入按钮名称');
ConfigTabModel::set($data);
return Json::successful('添加菜单成功!');
}
/**
* 修改分类
* @param $id
* @return mixed
*/
public function edit($id){
$menu = ConfigTabModel::get($id)->getData();
if(!$menu) return Json::fail('数据不存在!');
$form = Form::create(Url::build('update',array('id'=>$id)),[
Form::input('title','分类昵称',$menu['title']),
Form::input('eng_title','分类字段',$menu['eng_title']),
Form::frameInputOne('icon','图标',Url::build('admin/widget.widgets/icon',array('fodder'=>'icon')),$menu['icon'])->icon('ionic'),
Form::radio('type','类型',$menu['type'])->options([['value'=>0,'label'=>'系统'],['value'=>1,'label'=>'公众号'],['value'=>2,'label'=>'小程序'],['value'=>3,'label'=>'其它']]),
Form::radio('status','状态',$menu['status'])->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']])
]);
$form->setMethod('post')->setTitle('添加分类配置');
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
/**
* @param Request $request
* @param $id
* @return \think\response\Json
*/
public function update(Request $request, $id)
{
$data = Util::postMore(['title','status','eng_title','icon','type'],$request);
if(!$data['title']) return Json::fail('请输入分类昵称');
if(!$data['eng_title']) return Json::fail('请输入分类字段');
if(!ConfigTabModel::get($id)) return Json::fail('编辑的记录不存在!');
ConfigTabModel::edit($data,$id);
return Json::successful('修改成功!');
}
/**
* @param $id
* @return \think\response\Json
*/
public function delete($id){
if(!ConfigTabModel::del($id))
return Json::fail(ConfigTabModel::getErrorInfo('删除失败,请稍候再试!'));
else
return Json::successful('删除成功!');
}
}
|
||||
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
<?php
/**
*
* @author: xaboy<365615158@qq.com>
* @day: 2017/11/02
*/
namespace app\admin\model\system;
use traits\ModelTrait;
use basic\ModelBasic;
use think\Db;
/**
* 配置分类model
*
* Class SystemConfigTab
* @package app\admin\model\system
*/
class SystemConfigTab extends ModelBasic {
use ModelTrait;
/**
* 获取单选按钮或者多选按钮的显示值
* */
public static function getRadioOrCheckboxValueInfo($menu_name,$value){
$parameter = array();
$option = array();
$config_one = \app\admin\model\system\SystemConfig::getOneConfig('menu_name',$menu_name);
// dump($config_one);
// exit();
// if(empty($menu) || !($config_one = self::get(['menu_name'=>$menu]))) return false;
$parameter = explode("\n",$config_one['parameter']);
foreach ($parameter as $k=>$v){
if(isset($v) && !empty($v)){
$option[$k] = explode('=',$v);
}
}
// $value = json_decode($value,true);
if(!is_array($value)){
$value = explode("\n",$value);
}
// dump($value);
// dump($option);
$value_arr = array();//选项的值
foreach ($option as $k=>$v){
foreach ($v as $kk=>$vv){
if(is_array($value)) {
if (in_array($v[0], $value)) {
$value_arr[$k] = $v[1];
}
}
break;
}
}
if(empty($value_arr)){
return '空';
}
return $value_arr;
// exit();
// if(is_array($value)){
// foreach ($value as $k=>$value_v){
// if(in_array($value_v,$value_arr)){
// $i[$k] = 1;
// }
// }
// if(count($value) != $i) return self::setErrorInfo('输入的值不属于选项中的参数');
// }else{
// if(in_array($value,$value_arr)){
// $i++;
// }
// if(!$i) return self::setErrorInfo('输入的值不属于选项中的参数');
// }
// if($config_one['type'] == 'radio' && is_array($value)) return self::setErrorInfo('单选按钮的值是字符串不是数组');
}
/**
* 插入数据到数据库
* */
public static function set($data)
{
return self::create($data);
}
/**
* 获取全部
* */
public static function getAll($type = 0){
$where['status'] = 1;
if($type>-1)$where['type'] = $type;
return Db::name('SystemConfigTab')->where($where)->select();
}
/**
* 获取配置分类
* */
public static function getSystemConfigTabPage($where = array())
{
$model = new self;
if($where['title'] != '') $model = $model->where('title','LIKE',"%$where[title]%");
if($where['status'] != '') $model = $model->where('status',$where['status']);
return self::page($model,$where);
}
public static function edit($data,$id,$field='id')
{
return self::update($data,[$field=>$id]);
}
/**
* 更新数据
* @access public
* @param array $data 数据数组
* @param array $where 更新条件
* @param array|true $field 允许字段
* @return $this
*/
public static function update($data = [], $where = [], $field = null)
{
$model = new static();
if (!empty($field)) {
$model->allowField($field);
}
$result = $model->isUpdate(true)->save($data, $where);
return $model;
}
}
|
||||
<?php
/**
*
* @author: xaboy<365615158@qq.com>
* @day: 2017/11/02
*/
namespace app\admin\model\system;
use traits\ModelTrait;
use basic\ModelBasic;
use think\Db;
/**
* 配置分类model
*
* Class SystemConfigTab
* @package app\admin\model\system
*/
class SystemConfigTab extends ModelBasic {
use ModelTrait;
/**
* 获取单选按钮或者多选按钮的显示值
* */
public static function getRadioOrCheckboxValueInfo($menu_name,$value){
$parameter = array();
$option = array();
$config_one = SystemConfig::getOneConfig('menu_name',$menu_name);
$parameter = explode("\n",$config_one['parameter']);
foreach ($parameter as $k=>$v){
if(isset($v) && !empty($v)){
$data = explode('=',$v);
$option[$data[0]] = $data[1];
}
}
$str = '';
if(is_array($value)){
foreach ($value as $v){
$str .= $option[$v].',';
}
}else{
$str .= $option[$value];
}
return $str;
}
/**
* 插入数据到数据库
* */
public static function set($data)
{
return self::create($data);
}
/**
* 获取全部
* */
public static function getAll($type = 0){
$where['status'] = 1;
if($type>-1)$where['type'] = $type;
return Db::name('SystemConfigTab')->where($where)->select();
}
/**
* 获取配置分类
* */
public static function getSystemConfigTabPage($where = array())
{
$model = new self;
if($where['title'] != '') $model = $model->where('title','LIKE',"%$where[title]%");
if($where['status'] != '') $model = $model->where('status',$where['status']);
return self::page($model,$where);
}
public static function edit($data,$id,$field='id')
{
return self::update($data,[$field=>$id]);
}
/**
* 更新数据
* @access public
* @param array $data 数据数组
* @param array $where 更新条件
* @param array|true $field 允许字段
* @return $this
*/
public static function update($data = [], $where = [], $field = null)
{
$model = new static();
if (!empty($field)) {
$model->allowField($field);
}
$result = $model->isUpdate(true)->save($data, $where);
return $model;
}
}
|
||||
File diff suppressed because one or more lines are too long
37
composer.lock
generated
37
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "ae2e50326d8e83fd299c3350bb0f87d1",
|
||||
"content-hash": "3dd0118e5d08ef728cb0c2f4f7de15a5",
|
||||
"packages": [
|
||||
{
|
||||
"name": "doctrine/cache",
|
||||
@ -871,16 +871,16 @@
|
||||
},
|
||||
{
|
||||
"name": "topthink/framework",
|
||||
"version": "v5.0.11",
|
||||
"version": "v5.0.21",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/top-think/framework.git",
|
||||
"reference": "926c9edb0c2682b14f563cac2c8a93f42f729016"
|
||||
"reference": "ab826da071a7a47116a7f1d01f72228d6bcf212a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/top-think/framework/zipball/926c9edb0c2682b14f563cac2c8a93f42f729016",
|
||||
"reference": "926c9edb0c2682b14f563cac2c8a93f42f729016",
|
||||
"url": "https://api.github.com/repos/top-think/framework/zipball/ab826da071a7a47116a7f1d01f72228d6bcf212a",
|
||||
"reference": "ab826da071a7a47116a7f1d01f72228d6bcf212a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -918,7 +918,7 @@
|
||||
"orm",
|
||||
"thinkphp"
|
||||
],
|
||||
"time": "2017-09-13T03:30:29+00:00"
|
||||
"time": "2018-09-04T09:18:48+00:00"
|
||||
},
|
||||
{
|
||||
"name": "topthink/think-captcha",
|
||||
@ -1078,16 +1078,16 @@
|
||||
},
|
||||
{
|
||||
"name": "tp5er/tp5-databackup",
|
||||
"version": "1.0.0",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/tp5er/tp5-databackup.git",
|
||||
"reference": "10abd4383cf78844e1c22584fd823ef1d18e75dc"
|
||||
"reference": "101477abe810fb91bad5c1304a93c5f461db6dc8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/tp5er/tp5-databackup/zipball/10abd4383cf78844e1c22584fd823ef1d18e75dc",
|
||||
"reference": "10abd4383cf78844e1c22584fd823ef1d18e75dc",
|
||||
"url": "https://api.github.com/repos/tp5er/tp5-databackup/zipball/101477abe810fb91bad5c1304a93c5f461db6dc8",
|
||||
"reference": "101477abe810fb91bad5c1304a93c5f461db6dc8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1110,23 +1110,24 @@
|
||||
}
|
||||
],
|
||||
"description": "Implement the database backup restore",
|
||||
"time": "2017-12-29T05:36:58+00:00"
|
||||
"time": "2018-04-07T11:20:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "xaboy/form-builder",
|
||||
"version": "1.2.3",
|
||||
"version": "1.2.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/xaboy/form-builder.git",
|
||||
"reference": "1b11a518429db5828147d5840ea18480586caa0c"
|
||||
"reference": "73cb5be3d9f57680f64d01ab424c4ac5c462f1b8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/xaboy/form-builder/zipball/1b11a518429db5828147d5840ea18480586caa0c",
|
||||
"reference": "1b11a518429db5828147d5840ea18480586caa0c",
|
||||
"url": "https://api.github.com/repos/xaboy/form-builder/zipball/73cb5be3d9f57680f64d01ab424c4ac5c462f1b8",
|
||||
"reference": "73cb5be3d9f57680f64d01ab424c4ac5c462f1b8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"type": "library",
|
||||
@ -1147,13 +1148,15 @@
|
||||
],
|
||||
"description": "PHP表单生成器,快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。",
|
||||
"homepage": "https://github.com/xaboy/form-builder",
|
||||
"time": "2018-08-07T06:29:30+00:00"
|
||||
"time": "2018-11-13T12:44:31+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"stability-flags": {
|
||||
"tp5er/tp5-databackup": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
|
||||
39
vendor/composer/installed.json
vendored
39
vendor/composer/installed.json
vendored
@ -894,17 +894,17 @@
|
||||
},
|
||||
{
|
||||
"name": "topthink/framework",
|
||||
"version": "v5.0.11",
|
||||
"version_normalized": "5.0.11.0",
|
||||
"version": "v5.0.21",
|
||||
"version_normalized": "5.0.21.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/top-think/framework.git",
|
||||
"reference": "926c9edb0c2682b14f563cac2c8a93f42f729016"
|
||||
"reference": "ab826da071a7a47116a7f1d01f72228d6bcf212a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/top-think/framework/zipball/926c9edb0c2682b14f563cac2c8a93f42f729016",
|
||||
"reference": "926c9edb0c2682b14f563cac2c8a93f42f729016",
|
||||
"url": "https://api.github.com/repos/top-think/framework/zipball/ab826da071a7a47116a7f1d01f72228d6bcf212a",
|
||||
"reference": "ab826da071a7a47116a7f1d01f72228d6bcf212a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -919,7 +919,7 @@
|
||||
"phpunit/phpunit": "4.8.*",
|
||||
"sebastian/phpcpd": "2.*"
|
||||
},
|
||||
"time": "2017-09-13T03:30:29+00:00",
|
||||
"time": "2018-09-04T09:18:48+00:00",
|
||||
"type": "think-framework",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
@ -1111,25 +1111,25 @@
|
||||
},
|
||||
{
|
||||
"name": "tp5er/tp5-databackup",
|
||||
"version": "1.0.0",
|
||||
"version_normalized": "1.0.0.0",
|
||||
"version": "dev-master",
|
||||
"version_normalized": "9999999-dev",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/tp5er/tp5-databackup.git",
|
||||
"reference": "10abd4383cf78844e1c22584fd823ef1d18e75dc"
|
||||
"reference": "101477abe810fb91bad5c1304a93c5f461db6dc8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/tp5er/tp5-databackup/zipball/10abd4383cf78844e1c22584fd823ef1d18e75dc",
|
||||
"reference": "10abd4383cf78844e1c22584fd823ef1d18e75dc",
|
||||
"url": "https://api.github.com/repos/tp5er/tp5-databackup/zipball/101477abe810fb91bad5c1304a93c5f461db6dc8",
|
||||
"reference": "101477abe810fb91bad5c1304a93c5f461db6dc8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"time": "2017-12-29T05:36:58+00:00",
|
||||
"time": "2018-04-07T11:20:53+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"installation-source": "source",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"tp5er\\": "src/"
|
||||
@ -1149,23 +1149,24 @@
|
||||
},
|
||||
{
|
||||
"name": "xaboy/form-builder",
|
||||
"version": "1.2.3",
|
||||
"version_normalized": "1.2.3.0",
|
||||
"version": "1.2.5",
|
||||
"version_normalized": "1.2.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/xaboy/form-builder.git",
|
||||
"reference": "1b11a518429db5828147d5840ea18480586caa0c"
|
||||
"reference": "73cb5be3d9f57680f64d01ab424c4ac5c462f1b8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/xaboy/form-builder/zipball/1b11a518429db5828147d5840ea18480586caa0c",
|
||||
"reference": "1b11a518429db5828147d5840ea18480586caa0c",
|
||||
"url": "https://api.github.com/repos/xaboy/form-builder/zipball/73cb5be3d9f57680f64d01ab424c4ac5c462f1b8",
|
||||
"reference": "73cb5be3d9f57680f64d01ab424c4ac5c462f1b8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"time": "2018-08-07T06:29:30+00:00",
|
||||
"time": "2018-11-13T12:44:31+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
|
||||
18
vendor/xaboy/form-builder/README.md
vendored
18
vendor/xaboy/form-builder/README.md
vendored
@ -1,5 +1,9 @@
|
||||
# form-builder
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/xaboy/form-builder">
|
||||
<img width="200" src="http://file.lotkk.com/form-builder.png">
|
||||
</a>
|
||||
</p>
|
||||
<h1 align="center">form-builder</h1>
|
||||
<p align="center">
|
||||
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="MIT" />
|
||||
<a href="https://github.com/xaboy">
|
||||
@ -17,19 +21,22 @@
|
||||
PHP表单生成器,快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及省市区三级联动、时间选择、日期选择、颜色选择、树型、文件/图片上传等功能。
|
||||
</p>
|
||||
|
||||
> 1.2.4 版本支持简单字段验证
|
||||
|
||||
#### 如果对您有帮助,您可以点右上角 "Star" 支持一下 谢谢!
|
||||
|
||||
#### 本项目还在不断开发完善中,如有建议或问题请[在这里提出](https://github.com/xaboy/form-builder/issues/new)
|
||||
|
||||
|
||||
## 安装
|
||||
`composer require xaboy/form-builder`
|
||||
|
||||
## 示例
|
||||
|
||||

|
||||

|
||||
|
||||
## 演示地址
|
||||
演示站后台:[ crmeb_v2.5 ]
|
||||
http://demo25.crmeb.net 账号:demo 密码:crmeb.com
|
||||
|
||||
### 例子 (TP框架)
|
||||
|
||||
@ -267,7 +274,8 @@ echo $html;
|
||||
## 以下组件公共方法
|
||||
* **col($span)** 配置col栅格规则,传入0-24的数字或`Col`类,默认为24
|
||||
* **value($value)** 设置组件的值
|
||||
* **validate(array $validate)** 添加验证规则
|
||||
* **validateAs(array $validate)** 添加验证规则
|
||||
* **validate()** 设置验证规则[规则说明](https://github.com/xaboy/form-builder/blob/master/src/components/Validate.php)
|
||||
|
||||
## 组件
|
||||
`namespace \FormBuilder\Form`
|
||||
|
||||
7
vendor/xaboy/form-builder/composer.json
vendored
7
vendor/xaboy/form-builder/composer.json
vendored
@ -2,7 +2,7 @@
|
||||
"name": "xaboy/form-builder",
|
||||
"description": "PHP表单生成器,快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。",
|
||||
"license": "MIT",
|
||||
"keyword": ["form","form-create","form-init","dynamic-form"],
|
||||
"keyword": ["form","form-create","form-init","dynamic-form","php-form"],
|
||||
"homepage": "https://github.com/xaboy/form-builder",
|
||||
"authors": [
|
||||
{
|
||||
@ -20,10 +20,11 @@
|
||||
"source": "https://github.com/xaboy/form-builder"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0"
|
||||
"php": ">=5.4.0",
|
||||
"ext-json": "*"
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
"master": "1.0.x-dev"
|
||||
}
|
||||
}
|
||||
|
||||
118
vendor/xaboy/form-builder/src/Form.php
vendored
118
vendor/xaboy/form-builder/src/Form.php
vendored
@ -9,6 +9,7 @@ namespace FormBuilder;
|
||||
|
||||
use FormBuilder\components\Cascader;
|
||||
use FormBuilder\components\FormStyle;
|
||||
use FormBuilder\components\Hidden;
|
||||
use FormBuilder\components\Row;
|
||||
use FormBuilder\traits\form\FormCascaderTrait;
|
||||
use FormBuilder\traits\form\FormCheckBoxTrait;
|
||||
@ -28,6 +29,7 @@ use FormBuilder\traits\form\FormTimePickerTrait;
|
||||
use FormBuilder\traits\form\FormTreeTrait;
|
||||
use FormBuilder\traits\form\FormUploadTrait;
|
||||
use FormBuilder\traits\form\FormOptionTrait;
|
||||
use FormBuilder\traits\form\FormValidateTrait;
|
||||
|
||||
/**
|
||||
* Class Form
|
||||
@ -52,7 +54,8 @@ class Form
|
||||
FormTimePickerTrait,
|
||||
FormTreeTrait,
|
||||
FormStyleTrait,
|
||||
FormOptionTrait;
|
||||
FormOptionTrait,
|
||||
FormValidateTrait;
|
||||
|
||||
/**
|
||||
* 三级联动 加载省市数据
|
||||
@ -85,12 +88,30 @@ class Form
|
||||
//iview 版本 2.14.3
|
||||
'iview-css' => '<link href="https://cdn.jsdelivr.net/npm/iview@2.14.3/dist/styles/iview.css" rel="stylesheet">',
|
||||
'iview' => '<script src="https://cdn.jsdelivr.net/npm/iview@2.14.3/dist/iview.min.js"></script>',
|
||||
//form-create 版本 1.3.3
|
||||
'form-create' => '<script src="https://cdn.jsdelivr.net/npm/form-create@1.4.0/dist/form-create.min.js"></script>',
|
||||
//form-create 版本 1.4.5
|
||||
'form-create' => '<script src="https://cdn.jsdelivr.net/npm/form-create@1.4.5/dist/form-create.min.js"></script>',
|
||||
'city-data' => '<script src="https://cdn.jsdelivr.net/npm/form-create/district/province_city.js"></script>',
|
||||
'city-area-data' => '<script src="https://cdn.jsdelivr.net/npm/form-create/district/province_city_area.js"></script>'
|
||||
];
|
||||
|
||||
/**
|
||||
* 加载 jquery
|
||||
* @var bool
|
||||
*/
|
||||
protected $linkJq = true;
|
||||
|
||||
/**
|
||||
* 加载 vue
|
||||
* @var bool
|
||||
*/
|
||||
protected $linkVue = true;
|
||||
|
||||
/**
|
||||
* 加载 iview
|
||||
* @var bool
|
||||
*/
|
||||
protected $linkIview = true;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -120,6 +141,10 @@ class Form
|
||||
*/
|
||||
protected $method = 'post';
|
||||
|
||||
protected $resetBtn = false;
|
||||
|
||||
protected $submitBtn = true;
|
||||
|
||||
/**
|
||||
* 表单配置
|
||||
* @var array|mixed
|
||||
@ -146,6 +171,30 @@ class Form
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $linkJq
|
||||
*/
|
||||
public function setLinkJq($linkJq)
|
||||
{
|
||||
$this->linkJq = (bool)$linkJq;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $linkVue
|
||||
*/
|
||||
public function setLinkVue($linkVue)
|
||||
{
|
||||
$this->linkVue = (bool)$linkVue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $linkIview
|
||||
*/
|
||||
public function setLinkIview($linkIview)
|
||||
{
|
||||
$this->linkIview = (bool)$linkIview;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@ -334,6 +383,7 @@ class Form
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否需要引入省市区数据
|
||||
* @param FormComponentDriver $component
|
||||
*/
|
||||
protected function checkLoadData(FormComponentDriver $component)
|
||||
@ -361,7 +411,10 @@ class Form
|
||||
$component = $this->components[$field];
|
||||
if (!($component instanceof FormComponentDriver))
|
||||
continue;
|
||||
$rules[] = $component->build();
|
||||
$rule = $component->build();
|
||||
if(!$component instanceof Hidden)
|
||||
$rule['validate'] = array_merge(isset($rule['validate']) ? $rule['validate'] : [],$component->validate()->build());
|
||||
$rules[] = $rule;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
@ -397,7 +450,6 @@ class Form
|
||||
{
|
||||
ob_start();
|
||||
$form = $this;
|
||||
$rule = $this->getRules();
|
||||
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'formScript.php';
|
||||
$script = ob_get_clean();
|
||||
return $script;
|
||||
@ -412,17 +464,61 @@ class Form
|
||||
{
|
||||
$_script = $this->script;
|
||||
$script = [
|
||||
$_script['iview-css'],
|
||||
$_script['jq'],
|
||||
$_script['vue'],
|
||||
$_script['iview'],
|
||||
$_script['form-create']
|
||||
];
|
||||
if ($this->loadCityAreaData == true)
|
||||
$script[] = $_script['city-area-data'];
|
||||
if ($this->loadCityData == true)
|
||||
$script[] = $_script['city-data'];
|
||||
return $script;
|
||||
if($this->linkJq)
|
||||
$script[] = $_script['jq'];
|
||||
if($this->linkIview){
|
||||
$script[] = $_script['iview'];
|
||||
$script[] = $_script['iview-css'];
|
||||
}
|
||||
if($this->linkVue)
|
||||
$script[] = $_script['vue'];
|
||||
return array_reverse($script);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否隐藏提交按钮(默认显示)
|
||||
* @param bool $isShow
|
||||
* @return Form
|
||||
*/
|
||||
public function hiddenSubmitBtn($isShow = false)
|
||||
{
|
||||
$this->submitBtn = !(bool)$isShow;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否隐藏重置按钮(默认隐藏)
|
||||
* @param bool $isShow
|
||||
* @return Form
|
||||
*/
|
||||
public function hiddenResetBtn($isShow = false)
|
||||
{
|
||||
$this->resetBtn = !(bool)$isShow;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isResetBtn()
|
||||
{
|
||||
return $this->resetBtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSubmitBtn()
|
||||
{
|
||||
return $this->submitBtn;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -433,6 +529,6 @@ class Form
|
||||
*/
|
||||
public static function create($action, array $components = [])
|
||||
{
|
||||
return new self($action, $components);
|
||||
return new static($action, $components);
|
||||
}
|
||||
}
|
||||
@ -8,11 +8,13 @@
|
||||
namespace FormBuilder;
|
||||
|
||||
use FormBuilder\components\Col;
|
||||
use FormBuilder\components\Validate;
|
||||
use FormBuilder\interfaces\FormComponentInterFace;
|
||||
use FormBuilder\traits\component\CallPropsTrait;
|
||||
|
||||
/**
|
||||
* Class FormComponentDriver
|
||||
*
|
||||
* @package FormBuilder
|
||||
*/
|
||||
abstract class FormComponentDriver implements FormComponentInterFace
|
||||
@ -20,54 +22,66 @@ abstract class FormComponentDriver implements FormComponentInterFace
|
||||
use CallPropsTrait;
|
||||
/**
|
||||
* 字段名
|
||||
*
|
||||
* @var String
|
||||
*/
|
||||
protected $field;
|
||||
|
||||
/**
|
||||
* 字段昵称
|
||||
*
|
||||
* @var String
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* 组件名称
|
||||
*
|
||||
* @var String
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* 组件的规则
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $props = [];
|
||||
|
||||
/**
|
||||
* 字段的值
|
||||
*
|
||||
* @var
|
||||
*/
|
||||
protected $value = '';
|
||||
|
||||
/**
|
||||
* 栅格规则
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $col = [];
|
||||
|
||||
/**
|
||||
* 字段验证规则
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $validate = [];
|
||||
|
||||
|
||||
protected $validateHandler = null;
|
||||
|
||||
/**
|
||||
* 组件属性设置规则
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $propsRule = [];
|
||||
|
||||
/**
|
||||
* FormComponentDriver constructor.
|
||||
*
|
||||
* @param String $field 字段名
|
||||
* @param String $title 字段昵称
|
||||
* @param String $value 字段值
|
||||
@ -94,9 +108,9 @@ abstract class FormComponentDriver implements FormComponentInterFace
|
||||
*/
|
||||
public function col($span)
|
||||
{
|
||||
if($span instanceof Col)
|
||||
if ($span instanceof Col)
|
||||
$this->col = $span->build();
|
||||
else if(is_numeric($span))
|
||||
else if (is_numeric($span))
|
||||
$this->col['span'] = $span;
|
||||
return $this;
|
||||
}
|
||||
@ -104,6 +118,7 @@ abstract class FormComponentDriver implements FormComponentInterFace
|
||||
|
||||
/**
|
||||
* 批量设置组件的规则
|
||||
*
|
||||
* @param array $props
|
||||
* @return $this
|
||||
*/
|
||||
@ -117,6 +132,7 @@ abstract class FormComponentDriver implements FormComponentInterFace
|
||||
|
||||
/**
|
||||
* 获取组件的规则
|
||||
*
|
||||
* @param $name
|
||||
* @return mixed|null
|
||||
*/
|
||||
@ -127,7 +143,8 @@ abstract class FormComponentDriver implements FormComponentInterFace
|
||||
|
||||
/**
|
||||
* 设置组件的值
|
||||
* @param $value
|
||||
*
|
||||
* @param $value
|
||||
* @param string $default
|
||||
* @return $this
|
||||
*/
|
||||
@ -140,6 +157,7 @@ abstract class FormComponentDriver implements FormComponentInterFace
|
||||
|
||||
/**
|
||||
* 获取组件的值
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
@ -149,6 +167,7 @@ abstract class FormComponentDriver implements FormComponentInterFace
|
||||
|
||||
/**
|
||||
* 获取组件的字段名
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getField()
|
||||
@ -158,6 +177,7 @@ abstract class FormComponentDriver implements FormComponentInterFace
|
||||
|
||||
/**
|
||||
* 设置组件的昵称
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getTitle()
|
||||
@ -166,40 +186,63 @@ abstract class FormComponentDriver implements FormComponentInterFace
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $required
|
||||
* @param string|null $message
|
||||
* @return $this
|
||||
*/
|
||||
public function required($required = true)
|
||||
public function required($message = null)
|
||||
{
|
||||
$this->props['required'] = (bool)$required;
|
||||
$this->validate()->required($message ?: $this->getPlaceHolder());
|
||||
$this->props['required'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置组件的值为必填
|
||||
* @param null $message
|
||||
* @return $this
|
||||
* @param string $pre
|
||||
* @return string
|
||||
*/
|
||||
protected function setRequired($message = '', $trigger = 'change', $type = null)
|
||||
protected function getPlaceHolder($pre = '请选择')
|
||||
{
|
||||
$validate = [
|
||||
'required' => true,
|
||||
'message' => $message,
|
||||
'trigger' => $trigger
|
||||
];
|
||||
if ($type !== null) $validate['type'] = $type;
|
||||
$this->validate[] = $validate;
|
||||
return $this;
|
||||
return $pre . $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加验证规则
|
||||
*
|
||||
* @param array $validate
|
||||
* @return $this
|
||||
*/
|
||||
public function validate(array $validate)
|
||||
public function validateAs(array $validate)
|
||||
{
|
||||
$this->validate = array_merge($this->validate,$validate);
|
||||
$this->validate = array_merge($this->validate, $validate);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Validate
|
||||
*/
|
||||
abstract protected function getValidateHandler();
|
||||
|
||||
/**
|
||||
* @param bool $clear
|
||||
* @return Validate
|
||||
*/
|
||||
public function validate($clear = false)
|
||||
{
|
||||
if ($clear || is_null($this->validateHandler))
|
||||
$this->validateHandler = $this->getValidateHandler();
|
||||
|
||||
return $this->validateHandler;
|
||||
}
|
||||
|
||||
public function validateFn($callback, $clear = false)
|
||||
{
|
||||
if (is_callable($callback)) $callback($this->validate($clear));
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setValidate(Validate $validate)
|
||||
{
|
||||
$this->validateHandler = $validate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
7
vendor/xaboy/form-builder/src/Helper.php
vendored
7
vendor/xaboy/form-builder/src/Helper.php
vendored
@ -28,11 +28,6 @@ class Helper
|
||||
return $var;
|
||||
}
|
||||
|
||||
public static function getVar($var, $default)
|
||||
{
|
||||
return $var === null ? $default : $var;
|
||||
}
|
||||
|
||||
public static function getVarType($var)
|
||||
{
|
||||
if (is_array($var)) return 'array';
|
||||
@ -56,7 +51,7 @@ class Helper
|
||||
}
|
||||
$type = self::getVarType($var);
|
||||
if (!in_array($type, $verify))
|
||||
throw new \Exception($title . '类型不为' . implode(',', $verify));
|
||||
throw new \Exception($title . '类型需为' . implode(',', $verify));
|
||||
}
|
||||
|
||||
public static function getDate($date)
|
||||
|
||||
8
vendor/xaboy/form-builder/src/Json.php
vendored
8
vendor/xaboy/form-builder/src/Json.php
vendored
@ -17,22 +17,22 @@ class Json
|
||||
|
||||
public static function succ($msg, $data = [])
|
||||
{
|
||||
return self::result(200, $msg, $data);
|
||||
return static::result(200, $msg, $data);
|
||||
}
|
||||
|
||||
public static function fail($msg, $data = [])
|
||||
{
|
||||
return self::result(400, $msg, $data);
|
||||
return static::result(400, $msg, $data);
|
||||
}
|
||||
|
||||
public static function uploadSucc($filePath, $msg = '上传成功', $data = [])
|
||||
{
|
||||
$data['filePath'] = $filePath;
|
||||
return self::succ($msg, $data);
|
||||
return static::succ($msg, $data);
|
||||
}
|
||||
|
||||
public static function uploadFail($msg = '上传失败', $data = [])
|
||||
{
|
||||
return self::fail($msg, $data);
|
||||
return static::fail($msg, $data);
|
||||
}
|
||||
}
|
||||
@ -75,22 +75,7 @@ class Cascader extends FormComponentDriver
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$this->placeholder('请选择' . $this->title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param string $trigger
|
||||
* @return $this
|
||||
*/
|
||||
public function required($message = null, $trigger = 'change')
|
||||
{
|
||||
$this->setRequired(
|
||||
Helper::getVar($message, $this->props['placeholder']),
|
||||
$trigger,
|
||||
'array'
|
||||
);
|
||||
return $this;
|
||||
$this->placeholder($this->getPlaceHolder());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,6 +125,14 @@ class Cascader extends FormComponentDriver
|
||||
return $this->props['type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Validate
|
||||
*/
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
return Validate::arr();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@ -56,15 +56,9 @@ class Checkbox extends FormComponentDriver
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $message
|
||||
* @param string $trigger
|
||||
* @return $this
|
||||
*/
|
||||
public function required($message = null, $trigger = 'change')
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
$this->setRequired(Helper::getVar($message,'请选择'.$this->title),$trigger,'array');
|
||||
return $this;
|
||||
return Validate::arr();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -60,15 +60,9 @@ class ColorPicker extends FormComponentDriver
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param string $trigger
|
||||
* @return $this
|
||||
*/
|
||||
public function required($message = null, $trigger = 'change')
|
||||
public function getValidateHandler()
|
||||
{
|
||||
parent::setRequired(Helper::getVar($message, '请选择' . $this->title), $trigger);
|
||||
return $this;
|
||||
return Validate::str();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -94,7 +94,7 @@ class DatePicker extends FormComponentDriver
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$this->placeholder('请选择' . $this->title);
|
||||
$this->placeholder($this->getPlaceHolder());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,6 +114,14 @@ class DatePicker extends FormComponentDriver
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getValidateHandler()
|
||||
{
|
||||
if(in_array($this->props['type'],['datetimerange','daterange']))
|
||||
return Validate::arr();
|
||||
else
|
||||
return Validate::date();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@ -87,7 +87,12 @@ class Frame extends FormComponentDriver
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$this->frameTitle('请选择' . $this->title);
|
||||
$this->frameTitle($this->getPlaceHolder());
|
||||
}
|
||||
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
return Validate::arr();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -34,6 +34,11 @@ class Hidden extends FormComponentDriver
|
||||
static::value($value);
|
||||
}
|
||||
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@ -94,34 +94,33 @@ class Input extends FormComponentDriver
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$this->placeholder('请输入' . $this->title);
|
||||
$this->placeholder($this->getPlaceHolder());
|
||||
}
|
||||
|
||||
protected function getPlaceHolder($pre = '请输入')
|
||||
{
|
||||
return parent::getPlaceHolder($pre);
|
||||
}
|
||||
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
return Validate::str(Validate::TRIGGER_BLUR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自适应内容高度,仅在 textarea 类型下有效
|
||||
* @param Number $minRows
|
||||
* @param Number $maxRows
|
||||
* @param Bool|Number $minRows
|
||||
* @param null|Number $maxRows
|
||||
* @return $this
|
||||
*/
|
||||
public function autoSize($minRows, $maxRows)
|
||||
public function autoSize($minRows = false, $maxRows = null)
|
||||
{
|
||||
$this->props['autosize'] = compact('minRows', 'maxRows');
|
||||
|
||||
$this->props['autosize'] = $maxRows === null ? boolval($minRows) : compact('minRows', 'maxRows');
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组件的值为必填
|
||||
* @param string $message
|
||||
* @return $this
|
||||
*/
|
||||
public function required($message = null, $trigger = 'blur')
|
||||
{
|
||||
parent::setRequired(Helper::getVar($message, $this->getProps('placeholder')), $trigger);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成表单规则
|
||||
* @return array
|
||||
|
||||
@ -51,7 +51,17 @@ class InputNumber extends FormComponentDriver
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$this->placeholder('请输入' . $this->title);
|
||||
$this->placeholder($this->getPlaceHolder());
|
||||
}
|
||||
|
||||
protected function getPlaceHolder($pre = '请输入')
|
||||
{
|
||||
return parent::getPlaceHolder($pre);
|
||||
}
|
||||
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
return Validate::num(Validate::TRIGGER_BLUR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -46,15 +46,9 @@ class Radio extends FormComponentDriver
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param string $trigger
|
||||
* @return $this
|
||||
*/
|
||||
public function required($message = null, $trigger = 'change')
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
$this->setRequired(Helper::getVar($message, '请选择' . $this->title), $trigger);
|
||||
return $this;
|
||||
return Validate::str();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -39,6 +39,11 @@ class Rate extends FormComponentDriver
|
||||
'clearable' => 'boolean',
|
||||
];
|
||||
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
return Validate::num();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@ -68,7 +68,7 @@ class Select extends FormComponentDriver
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$this->placeholder('请选择' . $this->title);
|
||||
$this->placeholder($this->getPlaceHolder());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,19 +89,12 @@ class Select extends FormComponentDriver
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null $message
|
||||
* @param string $trigger
|
||||
* @return $this
|
||||
*/
|
||||
public function required($message = null, $trigger = 'change')
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
$this->setRequired(
|
||||
Helper::getVar($message, '请选择' . $this->title),
|
||||
$trigger,
|
||||
$this->props['multiple'] == true ? 'array' : null
|
||||
);
|
||||
return $this;
|
||||
if($this->props['multiple'] == true)
|
||||
return Validate::arr();
|
||||
else
|
||||
return Validate::str();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -65,6 +65,14 @@ class Slider extends FormComponentDriver
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
if($this->props['range'] == true)
|
||||
return Validate::arr();
|
||||
else
|
||||
return Validate::num();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@ -70,6 +70,11 @@ class Switches extends FormComponentDriver
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
return Validate::str();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@ -75,7 +75,7 @@ class TimePicker extends FormComponentDriver
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$this->placeholder('请选择' . $this->title);
|
||||
$this->placeholder($this->getPlaceHolder());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,6 +109,14 @@ class TimePicker extends FormComponentDriver
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
if($this->props['type'] == 'timerange')
|
||||
return Validate::arr();
|
||||
else
|
||||
return Validate::str();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@ -40,7 +40,8 @@ class Tree extends FormComponentDriver
|
||||
*/
|
||||
protected $props = [
|
||||
'type' => self::TYPE_CHECKED,
|
||||
'data' => []
|
||||
'data' => [],
|
||||
'multiple'=>true
|
||||
];
|
||||
|
||||
/**
|
||||
@ -95,6 +96,14 @@ class Tree extends FormComponentDriver
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
if($this->props['multiple'])
|
||||
return Validate::arr();
|
||||
else
|
||||
return Validate::str();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@ -112,15 +112,9 @@ class Upload extends FormComponentDriver
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $message
|
||||
* @param string $trigger
|
||||
* @return $this
|
||||
*/
|
||||
public function required($message = null, $trigger = 'change')
|
||||
protected function getPlaceHolder($pre = '请上传')
|
||||
{
|
||||
parent::setRequired(Helper::getVar($message, '请上传' . $this->title), $trigger, 'array');
|
||||
return $this;
|
||||
return parent::getPlaceHolder($pre);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,6 +127,14 @@ class Upload extends FormComponentDriver
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getValidateHandler()
|
||||
{
|
||||
if($this->props['maxLength'] == 1)
|
||||
return Validate::str();
|
||||
else
|
||||
return Validate::arr();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
130
vendor/xaboy/form-builder/src/view/formScript.php
vendored
130
vendor/xaboy/form-builder/src/view/formScript.php
vendored
@ -1,77 +1,71 @@
|
||||
(function () {
|
||||
var getRule = function () {
|
||||
var rule = <?=json_encode($rule)?>;
|
||||
var rule = <?=json_encode($form->getRules())?>;
|
||||
rule.forEach(function (c) {
|
||||
if((c.type == 'cascader' || c.type == 'tree') && Object.prototype.toString.call(c.props.data) == '[object String]'){
|
||||
if(c.props.data.indexOf('js.') === 0){
|
||||
c.props.data = window[c.props.data.replace('js.','')];
|
||||
}
|
||||
if ((c.type == 'cascader' || c.type == 'tree') && Object.prototype.toString.call(c.props.data) == '[object String]') {
|
||||
if (c.props.data.indexOf('js.') === 0) {
|
||||
c.props.data = window[c.props.data.replace('js.', '')];
|
||||
}
|
||||
}
|
||||
});
|
||||
return rule;
|
||||
},vm = new Vue;
|
||||
return function create(el,callback) {
|
||||
var formData = {};
|
||||
if(!el) el = document.body;
|
||||
$f = formCreate.create(getRule(),{
|
||||
el:el,
|
||||
form:<?=json_encode($form->getConfig('form'))?>,
|
||||
row:<?=json_encode($form->getConfig('row'))?>,
|
||||
upload:{
|
||||
onExceededSize:function (file) {
|
||||
vm.$Message.error(file.name + '超出指定大小限制');
|
||||
},
|
||||
onFormatError:function () {
|
||||
vm.$Message.error(file.name + '格式验证失败');
|
||||
},
|
||||
onError:function (error) {
|
||||
vm.$Message.error(file.name + '上传失败,('+ error +')');
|
||||
},
|
||||
onSuccess:function (res) {
|
||||
if(res.code == 200){
|
||||
return res.data.filePath;
|
||||
}else{
|
||||
vm.$Message.error(res.msg);
|
||||
}
|
||||
}
|
||||
},
|
||||
//表单提交事件
|
||||
onSubmit: function (formData) {
|
||||
$f.submitStatus({loading: true});
|
||||
$.ajax({
|
||||
url:'<?=$form->getAction()?>',
|
||||
type:'<?=$form->getMethod()?>',
|
||||
dataType:'json',
|
||||
data:formData,
|
||||
success:function (res) {
|
||||
if(res.code == 200){
|
||||
vm.$Message.success(res.msg);
|
||||
formCreate.formSuccess && formCreate.formSuccess(res,$f,formData);
|
||||
callback && callback(0,res,$f,formData);
|
||||
$f.submitStatus({loading: false});
|
||||
var index = parent.layer.getFrameIndex(window.name);
|
||||
parent.layer.close(index);
|
||||
try{
|
||||
parent.formSuccess();
|
||||
}catch(e){
|
||||
console.log(e);
|
||||
}
|
||||
//TODO 表单提交成功!
|
||||
}else{
|
||||
vm.$Message.error(res.msg);
|
||||
$f.btn.finish();
|
||||
callback && callback(1,res,$f,formData);
|
||||
$f.submitStatus({loading: false});
|
||||
//TODO 表单提交失败
|
||||
}
|
||||
}, vm = new Vue,name = 'formBuilderExec<?= !$form->getId() ? '' : '_'.$form->getId() ?>';
|
||||
|
||||
window[name] = function create(el, callback) {
|
||||
if (!el) el = document.body;
|
||||
$f = formCreate.create(getRule(), {
|
||||
el: el,
|
||||
form:<?=json_encode($form->getConfig('form'))?>,
|
||||
row:<?=json_encode($form->getConfig('row'))?>,
|
||||
submitBtn:<?=$form->isSubmitBtn() ? '{}' : 'false'?>,
|
||||
resetBtn:<?=$form->isResetBtn() ? 'true' : '{}'?>,
|
||||
upload: {
|
||||
onExceededSize: function (file) {
|
||||
vm.$Message.error(file.name + '超出指定大小限制');
|
||||
},
|
||||
error:function () {
|
||||
vm.$Message.error('表单提交失败');
|
||||
$f.btn.finish();
|
||||
onFormatError: function () {
|
||||
vm.$Message.error(file.name + '格式验证失败');
|
||||
},
|
||||
onError: function (error) {
|
||||
vm.$Message.error(file.name + '上传失败,(' + error + ')');
|
||||
},
|
||||
onSuccess: function (res) {
|
||||
if (res.code == 200) {
|
||||
return res.data.filePath;
|
||||
} else {
|
||||
vm.$Message.error(res.msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return formData;
|
||||
},
|
||||
//表单提交事件
|
||||
onSubmit: function (formData) {
|
||||
$f.submitStatus({loading: true});
|
||||
$.ajax({
|
||||
url: '<?=$form->getAction()?>',
|
||||
type: '<?=$form->getMethod()?>',
|
||||
dataType: 'json',
|
||||
data: formData,
|
||||
success: function (res) {
|
||||
if (res.code == 200) {
|
||||
vm.$Message.success(res.msg);
|
||||
formCreate.formSuccess && formCreate.formSuccess(res, $f, formData);
|
||||
callback && callback(0, res, $f, formData);
|
||||
//TODO 表单提交成功!
|
||||
} else {
|
||||
vm.$Message.error(res.msg);
|
||||
$f.btn.finish();
|
||||
callback && callback(1, res, $f, formData);
|
||||
//TODO 表单提交失败
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
vm.$Message.error('表单提交失败');
|
||||
$f.btn.finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return $f;
|
||||
};
|
||||
}());
|
||||
return window[name];
|
||||
}());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user