123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- /**
- * Filter.php UTF-8
- * 前端页面搜索
- *
- * @date : 2017/11/27 16:35
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace cmf\view;
- class Filter {
- /**
- * @param array $data 数组
- * @param string $name 名称
- * @param string $current 当前默认值
- * @param string $select2
- * @param string $disable 是否不可更改
- *
- * @return string
- */
- public static function selectCommon($data, $name, $current, $select2 = 'select_2', $disable = '') {
- $txt = "<select class='form-control $select2' name='$name' $disable style='min-width: 200px'>";
- $txt .= "<option value='0' selected >".lang('please select')."</option>";
- foreach ($data as $_k => $_v) {
- $select = '';
- if ($current == $_k) {
- $select = ' selected ';
- }
- $txt .= "<option value='$_k' $select >$_v</option>";
- }
- $txt .= "</select>";
- return $txt;
- }
- /**
- * @param array $data 数组
- * @param string $name 名称
- * @param string $current 当前默认值
- * @param $key
- * @param string $select2
- *
- * @return string
- */
- public static function selectCommon2($data, $name, $current, $key, $select2 = 'select_2') {
- $txt = "<select class='form-control $select2' name='$name' style='min-width: 200px'>";
- $txt .= "<option value='0' selected >".lang('please select')."</option>";
- foreach ($data as $_k => $_v) {
- $select = '';
- if ($current == $_k) {
- $select = ' selected ';
- }
- $txt .= "<option value='$_k' $select >$_v[$key]</option>";
- }
- $txt .= "</select>";
- return $txt;
- }
- public static function timeChoose($start_time = '', $end_time = '', $format = 'yyyy-mm-dd hh:mm:ss') {
- $date = 'datetime';
- if ($format == 'yyyy-mm-dd') {
- $date = 'date';
- }
- if ($format == 'yyyy') {
- $date = 'year';
- }
- if ($format == 'hh:mm:ss') {
- $date = 'time';
- }
- if ($format == 'yyyy-mm') {
- $date = 'year-month';
- }
- // if (empty($start_time)) {
- // $start_time = request()->param('start_time');
- // }
- // if (empty($end_time)) {
- // $end_time = request()->param('end_time');
- // }
- $txt = '<input type="text" name="start_time" class="js-'.$date.' form-control input-inline date valid" value="'
- .$start_time.'"
- placeholder="'.lang('start time').'" style="width: 150px;" autocomplete="off">';
- if ($end_time) {
- $txt .= ' - ';
- $txt .= '<input type="text" class="js-'.$date
- .' form-control input-inline date valid" name="end_time" value="'
- .$end_time.'"
- placeholder="'.lang('end time').'" style="width: 150px;" autocomplete="off">';
- }
- return $txt;
- }
- /**
- * 设置时间选择框(仅为单个时间选择框)
- *
- * @param string $time 当前时间值
- * @param string $name 输入框name
- * @param string $placeholder 提示信息
- * @param string $format 时间格式
- *
- * @return string
- */
- public static function timeChoose2($time = '', $name = '', $placeholder = '', $format = 'yyyy-mm-dd hh:mm:ss') {
- $date = 'datetime';
- if ($format == 'yyyy-mm-dd') {
- $date = 'date';
- }
- if ($format == 'yyyy') {
- $date = 'year';
- }
- if ($format == 'hh:mm:ss') {
- $date = 'time';
- }
- if ($format == 'yyyy-mm') {
- $date = 'year-month';
- }
- $txt = '<input type="text" name="'.$name.'" class="js-'.$date.' form-control input-inline date valid" value="'
- .$time.'"
- placeholder="'.$placeholder.'" autocomplete="off">';
- return $txt;
- }
- public static function checkCommon($data, $name, $current, $inline = 'inline') {
- if (empty($data)) {
- return '';
- }
- $_current = $current;
- if (!is_array($current)) {
- $_current = explode(',', $current);
- }
- $_txt = "<div class='checkbox'>";
- foreach ($data as $_k => $_v) {
- $box_checked = '';
- if (in_array($_k, $_current)) {
- $box_checked = ' checked ';
- }
- $_txt
- .= <<<EOF
- <label "$inline">
- <input type="checkbox" name="$name" value="{$_k}" {$box_checked} > {$_v}
- </label>
-
- EOF;
- if (empty($inline)) {
- $_txt .= "<br />";
- }
- }
- $_txt .= '</div>';
- return $_txt;
- }
- /**
- * @param array $data
- * @param string $name
- * @param string $current
- * @param $inline
- *
- * @return string
- */
- public static function radioCommon($data = [], $name = '', $current = '', $inline = 'radio-inline') {
- $_html = '';
- foreach ($data as $_k => $_v) {
- $radio_checked = '';
- if ($current == $_k) {
- $radio_checked = ' checked ';
- }
- $_html
- .= <<<EOF
- <label class="$inline">
- <input type="radio" name="$name" value="{$_k}" {$radio_checked} > {$_v}
- </label>
- EOF;
- }
- return $_html;
- }
- public static function button($button = []) {
- /**
- * $button = ['type' => 'search|clear', 'title' => 'xx', 'uri' => null]];
- */
- $_html = '';
- if ($button['type'] == 'search') {
- $_html .= "<button id='search' class='btn btn-success'>{$button['title']}</button>";
- }
- if ($button['type'] == 'clear') {
- $uri = empty($button['uri']) ? url() : $button['uri'];
- $_html .= "<a class='btn btn-default' href='".$uri."'>{$button['title']}</a>";
- }
- return $_html;
- }
- public static function text($name = '', $value = '', $placeholder = '') {
- return '<input type="text" class="form-control" name="'.$name.'" style="width: 180px;"
- value="'.$value.'" placeholder="'.$placeholder.'">';
- }
- public static function text2($name = '', $value = '', $placeholder = '', $required = '') {
- return '<input type="text" class="form-control" name="'.$name.'"
- value="'.$value.'" placeholder="'.$placeholder.'" '.$required.'>';
- }
- }
|