Filter.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * Filter.php UTF-8
  4. * 前端页面搜索
  5. *
  6. * @date : 2017/11/27 16:35
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace cmf\view;
  13. class Filter {
  14. /**
  15. * @param array $data 数组
  16. * @param string $name 名称
  17. * @param string $current 当前默认值
  18. * @param string $select2
  19. * @param string $disable 是否不可更改
  20. *
  21. * @return string
  22. */
  23. public static function selectCommon($data, $name, $current, $select2 = 'select_2', $disable = '') {
  24. $txt = "<select class='form-control $select2' name='$name' $disable style='min-width: 200px'>";
  25. $txt .= "<option value='0' selected >".lang('please select')."</option>";
  26. foreach ($data as $_k => $_v) {
  27. $select = '';
  28. if ($current == $_k) {
  29. $select = ' selected ';
  30. }
  31. $txt .= "<option value='$_k' $select >$_v</option>";
  32. }
  33. $txt .= "</select>";
  34. return $txt;
  35. }
  36. /**
  37. * @param array $data 数组
  38. * @param string $name 名称
  39. * @param string $current 当前默认值
  40. * @param $key
  41. * @param string $select2
  42. *
  43. * @return string
  44. */
  45. public static function selectCommon2($data, $name, $current, $key, $select2 = 'select_2') {
  46. $txt = "<select class='form-control $select2' name='$name' style='min-width: 200px'>";
  47. $txt .= "<option value='0' selected >".lang('please select')."</option>";
  48. foreach ($data as $_k => $_v) {
  49. $select = '';
  50. if ($current == $_k) {
  51. $select = ' selected ';
  52. }
  53. $txt .= "<option value='$_k' $select >$_v[$key]</option>";
  54. }
  55. $txt .= "</select>";
  56. return $txt;
  57. }
  58. public static function timeChoose($start_time = '', $end_time = '', $format = 'yyyy-mm-dd hh:mm:ss') {
  59. $date = 'datetime';
  60. if ($format == 'yyyy-mm-dd') {
  61. $date = 'date';
  62. }
  63. if ($format == 'yyyy') {
  64. $date = 'year';
  65. }
  66. if ($format == 'hh:mm:ss') {
  67. $date = 'time';
  68. }
  69. if ($format == 'yyyy-mm') {
  70. $date = 'year-month';
  71. }
  72. // if (empty($start_time)) {
  73. // $start_time = request()->param('start_time');
  74. // }
  75. // if (empty($end_time)) {
  76. // $end_time = request()->param('end_time');
  77. // }
  78. $txt = '<input type="text" name="start_time" class="js-'.$date.' form-control input-inline date valid" value="'
  79. .$start_time.'"
  80. placeholder="'.lang('start time').'" style="width: 150px;" autocomplete="off">';
  81. if ($end_time) {
  82. $txt .= ' - ';
  83. $txt .= '<input type="text" class="js-'.$date
  84. .' form-control input-inline date valid" name="end_time" value="'
  85. .$end_time.'"
  86. placeholder="'.lang('end time').'" style="width: 150px;" autocomplete="off">';
  87. }
  88. return $txt;
  89. }
  90. /**
  91. * 设置时间选择框(仅为单个时间选择框)
  92. *
  93. * @param string $time 当前时间值
  94. * @param string $name 输入框name
  95. * @param string $placeholder 提示信息
  96. * @param string $format 时间格式
  97. *
  98. * @return string
  99. */
  100. public static function timeChoose2($time = '', $name = '', $placeholder = '', $format = 'yyyy-mm-dd hh:mm:ss') {
  101. $date = 'datetime';
  102. if ($format == 'yyyy-mm-dd') {
  103. $date = 'date';
  104. }
  105. if ($format == 'yyyy') {
  106. $date = 'year';
  107. }
  108. if ($format == 'hh:mm:ss') {
  109. $date = 'time';
  110. }
  111. if ($format == 'yyyy-mm') {
  112. $date = 'year-month';
  113. }
  114. $txt = '<input type="text" name="'.$name.'" class="js-'.$date.' form-control input-inline date valid" value="'
  115. .$time.'"
  116. placeholder="'.$placeholder.'" autocomplete="off">';
  117. return $txt;
  118. }
  119. public static function checkCommon($data, $name, $current, $inline = 'inline') {
  120. if (empty($data)) {
  121. return '';
  122. }
  123. $_current = $current;
  124. if (!is_array($current)) {
  125. $_current = explode(',', $current);
  126. }
  127. $_txt = "<div class='checkbox'>";
  128. foreach ($data as $_k => $_v) {
  129. $box_checked = '';
  130. if (in_array($_k, $_current)) {
  131. $box_checked = ' checked ';
  132. }
  133. $_txt
  134. .= <<<EOF
  135. <label "$inline">
  136. <input type="checkbox" name="$name" value="{$_k}" {$box_checked} > {$_v}
  137. </label>
  138. &nbsp;&nbsp;
  139. EOF;
  140. if (empty($inline)) {
  141. $_txt .= "<br />";
  142. }
  143. }
  144. $_txt .= '</div>';
  145. return $_txt;
  146. }
  147. /**
  148. * @param array $data
  149. * @param string $name
  150. * @param string $current
  151. * @param $inline
  152. *
  153. * @return string
  154. */
  155. public static function radioCommon($data = [], $name = '', $current = '', $inline = 'radio-inline') {
  156. $_html = '';
  157. foreach ($data as $_k => $_v) {
  158. $radio_checked = '';
  159. if ($current == $_k) {
  160. $radio_checked = ' checked ';
  161. }
  162. $_html
  163. .= <<<EOF
  164. <label class="$inline">
  165. <input type="radio" name="$name" value="{$_k}" {$radio_checked} > {$_v}
  166. </label>
  167. EOF;
  168. }
  169. return $_html;
  170. }
  171. public static function button($button = []) {
  172. /**
  173. * $button = ['type' => 'search|clear', 'title' => 'xx', 'uri' => null]];
  174. */
  175. $_html = '';
  176. if ($button['type'] == 'search') {
  177. $_html .= "<button id='search' class='btn btn-success'>{$button['title']}</button>";
  178. }
  179. if ($button['type'] == 'clear') {
  180. $uri = empty($button['uri']) ? url() : $button['uri'];
  181. $_html .= "<a class='btn btn-default' href='".$uri."'>{$button['title']}</a>";
  182. }
  183. return $_html;
  184. }
  185. public static function text($name = '', $value = '', $placeholder = '') {
  186. return '<input type="text" class="form-control" name="'.$name.'" style="width: 180px;"
  187. value="'.$value.'" placeholder="'.$placeholder.'">';
  188. }
  189. public static function text2($name = '', $value = '', $placeholder = '', $required = '') {
  190. return '<input type="text" class="form-control" name="'.$name.'"
  191. value="'.$value.'" placeholder="'.$placeholder.'" '.$required.'>';
  192. }
  193. }