7ea6dafb21a40c378d677905747c1d4008d75734.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | input.php 输出input的html代码
  5. |--------------------------------------------------------------------------
  6. */
  7. namespace MazeApp\Manage\Lib;
  8. use Maze;
  9. class Input
  10. {
  11. /**
  12. * desc
  13. *
  14. * @return string
  15. */
  16. static public function modal($modal, $desc)
  17. {
  18. return '<a href="#maze_modal" data-toggle="modal" onclick="$(\'#maze_modal_body\').html($(this).next().html())">' . $modal . '</a><div style="display:none;">' . $desc . '</div>';
  19. }
  20. /**
  21. * desc
  22. *
  23. * @return string
  24. */
  25. static public function desc($desc)
  26. {
  27. return '';
  28. return $desc;
  29. }
  30. /**
  31. * hr 分割线
  32. *
  33. * @return string
  34. */
  35. static public function hr($param)
  36. {
  37. return '<div class="maze_form_hr '.(isset($param['class']) ? $param['class'] : '').'" '.(isset($param['attr']) ? $param['attr'] : '').'>' . $param['name'] . '</div>';
  38. }
  39. /**
  40. * cue
  41. *
  42. * @return string
  43. */
  44. static public function cue($param)
  45. {
  46. $param['cue'] = isset($param['cue']) ? $param['cue'] : '';
  47. if(strpos($param['name'], '-') !== false)
  48. {
  49. $temp = explode('-', $param['name']);
  50. $param['name'] = $temp[0];
  51. $param['cue'] = $temp[1];
  52. }
  53. elseif(strpos($param['name'], '(') !== false)
  54. {
  55. $temp = explode('(', $param['name']);
  56. $param['name'] = $temp[0];
  57. $param['cue'] = str_replace(')', '', $temp[1]);
  58. }
  59. elseif(strpos($param['name'], '(') !== false)
  60. {
  61. $temp = explode('(', $param['name']);
  62. $param['name'] = $temp[0];
  63. $param['cue'] = str_replace(')', '', $temp[1]);
  64. }
  65. return $param;
  66. }
  67. /**
  68. * pageLeft
  69. *
  70. * @return string
  71. */
  72. static public function pageLeft($param)
  73. {
  74. $param = self::cue($param);
  75. if($param['cue'])
  76. {
  77. $param['cue'] = '<span style="font-size:12px;font-weight:normal;font-color:#bababa;margin-left:5px;">[' . $param['cue'] . ']</span>';
  78. }
  79. $html = '<label style="font-size:14px;font-weight:bold;">' . $param['name'] . $param['cue'] . '</label>';
  80. return $html;
  81. }
  82. /**
  83. * textarea
  84. *
  85. * @return string
  86. */
  87. static public function textarea($param)
  88. {
  89. 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>';
  90. 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>';
  91. }
  92. /**
  93. * image
  94. *
  95. * @return string
  96. */
  97. static public function image($param)
  98. {
  99. if(isset($param['value']))
  100. {
  101. $pic = 'src="' . $param['value'] . '"';
  102. }
  103. elseif(isset($param['places']))
  104. {
  105. $pic = 'src="http://placehold.it/'.$param['place'].'"';
  106. }
  107. else
  108. {
  109. $pic = 'src="" style=display:none;';
  110. }
  111. return '<input type="button" class="form-control image_upload" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="选择文件"/>
  112. <div style="margin:10px;">
  113. <img ' . $pic . ' class="update_value" update_type="src" id="show_' . $param['name'] . '_' . $param['index'] . '" width="150" /></div>
  114. <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'] : '')) . '">';
  115. }
  116. /**
  117. * images
  118. *
  119. * @return string
  120. */
  121. static public function images($param)
  122. {
  123. $pic = '';
  124. if(isset($param['value']))
  125. {
  126. $temp = explode(',', $param['value']);
  127. foreach($temp as $k => $v)
  128. {
  129. $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>';
  130. }
  131. }
  132. 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="选择文件"/>
  133. <div style="margin:10px;" update_type="html" class="update_value ' . $param['name'] . '_' . $param['index'] . '_mul">'.$pic.'</div>
  134. <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'] : '')) . '">';
  135. }
  136. /**
  137. * upload
  138. *
  139. * @return string
  140. */
  141. static public function upload($param)
  142. {
  143. return '<input type="file" class="form-control image_upload" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '"/>
  144. <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'] : '')) . '">
  145. </div>';
  146. //return '<input type="file" class="form-control" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '" name="' . $param['name'] . '"/>';
  147. }
  148. /**
  149. * editor
  150. *
  151. * @return string
  152. */
  153. static public function editor($param)
  154. {
  155. 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>';
  156. }
  157. /**
  158. * selector
  159. *
  160. * @return string
  161. */
  162. static public function selector($param, $type = '')
  163. {
  164. $html = '';
  165. if(isset($param['key']) && strpos($param['key'], '.css') !== false)
  166. {
  167. $param['key'] = '<link rel="stylesheet" href="'.$param['key'].'"/>';
  168. }
  169. if(isset($param['option']))
  170. {
  171. foreach($param['option'] as $k => $v)
  172. {
  173. $check = '';
  174. if((isset($param['value']) && $param['value'] == $k) || (empty($param['value']) && isset($param['default']) && $param['default'] == $k))
  175. {
  176. $check = 'checked';
  177. }
  178. if(is_array($v))
  179. {
  180. $value = $v['name'];
  181. }
  182. else
  183. {
  184. $value = $v;
  185. }
  186. $html .= '<a href="javascript:;" onclick="selector($(this))" class="' . $param['name'] . '_selector selector" data-check="' . $check . '" data-name="' . $param['name'] . '" data-value="' . $k . '">' . $value . '</a>&nbsp;&nbsp;';
  187. }
  188. $html .= self::hidden($param);
  189. }
  190. return '<div class="am-btn-group" >' . $html . '</div>';
  191. }
  192. /**
  193. * radio
  194. *
  195. * @return string
  196. */
  197. static public function radio($param, $type = '')
  198. {
  199. $html = '';
  200. if(isset($param['option']))
  201. {
  202. if(isset($param['option']['state']) && $param['option']['state'] == 1)
  203. {
  204. if(isset($param['value']))
  205. {
  206. $param['value'] = explode(',', $param['value']);
  207. }
  208. else
  209. {
  210. $param['value'] = array();
  211. }
  212. # 处理比较复杂的多维数组
  213. unset($param['option']['state']);
  214. foreach($param['option'] as $k => $v)
  215. {
  216. $check = '';
  217. if(isset($param['update_parent']))
  218. {
  219. $input_type = $param['update_parent'];
  220. }
  221. else
  222. {
  223. $input_type = $param['update'];
  224. }
  225. //{check}
  226. $html .= '<input update_type="checked" class="update_value checkbox-checkall '.(isset($param['valid']) ? $param['valid'] : '').'" type="' . $input_type . '" name="temp[]" value="' . $k . '"/> ' . $v['name'] . ' &nbsp;&nbsp;<br />';
  227. $span = array('','');
  228. if(isset($v['child']) && $v['child'])
  229. {
  230. //$i = 1;
  231. $j = -1;
  232. $html .= '<ul style="list-style:none;margin:0px;display:;" class="">';
  233. foreach($v['child'] as $ki => $vi)
  234. {
  235. if(!is_array($vi))
  236. {
  237. $temp = $vi;
  238. $vi = array();
  239. $vi['name'] = $temp;
  240. $vi['id'] = $ki;
  241. }
  242. if(isset($v['url']))
  243. {
  244. $span = array('<span class="edit" data-url="'.Maze::url($v['url'] . '?id=' . $vi['id']).'">', '</span>');
  245. }
  246. $check = '';
  247. $disabled = 'disabled="true"';
  248. 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']))))
  249. {
  250. $check = 'checked';
  251. $disabled = '';
  252. $j++;
  253. }
  254. $input = '';
  255. if(isset($param['update_input']))
  256. {
  257. if(isset($param['update_input_data']) && isset($param['update_input_data'][$j]))
  258. {
  259. $input_value = $param['update_input_data'][$j];
  260. }
  261. else
  262. {
  263. $input_value = 1;
  264. }
  265. $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.'/>';
  266. }
  267. $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] . '&nbsp;&nbsp;'.$input.'</li>';
  268. //++$i;
  269. }
  270. $html .= '</ul>';
  271. }
  272. $html .= '<br />';
  273. }
  274. }
  275. else
  276. {
  277. $js = '';
  278. if(isset($param['show']) && !is_array($param['show']))
  279. {
  280. $js = 'onclick="inputShow($(this), \''.$param['show'].'\')"';
  281. }
  282. foreach($param['option'] as $k => $v)
  283. {
  284. $check = '';
  285. if(is_array($v))
  286. {
  287. $value = $v['name'];
  288. isset($v['id']) && $k = $v['id'];
  289. }
  290. else
  291. {
  292. $value = $v;
  293. }
  294. if(isset($param['bit'][$k]))
  295. {
  296. if(isset($param['value']) && ($param['value'] & $k) > 0)
  297. {
  298. $check = 'checked';
  299. }
  300. }
  301. elseif(isset($param['value']))
  302. {
  303. if(is_string($param['value']) && strpos(',' . $param['value'], ',' . $k) !== false)
  304. {
  305. $check = 'checked';
  306. }
  307. elseif(is_array($param['value']) && in_array($k, $param['value']))
  308. {
  309. $check = 'checked';
  310. }
  311. }
  312. elseif(isset($param['default']))
  313. {
  314. if(is_string($param['default']) && strpos(',' . $param['default'], ',' . $k) !== false)
  315. {
  316. $check = 'checked';
  317. }
  318. elseif(is_array($param['default']) && in_array($k, $param['default']))
  319. {
  320. $check = 'checked';
  321. }
  322. }
  323. $html .= '<input update_type="checked" class="update_value '.(isset($param['valid']) ? $param['valid'] : '').'" type="' . $param['update'] . '" name="' . $param['name'] . '[]" value="' . $k . '" '.$check. ' '.$js.'/> ' . $value . ' &nbsp;&nbsp;';
  324. }
  325. }
  326. }
  327. return '<div class="am-btn-group" >' . $html . '</div>';
  328. }
  329. /**
  330. * select
  331. *
  332. * @return string
  333. */
  334. static public function select($param, $class = '', $hidden = '', $change = '')
  335. {
  336. $html = $class ? '<div class="'.$class.'">' : '';
  337. $child_class = '';
  338. if(isset($param['child']))
  339. {
  340. $child_param['name'] = strpos($param['name'], 'add_') !== false ? 'add_' . $param['child_name'] : 'set_' . $param['child_name'];
  341. isset($param['value']) && $param['value'] = $param['value'];
  342. isset($param['child_value']) && $child_param['value'] = $param['child_value'];
  343. $change = 'style="width:45%" id="'.$param['name'].'" data-child="'.$child_param['name'].'_child" ';
  344. $child_class = ' change';
  345. //$param['name'] .= '_parent';
  346. }
  347. $html .= $hidden . '<select class="update_value form-control '.$child_class.' '.(isset($param['valid']) ? $param['valid'] : '').'" name="' . $param['name'] . '" ' . $change . '>';
  348. if(isset($param['option']))
  349. {
  350. if(isset($param['lang']) && $param['lang'])
  351. {
  352. $html .= '<option value="0" selected>' . $param['lang'] . '</option>';
  353. }
  354. foreach($param['option'] as $k => $v)
  355. {
  356. if(is_array($v))
  357. {
  358. $value = $v['name'];
  359. isset($v['id']) && $k = $v['id'];
  360. }
  361. else
  362. {
  363. $value = $v;
  364. }
  365. $check = '';
  366. 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))
  367. {
  368. $check = 'selected';
  369. }
  370. if(is_array($v))
  371. {
  372. $value = isset($v['name']) ? $v['name'] : $v['lang'];
  373. }
  374. else
  375. {
  376. $value = $v;
  377. }
  378. $html .= '<option value="' . $k . '" '.$check.'>' . $value . '</option>';
  379. }
  380. }
  381. $html .= '</select>';
  382. if(isset($param['child']))
  383. {
  384. $child = $child_param['name'];
  385. $hidden = self::hidden(array('name' => $child, 'class' => $child . '_child_value'));
  386. foreach($param['child'] as $k => $v)
  387. {
  388. $child_param['name'] = 'child-' . $k;
  389. $child_param['option'] = $v;
  390. $html .= self::select($child_param, $child . '_child '.$child .'_child_'.$k.'" parent="'.$k.'" style="display:none;margin-top: -35px;margin-left: 47%;"', $hidden);
  391. }
  392. }
  393. $html .= $class ? '</div>' : '';
  394. return $html;
  395. }
  396. /**
  397. * radio
  398. *
  399. * @return string
  400. */
  401. static public function checkbox($param)
  402. {
  403. return self::radio($param);
  404. }
  405. /**
  406. * text
  407. *
  408. * @return string
  409. */
  410. static public function text($param, $class = '')
  411. {
  412. if($class)
  413. {
  414. return '<div class="">'.self::text($param, false).'</div>';
  415. }
  416. else
  417. {
  418. $auto = '';
  419. if(isset($param['autocomplete']))
  420. {
  421. $auto = 'complete="' . Maze::url($param['autocomplete']) . '"';
  422. }
  423. 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'] : '').'"/>';
  424. }
  425. }
  426. /**
  427. * password
  428. *
  429. * @return string
  430. */
  431. static public function password($param)
  432. {
  433. $param['value'] = '';
  434. return self::text($param);
  435. }
  436. /**
  437. * hidden
  438. *
  439. * @return string
  440. */
  441. static public function hidden($param)
  442. {
  443. $param['update'] = 'hidden';
  444. return self::text($param, '');
  445. }
  446. /**
  447. * time
  448. *
  449. * @return string
  450. */
  451. static public function time($param)
  452. {
  453. 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()"/>';
  454. }
  455. /**
  456. * date
  457. *
  458. * @return string
  459. */
  460. static public function date($param)
  461. {
  462. 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\'})"/>';
  463. }
  464. /**
  465. * div
  466. *
  467. * @return string
  468. */
  469. static public function node($param, $type = 'div')
  470. {
  471. $result = array('','');
  472. foreach($param as $k => $v)
  473. {
  474. $result[0] .= '<'.$type.' '.$v.'>';
  475. $result[1] .= '</'.$type.'>';
  476. }
  477. return $result;
  478. }
  479. }