Input.php 27 KB

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