diff --git a/src/addons/Route.php b/src/addons/Route.php index b399df4..6d820bc 100644 --- a/src/addons/Route.php +++ b/src/addons/Route.php @@ -51,9 +51,9 @@ public static function execute($addon = null, $controller = null, $action = null } // 监听addon_module_init Event::trigger('addon_module_init', $request); - $class = get_addons_class($addon, 'controller', $controller,$module); + $class = get_addons_class($addon, 'controller', $controller); if (!$class) { - throw new HttpException(404, lang('addon controller %s not found', [Str::studly($module.DS.$controller)])); + throw new HttpException(404, lang('addon controller %s not found', [Str::studly($addon.DS.$controller)])); } //加载app配置 // 重写视图基础路径 diff --git a/src/helper.php b/src/helper.php index 54ec55c..84a1802 100644 --- a/src/helper.php +++ b/src/helper.php @@ -218,7 +218,7 @@ function get_addons_instance($name) * @param string $class 当前类名 * @return string */ - function get_addons_class($name, $type = 'hook', $class = null, $module = 'backend') + function get_addons_class($name, $type = 'hook', $class = null) { $name = trim($name); // 处理多级控制器情况 @@ -232,14 +232,11 @@ function get_addons_class($name, $type = 'hook', $class = null, $module = 'backe } switch ($type) { case 'controller': - if($module){ - $namespace = '\\addons\\' . $name . '\\' . $module . '\\controller\\' . $class; - }else{ - $namespace = '\\addons\\' . $name . '\\controller\\' . $class; - } + $namespace = '\\addons\\' . $name . '\\controller\\' . $class; break; default: $namespace = '\\addons\\' . $name . '\\Plugin'; + break; } return class_exists($namespace) ? $namespace : ''; @@ -1108,6 +1105,6 @@ function form_selectpage($name = 'selectpage', $list = [], $options = [], $value */ function form_autocomplete($name = 'autocomplete', $list = [], $options = [], $value=null) { - return Form::autocomplete( $name, $list , $options ,$attr ,$value) ; + return Form::autocomplete( $name, $list , $options ,$value) ; } } diff --git a/src/helper/FormHelper.php b/src/helper/FormHelper.php index dd2dfcb..eb5eb7f 100644 --- a/src/helper/FormHelper.php +++ b/src/helper/FormHelper.php @@ -6,7 +6,7 @@ * 版权所有 2017-2028 FunAdmin,并保留所有权利。 * 网站地址: http://www.funadmin.com * ---------------------------------------------------------------------------- - * 采用最新Thinkphp6 + layui 实现 + * 采用最新Thinkphp8 + layui 实现 * ============================================================================ * Author: yuege * Date: 2019/9/22 @@ -24,6 +24,7 @@ class FormHelper * @var array */ protected static $instance; + /** * 获取单例 * @param array $options @@ -37,6 +38,7 @@ public static function instance($options = []) return self::$instance; } + /** * @param $name * @param $value @@ -48,36 +50,36 @@ public static function instance($options = []) * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function config($name='',$options=[],$value='') + public function config($name = '', $options = [], $value = '') { - $where = ['code'=>$name]; + $where = ['code' => $name]; $data = \app\common\model\Config::where($where)->find(); - if(!$data) return ''; - $extra=[]; - if(!empty($options['extra'])){ + if (!$data) return ''; + $extra = []; + if (!empty($options['extra'])) { $data['extra'] = $options['extra']; } - if ($data['extra'] && is_string($data['extra'])){ - $arr = array_filter(explode("\n",str_replace("\r",'',$data['extra']))); - foreach ($arr as $v){ - $kk = explode(':',$v); + if ($data['extra'] && is_string($data['extra'])) { + $arr = array_filter(explode("\n", str_replace("\r", '', $data['extra']))); + foreach ($arr as $v) { + $kk = explode(':', $v); $extra[$kk[0]] = $kk[1]; } } - $options['verify'] = $options['verify']??$data['verify']; - $options['label'] = $options['label']??$data['remark']; - $value = $value?:$data['value']; + $options['verify'] = $options['verify'] ?? $data['verify']; + $options['label'] = $options['label'] ?? $data['remark']; + $value = $value ?: $data['value']; switch ($data['type']) { case'switch': - $list = ($options['list']??$extra); - $form = $this->switchs($name,$list,$options,$value); + $list = ($options['list'] ?? $extra); + $form = $this->switchs($name, $list, $options, $value); break; case'radio': - $list = ($options['list']??$extra); - $form = $this->radio($name,$list,$options,$value); + $list = ($options['list'] ?? $extra); + $form = $this->radio($name, $list, $options, $value); break; case 'hidden': - $form = $this->hidden($name, $options, $value); + $form = $this->hidden($name, $options, $value); break; case 'float': case 'decimal': @@ -85,128 +87,128 @@ public function config($name='',$options=[],$value='') $form = $this->number($name, $options, $value); break; case 'select': - $attr = $options['attr']??['id','title']; - $list = ($options['list']??$extra); - $form = $this->multiselect($name,$list,$options,$attr,$value); + $attr = $options['attr'] ?? ['id', 'title']; + $list = ($options['list'] ?? $extra); + $form = $this->multiselect($name, $list, $options, $attr, $value); break; case 'selects': $options['multiple'] = 'multiple'; - $attr = $options['attr']??['id','title']; - $list = ($options['list']??$extra); - $form = $this->multiselect($name,$list,$options,$attr,$value); + $attr = $options['attr'] ?? ['id', 'title']; + $list = ($options['list'] ?? $extra); + $form = $this->multiselect($name, $list, $options, $attr, $value); break; case 'xmselect': - $attr = $options['attr']??['id','title']; - $list = ($options['list']??$extra); - $form = $this->xmselect($name,$list, $options,$attr,$value); + $attr = $options['attr'] ?? ['id', 'title']; + $list = ($options['list'] ?? $extra); + $form = $this->xmselect($name, $list, $options, $attr, $value); break; case 'selectpage': - $list = ($options['list']??$extra); - $form = $this->selectpage($name,$list,$options,$value); + $list = ($options['list'] ?? $extra); + $form = $this->selectpage($name, $list, $options, $value); break; case 'tags': - $form = $this->tags($name, $options,$value); + $form = $this->tags($name, $options, $value); break; case 'checkbox': - $list = ($options['list']??$extra); - $form = $this->checkbox($name,$list, $options,$value); + $list = ($options['list'] ?? $extra); + $form = $this->checkbox($name, $list, $options, $value); break; case 'textarea': - $form = $this->textarea($name, $options,$value); + $form = $this->textarea($name, $options, $value); break; case 'range': - $form = $this->range($name, $options, $value); + $form = $this->range($name, $options, $value); break; case 'daterange': $options['type'] = 'datetime'; $options['range'] = true; - $form = $this->date($name, $options,$value); + $form = $this->date($name, $options, $value); break; case 'year': $options['type'] = 'year'; - $form = $this->date($name, $options,$value); + $form = $this->date($name, $options, $value); break; case 'month': $options['type'] = 'month'; - $form = $this->date($name, $options,$value); + $form = $this->date($name, $options, $value); break; case 'time': $options['type'] = 'time'; - $form = $this->date($name, $options,$value); + $form = $this->date($name, $options, $value); break; case 'date': case 'datetime': $options['type'] = 'datetime'; - $form = $this->date($name, $options,$value); + $form = $this->date($name, $options, $value); break; case 'password': - $form = $this->password($name, $options,$value); + $form = $this->password($name, $options, $value); break; case 'image': case 'file': - $form = $this->upload($name,$options,$value); + $form = $this->upload($name, $options, $value); break; case "images": case 'files': $options['num'] = 100; - $form = $this->upload($name,$options,$value); + $form = $this->upload($name, $options, $value); break; case 'editor': - $form = $this->editor($name,$options,$value); + $form = $this->editor($name, $options, $value); break; case 'color': - $form = $this->color($name,$options,$value); + $form = $this->color($name, $options, $value); break; case 'icon': - $form = $this->icon($name,$options,$value); + $form = $this->icon($name, $options, $value); break; case 'token': - $form = $this->token($name,$value); + $form = $this->token($name, $value); break; case 'email': - $form = $this->email($name,$options,$value); + $form = $this->email($name, $options, $value); break; case 'tel': - $form = $this->tel($name,$options,$value); + $form = $this->tel($name, $options, $value); break; case 'url': - $form = $this->url($name,$options,$value); + $form = $this->url($name, $options, $value); break; case 'rate': - $form = $this->rate($name,$options,$value); + $form = $this->rate($name, $options, $value); break; case 'slider': - $form = $this->slider($name,$options,$value); + $form = $this->slider($name, $options, $value); break; case 'arrays': case 'array': - $attr = $options['attr']??['id','title']; - $list = ($options['list']??$extra); - $form = $this->arrays($name,$list,$options); + $attr = $options['attr'] ?? ['id', 'title']; + $list = ($options['list'] ?? $extra); + $form = $this->arrays($name, $list, $options); break; case 'selectn': - $attr = $options['attr']??['id','title']; - $list = ($options['list']??$extra); - $form = $this->selectn($name,$list,$options,$attr,$value); + $attr = $options['attr'] ?? ['id', 'title']; + $list = ($options['list'] ?? $extra); + $form = $this->selectn($name, $list, $options, $attr, $value); break; case 'selectplus': - $attr = $options['attr']??['id','title']; - $list = ($options['list']??$extra); - $form = $this->selectplus($name,$list,$options,$attr,$value); + $attr = $options['attr'] ?? ['id', 'title']; + $list = ($options['list'] ?? $extra); + $form = $this->selectplus($name, $list, $options, $attr, $value); break; case 'city': - $form = $this->city($name,$options,$value); + $form = $this->city($name, $options, $value); break; case 'region': - $form = $this->region($name,$options,$value); + $form = $this->region($name, $options, $value); break; case 'autocomplete': - $attr = $options['attr']??['id','title']; - $list = ($options['list']??$extra); - $form = $this->autocomplete($name,$list,$options,$attr,$value); + $attr = $options['attr'] ?? ['id', 'title']; + $list = ($options['list'] ?? $extra); + $form = $this->autocomplete($name, $list, $options, $attr, $value); break; default : - $form = $this->input($name, 'text',$options,$value); + $form = $this->input($name, 'text', $options, $value); break; } @@ -214,7 +216,7 @@ public function config($name='',$options=[],$value='') } - public function token($name = '__token__', $type = 'md5') + public function token($name = '__token__', $type = 'md5') { $str = ''; if (function_exists('token')) { @@ -230,19 +232,20 @@ public function token($name = '__token__', $type = 'md5') * @param array $options * @return string */ - public function input(string $name = '', string $type = 'text',array $options = [], $value = '') + public function input(string $name = '', string $type = 'text', array $options = [], $value = '') { - $type = $options['type']??$type; + $type = $options['type'] ?? $type; $disorread = $this->readonlyOrdisabled($options); if ($type == 'hidden') { return <<getDataPropAttr($name,$value,$options)} autocomplete="off" class="layui-input {$this->getClass($options)} {$disorread}"/> + getDataPropAttr($name, $value, $options)} autocomplete="off" class="layui-input {$this->getClass($options)} {$disorread}"/> EOF; } + $options['affix'] = $options['affix']??'clear'; $str = <<{$this->label($name, $options)}
- getDataPropAttr($name,$value,$options)} autocomplete="off" + getDataPropAttr($name, $value, $options)} autocomplete="off" {$this->getStyle($options)} class="layui-input {$this->getClass($options)} $disorread "/> {$this->tips($options)}
@@ -257,48 +260,48 @@ public function input(string $name = '', string $type = 'text',array $options = * @param $value * @return string */ - public function text(string $name,array $options = [], $value = null) + public function text(string $name, array $options = [], $value = null) { - return $this->input( $name,'text',$options, $value); + return $this->input($name, 'text', $options, $value); } /** * 创建一个密码输入字段 * - * @param string $name - * @param array $options + * @param string $name + * @param array $options * * @return string */ - public function password(string $name, array $options = [],$value='') + public function password(string $name, array $options = [], $value = '') { - $options['verify'] = isset($options['verify'])?$options['verify']:'pass'; + $options['verify'] = $options['verify'] ?? 'pass'; $options['type'] = 'password'; - return $this->input($name, 'password', $options,$value); + return $this->input($name, 'password', $options, $value); } /** * 创建一个范围输入选择器 * - * @param string $name - * @param null $value - * @param array $options + * @param string $name + * @param null $value + * @param array $options * * @return string */ - public function range($name, $options = [], $value = null) + public function range($name, $options = [], $value = null) { $disorread = $this->readonlyOrdisabled($options); - $str = <<{$this->label($name, $options)}
- getOptionsAttr($name,$options)} type="text" name="{$name}_min" autocomplete="off" class="layui-input {$this->getClass($options)} {$disorread} "/> + getOptionsAttr($name, $options)} type="text" name="{$name}_min" autocomplete="off" class="layui-input {$this->getClass($options)} {$disorread} "/>
-
- getOptionsAttr($name,$options)} type="text" name="{$name}_max" autocomplete="off" class="layui-input {$this->getClass($options)} {$disorread}" /> + getOptionsAttr($name, $options)} type="text" name="{$name}_max" autocomplete="off" class="layui-input {$this->getClass($options)} {$disorread}" />
@@ -310,75 +313,75 @@ public function range($name, $options = [], $value = null) /** * 创建一个隐藏的输入字段 * - * @param string $name - * @param null $value - * @param array $options + * @param string $name + * @param null $value + * @param array $options * * @return string */ - public function hidden($name, $options = [],$value = null) + public function hidden($name, $options = [], $value = null) { - return $this->input( $name,'hidden', $options, $value); + return $this->input($name, 'hidden', $options, $value); } /** * 创建一个电子邮件输入字段 * - * @param string $name - * @param null $value - * @param array $options + * @param string $name + * @param null $value + * @param array $options * * @return string */ - public function email($name, $options = [],$value = null) + public function email($name, $options = [], $value = null) { - $options['verify'] = isset($options['verify'])?$options['verify']:'email'; - return $this->input( $name,'email', $options, $value); + $options['verify'] = $options['verify'] ?? 'email'; + return $this->input($name, 'email', $options, $value); } /** * 创建一个tel输入字段 * - * @param string $name - * @param null $value - * @param array $options + * @param string $name + * @param null $value + * @param array $options * * @return string */ - public function tel($name, $options = [],$value = null) + public function tel($name, $options = [], $value = null) { - $options['verify'] = isset($options['verify'])?$options['verify']:'phone'; - return $this->input( $name,'tel', $options, $value); + $options['verify'] = $options['verify'] ?? 'phone'; + return $this->input($name, 'tel', $options, $value); } /** * 创建一个数字输入字段 * - * @param string $name - * @param null $value - * @param array $options + * @param string $name + * @param null $value + * @param array $options * * @return string */ - public function number($name, $options = [],$value = null) + public function number($name, $options = [], $value = null) { - $options['verify'] = isset($options['verify'])?$options['verify']:'number'; - return $this->input( $name,'number', $options, $value); + $options['verify'] = $options['verify'] ?? 'number'; + return $this->input($name, 'number', $options, $value); } /** * 创建一个url输入字段 * - * @param string $name - * @param null $value - * @param array $options + * @param string $name + * @param null $value + * @param array $options * * @return string */ - public function url($name, $options = [],$value = null) + public function url($name, $options = [], $value = null) { - $options['verify'] = isset($options['verify'])?$options['verify']:'url'; - return $this->input( $name,'url', $options, $value); + $options['verify'] = $options['verify'] ?? 'url'; + return $this->input($name, 'url', $options, $value); } /** @@ -388,15 +391,15 @@ public function url($name, $options = [],$value = null) * @param $value * @return string */ - public function rate($name = '', $options = [], $value = '') + public function rate($name = '', $options = [], $value = '') { - $options['filter'] = $options['filter']??'rate'; + $options['filter'] = $options['filter'] ?? 'rate'; $str = << - {$this->label($name,$options)} + {$this->label($name, $options)}
- getNameValueAttr($name,$value,$options)} class='layui-input'> -
getOptionsAttr($name,$options)} {$this->getStyle($options)} class='{$this->getClass($options)}'> + layverify($options)} {$this->getNameValueAttr($name, $value, $options)} class='layui-input'> +
getOptionsAttr($name, $options)} {$this->getStyle($options)} class='{$this->getClass($options)}'> {$this->tips($options)}
@@ -405,6 +408,7 @@ public function rate($name = '', $options = [], $value = '') return $str; } + /** * 滑块 * @param $name @@ -412,16 +416,15 @@ public function rate($name = '', $options = [], $value = '') * @param $value * @return string */ - public function slider($name = '', $options = [], $value = '') + public function slider($name = '', $options = [], $value = '') { - list($name,$id) = $this->getNameId($name,$options); - $options['filter'] = $options['filter']??'slider'; - $disorread = $this->readonlyOrdisabled($options)? 'layui-disabled' : ''; + list($name, $id) = $this->getNameId($name, $options); + $options['filter'] = $options['filter'] ?? 'slider'; + $disorread = $this->readonlyOrdisabled($options) ? 'layui-disabled' : ''; $str = <<{$this->label($name, $options)}
- getNameValueAttr($name,$value,$options)} class='layui-input layui-input-inline'> -
getOptionsAttr($name,$options)} style='top:16px' class='{$disorread} {$this->getClass($options)}'> +
getDataPropAttr($name,$value, $options)} style='top:16px' class='{$disorread} {$this->getClass($options)}'> {$this->tips($options)}
@@ -430,6 +433,7 @@ public function slider($name = '', $options = [], $value = '') return $str; } + /** * @param $name * @param $radiolist @@ -437,29 +441,29 @@ public function slider($name = '', $options = [], $value = '') * @param string $value * @return string */ - public function radio($name = '', $radiolist=[], $options = [], $value = '') + public function radio($name = '', $radiolist = [], $options = [], $value = '') { $input = ''; - $radiolist = $this->getArray($name,$radiolist); + $radiolist = $this->getArray($name, $radiolist); if (is_array($radiolist)) { foreach ($radiolist as $k => $v) { if (is_string($v) && strpos($v, ':') !== false) { $v = explode(":", $v); $input .= <<getDataPropAttr($name,$v[0],$options)} class="{$this->getClass($options)}" type="radio" {$this->selectedOrchecked($value, $v[0], 2)} title="{$this->__($v[1])}" /> +getDataPropAttr($name, $v[0], $options)} class="{$this->getClass($options)}" type="radio" {$this->selectedOrchecked($value, $v[0], 2)} title="{$this->__($v[1])}" /> EOF; - } else{ - $input .=<<getDataPropAttr($name,$k,$options)} class="{$this->getClass($options)}" type="radio" {$this->selectedOrchecked($value, $k, 2)} title="{$this->__($v)}" /> + } else { + $input .= <<getDataPropAttr($name, $k, $options)} class="{$this->getClass($options)}" {$this->getNameValueAttr($name, $value, $options)} type="radio" {$this->selectedOrchecked($value, $k, 2)} title="{$this->__($v)}" /> EOF; } } } else { - $input .=<<getDataPropAttr($name,$radiolist,$options)} class="{$this->getClass($options)}" type="radio" title="{$this->__($radiolist)}" /> + $input .= <<getDataPropAttr($name, $radiolist, $options)} class="{$this->getClass($options)}" type="radio" title="{$this->__($radiolist)}" /> EOF; } - $str =<<{$this->label($name, $options)}
{$input} @@ -480,15 +484,15 @@ public function radio($name = '', $radiolist=[], $options = [], $value = '') * switch是关键字不能用 */ - public function switchs($name = '', $switch=[], $options = [], $value = '') + public function switchs($name = '', $switch = [], $options = [], $value = '') { - $switchArr = $this->getArray($name,$switch); + $switchArr = $this->getArray($name, $switch); $switchStr = $switchArr ? $this->__($switchArr[1]) . '|' . $this->__($switchArr[0]) : $this->__('open') . '|' . 'close'; - $checked = $value?'checked="true"':''; + $checked = $value ? 'checked="true"' : ''; $str = << {$this->label($name, $options)}
- getDataPropAttr($name,$value,$options)} class="{$this->getClass($options)}" type="checkbox" {$checked} lay-skin="switch" lay-text="{$switchStr}" data-text="{$this->__($value)}"/> + getDataPropAttr($name, $value, $options)} class="{$this->getClass($options)}" type="checkbox" {$checked} lay-skin="switch" lay-text="{$switchStr}" data-text="{$this->__($value)}"/> {$this->tips($options)}
' @@ -505,17 +509,17 @@ public function switchs($name = '', $switch=[], $options = [], $value = '') * @param $value * @return string */ - public function checkbox($name = '', $list = [], $options = [], $value = '') + public function checkbox($name = '', $list = [], $options = [], $value = '') { - $name = $options['formname']??$name; + $name = $options['formname'] ?? $name; if (empty($value)) $value = $name; - $value = $this->getArray($name,$value); - $list = $this->getArray($name,$list); + $value = $this->getArray($name, $value); + $list = $this->getArray($name, $list); $input = ''; if (is_array($list) && $list) { foreach ($list as $k => $v) { - if (is_string($v) && (Str::contains($v, ':') || Str::contains($v, ':')) ) { - $v =str_replace(':',':',$v); + if (is_string($v) && (Str::contains($v, ':') || Str::contains($v, ':'))) { + $v = str_replace(':', ':', $v); $v = explode(":", $v); $check = ''; if (is_array($value) && in_array($v[0], $value) || $v[0] == $value) { @@ -524,27 +528,27 @@ public function checkbox($name = '', $list = [], $options = [], $value = '') $value_tmp = $k; $name_tmp = $name[$v[0]]; $input .= <<getDataPropAttr($name_tmp,$value_tmp,$options)} class="{$this->getClass($options)}" type="checkbox" {$check} title="{$this->__($v[1])}"/> +getDataPropAttr($name_tmp, $value_tmp, $options)} class="{$this->getClass($options)}" type="checkbox" {$check} title="{$this->__($v[1])}"/> EOF; } else { $check = ''; - if ((is_array($value) && is_array($v) && in_array($v[0], $value)) || $value == $v) { + if ((is_array($value) && is_array($v) && in_array($v[0], $value)) || $value == $v) { $check = 'checked'; - } elseif ((is_array($value) && is_string($v) && in_array($k, $value)) || $value == $v) { + } elseif ((is_array($value) && is_string($v) && in_array($k, $value)) || $value == $v) { $check = 'checked'; } $value_tmp = $k; - $name_tmp =$name[$k]; + $name_tmp = $name.'['.$k.']'; $input .= <<getDataPropAttr($name_tmp,$value_tmp,$options)} class="{$this->getClass($options)}" type="checkbox" {$check} title="{$this->__($v)}"/> +getDataPropAttr($name_tmp, $value_tmp, $options)} class="{$this->getClass($options)}" type="checkbox" {$check} title="{$this->__($v)}"/> EOF; } } } else { $value_tmp = $value; - $name_tmp ="{$name}[]"; + $name_tmp = "{$name}[]"; $input .= <<getDataPropAttr($name_tmp,$value_tmp,$options)} class="{$this->getClass($options)}" type="checkbox" title="{$this->__($value)}"/> +getDataPropAttr($name_tmp, $value_tmp, $options)} class="{$this->getClass($options)}" type="checkbox" title="{$this->__($value)}"/> EOF; } $str = <<getNameId($name,$options); + list($name, $id) = $this->getNameId($name, $options); $arr = ''; $tr = ''; - if(!empty($list)){ - foreach($list as $key=>$val){ - $tr.=<< $val) { + $tr .= << -
getDataPropAttr("{$name}[key][]",$key,$options)} placeholder="{$this->__('Key')}" class="layui-input key"> +
getDataPropAttr("{$name}[key][]", $key, $options)} placeholder="{$this->__('Key')}" class="layui-input key">
-
getDataPropAttr("{$name}[value][]",$val,$options)} placeholder="{$this->__('Value')}" class="layui-input value"> +
getDataPropAttr("{$name}[value][]", $val, $options)} placeholder="{$this->__('Value')}" class="layui-input value">
@@ -594,10 +598,10 @@ public function arrays($name = '', $list = [], $options = []) EOF; - } + } -}else{ - $tr.=<< @@ -619,9 +623,9 @@ public function arrays($name = '', $list = [], $options = []) EOF; } - $arr .=<< - {$this->label($name,$options)} + {$this->label($name, $options)}
@@ -641,6 +645,7 @@ public function arrays($name = '', $list = [], $options = []) $str = '
' . $arr . '
'; return $str; } + /** * 文本 * @param null $name @@ -648,12 +653,12 @@ public function arrays($name = '', $list = [], $options = []) * @param $value * @return string */ - public function textarea($name = '', $options = [], $value = '') + public function textarea($name = '', $options = [], $value = '') { $str = <<{$this->label($name,$options)} +
{$this->label($name, $options)}
- {$this->tips($options)}
@@ -670,25 +675,25 @@ public function textarea($name = '', $options = [], $value = '') * @param $value * @return string */ - public function selectn($name = '', $select= [], $options=[], $attr=[], $value='') + public function selectn($name = '', $select = [], $options = [], $attr = [], $value = '') { - $name = $options['formname']??$name; + $name = $options['formname'] ?? $name; $label = $options['label'] ?? $name; - $options['url'] = $options['url'] ?? ''; - $options['delimiter'] = $options['delimiter'] ?? ''; - $options['search']= isset($options['search']) ? true : ''; - $options['num'] = $options['num'] ?? 3; - $options['last'] = $options['last'] ?? ''; + $options['url'] = $options['url'] ?? ''; + $options['delimiter'] = $options['delimiter'] ?? ''; + $options['search'] = isset($options['search']) ? true : ''; + $options['num'] = $options['num'] ?? 3; + $options['last'] = $options['last'] ?? ''; if ($attr) { $attr = is_array($attr) ? implode(',', $attr) : $attr; } - $options['filter'] = $options['filter']??'selectN'; - $options['data'] = json_encode((array)$select, JSON_UNESCAPED_UNICODE); - $options['attr'] = $attr; + $options['filter'] = $options['filter'] ?? 'selectN'; + $options['data'] = json_encode((array)$select, JSON_UNESCAPED_UNICODE); + $options['attr'] = $attr; $str = <<{$this->label($name,$options)} +
{$this->label($name, $options)}
-
getDataPropAttr($name, $value, $options)} class="{$this->getClass($options)}" {$this->laysearch($options)} {$this->readonlyOrdisabled($options)} >
{$this->tips($options)} @@ -698,6 +703,7 @@ public function selectn($name = '', $select= [], $options=[], $attr=[], $value= return $str; } + /** * @param $name * @param $select @@ -706,26 +712,26 @@ public function selectn($name = '', $select= [], $options=[], $attr=[], $value= * @param $value * @return string */ - public function selectplus($name = '', $select= [], $options=[], $attr=[], $value='') + public function selectplus($name = '', $select = [], $options = [], $attr = [], $value = '') { - list($name,$id) = $this->getNameId($name,$select); - $options['url'] = $options['url'] ?? ''; - $options['delimiter'] = $options['delimiter'] ?? ''; - $options['fielddelimiter'] = $options['fielddelimiter'] ?? ''; - $options['verify'] = $options['verify']??''; - $multiple = isset($options['multiple']) ? 'multiple="multiple"' : ''; - - $options['multiple'] = $multiple?1:''; + list($name, $id) = $this->getNameId($name, $select); + $options['url'] = $options['url'] ?? ''; + $options['delimiter'] = $options['delimiter'] ?? ''; + $options['fielddelimiter'] = $options['fielddelimiter'] ?? ''; + $options['verify'] = $options['verify'] ?? ''; + $multiple = !empty($options['multiple']) ? 'multiple="multiple"' : ''; + + $options['multiple'] = $multiple ? 1 : ''; if ($attr) { $attr = is_array($attr) ? implode(',', $attr) : $attr; } $options['attr'] = $attr; $options['data'] = json_encode((array)$select, JSON_UNESCAPED_UNICODE); - $options['filter'] = $options['filter']??"selectPlus"; + $options['filter'] = $options['filter'] ?? "selectPlus"; $str = <<{$this->label($name,$options)} +
{$this->label($name, $options)}
-
getDataPropAttr($name,$value,$options)} data-verify ="{$options['verify']}" {$multiple} > +
getDataPropAttr($name, $value, $options)} {$multiple} >
{$this->tips($options)}
@@ -735,8 +741,9 @@ public function selectplus($name = '', $select= [], $options=[], $attr=[], $val return $str; } - public function autocomplete($name='',$list=[],$options=[],$attr=[],$value=''){ - list($name,$id)= $this->getNameId($name,$options); + public function autocomplete($name = '', $list = [], $options = [], $attr = [], $value = '') + { + list($name, $id) = $this->getNameId($name, $options); $disorread = $this->readonlyOrdisabled($options); $options['filter'] = 'autoComplete'; $data = json_encode($list); @@ -745,13 +752,13 @@ public function autocomplete($name='',$list=[],$options=[],$attr=[],$value=''){
{$this->label($name, $options)}
getDataPropAttr($name,$value,$options)} + {$this->getDataPropAttr($name, $value, $options)} {$this->getStyle($options)} class="layui-input {$this->getClass($options)} $disorread "/> {$this->tips($options)}
EOF; - return $str; + return $str; } /** @@ -762,10 +769,11 @@ public function autocomplete($name='',$list=[],$options=[],$attr=[],$value=''){ * @param $value * @return string */ - public function select($name = '', $select=[], $options=[], $attr=[], $value='') + public function select($name = '', $select = [], $options = [], $attr = [], $value = '') { - return $this->multiselect($name,$select,$options,$attr,$value); + return $this->multiselect($name, $select, $options, $attr, $value); } + /** * @param $name * @param $select @@ -774,20 +782,20 @@ public function select($name = '', $select=[], $options=[], $attr=[], $value='' * @param $value * @return string */ - public function multiselect($name = '', $select=[], $options=[], $attr=[], $value='') + public function multiselect($name = '', $select = [], $options = [], $attr = [], $value = '') { - list($name,$id)= $this->getNameId($name,$options); + list($name, $id) = $this->getNameId($name, $options); $op = ''; if ($select) { foreach ($select as $k => $v) { $selected = ''; - if (is_array($v) && (is_array($value) && is_array($attr) && !empty($attr) && in_array($v[$attr[0]], $value) || (is_array($attr) && !empty($attr) && $v[$attr[0]] == $value))) { + if (is_array($v) && (is_array($value) && is_array($attr) && !empty($attr) && in_array($v[$attr[0]], $value) || (is_array($attr) && !empty($attr) && $v[$attr[0]] == $value))) { $selected = 'selected'; } if (is_array($value) && in_array($k, $value) && !$attr) { $selected = 'selected'; } - if(is_string($v)){ + if (is_string($v)) { $op .= ''; } if (!empty($attr) && (is_array($v) || is_object($v))) { @@ -807,9 +815,9 @@ public function multiselect($name = '', $select=[], $options=[], $attr=[], $val $attr = is_array($attr) ? implode(',', $attr) : $attr; $options['attr'] = $attr; $str = << {$this->label($name,$options)} +
{$this->label($name, $options)}
- getDataPropAttr($name, $value, $options)} class="layui-select-url layui-select {$this->getClass($options)}" {$multiple} > {$op} @@ -820,6 +828,7 @@ public function multiselect($name = '', $select=[], $options=[], $attr=[], $val return $str; } + /** * @param $name * @param $select @@ -828,9 +837,9 @@ public function multiselect($name = '', $select=[], $options=[], $attr=[], $val * @param $value * @return string */ - public function xmselect($name = '', $select=[], $options=[], $attr=[], $value='') + public function xmselect($name = '', $select = [], $options = [], $attr = [], $value = '') { - list($name,$id) = $this->getNameId($name,$options); + list($name, $id) = $this->getNameId($name, $options); $op = ''; if (is_array($select)) { $op .= " data-data='" . json_encode($select, JSON_UNESCAPED_UNICODE) . "'"; @@ -838,43 +847,45 @@ public function xmselect($name = '', $select=[], $options=[], $attr=[], $value= if (is_object($select)) { $op .= " data-data='" . json_encode((array)$select, JSON_UNESCAPED_UNICODE) . "'"; } - $attr = is_array($attr) ? implode(',', $attr):$attr; + $attr = is_array($attr) ? implode(',', $attr) : $attr; $value = is_array($value) ? implode($value) : $value; $options['attr'] = $options['attr'] ?? $attr; $options['lang'] = $options['lang'] ?? ''; - $options['tips'] = $options['tips']?? ''; - $options['empty'] = $options['empty'] ?? ''; - $options['repeat'] = $options['repeat'] ??''; - $options['content'] = $options['content'] ?? ''; + $options['tips'] = $options['tips'] ?? ''; + $options['empty'] = $options['empty'] ?? ''; + $options['repeat'] = $options['repeat'] ?? ''; + $options['content'] = $options['content'] ?? ''; $options['searchTips'] = $options['searchTips'] ?? ''; $options['style'] = $options['style'] ?? ''; $options['filterable'] = $options['filterable'] ?? ''; - $options['remoteSearch'] = $options['remoteSearch'] ?? ''; - $options['remoteMethod'] = $options['remoteMethod'] ?? ''; - $options['height'] = $options['height'] ??''; - $options['paging'] = $options['paging'] ??''; - $options['size'] = $options['size'] ??''; - $options['pageSize'] = $options['pageSize'] ??''; - $options['pageRemote'] = $options['pageRemote'] ??''; - $options['clickClose'] = $options['clickClose'] ??''; - $options['reqext'] = $options['reqtext'] ??''; - $options['radio'] = $options['radio'] ?? ''; - $options['url'] = $options['url'] ??''; - $options['tree'] = $options['tree'] ??''; - $options['prop'] = $options['prop'] ??''; - $options['parentField'] = $options['parentField'] ??'pid'; - $options['max'] = $options['max'] ??''; - $options['verify'] = $options['verify'] ??''; - $options['disabled'] = $options['disabled'] ??''; - $options['create'] = $options['create'] ??''; - $options['theme'] = $options['theme'] ??''; - $options['value'] = $options['value'] ??''; - $options['autorow'] = $options['autorow'] ??''; + $options['remoteSearch'] = $options['remoteSearch'] ?? ''; + $options['remoteMethod'] = $options['remoteMethod'] ?? ''; + $options['height'] = $options['height'] ?? ''; + $options['paging'] = $options['paging'] ?? ''; + $options['size'] = $options['size'] ?? ''; + $options['pageSize'] = $options['pageSize'] ?? ''; + $options['pageRemote'] = $options['pageRemote'] ?? ''; + $options['clickClose'] = $options['clickClose'] ?? ''; + $options['layReqText'] = $options['reqText'] ?? ($options['layReqText']??''); + $options['layVerify'] = $options['verify'] ?? ($options['layVerify']??''); + $options['layVerType'] = $options['layVerType']?? ($options['verType']??($options['vertype']??'')); + $options['radio'] = $options['radio'] ?? ''; + $options['url'] = $options['url'] ?? ''; + $options['tree'] = $options['tree'] ?? ''; + $options['prop'] = $options['prop'] ?? ''; + $options['parentField'] = $options['parentField'] ?? 'pid'; + $options['max'] = $options['max'] ?? ''; + $options['verify'] = $options['verify'] ?? ''; + $options['disabled'] = $options['disabled'] ?? ''; + $options['create'] = $options['create'] ?? ''; + $options['theme'] = $options['theme'] ?? ''; + $options['value'] = $options['value'] ?? ''; + $options['autorow'] = $options['autorow'] ?? ($options['autoRow']??''); $options['filter'] = 'xmSelect'; - $options['toolbar'] = isset($options['toolbar'])?json_encode($options['toolbar'],JSON_UNESCAPED_UNICODE) : ''; + $options['toolbar'] = isset($options['toolbar']) ? json_encode($options['toolbar'], JSON_UNESCAPED_UNICODE) : ''; $str = <<{$this->label($name,$options)} -
getDataPropAttr($name,$value,$options)} class="layui-input-block {$this->getClass($options)} " {$op}> +
{$this->label($name, $options)} +
getDataPropAttr($name, $value, $options)} class="layui-input-block {$this->getClass($options)} " {$op}> {$this->tips($options)}
@@ -890,17 +901,18 @@ public function xmselect($name = '', $select=[], $options=[], $attr=[], $value= * @param $value * @return string */ - public function selectpage(string $name,array $lists= [],array $options = [],$value=null) + public function selectpage(string $name, array $lists = [], array $options = [], $value = null) { - list($name,$id) = $this->getNameId($name,$options); + list($name, $id) = $this->getNameId($name, $options); $options['filter'] = 'selectPage'; - $options['data'] = empty($lists)?'':json_encode($lists); - $options['field'] = $options['field']??'title'; - $options['primarykey'] = $options['field']??'id'; - $options['multiple'] = $options['multiple']??''; + $options['data'] = empty($lists) ? '' : json_encode($lists); + $options['field'] = $options['field'] ?? 'title'; + $options['primaryKey'] = $options['field'] ?? 'id'; + $options['multiple'] = $options['multiple'] ?? ''; $options['init'] = $value; - return $this->input($name,'text',$options, $value); + return $this->input($name, 'text', $options, $value); } + /** * @param $name * @param $value @@ -910,15 +922,21 @@ public function selectpage(string $name,array $lists= [],array $options = [],$v */ public function tags($name = '', $options = [], $value = '') { - list($name,$id) = $this->getNameId($name,$options); + list($name, $id) = $this->getNameId($name, $options); $options['filter'] = $options['filter'] ?? 'tags'; $options['placeholder'] = $options['placeholder'] ?? 'Space To Generate Tags'; + $labelOptions = $options; + $verify = ''; + if (isset($options['verify'])) { + $verify = $this->layverify($options); + unset($options['verify']); + } $str = <<{$this->label($name,$options)} +
{$this->label($name, $labelOptions)}
- - getOptionsAttr($name,$options)} class="{$this->getClass($options)}" type="text" /> + getOptionsAttr($name, $options)} class="{$this->getClass($options)}" type="text" /> +
@@ -934,16 +952,17 @@ public function tags($name = '', $options = [], $value = '') * @return string * 颜色选择 */ - public function color($name = '', $options = [], $value = '') + public function color($name = '', $options = [], $value = '') { - list($name,$id) = $this->getNameId($name,$options); + list($name, $id) = $this->getNameId($name, $options); $format = $options['format'] ?? 'hex'; - $options['filter'] = $options['filter']??'colorPicker'; + $options['filter'] = $options['filter'] ?? 'colorPicker'; + $options['verify'] = $options['verify'] ?? ''; $str = <<{$this->label($name,$options)} +
{$this->label($name, $options)}
- getNameValueAttr($name,$value,$options)} lay-verify="{$options['verify']}" class="layui-input layui-input-inline {$this->getClass($options)}" type="text" /> -
getOptionsAttr($name,$options)} data-format = "{$format}" >
+ getNameValueAttr($name, $value, $options)} lay-verify="{$options['verify']}" lay-vertype="tips" class="layui-input layui-input-inline {$this->getClass($options)}" type="text" /> +
getOptionsAttr($name, $options)} data-format = "{$format}" >
EOF; @@ -953,20 +972,19 @@ public function color($name = '', $options = [], $value = '') /** * @param $name + * @param $options * @param $value - * @param array $options * @return string - * 图标,有点小问题 */ - public function icon($name = '', $options = [], $value = '') + public function icon($name = '', $options = [], $value = '') { - list($name,$id) = $this->getNameId($name,$options); + list($name, $id) = $this->getNameId($name, $options); $value = $value ?: 'layui-icon layui-icon-app'; $options['filter'] = 'iconPicker'; $str = <<{$this->label($name,$options)} +
{$this->label($name, $options)}
- getDataPropAttr($name,$value,$options)} type="hidden" name="' class="hide {$this->getClass($options)}" /> + getDataPropAttr($name, $value, $options)} type="text" name="' class="hide layui-input layui-hide {$this->getClass($options)}" />
EOF; @@ -975,35 +993,39 @@ public function icon($name = '', $options = [], $value = '') } /** - * @param null $name - * @param array $options + * @param $name + * @param $options + * @param $value * @return string - * 日期 */ - public function date($name='', $options=[], $value='') + public function date($name = '', $options = [], $value = '') { - list($name,$id) = $this->getNameId($name,$options); - $options['placeholder'] = $options['placeholder']??'yyyy-MM-dd HH:mm:ss'; - $options['filter'] = $options['filter']??'date'; + list($name, $id) = $this->getNameId($name, $options); + $options['placeholder'] = $options['placeholder'] ?? 'yyyy-MM-dd HH:mm:ss'; + $options['filter'] = $options['filter'] ?? 'date'; $str = << {$this->label($name, $options)}
- getDataPropAttr($name,$value,$options)} class="layui-input {$this->getClass($options)} {$this->readonlyOrdisabled($options)}" type="text" /> + getDataPropAttr($name, $value, $options)} class="layui-input {$this->getClass($options)} {$this->readonlyOrdisabled($options)}" type="text" /> +
+ EOF; return $str; } + /** - * 城市选择 - * @param string $name + * @param $name * @param $options + * @param $value * @return string + * 城市选择 */ - public function city($name = 'cityPicker', $options = [],$value='') + public function city($name = 'cityPicker', $options = [], $value = '') { - list($name,$id) = $this->getNameId($name,$options); + list($name, $id) = $this->getNameId($name, $options); $options['provinceId'] = $options['provinceId'] ?? 'province_id'; $options['cityId'] = $options['cityId'] ?? 'city_id'; $options['districtId'] = $options['districtId'] ?? 'area_id'; @@ -1014,7 +1036,7 @@ public function city($name = 'cityPicker', $options = [],$value='')
- getDataPropAttr($name,$value,$options)} type="hidden" autocomplete="off" class="layui-input {$this->getClass($options)} " /> + getDataPropAttr($name, $value, $options)} type="text" autocomplete="off" class="layui-input layui-form-required-hidden {$this->getClass($options)} " />
EOF; @@ -1028,15 +1050,15 @@ public function city($name = 'cityPicker', $options = [],$value='') * @param $options * @return string */ - public function region($name = 'region', $options = [],$value='') + public function region($name = 'region', $options = [], $value = '') { - list($name,$id) = $this->getNameId($name,$options); + list($name, $id) = $this->getNameId($name, $options); $options['filter'] = 'region'; $str = <<{$this->label($name,$options)} +
{$this->label($name, $options)}
- -
getOptionsAttr($name,$options)} class="{$this->getClass($options)}" id="{$id}" name="{$name}"> + layverify($options)} /> +
getOptionsAttr($name, $options)} class="{$this->getClass($options)}" id="{$id}" name="{$name}">
@@ -1053,42 +1075,42 @@ public function region($name = 'region', $options = [],$value='') * @return string * 编辑器 */ - public function editor($name = 'container', $options = [], $value = '') + public function editor($name = 'container', $options = [], $value = '') { $options['id'] = $options['id'] ?? $name; $options['path'] = $options['path'] ?? 'upload'; - $options['height'] =$options['height'] ?? '400px'; - $options['url'] =$options['url'] ?? ''; - $options['editor'] = $options['editor'] ?? (syscfg('upload','upload_editor')?:'tinymce'); + $options['height'] = $options['height'] ?? '400px'; + $options['url'] = $options['url'] ?? ''; + $options['editor'] = $options['editor'] ?? (syscfg('upload', 'upload_editor') ?: 'tinymce'); $options['filter'] = 'editor'; - if($options['editor'] =='tinymce'){ + if ($options['editor'] == 'tinymce') { // tinyedit $content = <<getDataPropAttr($name,$value,$options)} lay-editor type="text/plain">{$value} + EOF; - }else{ + } else { //百度。quill wangeditor ckeditor,editormd $text = ''; if (isset($options['textarea'])) { $verify = ''; - if(!empty($options['verify'])){ - $verify = 'lay-verify ="'.$options['verify'].'"'; + if (!empty($options['verify'])) { + $verify = 'lay-verify ="' . $options['verify'] . '"'; } - $text= <<getNameValueAttr($name,$value,$options)} + $text = <<getNameValueAttr($name, $value, $options)} EOF; } - if(!empty($options['verify'])){ + if (!empty($options['verify'])) { unset($options['verify']); } $content = <<getDataPropAttr($name,$value,$options)} lay-editor type="text/plain" > +
getDataPropAttr($name, $value, $options)} lay-editor type="text/plain" > {$text}
EOF; } - $str = <<{$this->label($name, $options)}
{$content} @@ -1098,6 +1120,7 @@ public function editor($name = 'container', $options = [], $value = '') return $str; } + /** * 上传 * @param string $name @@ -1105,27 +1128,27 @@ public function editor($name = 'container', $options = [], $value = '') * @param array $options * @return string */ - public function upload($name = 'avatar', $options = [], $value = '') - { - list($name,$id) = $this->getNameId($name,$options); - if (!isset($options['type'])) $options['type'] = 'radio'; - if (!isset($options['mime'])) $options['mime'] = 'images'; - if (!isset($options['num'])) $options['num'] = 1; - if (isset($options['num']) && $options['num'] == '*') $options['num'] = 100; - if (!isset($options['path'])) $options['path'] = 'upload'; //上传路劲 - $css = isset($options['css']) ? $options['css'] : 'display:inline-block;'; + public function upload($name = 'avatar', $options = [], $value = '') + { + list($name, $id) = $this->getNameId($name, $options); + if (empty($options['type'])) $options['type'] = 'radio'; + if (empty($options['mime'])) $options['mime'] = 'images'; + if (empty($options['num'])) $options['num'] = 1; + if (!empty($options['num']) && $options['num'] == '*') $options['num'] = 100; + if (empty($options['path'])) $options['path'] = 'upload'; //上传路劲 + $css = $options['css'] ?? 'display:inline-block;'; $li = ''; $croper_container = ''; - if (isset($options['cropper'])) { - $cops = ['name'=>$name, + if (!empty($options['cropper'])) { + $cops = ['name' => $name, 'path' => $options['path'], 'width' => $options['saveW'] ?? '300', 'height' => $options['saveW'] ?? '300', 'mark' => $options['mark'] ?? 1, - 'area' => $options['area'] ?json_encode($options['area']): json_encode(['100%','100%']), + 'area' => !empty($options['area']) ? json_encode($options['area']) : json_encode(['100%', '100%']), 'filter' => 'cropper', ]; - $data_value = $this->getOptionsAttr($name,$cops); + $data_value = $this->getOptionsAttr($name, $cops); $croper_container = << {$this->__('Cropper')} @@ -1135,33 +1158,33 @@ public function upload($name = 'avatar', $options = [], $value = '') $values = []; if ($value && is_string($value)) { $values = explode(',', $value); - }else{ - $values = is_array($value) ? $value :[]; + } else { + $values = is_array($value) ? $value : []; } if (!empty(array_filter($values))) { foreach ($values as $k => $v) { if ($k + 1 <= $options['num']) { switch ($options['mime']) { case 'video': - $v = $v?:'/static/backend/images/filetype/video.png'; + $v = $v ?: '/static/backend/images/filetype/video.png'; $li .= << EOF; break; case 'audio': - $v = $v?:'/static/backend/images/filetype/audio.jpg'; + $v = $v ?: '/static/backend/images/filetype/audio.jpg'; $li .= << EOF; break; case 'images': - $v = $v?:'/static/backend/images/filetype/image.jpg'; + $v = $v ?: '/static/backend/images/filetype/image.jpg'; $li .= << EOF; break; case 'image': - $v = $v?:'/static/backend/images/filetype/image.jpg'; + $v = $v ?: '/static/backend/images/filetype/image.jpg'; $li .= << EOF; @@ -1193,23 +1216,24 @@ public function upload($name = 'avatar', $options = [], $value = '') 'num' => $options['num'] ?? '', 'type' => $options['type'] ?? '', 'size' => $options['size'] ?? '', - 'exts' => $options['exts'] ?? '*', - 'accept' => $options['accept'] ?? 'file', - 'multiple' => $options['multiple'] ?? '', - 'selecturl' => $options['selecturl'] ?? '', - 'tableurl' => $options['tableurl'] ?? '', - 'chunk' => $options['chunk'] ?? false, + 'exts' => $options['exts'] ?? '*', + 'accept' => $options['accept'] ?? 'file', + 'multiple' => $options['multiple'] ?? '', + 'selecturl' => $options['selecturl'] ?? '', + 'tableurl' => $options['tableurl'] ?? '', + 'chunk' => $options['chunk'] ?? false, ]; $options = array_merge($op, $options); - $label = $this->label($name,$options) ; - $verify = $options['verify']??""; + $label = $this->label($name, $options); + $verify = $options['verify'] ?? ""; $options['verify'] = ''; $select_container = ''; if ((isset($options['select']) && $options['select']) || !isset($options['select'])) { $select_options = $options; $select_options['filter'] = $options['select'] ?? 'upload-select'; //可选upload-choose - $select_container = <<getOptionsAttr($name,$select_options)} class="layui-btn layui-btn-sm layui-btn-danger {$options['select']}">{$this->__('Choose')} + $options['select'] = $select_options['filter']; + $select_container = <<getOptionsAttr($name, $select_options)} class="layui-btn layui-btn-sm layui-btn-danger {$options['select']}">{$this->__('Choose')} EOF; } @@ -1223,9 +1247,9 @@ public function upload($name = 'avatar', $options = [], $value = '')
{$label}
- getNameValueAttr($name,$value,$options)} lay-verify="{$verify}" type="text" class="layui-input layui-input-upload attach {$this->getClass($options)}" /> + getNameValueAttr($name, $value, $options)} lay-verify="{$verify}" type="text" class="layui-input layui-input-upload attach {$this->getClass($options)}" /> {$croper_container} - + {$select_container}
{$li}
@@ -1237,12 +1261,13 @@ public function upload($name = 'avatar', $options = [], $value = '') return $str; } + /** * @param bool $reset * @param array $options * @return string */ - public function closebtn($reset = true, $options = []) + public function closebtn($reset = true, $options = []) { $show = ''; if (!isset($options['show']) || isset($options['hide'])) { @@ -1250,7 +1275,7 @@ public function closebtn($reset = true, $options = []) } $str = << -
EOF; @@ -1264,13 +1289,13 @@ public function closebtn($reset = true, $options = []) * @param array $options * @return string */ - public function submitbtn($reset=true, $options=[]) + public function submitbtn($reset = true, $options = []) { $show = ''; if (!isset($options['show']) || isset($options['hide'])) { $show = 'layui-hide'; } - if($reset){ + if ($reset) { $reset = <<{$this->__('Reset')} EOF; @@ -1287,9 +1312,10 @@ public function submitbtn($reset=true, $options=[]) return $str; } - public function submit($reset=true, $options=[]){ + public function submit($reset = true, $options = []) + { - return $this->submitbtn($reset,$options); + return $this->submitbtn($reset, $options); } @@ -1297,7 +1323,8 @@ public function submit($reset=true, $options=[]){ * @param $html * @return string */ - public function html($html,$options=[]){ + public function html($html, $options = []) + { return $this->entities($html); } @@ -1306,7 +1333,8 @@ public function html($html,$options=[]){ * @param $script * @return string */ - public function script(string $script,$options=[]){ + public function script(string $script, $options = []) + { return $script; } @@ -1315,7 +1343,8 @@ public function script(string $script,$options=[]){ * @param $style * @return mixed */ - public function style(string $style,$options=[]){ + public function style(string $style, $options = []) + { return $style; } @@ -1325,15 +1354,16 @@ public function style(string $style,$options=[]){ * @param $options * @return string */ - public function js($name=[],$options=[]){ - if(is_string($name)){ - $name = explode(',',$name); + public function js($name = [], $options = []) + { + if (is_string($name)) { + $name = explode(',', $name); } $str = ''; - $v = $options['version'] || $options['v']; + $v = !empty($options['version']) ?$options['version']: (!empty($options['v'])?$options['v']:""); foreach ($name as $src) { - $src = $v?$src.'?v='.$v:$src; - $str .=''; + $src = $v ? $src . '?v=' . $v : $src; + $str .= ''; } return $str; } @@ -1344,44 +1374,48 @@ public function js($name=[],$options=[]){ * @param $options * @return string */ - public function link($name=[],$options=[]){ - if(is_string($name)){ - $name = explode(',',$name); + public function link($name = [], $options = []) + { + if (is_string($name)) { + $name = explode(',', $name); } $str = ''; - $v = $options['version'] || $options['v']; + $v = !empty($options['version']) ?$options['version']: (!empty($options['v'])?$options['v']:""); foreach ($name as $src) { - $src = $v?$src.'?v='.$v:$src; - $str .=''; + $src = $v ? $src . '?v=' . $v : $src; + $str .= ''; } return $str; } + /** * @param $label * @param $options * @return string */ - public function label($name,$options= [],$escape_html = true){ - $label = $options['label']??$name; + public function label($name, $options = [], $escape_html = true) + { + $label = $options['label'] ?? $name; if ($escape_html) { $label = $this->entities($label); } $class = ''; - if(isset($options['labelHide']) || isset($options['labelhide'])){ - $class .=' layui-hide'; + if (isset($options['labelHide']) || isset($options['labelhide'])) { + $class .= ' layui-hide'; } - $data = << {$this->getTitle($label)} EOF; - if(isset($options['labelRemove']) || isset($options['labelremove'])){ + if (isset($options['labelRemove']) || isset($options['labelremove'])) { $data = ''; } return $data; } + /** * 将HTML字符串转换为实体 * - * @param string $value + * @param string $value * * @return string */ @@ -1405,7 +1439,7 @@ protected function entity_decode($value) * @return string * 提示 */ - protected function tips($options = []) + protected function tips($options = []) { $tips = ''; if (isset($options['tips'])) { @@ -1421,19 +1455,21 @@ protected function tips($options = []) * @ 验证 * @return string */ - protected function layverify($options = []) + protected function layverify($options = []) { $verify = ''; if (isset($options['verify'])) { - $verify .= ' lay-verify="' . $options['verify'] . '"'; + $verify .= 'data-verify="' . $options['verify'] . '" lay-verify="' . $options['verify'] . '"'; } - $type ='tips'; + $type = 'tips'; if (isset($options['verType']) && $options['verType']) { $type = $options['verType']; + }else if (isset($options['vertype']) && $options['vertype']) { + $type = $options['vertype']; } - $verify.= ' lay-verType="' . $type . '" '; + $verify .= ' lay-verType="' . $type . '" '; if (isset($options['reqText']) && $options['reqText']) { - $verify.= ' lay-reqText="' . $options['reqText'] . '" '; + $verify .= ' lay-reqText="' . $options['reqText'] . '" '; } return $verify; } @@ -1442,47 +1478,52 @@ protected function layverify($options = []) * @param $options * @return string */ - protected function layfilter($options = []) + protected function layfilter($options = []) { - $filter = ''; + $str = ''; if (isset($options['filter'])) { - $filter = ' lay-filter="' . $options['filter'] . '"'; + $str = ' lay-filter="' . $options['filter'] . '"'; } - return $filter; + return $str; } - protected function layaffix($options = []) + + protected function layaffix($options = []) { - $affix = ''; + $str = ''; if (isset($options['affix'])) { - $affix = ' lay-affix="' . $options['affix'] . '"'; + $str = ' lay-affix="' . $options['affix'] . '"'; } - return $affix; + return $str; } - protected function layautocomplete($options = []) + + protected function layautocomplete($options = []) { - $affix = ' '; - if (isset($options['affix'])) { - $affix = ' autocomplete="'.$options['autocomplete'] .'"'; + $str = ' '; + if (isset($options['autocomplete'])) { + $str = ' autocomplete="' . $options['autocomplete'] . '"'; } - return $affix; + return $str; } - protected function laysubmit($options = []) + + protected function laysubmit($options = []) { - $affix = ' '; + $str = ' '; if (isset($options['submit'])) { - $affix = ' lay-submit="'.$options['submit'] .'"'; + $str = ' lay-submit="' . $options['submit'] . '"'; } - return $affix; + return $str; } - protected function layignore($options = []) + + protected function layignore($options = []) { - $affix = ' '; + $str = ' '; if (isset($options['ignore'])) { - $affix = ' lay-ignore="'.$options['ignore'] .'"'; + $str = ' lay-ignore="' . $options['ignore'] . '"'; } - return $affix; + return $str; } - protected function laystep($options = []) + + protected function laystep($options = []) { $str = ' '; if (isset($options['step'])) { @@ -1490,26 +1531,28 @@ protected function laystep($options = []) } return $str; } + /**搜索 * @return string */ - protected function laysearch($options = []) + protected function laysearch($options = []) { - $search = ''; + $str = ''; if (!isset($options['search']) || $options['search'] == true) { - $search = ' lay-search'; + $str = ' lay-search'; } - return $search; + return $str; } - protected function layskin($options = []) + protected function layskin($options = []) { - $search = ''; + $str = ''; if (isset($options['skin'])) { - $affix = ' lay-skin="'.$options['skin'] .'"'; + $str = ' lay-skin="' . $options['skin'] . '"'; } - return $search; + return $str; } + /** * @param $ops * @param $val @@ -1517,7 +1560,7 @@ protected function layskin($options = []) * @return string * 是否选中 */ - protected function selectedOrchecked($select=[], $val='', $type = 1) + protected function selectedOrchecked($select = [], $val = '', $type = 1) { if ($select == $val) { if ($type == 1) return 'selected'; @@ -1526,7 +1569,7 @@ protected function selectedOrchecked($select=[], $val='', $type = 1) return ''; } - protected function labelRequire($options=[]) + protected function labelRequire($options = []) { if (isset($options['verify']) && ($options['verify'] == 'required' || strpos($options['verify'], 'required') !== false)) { return 'required'; @@ -1534,10 +1577,10 @@ protected function labelRequire($options=[]) return ''; } - protected function readonlyOrdisabled($options=[]) + protected function readonlyOrdisabled($options = []) { - if (isset($options['readonly']) && $options['readonly']) { + if (isset($options['readonly']) && $options['readonly']) { return 'readonly'; } if (isset($options['disabled']) && $options['disabled']) { @@ -1545,33 +1588,36 @@ protected function readonlyOrdisabled($options=[]) } return ''; } + //自定义class属性 - protected function getClass($options=[]) + protected function getClass($options = []) { if (isset($options['class']) && $options['class']) { $classArr = is_array($options['class']) ? $options['class'] : explode(',', $options['class']); - return ' ' .implode(' ', $classArr).' '; + return ' ' . implode(' ', $classArr) . ' '; } return ''; } - protected function getStyle( $options=[]) + + protected function getStyle($options = []) { $options['style'] = ''; if (!empty($options['style']) || !empty($options['css'])) { - return ' style="' . $options['style'] . $options['style'].'" '; + return ' style="' . $options['style'] . $options['style'] . '" '; } return ' '; } - protected function getExtend($options=[]) + + protected function getExtend($options = []) { - if(is_array($options['extend'])) { + if (is_array($options['extend'])) { $attr = ' '; - foreach($options['extend'] as $key => $value) { - $attr.= $key .'="'.$value . '"'; + foreach ($options['extend'] as $key => $value) { + $attr .= $key . '="' . $value . '"'; } return $attr; - }else{ - return ' ' . $options['extend'].' '; + } else { + return ' ' . $options['extend'] . ' '; } } @@ -1580,11 +1626,13 @@ protected function getExtend($options=[]) * @param $options * @return string */ - protected function getNameValueAttr($name='',$value='',$options=[]){ - list($name,$id) = $this->getNameId($name,$options); - $value = $this->getValue($name,$value); - return <<getNameId($name, $options); + $value = $this->getValue($name, $value); + $value = isset($value) ? 'data-value="'.$value.'" value="'.$value.'"':''; + return <<getExtend($options); - }else{ - $options['id'] = $options['id']??$name; - $options['name'] = $options['formname']??($options['fromName']??$name); + $attr .= $this->getExtend($options); + } else { + $options['id'] = $options['id'] ?? $name; + $options['name'] = $options['formname'] ?? ($options['fromName'] ?? $name); $options['label'] = $options['label'] ?? $name; $options['tips'] = $options['tips'] ?? ''; $options['filter'] = $options['filter'] ?? $name; foreach ($options as $key => $val) { - switch ($key){ + switch ($key) { case 'class': case 'tips': case 'css': case 'label': break; case 'placeholder': - $attr.= $key.'="'. $this->__($val).'" '; + $attr .= $key . '="' . $this->__($val) . '" '; break; case 'verify': - $attr.= $this->layverify($options); + $attr .= $this->layverify($options); break; case 'filter': - $attr.= $this->layfilter($options); + $attr .= $this->layfilter($options); break; case 'step': - $attr.= $this->laystep($options); + $attr .= $this->laystep($options); break; case 'affix': - $attr.= $this->layaffix($options); + $attr .= $this->layaffix($options); break; case 'autocomplete': - $attr.= $this->layautocomplete($options); + $attr .= $this->layautocomplete($options); break; case 'submit': - $attr.= $this->laysubmit($options); + $attr .= $this->laysubmit($options); break; case 'ignore': - $attr.= $this->layignore($options); + $attr .= $this->layignore($options); break; case 'style': - $attr.= $this->getStyle($options); + $attr .= $this->getStyle($options); case 'readonly': case 'disabled': - $attr.= $this->readonlyOrdisabled($options); + $attr .= $this->readonlyOrdisabled($options); break; case 'search': - $attr.= $this->laysearch($options); + $attr .= $this->laysearch($options); break; case 'skin': - $attr.= $this->layskin($options); + $attr .= $this->layskin($options); break; case 'value': - $attr .= $key."='".$this->entities($val) ."' data-".$key."='".$this->entities($val)."' "; + $attr .= $key . "='" . $this->entities($val) . "' data-" . $key . "='" . $this->entities($val) . "' "; break; case 'attr': - if(is_object($val) || is_array($val)){ + if (is_object($val) || is_array($val)) { $val = (array)$val; - $val = implode(',',$val); + $val = implode(',', $val); } - $attr .= " data-".$key."='".$val."' "; + $attr .= " data-" . $key . "='" . $val . "' "; break; default: - if(is_object($val) || is_array($val)){ + if (is_object($val) || is_array($val)) { $val = (array)$val; - $val = $val[$name]?? json_encode($val, JSON_UNESCAPED_UNICODE); + $val = $val[$name] ?? json_encode($val, JSON_UNESCAPED_UNICODE); } - $attr .= " data-".$key."='".$val."' "; + $attr .= " data-" . $key . "='" . $val . "' "; break; } @@ -1677,9 +1726,10 @@ public function getOptionsAttr($name='',$options=[]){ * @param $options * @return string */ - protected function getDataPropAttr($name='',$value='',$options=[]){ - $str = $this->getNameValueAttr($name,$value,$options); - $str .=$this->getOptionsAttr($name,$options); + protected function getDataPropAttr($name = '', $value = '', $options = []) + { + $str = $this->getNameValueAttr($name, $value, $options); + $str .= $this->getOptionsAttr($name, $options); return $str; } @@ -1689,13 +1739,14 @@ protected function getDataPropAttr($name='',$value='',$options=[]){ * @param $value * @return string */ - protected function getValue($name,$value){ + protected function getValue($name, $value) + { - if(is_object($value) || is_array($value)){ + if (is_object($value) || is_array($value)) { $value = (array)$value; - $value = $value[$name]??implode(',',$value); + $value = $value[$name] ?? implode(',', $value); } - $value = !is_null($value) ? $value : ''; + $value = !is_null($value) ? $value : ''; return $this->entities($value); } @@ -1706,10 +1757,11 @@ protected function getValue($name,$value){ * @param $options * @return array */ - protected function getNameId($name='',$options=[]){ - $name = $options['formname']??$name; - $id = $options['id']??$name; - return [$name,$id]; + protected function getNameId($name = '', $options = []) + { + $name = $options['formname'] ?? $name; + $id = $options['id'] ?? $name; + return [$name, $id]; } /** @@ -1718,10 +1770,11 @@ protected function getNameId($name='',$options=[]){ * @param $value * @return array|false|mixed|string[] */ - protected function getArray($name='', $value= []){ + protected function getArray($name = '', $value = []) + { - if (is_string($value) && strpos($value, "\n") !== false) return explode("\n", $value); - if (is_string($value) && strpos($value, ",") !== false) return explode(",", $value); + if (is_string($value) && strpos($value, "\n") !== false) return explode("\n", $value); + if (is_string($value) && strpos($value, ",") !== false) return explode(",", $value); if (is_string($value) && strpos($value, "|") !== false) return explode("|", $value); return $value; } @@ -1731,10 +1784,13 @@ protected function getArray($name='', $value= []){ * @param $string * @return float|int|mixed|string */ - protected function __($string=''){ + protected function __($string = '') + { return lang($this->entity_decode($string)); } - protected function getTitle($string){ + + protected function getTitle($string) + { return $this->__(Str::title($string)); }