123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540 |
- <?php
- /*
- |--------------------------------------------------------------------------
- | input.php 输出input的html代码
- |--------------------------------------------------------------------------
- */
- namespace MazeApp\Manage\Lib;
- use Maze;
- class Input
- {
- /**
- * desc
- *
- * @return string
- */
- static public function modal($modal, $desc)
- {
- return '<a href="#maze_modal" data-toggle="modal" onclick="$(\'#maze_modal_body\').html($(this).next().html())">' . $modal . '</a><div style="display:none;">' . $desc . '</div>';
- }
-
- /**
- * desc
- *
- * @return string
- */
- static public function desc($desc)
- {
- return '';
- return $desc;
- }
-
- /**
- * hr 分割线
- *
- * @return string
- */
- static public function hr($param)
- {
- return '<div class="maze_form_hr '.(isset($param['class']) ? $param['class'] : '').'" '.(isset($param['attr']) ? $param['attr'] : '').'>' . $param['name'] . '</div>';
- }
-
- /**
- * cue
- *
- * @return string
- */
- static public function cue($param)
- {
- $param['cue'] = isset($param['cue']) ? $param['cue'] : '';
- if(strpos($param['name'], '-') !== false)
- {
- $temp = explode('-', $param['name']);
- $param['name'] = $temp[0];
- $param['cue'] = $temp[1];
- }
- elseif(strpos($param['name'], '(') !== false)
- {
- $temp = explode('(', $param['name']);
- $param['name'] = $temp[0];
- $param['cue'] = str_replace(')', '', $temp[1]);
- }
- elseif(strpos($param['name'], '(') !== false)
- {
- $temp = explode('(', $param['name']);
- $param['name'] = $temp[0];
- $param['cue'] = str_replace(')', '', $temp[1]);
- }
-
- return $param;
- }
-
- /**
- * pageLeft
- *
- * @return string
- */
- static public function pageLeft($param)
- {
- $param = self::cue($param);
-
- if($param['cue'])
- {
- $param['cue'] = '<span style="font-size:12px;font-weight:normal;font-color:#bababa;margin-left:5px;">[' . $param['cue'] . ']</span>';
- }
-
- $html = '<label style="font-size:14px;font-weight:bold;">' . $param['name'] . $param['cue'] . '</label>';
-
- return $html;
- }
- /**
- * textarea
- *
- * @return string
- */
- static public function textarea($param)
- {
- return '<textarea style="height:100px;" update_type="value" class="update_value form-control '.(isset($param['valid']) ? $param['valid'] : '').'" name="' . $param['name'] . '" >' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '</textarea>';
-
- return '<textarea style="height:100px;" update_type="value" class="update_value form-control '.(isset($param['valid']) ? $param['valid'] : '').'" name="' . $param['name'] . '" value="'.(isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')).'">' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '</textarea>';
- }
- /**
- * image
- *
- * @return string
- */
- static public function image($param)
- {
- if(isset($param['value']))
- {
- $pic = 'src="' . $param['value'] . '"';
- }
- elseif(isset($param['places']))
- {
- $pic = 'src="http://placehold.it/'.$param['place'].'"';
- }
- else
- {
- $pic = 'src="" style=display:none;';
- }
- return '<input type="button" class="form-control image_upload" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="选择文件"/>
- <div style="margin:10px;">
- <img ' . $pic . ' class="update_value" update_type="src" id="show_' . $param['name'] . '_' . $param['index'] . '" width="150" /></div>
- <input type="text" class="update_value form-control '.(isset($param['valid']) ? $param['valid'] : '').'" name="' . $param['name'] . '" id="' . $param['name'] . '_' . $param['index'] . '" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '">';
- }
- /**
- * images
- *
- * @return string
- */
- static public function images($param)
- {
- $pic = '';
- if(isset($param['value']))
- {
- $temp = explode(',', $param['value']);
- foreach($temp as $k => $v)
- {
- $pic .= '<a href="javascript:;" title="点此删除" onclick="picDel(\''.$v.'\', $(this), \''.$param['name'] . '_' . $param['index'].'\')"><img src="'.$v.'" id="show_' . $param['name'] . '_' . $param['index'] . '_'.$k.'" width="150" style="margin-left:5px;" alt="点此删除"/></a>';
- }
- }
- return '<input type="button" class="form-control image_upload" mul="yes" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="选择文件"/>
- <div style="margin:10px;" update_type="html" class="update_value ' . $param['name'] . '_' . $param['index'] . '_mul">'.$pic.'</div>
-
- <input type="text" class="update_value form-control '.(isset($param['valid']) ? $param['valid'] : '').'" name="' . $param['name'] . '" id="' . $param['name'] . '_' . $param['index'] . '" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '">';
- }
- /**
- * upload
- *
- * @return string
- */
- static public function upload($param)
- {
- return '<input type="file" class="form-control image_upload" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '"/>
- <div style="margin:10px;"><input type="text" class="update_value form-control '.(isset($param['valid']) ? $param['valid'] : '').'" name="' . $param['name'] . '" id="' . $param['name'] . '_' . $param['index'] . '" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '">
- </div>';
- //return '<input type="file" class="form-control" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '" name="' . $param['name'] . '"/>';
- }
- /**
- * editor
- *
- * @return string
- */
- static public function editor($param)
- {
- return '<textarea update_type="value" class="update_value editor" id="' . $param['name'] . '_editor" key="' . (isset($param['key']) ? $param['key'] : 1) . '" name="' . $param['name'] . '" rows="8" >' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '</textarea>';
- }
- /**
- * selector
- *
- * @return string
- */
- static public function selector($param, $type = '')
- {
- $html = '';
-
- if(isset($param['key']) && strpos($param['key'], '.css') !== false)
- {
- $param['key'] = '<link rel="stylesheet" href="'.$param['key'].'"/>';
- }
- if(isset($param['option']))
- {
- foreach($param['option'] as $k => $v)
- {
- $check = '';
- if((isset($param['value']) && $param['value'] == $k) || (empty($param['value']) && isset($param['default']) && $param['default'] == $k))
- {
- $check = 'checked';
- }
- if(is_array($v))
- {
- $value = $v['name'];
- }
- else
- {
- $value = $v;
- }
-
- $html .= '<a href="javascript:;" onclick="selector($(this))" class="' . $param['name'] . '_selector selector" data-check="' . $check . '" data-name="' . $param['name'] . '" data-value="' . $k . '">' . $value . '</a> ';
- }
-
- $html .= self::hidden($param);
- }
- return '<div class="am-btn-group" >' . $html . '</div>';
- }
-
-
- /**
- * radio
- *
- * @return string
- */
- static public function radio($param, $type = '')
- {
- $html = '';
- if(isset($param['option']))
- {
- if(isset($param['option']['state']) && $param['option']['state'] == 1)
- {
- if(isset($param['value']))
- {
- $param['value'] = explode(',', $param['value']);
- }
- else
- {
- $param['value'] = array();
- }
- # 处理比较复杂的多维数组
- unset($param['option']['state']);
- foreach($param['option'] as $k => $v)
- {
- $check = '';
- if(isset($param['update_parent']))
- {
- $input_type = $param['update_parent'];
- }
- else
- {
- $input_type = $param['update'];
- }
-
- //{check}
- $html .= '<input update_type="checked" class="update_value checkbox-checkall '.(isset($param['valid']) ? $param['valid'] : '').'" type="' . $input_type . '" name="temp[]" value="' . $k . '"/> ' . $v['name'] . ' <br />';
- $span = array('','');
- if(isset($v['child']) && $v['child'])
- {
- //$i = 1;
- $j = -1;
- $html .= '<ul style="list-style:none;margin:0px;display:;" class="">';
- foreach($v['child'] as $ki => $vi)
- {
- if(!is_array($vi))
- {
- $temp = $vi;
- $vi = array();
- $vi['name'] = $temp;
- $vi['id'] = $ki;
- }
- if(isset($v['url']))
- {
- $span = array('<span class="edit" data-url="'.Maze::url($v['url'] . '?id=' . $vi['id']).'">', '</span>');
- }
- $check = '';
- $disabled = 'disabled="true"';
- if((isset($param['value']) && in_array($ki, $param['value'])) || (empty($param['value']) && isset($param['default']) && is_array($param['default']) && (in_array($k . '_' . $ki, $param['default']))))
- {
- $check = 'checked';
- $disabled = '';
- $j++;
- }
- $input = '';
-
- if(isset($param['update_input']))
- {
- if(isset($param['update_input_data']) && isset($param['update_input_data'][$j]))
- {
- $input_value = $param['update_input_data'][$j];
- }
- else
- {
- $input_value = 1;
- }
-
- $input = '['.$param['update_input'].']:<input class="form-control" name="' . $param['name'] . '_input[]" type="text" value="'.$input_value.'" style="width:5%;margin:5px;display:inline" placeholder="'.$param['update_input'].'" '.$disabled.'/>';
- }
-
- $html .= '<li><input update_type="checked" class="update_value checkbox-checkall-' . $k . ' '.(isset($param['valid']) ? $param['valid'] : '').'" type="' . $param['update'] . '" name="' . $param['name'] . '[]" value="' . $ki . '" '.$check.'/> ' . $span[0] . $vi['name'] . $span[1] . ' '.$input.'</li>';
- //++$i;
- }
- $html .= '</ul>';
- }
- $html .= '<br />';
- }
- }
- else
- {
- $js = '';
- if(isset($param['show']) && !is_array($param['show']))
- {
- $js = 'onclick="inputShow($(this), \''.$param['show'].'\')"';
- }
- foreach($param['option'] as $k => $v)
- {
- $check = '';
- if(is_array($v))
- {
- $value = $v['name'];
- isset($v['id']) && $k = $v['id'];
- }
- else
- {
- $value = $v;
- }
-
- if(isset($param['bit'][$k]))
- {
- if(isset($param['value']) && ($param['value'] & $k) > 0)
- {
- $check = 'checked';
- }
- }
- elseif(isset($param['value']))
- {
- if(is_string($param['value']) && strpos(',' . $param['value'], ',' . $k) !== false)
- {
- $check = 'checked';
- }
- elseif(is_array($param['value']) && in_array($k, $param['value']))
- {
- $check = 'checked';
- }
- }
- elseif(isset($param['default']))
- {
- if(is_string($param['default']) && strpos(',' . $param['default'], ',' . $k) !== false)
- {
- $check = 'checked';
- }
- elseif(is_array($param['default']) && in_array($k, $param['default']))
- {
- $check = 'checked';
- }
- }
- $html .= '<input update_type="checked" class="update_value '.(isset($param['valid']) ? $param['valid'] : '').'" type="' . $param['update'] . '" name="' . $param['name'] . '[]" value="' . $k . '" '.$check. ' '.$js.'/> ' . $value . ' ';
- }
- }
- }
- return '<div class="am-btn-group" >' . $html . '</div>';
- }
- /**
- * select
- *
- * @return string
- */
- static public function select($param, $class = '', $hidden = '', $change = '')
- {
- $html = $class ? '<div class="'.$class.'">' : '';
-
- if(isset($param['child']))
- {
- $child_param['name'] = strpos($param['name'], 'add_') !== false ? 'add_' . $param['child_name'] : 'set_' . $param['child_name'];
- isset($param['value']) && $param['value'] = $param['value'];
- isset($param['child_value']) && $child_param['value'] = $param['child_value'];
-
- $change = 'style="width:45%" id="'.$param['name'].'" data-child="'.$child_param['name'].'_child" ';
- $class = ' change';
- //$param['name'] .= '_parent';
-
- }
- $html .= $hidden . '<select class="update_value form-control '.$class.' '.(isset($param['valid']) ? $param['valid'] : '').'" name="' . $param['name'] . '" ' . $change . '>';
- if(isset($param['option']))
- {
- if(isset($param['lang']) && $param['lang'])
- {
- $html .= '<option value="0" selected>' . $param['lang'] . '</option>';
- }
- foreach($param['option'] as $k => $v)
- {
- if(is_array($v))
- {
- $value = $v['name'];
- isset($v['id']) && $k = $v['id'];
- }
- else
- {
- $value = $v;
- }
- $check = '';
-
- if((isset($param['value']) && $param['value'] == $k) || (isset($param['bit'][$k]) && isset($param['value']) && ($param['value'] & $k) > 0) || (empty($param['value']) && isset($param['default']) && $param['default'] == $k))
- {
- $check = 'selected';
- }
- if(is_array($v))
- {
- $value = isset($v['name']) ? $v['name'] : $v['lang'];
- }
- else
- {
- $value = $v;
- }
- $html .= '<option value="' . $k . '" '.$check.'>' . $value . '</option>';
- }
- }
- $html .= '</select>';
-
-
- if(isset($param['child']))
- {
- $child = $child_param['name'];
- $hidden = self::hidden(array('name' => $child, 'class' => $child . '_child_value'));
- foreach($param['child'] as $k => $v)
- {
- $child_param['name'] = 'child-' . $k;
- $child_param['option'] = $v;
-
- $html .= self::select($child_param, $child . '_child '.$child .'_child_'.$k.'" parent="'.$k.'" style="display:none;margin-top: -35px;margin-left: 27%;"', $hidden);
- }
- }
-
- $html .= $class ? '</div>' : '';
- return $html;
- }
- /**
- * radio
- *
- * @return string
- */
- static public function checkbox($param)
- {
- return self::radio($param);
- }
- /**
- * text
- *
- * @return string
- */
- static public function text($param, $class = '')
- {
- if($class)
- {
- return '<div class="">'.self::text($param, false).'</div>';
- }
- else
- {
- $auto = '';
- if(isset($param['autocomplete']))
- {
- $auto = 'complete="' . Maze::url($param['autocomplete']) . '"';
- }
- return '<input ' . $auto . ' type="' . (isset($param['update']) ? $param['update'] : 'text') . '" class="update_value ' . (isset($param['class']) ? $param['class'] : 'form-control') .' '.(isset($param['valid']) ? $param['valid'] : '').'" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '" name="' . $param['name'] . '" id="' . $param['name'] . '_value" placeholder="'.(isset($param['placeholder']) ? $param['placeholder'] : '').'"/>';
- }
- }
- /**
- * password
- *
- * @return string
- */
- static public function password($param)
- {
- $param['value'] = '';
- return self::text($param);
- }
- /**
- * hidden
- *
- * @return string
- */
- static public function hidden($param)
- {
- $param['update'] = 'hidden';
- return self::text($param, '');
- }
- /**
- * time
- *
- * @return string
- */
- static public function time($param)
- {
- return '<input type="text" value="' . ((isset($param['value']) && $param['value'] > 0) ? date('Y-m-d', $param['value']) : ((isset($param['default']) && $param['default'] > 0) ? date('Y-m-d', $param['default']) : '')) . '" placeholder="'.(isset($param['lang']) ? $param['lang'] : '').'" name="' . $param['name'] . '" class="update_value form-control '.(isset($param['valid']) ? $param['valid'] : '').'" readonly onclick="WdatePicker()"/>';
- }
-
- /**
- * date
- *
- * @return string
- */
- static public function date($param)
- {
- return '<input type="text" value="' . ((isset($param['value']) && $param['value'] > 0) ? date('Y-m-d H:i:s', $param['value']) : ((isset($param['default']) && $param['default'] > 0) ? date('Y-m-d H:i:s', $param['default']) : '')) . '" placeholder="'.(isset($param['lang']) ? $param['lang'] : '').'" name="' . $param['name'] . '" class="update_value form-control '.(isset($param['valid']) ? $param['valid'] : '').'" readonly onclick="WdatePicker({dateFmt:\'yyyy-MM-dd HH:mm:ss\'})"/>';
- }
- /**
- * div
- *
- * @return string
- */
- static public function node($param, $type = 'div')
- {
- $result = array('','');
- foreach($param as $k => $v)
- {
- $result[0] .= '<'.$type.' '.$v.'>';
- $result[1] .= '</'.$type.'>';
- }
- return $result;
- }
- }
|