Input.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. <?php
  2. namespace Manage\Src\Lib;
  3. use Dever;
  4. class Input
  5. {
  6. public static function __callStatic($name, $param = array())
  7. {
  8. $method = '_' . $name;
  9. $result = call_user_func_array(array(__CLASS__, $method), $param);
  10. if ($result && is_string($result) && $name != 'pageLeft') {
  11. if (layadmin()) {
  12. if (strstr($result, '<select')) {
  13. $result = str_replace('form-control', 'form-control layui-input layui-select', $result);
  14. $result = str_replace('<select', '<select lay-ignore ', $result);
  15. } elseif (strstr($result, 'radio')) {
  16. $result = str_replace('form-control', 'form-control layui-radio', $result);
  17. } elseif (strstr($result, 'checkbox')) {
  18. $result = str_replace('form-control', 'form-control layui-checkbox', $result);
  19. } else {
  20. $result = str_replace('form-control', 'form-control layui-input', $result);
  21. }
  22. if (isset($param[1]) && !$param[1]) {
  23. $result = '<div class="layui-inline"><div class="layui-input-inline">'.$result.'</div></div>';
  24. } else {
  25. $result = '<div>'.$result.'</div>';
  26. }
  27. } else {
  28. if (isset($param[1])) {
  29. $result = '<div style="display:inline;margin-right: 10px;">'.$result.'</div>';
  30. } else {
  31. $result = '<div>'.$result.'</div>';
  32. }
  33. }
  34. }
  35. return $result;
  36. }
  37. /**
  38. * 地图
  39. *
  40. * @return string
  41. */
  42. public static function _map($param)
  43. {
  44. $url = Dever::url('map', 'manage');
  45. $html = self::text($param);
  46. $id = $param['name'] . '_value';
  47. $iframe_id = $id . '_map';
  48. $html .= '<iframe id="'.$iframe_id.'" src="'.$url.'" style="margin-top:10px;display: block;" width="800" height="500" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes" onload="mapLoad()"></iframe>';
  49. $html .= '<script>$(function()
  50. {
  51. $("#'.$id.'").blur(function()
  52. {
  53. layui.layer.msg("搜索中...");
  54. $("#'.$iframe_id.'")[0].contentWindow.search($(this).val());
  55. });
  56. });
  57. function _mapLoad(){
  58. if ($("#'.$id.'").val()) {
  59. $("#'.$iframe_id.'")[0].contentWindow.showMaker($("#'.$id.'").val());
  60. }
  61. }
  62. function _closeMsg() {
  63. layui.layer.closeAll();
  64. }
  65. function _setMap(x, y, z) {
  66. var val = $("#'.$id.'").val();
  67. if (val) {
  68. var temp = val.split(",");
  69. val = temp[0];
  70. }
  71. $("#'.$id.'").val(val + "," + x + "," + y + "," + z);
  72. }</script>';
  73. return $html;
  74. }
  75. /**
  76. * desc
  77. *
  78. * @return string
  79. */
  80. public static function _modal($modal, $desc)
  81. {
  82. return '<a href="javascript:;" onclick="showAlert($(this).next().html());initLayui();">' . $modal . '</a><div style="display:none;">' . $desc . '</div>';
  83. }
  84. /**
  85. * desc
  86. *
  87. * @return string
  88. */
  89. public static function _desc($desc)
  90. {
  91. return '';
  92. return $desc;
  93. }
  94. /**
  95. * hr 分割线
  96. *
  97. * @return string
  98. */
  99. public static function _hr($param)
  100. {
  101. if (layadmin()) {
  102. $col = '';
  103. if (isset($param['right'])) {
  104. $col = '</div><div class="layui-col-md6">';
  105. }
  106. $html = '</div></div></div>'.$col.'<div class="layui-card"><div class="layui-card-header">[' . $param['name'] . ']</div><div class="layui-card-body"><div>';
  107. return $html;
  108. }
  109. return '<div class="dever_form_hr ' . (isset($param['class']) ? $param['class'] : '') . '" ' . (isset($param['attr']) ? $param['attr'] : '') . '>' . $param['name'] . '</div>';
  110. }
  111. /**
  112. * cue
  113. *
  114. * @return string
  115. */
  116. public static function _cue($param)
  117. {
  118. $param['cue'] = isset($param['cue']) ? $param['cue'] : '';
  119. if (strpos($param['name'], '-') !== false) {
  120. $temp = explode('-', $param['name']);
  121. $param['name'] = $temp[0];
  122. $param['cue'] = $temp[1];
  123. } elseif (strpos($param['name'], '(') !== false) {
  124. $temp = explode('(', $param['name']);
  125. $param['name'] = $temp[0];
  126. $param['cue'] = str_replace(')', '', $temp[1]);
  127. } elseif (strpos($param['name'], '(') !== false) {
  128. $temp = explode('(', $param['name']);
  129. $param['name'] = $temp[0];
  130. $param['cue'] = str_replace(')', '', $temp[1]);
  131. }
  132. return $param;
  133. }
  134. /**
  135. * pageLeft
  136. *
  137. * @return string
  138. */
  139. public static function _pageLeft($param)
  140. {
  141. $param = self::cue($param);
  142. if ($param['cue']) {
  143. $param['cue'] = '<span style="font-size:12px;font-weight:normal;font-color:#bababa;margin-left:5px;">[' . $param['cue'] . ']</span>';
  144. }
  145. $class = '';
  146. if (layadmin()) {
  147. //$class = 'layui-form-label';
  148. }
  149. $html = '<div><label style="font-size:14px;font-weight:bold;" class="'.$class.'">' . $param['name'] . $param['cue'] . '</label></div>';
  150. return $html;
  151. }
  152. /**
  153. * textarea
  154. *
  155. * @return string
  156. */
  157. public static function _textarea($param)
  158. {
  159. 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>';
  160. 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>';
  161. }
  162. /**
  163. * image
  164. *
  165. * @return string
  166. */
  167. public static function _image($param)
  168. {
  169. if (isset($param['value']) && $param['value']) {
  170. $pic = 'src="' . $param['value'] . '"';
  171. } elseif (isset($param['places'])) {
  172. $pic = 'src="http://placehold.it/' . $param['place'] . '"';
  173. } else {
  174. $pic = 'src="" style=display:none;';
  175. }
  176. 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="选择文件"/>
  177. <div style="margin:10px;">
  178. <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>
  179. <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'] : '')) . '">';
  180. }
  181. /**
  182. * images
  183. *
  184. * @return string
  185. */
  186. public static function _images($param)
  187. {
  188. $pic = '';
  189. if (isset($param['value'])) {
  190. $temp = explode(',', $param['value']);
  191. foreach ($temp as $k => $v) {
  192. $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>';
  193. }
  194. }
  195. 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="选择文件"/>
  196. <div style="margin:10px;" update_type="html" class="update_value ' . $param['name'] . '_' . $param['index'] . '_mul">' . $pic . '</div>
  197. <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'] : '')) . '">';
  198. }
  199. /**
  200. * upload
  201. *
  202. * @return string
  203. */
  204. public static function _upload($param)
  205. {
  206. return '<input type="button" style="width:10%;" class="form-control image_upload" t="file" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="选择文件"/>
  207. <div style="margin-top: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'] : '')) . '">
  208. </div>';
  209. //return '<input type="file" class="form-control" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '" name="' . $param['name'] . '"/>';
  210. }
  211. /**
  212. * upload
  213. *
  214. * @return string
  215. */
  216. public static function _uploads($param)
  217. {
  218. $file = '';
  219. if (isset($param['value']) && $param['value']) {
  220. $temp = explode(',', $param['value']);
  221. foreach ($temp as $k => $v) {
  222. $upload = Dever::load('upload/file-check', array('option_key' => md5($v)));
  223. $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>';
  224. }
  225. }
  226. return '<input type="button" 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'] . '" value="选择文件"/>
  227. <ul style="margin:10px;" update_type="html" class="update_value ' . $param['name'] . '_' . $param['index'] . '_mul">' . $file . '</ul>
  228. <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'] : '')) . '">';
  229. //return '<input type="file" class="form-control" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '" name="' . $param['name'] . '"/>';
  230. }
  231. /**
  232. * editor
  233. *
  234. * @return string
  235. */
  236. public static function _editor($param)
  237. {
  238. 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>';
  239. }
  240. /**
  241. * markdown
  242. *
  243. * @return string
  244. */
  245. public static function _markdown($param)
  246. {
  247. 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>';
  248. }
  249. /**
  250. * selector
  251. *
  252. * @return string
  253. */
  254. public static function _selector($param, $type = '')
  255. {
  256. $html = '';
  257. if (isset($param['key']) && strpos($param['key'], '.css') !== false) {
  258. $param['key'] = '<link rel="stylesheet" href="' . $param['key'] . '"/>';
  259. }
  260. if (isset($param['option'])) {
  261. foreach ($param['option'] as $k => $v) {
  262. $check = '';
  263. if ((isset($param['value']) && $param['value'] == $k) || (empty($param['value']) && isset($param['default']) && $param['default'] == $k)) {
  264. $check = 'checked';
  265. }
  266. if (is_array($v)) {
  267. $value = $v['name'];
  268. } else {
  269. $value = $v;
  270. }
  271. $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;';
  272. }
  273. $html .= self::hidden($param);
  274. }
  275. return '<div class="am-btn-group" >' . $html . '</div>';
  276. }
  277. /**
  278. * radio
  279. *
  280. * @return string
  281. */
  282. public static function _radio($param, $type = '')
  283. {
  284. $html = '';
  285. if (isset($param['option'])) {
  286. if (isset($param['option']['state']) && $param['option']['state'] >= 1) {
  287. if (isset($param['value'])) {
  288. $param['value'] = explode(',', $param['value']);
  289. } else {
  290. $param['value'] = array();
  291. }
  292. # 处理比较复杂的多维数组
  293. unset($param['option']['state']);
  294. $j = -1;
  295. foreach ($param['option'] as $k => $v) {
  296. $check = '';
  297. if (isset($param['update_parent'])) {
  298. $input_type = $param['update_parent'];
  299. } else {
  300. $input_type = $param['update'];
  301. }
  302. //{check}
  303. $html .= '<input update_type="checked" class="update_value checkbox-checkall ' . (isset($param['valid']) ? $param['valid'] : '') . '" type="' . $input_type . '" name="temp[]" value="'.$param['name'] . '-' . $k . '"/> -----【' . $v['name'] . '】-----&nbsp;&nbsp;<br />';
  304. $span = array('', '');
  305. if (isset($v['child']) && $v['child']) {
  306. //$i = 1;
  307. $html .= '<ul style="list-style:none;margin:0px;display:;" class="">';
  308. foreach ($v['child'] as $ki => $vi) {
  309. if (!is_array($vi)) {
  310. $temp = $vi;
  311. $vi = array();
  312. $vi['name'] = $temp;
  313. $vi['id'] = $ki;
  314. }
  315. if (isset($v['url'])) {
  316. $span = array('<span class="edit" data-url="' . Dever::url($v['url'] . '?id=' . $vi['id']) . '">', '</span>');
  317. }
  318. $check = '';
  319. $disabled = 'disabled="true"';
  320. if (isset($param['value']) && in_array($ki, $param['value'])) {
  321. $check = 'checked';
  322. $disabled = '';
  323. $j++;
  324. } elseif (isset($param['default']) && is_array($param['default']) && (in_array($k . '_' . $ki, $param['default']))) {
  325. $check = 'checked';
  326. $disabled = '';
  327. $j++;
  328. }
  329. $input = $input_value = '';
  330. if (isset($param['update_input'])) {
  331. if (isset($param['update_input_data']) && isset($param['update_input_data'][$j])) {
  332. $input_value = $param['update_input_data'][$j];
  333. if ($disabled) {
  334. $input_value = '';
  335. }
  336. } else {
  337. $input_value = isset($param['update_input_default']) ? $param['update_input_default'] : '';
  338. }
  339. if ($param['update_input']) {
  340. $input = '[' . $param['update_input'] . ']';
  341. }
  342. $input = $input . ': <input class="form-control" name="' . $param['name'] . '_input[]" type="text" value="' . $input_value . '" style="width:20%;margin:5px;display:inline" placeholder="' . $param['update_input'] . '" ' . $disabled . '/>';
  343. }
  344. $html .= '<li><input update_type="checked" class="update_value checkbox-checkall-' . $param['name'] . '-'. $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>';
  345. //++$i;
  346. }
  347. $html .= '</ul>';
  348. }
  349. $html .= '<br />';
  350. }
  351. } else {
  352. $js = '';
  353. if (isset($param['control']) && is_string($param['control'])) {
  354. //print_r($param);die;
  355. $js = ' show_id="' . $param['control'] . '" onclick="inputShow($(this), \'' . $param['control'] . '\', \'input\')"';
  356. } elseif (isset($param['bind'])) {
  357. $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
  358. $js = $param['bind'][0] . '="' . $param['bind'][1] . '(\'' . $param['name'] . '\', $(this), ' . $param['bind'][2] . ')" ';
  359. $js .= ' onload="' . $param['bind'][1] . '(\'' . $param['name'] . '\', $(this), ' . $param['bind'][2] . ')" ';
  360. }
  361. $param['parent'] = isset($param['parent']) ? $param['parent'] : '0';
  362. $param['parent'] .= '_' . $param['name'];
  363. if ($param['update'] == 'checkbox' && empty($param['checkall'])) {
  364. $html .= '<input update_type="checked" class="checkbox-checkall ' . $param['name'] . ' update_value" type="' . $param['update'] . '" name="temp_' . $param['name'] . '[]" value="' . $param['parent'] . '"/> 全选 &nbsp;&nbsp;';
  365. }
  366. foreach ($param['option'] as $k => $v) {
  367. $check = '';
  368. if (is_array($v)) {
  369. $value = $v['name'];
  370. isset($v['id']) && $k = $v['id'];
  371. } else {
  372. $value = $v;
  373. }
  374. if (isset($param['bit'][$k])) {
  375. if (isset($param['value']) && ($param['value'] & $k) > 0) {
  376. $check = 'checked';
  377. }
  378. } elseif (isset($param['value'])) {
  379. if (is_string($param['value']) && strpos(',' . $param['value'] . ',', ',' . $k . ',') !== false) {
  380. $check = 'checked';
  381. } elseif (is_array($param['value']) && in_array($k, $param['value'])) {
  382. $check = 'checked';
  383. }
  384. } elseif (isset($param['default'])) {
  385. if (is_string($param['default']) && strpos(',' . $param['default'], ',' . $k) !== false) {
  386. $check = 'checked';
  387. } elseif (is_array($param['default']) && in_array($k, $param['default'])) {
  388. $check = 'checked';
  389. }
  390. }
  391. $cjs = $js;
  392. if (isset($param['control']) && is_string($param['control']) && $param['control'] != $param['name']) {
  393. $cjs = str_replace('update_', '', str_replace($param['control'], $param['name'], $js));
  394. }
  395. $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;';
  396. if (isset($param['bind'])) {
  397. //$html .= '<script>$(document).ready(function(){$(".checkbox-checkall-'.$param['parent'].'").click();})</script>';
  398. }
  399. }
  400. }
  401. }
  402. return '<div class="am-btn-group" >' . $html . '</div>';
  403. }
  404. /**
  405. * group
  406. *
  407. * @return string
  408. */
  409. public static function _group($param, $class = '', $hidden = '', $change = '')
  410. {
  411. $html = $class ? '<div class="' . $class . '">' : '';
  412. $html .= $hidden . '<select class="update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" ' . $change . '>';
  413. if (isset($param['option'])) {
  414. foreach ($param['option'] as $k => $v) {
  415. if ($v['id'] <= 0) {
  416. $html .= '<option value="0" selected>' . $v['name'] . '</option>';
  417. } else {
  418. $html .= '<optgroup label="' . $v['name'] . '">';
  419. if (isset($v['child'])) {
  420. foreach ($v['child'] as $k1 => $v1) {
  421. $selected = '';
  422. if ((isset($param['value']) && $param['value'] == $v1['id']) || (empty($param['value']) && isset($param['default']) && $param['default'] == $v1['id'])) {
  423. $selected = 'selected';
  424. }
  425. $html .= '<option value="' . $v1['id'] . '" ' . $selected . '>' . $v1['name'] . '</option>';
  426. }
  427. }
  428. $html .= '</optgroup>';
  429. }
  430. }
  431. }
  432. $html .= '</select>';
  433. $html .= $class ? '</div>' : '';
  434. return $html;
  435. }
  436. /**
  437. * linkage select 多级联动
  438. *
  439. * @return string
  440. */
  441. public static function _linkage($param, $class = '', $hidden = '', $change = '')
  442. {
  443. $div = 'div';
  444. $w = 'width:20%;';
  445. if ($class == 'span') {
  446. $div = 'span';
  447. $w = '';
  448. }
  449. if (!isset($param['search_state'])) {
  450. $param['search_state'] = false;
  451. }
  452. # 当前级别
  453. $level = 1;
  454. # 传入的参数
  455. $level_param = '';
  456. if (isset($param['linkage'])) {
  457. $level_param = $param['linkage'];
  458. }
  459. $id = 'dever-linkage-' . $param['name'];
  460. $html = '<' . $div . ' class="' . $class . '" id="' . $id . '" >';
  461. # 默认值
  462. if (isset($param['value']) && is_array($param['value'])) {
  463. $param['value'] = implode(',', $param['value']);
  464. }
  465. $html .= '<script>function _linkage_' . $param['name'] . '(level){select_linkage(level, "' . $id . '","' . $param['option'] . '", "' . $param['name'] . '", "' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '", "' . (isset($param['valid']) ? $param['valid'] : '') . '", "' . $w . '", false, "'.$param['search_state'].'", "'.$level_param.'")};';
  466. $html .= '$(document).ready(function(){linkage_' . $param['name'] . '(' . $level . ')});</script>';
  467. $html .= '</' . $div . '>';
  468. return $html;
  469. }
  470. /**
  471. * select
  472. *
  473. * @return string
  474. */
  475. public static function _select($param, $class = '', $hidden = '', $change = '')
  476. {
  477. $html = $class ? '<div class="' . $class . '">' : '';
  478. $child_class = '';
  479. if (isset($param['child'])) {
  480. $child_param['name'] = 'update_' . $param['child_name'];
  481. isset($param['value']) && $param['value'] = $param['value'];
  482. isset($param['child_value']) && $child_param['value'] = $param['child_value'];
  483. $change = 'style="width:45%" id="' . $param['name'] . '" data-child="' . $child_param['name'] . '_child" ';
  484. $child_class = ' change';
  485. //$param['name'] .= '_parent';
  486. }
  487. if (isset($param['control']) && is_string($param['control'])) {
  488. //print_r($param);die;
  489. $change = ' show_id="' . $param['control'] . '" onchange="inputShow($(this), \'' . $param['control'] . '\')"';
  490. } elseif (isset($param['bind'])) {
  491. $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
  492. $change = $param['bind'][0] . '="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
  493. $child_class .= ' change';
  494. }
  495. $html .= $hidden . '<select class="update_value form-control ' . $child_class . ' ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" ' . $change . '>';
  496. if (isset($param['option'])) {
  497. if (isset($param['lang']) && $param['lang']) {
  498. $html .= '<option value="0" selected>' . $param['lang'] . '</option>';
  499. }
  500. foreach ($param['option'] as $k => $v) {
  501. if (is_array($v)) {
  502. $value = $v['name'];
  503. isset($v['id']) && $k = $v['id'];
  504. } else {
  505. $value = $v;
  506. }
  507. $check = '';
  508. 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)) {
  509. $check = 'selected';
  510. }
  511. $parent = '';
  512. if (isset($param['parent']) && $param['parent'] && isset($v[$param['parent']])) {
  513. $parent = $v[$param['parent']];
  514. }
  515. if (is_array($v)) {
  516. $value = isset($v['name']) ? $v['name'] : $v['lang'];
  517. } else {
  518. $value = $v;
  519. }
  520. $html .= '<option parent="'.$parent.'" value="' . $k . '" ' . $check . '>' . $value . '</option>';
  521. }
  522. }
  523. $html .= '</select>';
  524. if (isset($param['child'])) {
  525. $child = $child_param['name'];
  526. $hidden = self::hidden(array('name' => $child, 'class' => $child . '_child_value'));
  527. foreach ($param['child'] as $k => $v) {
  528. $child_param['name'] = 'child-' . $k;
  529. $child_param['option'] = $v;
  530. $html .= self::select($child_param, $child . '_child ' . $child . '_child_' . $k . '" parent="' . $k . '" style="display:none;margin-top: -35px;margin-left: 47%;"', $hidden);
  531. }
  532. }
  533. $html .= $class ? '</div>' : '';
  534. return $html;
  535. }
  536. /**
  537. * radio
  538. *
  539. * @return string
  540. */
  541. public static function _checkbox($param)
  542. {
  543. return self::radio($param);
  544. }
  545. /**
  546. * text
  547. *
  548. * @return string
  549. */
  550. public static function _text($param, $class = '')
  551. {
  552. if ($class) {
  553. return '<div class="">' . self::text($param, false) . '</div>';
  554. } else {
  555. $auto = $input = '';
  556. $value = (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : ''));
  557. if (isset($param['autocomplete'])) {
  558. if (empty($param['autocomplete'][1])) {
  559. $param['autocomplete'][1] = 'value';
  560. }
  561. if ($param['autocomplete'][1] == 'id') {
  562. $input = self::hidden(array('name' => $param['name'], 'value' => $value));
  563. $input = '<script>var autocomplete_value = [];</script>';
  564. if (isset($param['autocomplete'][2]) && $value) {
  565. # 重新定义value
  566. $value = Dever::load($param['autocomplete'][2], $value);
  567. if (is_array($value)) {
  568. $html = '<div style="margin-top: 10px;width: 60%;overflow: auto;max-height: 500px;"><table id="'.$param['name'].'_value_show" class="table table-small-font table-bordered">';
  569. foreach ($value as $k => $v) {
  570. $link = '';
  571. $attr = '';
  572. $pic = '';
  573. if (isset($v['pic']) && $v['pic']) {
  574. $pic = '<a href="javascript:;"><img src="'.$v['pic'].'" width="100"></a>&nbsp;&nbsp;';
  575. }
  576. if (isset($v['link']) && $v['link']) {
  577. $link = $v['link'];
  578. $attr = ' target="_blank"';
  579. }
  580. $html .= '<tr><td width="90%"><input type="checkbox" checked name="'.$param['name'].'[]" value="'.$v['id'].'"/>&nbsp;&nbsp;'.$pic.'<a href="'.$link.'" '.$attr.' title="'.$v['value'].'">'.$v['value'].'</td><td width="10%"><a href="javascript:;" onclick="autocomplete_del($(this), \''.$param['name'].'_value\', \''.$v['id'].'\')">[删除]</a></td></tr><script>autocomplete_value.push('.$v['id'].');</script>';
  581. }
  582. $html .= '</table></div>';
  583. $input .= $html;
  584. $value = '';
  585. }
  586. }
  587. $param['name'] = $param['name'] . '_temp';
  588. }
  589. $auto = 'complete="' . Dever::url($param['autocomplete'][0]) . '" complete_callback="' . $param['autocomplete'][1] . '" ';
  590. }
  591. if (isset($param['bind'])) {
  592. $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
  593. $auto .= $param['bind'][0] . '="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
  594. $auto .= ' onload="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
  595. }
  596. if (isset($param['autocomplete'][3])) {
  597. $auto .= ' complete_cate="' . $param['autocomplete'][3] . '" ';
  598. }
  599. 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;
  600. }
  601. }
  602. /**
  603. * color
  604. *
  605. * @return string
  606. */
  607. public static function _color($param)
  608. {
  609. $param['class'] = 'dever-color form-control';
  610. $param['update'] = 'text';
  611. $param['default'] = '#000000';
  612. return self::text($param, '');
  613. }
  614. /**
  615. * password
  616. *
  617. * @return string
  618. */
  619. public static function _password($param)
  620. {
  621. $param['value'] = '';
  622. return self::text($param);
  623. }
  624. /**
  625. * hidden
  626. *
  627. * @return string
  628. */
  629. public static function _hidden($param)
  630. {
  631. $param['update'] = 'hidden';
  632. return self::text($param, '');
  633. }
  634. /**
  635. * time
  636. *
  637. * @return string
  638. */
  639. public static function _time($param)
  640. {
  641. 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"/>';
  642. }
  643. /**
  644. * date
  645. *
  646. * @return string
  647. */
  648. public static function _date($param)
  649. {
  650. 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"/>';
  651. }
  652. /**
  653. * div
  654. *
  655. * @return string
  656. */
  657. public static function _node($param, $type = 'div')
  658. {
  659. $result = array('', '');
  660. foreach ($param as $k => $v) {
  661. $result[0] .= '<' . $type . ' ' . $v . '>';
  662. $result[1] .= '</' . $type . '>';
  663. }
  664. return $result;
  665. }
  666. }