Input.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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] && ((isset($param[0]['update']) && $param[0]['update'] != 'hidden') || !isset($param[0]['update']))) {
  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[0]['update']) && $param[0]['update'] == 'hidden') {
  29. } elseif (isset($param[1]) && !$param[1]) {
  30. $result = '<div style="display:inline;margin-right: 10px;">'.$result.'</div>';
  31. }
  32. }
  33. }
  34. return $result;
  35. }
  36. /**
  37. * 地图
  38. *
  39. * @return string
  40. */
  41. public static function _map($param)
  42. {
  43. $url = Dever::url('map', 'manage');
  44. $html = self::text($param);
  45. $id = $param['name'] . '_value';
  46. $iframe_id = $id . '_map';
  47. $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>';
  48. $html .= '<script>$(function()
  49. {
  50. $("#'.$id.'").blur(function()
  51. {
  52. layui.layer.msg("搜索中...");
  53. $("#'.$iframe_id.'")[0].contentWindow.search($(this).val());
  54. });
  55. });
  56. function mapLoad(){
  57. if ($("#'.$id.'").val()) {
  58. $("#'.$iframe_id.'")[0].contentWindow.showMaker($("#'.$id.'").val());
  59. }
  60. }
  61. function closeMsg() {
  62. layui.layer.closeAll();
  63. }
  64. function setMap(x, y, z) {
  65. var val = $("#'.$id.'").val();
  66. if (val) {
  67. var temp = val.split(",");
  68. val = temp[0];
  69. }
  70. $("#'.$id.'").val(val + "," + x + "," + y + "," + z);
  71. }</script>';
  72. return $html;
  73. }
  74. /**
  75. * desc
  76. *
  77. * @return string
  78. */
  79. public static function _modal($modal, $desc)
  80. {
  81. return '<a href="javascript:;" onclick="showAlert($(this).next().html());initLayui();">' . $modal . '</a><div style="display:none;">' . $desc . '</div>';
  82. }
  83. /**
  84. * desc
  85. *
  86. * @return string
  87. */
  88. public static function _desc($desc)
  89. {
  90. return '';
  91. return $desc;
  92. }
  93. /**
  94. * hr 分割线
  95. *
  96. * @return string
  97. */
  98. public static function _hr($param)
  99. {
  100. if (layadmin()) {
  101. $col = '';
  102. if (isset($param['right'])) {
  103. $col = '</div><div class="layui-col-md6">';
  104. }
  105. $html = '</div></div></div>'.$col.'<div class="layui-card"><div class="layui-card-header">[' . $param['name'] . ']</div><div class="layui-card-body"><div>';
  106. return $html;
  107. }
  108. return '<div class="dever_form_hr ' . (isset($param['class']) ? $param['class'] : '') . '" ' . (isset($param['attr']) ? $param['attr'] : '') . '>' . $param['name'] . '</div>';
  109. }
  110. /**
  111. * cue
  112. *
  113. * @return string
  114. */
  115. public static function _cue($param)
  116. {
  117. $param['cue'] = isset($param['cue']) ? $param['cue'] : '';
  118. if (strpos($param['name'], '-') !== false) {
  119. $temp = explode('-', $param['name']);
  120. $param['name'] = $temp[0];
  121. $param['cue'] = $temp[1];
  122. } elseif (strpos($param['name'], '(') !== false) {
  123. $temp = explode('(', $param['name']);
  124. $param['name'] = $temp[0];
  125. $param['cue'] = str_replace(')', '', $temp[1]);
  126. } elseif (strpos($param['name'], '(') !== false) {
  127. $temp = explode('(', $param['name']);
  128. $param['name'] = $temp[0];
  129. $param['cue'] = str_replace(')', '', $temp[1]);
  130. }
  131. return $param;
  132. }
  133. /**
  134. * pageLeft
  135. *
  136. * @return string
  137. */
  138. public static function _pageLeft($param)
  139. {
  140. $param = self::cue($param);
  141. if ($param['cue']) {
  142. $param['cue'] = '<span style="font-size:12px;font-weight:normal;font-color:#bababa;margin-left:5px;">[' . $param['cue'] . ']</span>';
  143. }
  144. $class = '';
  145. if (layadmin()) {
  146. //$class = 'layui-form-label';
  147. }
  148. $html = '<div><label style="font-size:14px;font-weight:bold;" class="'.$class.'">' . $param['name'] . $param['cue'] . '</label></div>';
  149. return $html;
  150. }
  151. /**
  152. * textarea
  153. *
  154. * @return string
  155. */
  156. public static function _textarea($param)
  157. {
  158. 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>';
  159. 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>';
  160. }
  161. /**
  162. * image
  163. *
  164. * @return string
  165. */
  166. public static function _image($param)
  167. {
  168. if (isset($param['value']) && $param['value']) {
  169. $pic = 'src="' . $param['value'] . '"';
  170. } elseif (isset($param['places'])) {
  171. $pic = 'src="http://placehold.it/' . $param['place'] . '"';
  172. } else {
  173. $pic = 'src="" style=display:none;';
  174. }
  175. $class = 'width:100px;display:inline;';
  176. if (layadmin()) {
  177. $class .= 'padding-left:0px;';
  178. }
  179. return '<input type="button" style="'.$class.'" class="form-control image_upload" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="本地上传"/>
  180. <input type="button" style="'.$class.'" class="form-control upload_show" v="' . $param['name'] . '_' . $param['index'] . '" id="file_show_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="图库"/>
  181. <div style="margin-top:10px;display:none;" class="layui-progress layui-progress-big" id="file_' . $param['name'] . '_' . $param['index'] . '_progress" lay-filter="file_' . $param['name'] . '_' . $param['index'] . '_progress" lay-showPercent="true">
  182. <div class="layui-progress-bar" lay-percent="0%"></div>
  183. </div>
  184. <div style="margin:10px;">
  185. <img ' . $pic . ' class="update_value" update_type="src" id="show_' . $param['name'] . '_' . $param['index'] . '" width="150" /></div>
  186. <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'] : '')) . '">';
  187. }
  188. /**
  189. * images
  190. *
  191. * @return string
  192. */
  193. public static function _images($param)
  194. {
  195. $pic = '';
  196. if (isset($param['value']) && $param['value']) {
  197. $temp = explode(',', $param['value']);
  198. foreach ($temp as $k => $v) {
  199. $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>';
  200. }
  201. }
  202. $class = 'width:100px;display:inline;';
  203. if (layadmin()) {
  204. $class .= 'padding-left:0px;';
  205. }
  206. return '<input type="button" style="'.$class.'" class="form-control image_upload" mul="yes" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="本地上传"/>
  207. <input type="button" style="'.$class.'" class="form-control upload_show" mul="yes" v="' . $param['name'] . '_' . $param['index'] . '" id="file_show_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="图库"/>
  208. <div style="margin-top:10px;display:none;" class="layui-progress layui-progress-big" id="file_' . $param['name'] . '_' . $param['index'] . '_progress" lay-filter="file_' . $param['name'] . '_' . $param['index'] . '_progress" lay-showPercent="true">
  209. <div class="layui-progress-bar" lay-percent="0%"></div>
  210. </div>
  211. <div style="margin:10px;" update_type="html" class="update_value ' . $param['name'] . '_' . $param['index'] . '_mul">' . $pic . '</div>
  212. <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'] : '')) . '">';
  213. }
  214. /**
  215. * upload
  216. *
  217. * @return string
  218. */
  219. public static function _upload($param)
  220. {
  221. $class = 'width:100px;display:inline;';
  222. if (layadmin()) {
  223. $class .= 'padding-left:0px;';
  224. }
  225. return '<input type="button" style="'.$class.'" class="form-control image_upload" t="file" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="本地上传"/>
  226. <input type="button" style="'.$class.'" class="form-control upload_show" t="file" v="' . $param['name'] . '_' . $param['index'] . '" id="file_show_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="文件库"/>
  227. <div style="margin-top:10px;display:none;" class="layui-progress layui-progress-big" id="file_' . $param['name'] . '_' . $param['index'] . '_progress" lay-filter="file_' . $param['name'] . '_' . $param['index'] . '_progress" lay-showPercent="true">
  228. <div class="layui-progress-bar" lay-percent="0%"></div>
  229. </div>
  230. <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'] : '')) . '">
  231. </div>';
  232. //return '<input type="file" class="form-control" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '" name="' . $param['name'] . '"/>';
  233. }
  234. /**
  235. * upload
  236. *
  237. * @return string
  238. */
  239. public static function _uploads($param)
  240. {
  241. $file = '';
  242. if (isset($param['value']) && $param['value']) {
  243. $temp = explode(',', $param['value']);
  244. foreach ($temp as $k => $v) {
  245. $upload = Dever::load('upload/file-check', array('option_key' => md5($v)));
  246. $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>';
  247. }
  248. }
  249. $class = 'width:100px;display:inline;';
  250. if (layadmin()) {
  251. $class .= 'padding-left:0px;';
  252. }
  253. return '<input type="button" style="'.$class.'" class="form-control image_upload" t="file" mul="yes" v="' . $param['name'] . '_' . $param['index'] . '" id="file_show_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="本地上传"/>
  254. <input type="button" style="'.$class.'" class="form-control upload_show" t="file" mul="yes" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="文件库"/>
  255. <div style="margin-top:10px;display:none;" class="layui-progress layui-progress-big" id="file_' . $param['name'] . '_' . $param['index'] . '_progress" lay-filter="file_' . $param['name'] . '_' . $param['index'] . '_progress" lay-showPercent="true">
  256. <div class="layui-progress-bar" lay-percent="0%"></div>
  257. </div>
  258. <ul style="margin:10px;" update_type="html" class="update_value ' . $param['name'] . '_' . $param['index'] . '_mul">' . $file . '</ul>
  259. <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'] : '')) . '">';
  260. //return '<input type="file" class="form-control" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '" name="' . $param['name'] . '"/>';
  261. }
  262. /**
  263. * editor
  264. *
  265. * @return string
  266. */
  267. public static function _editor($param)
  268. {
  269. $width = '100%';
  270. $html = '';
  271. if (isset($param['editor'])) {
  272. $width = '70%';
  273. $html .= '<div class="layui-col-lg6" style="display:inline;position: absolute;left: 740px;"><div><label style="font-size:14px;font-weight:bold;" class="">'.$param['editor']['name'].'</label></div><div>';
  274. foreach ($param['editor']['button'] as $k => $v) {
  275. if (isset($v['type'])) {
  276. if ($v['type'] == 'image') {
  277. $param['key'] = $v['key'];
  278. } elseif ($v['type'] == 'media') {
  279. $param['media'] = $v['key'];
  280. }
  281. $v['type'] = 'editor_tool" tool="' . $v['type'];
  282. } else {
  283. $v['type'] = 'upload_show_editor';
  284. }
  285. $html .= '<input type="button" style="width:100px;display:inline;padding-left:0px;margin:5px;" class="form-control layui-input '.$v['type'].'" editor_id="' . $param['name'] . '_editor" key="'.$v['key'].'" value="'.$v['name'].'">';
  286. }
  287. $html .= '</div></div>';
  288. }
  289. return $html . '<textarea style="'.$width.';display: inline" update_type="value" class=" update_value editor" id="' . $param['name'] . '_editor" key="' . (isset($param['key']) ? $param['key'] : 1) . '" media="' . (isset($param['media']) ? $param['media'] : "") . '" name="' . $param['name'] . '" rows="18" cols="100" >' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '</textarea>';
  290. }
  291. /**
  292. * markdown
  293. *
  294. * @return string
  295. */
  296. public static function _markdown($param)
  297. {
  298. 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>';
  299. }
  300. /**
  301. * selector
  302. *
  303. * @return string
  304. */
  305. public static function _selector($param, $type = '')
  306. {
  307. $html = '';
  308. if (isset($param['key']) && strpos($param['key'], '.css') !== false) {
  309. $param['key'] = '<link rel="stylesheet" href="' . $param['key'] . '"/>';
  310. }
  311. if (isset($param['option'])) {
  312. foreach ($param['option'] as $k => $v) {
  313. $check = '';
  314. if ((isset($param['value']) && $param['value'] == $k) || (empty($param['value']) && isset($param['default']) && $param['default'] == $k)) {
  315. $check = 'checked';
  316. }
  317. if (is_array($v)) {
  318. $value = $v['name'];
  319. } else {
  320. $value = $v;
  321. }
  322. $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;';
  323. }
  324. $html .= self::hidden($param);
  325. }
  326. return '<div class="am-btn-group" >' . $html . '</div>';
  327. }
  328. /**
  329. * radio
  330. *
  331. * @return string
  332. */
  333. public static function _radio($param, $type = '')
  334. {
  335. $html = '';
  336. if (isset($param['option'])) {
  337. if (isset($param['option']['state']) && $param['option']['state'] >= 1) {
  338. if (isset($param['value'])) {
  339. $param['value'] = explode(',', $param['value']);
  340. } else {
  341. $param['value'] = array();
  342. }
  343. # 处理比较复杂的多维数组
  344. unset($param['option']['state']);
  345. $j = -1;
  346. foreach ($param['option'] as $k => $v) {
  347. $check = '';
  348. if (isset($param['update_parent'])) {
  349. $input_type = $param['update_parent'];
  350. } else {
  351. $input_type = $param['update'];
  352. }
  353. //{check}
  354. $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 />';
  355. $span = array('', '');
  356. if (isset($v['child']) && $v['child']) {
  357. //$i = 1;
  358. $html .= '<ul style="list-style:none;margin:0px;display:;" class="">';
  359. foreach ($v['child'] as $ki => $vi) {
  360. if (!is_array($vi)) {
  361. $temp = $vi;
  362. $vi = array();
  363. $vi['name'] = $temp;
  364. $vi['id'] = $ki;
  365. }
  366. if (isset($v['url'])) {
  367. $span = array('<span class="edit" data-url="' . Dever::url($v['url'] . '?id=' . $vi['id']) . '">', '</span>');
  368. }
  369. $check = '';
  370. $disabled = 'disabled="true"';
  371. if (isset($param['value']) && in_array($ki, $param['value'])) {
  372. $check = 'checked';
  373. $disabled = '';
  374. $j++;
  375. } elseif (isset($param['default']) && is_array($param['default']) && (in_array($k . '_' . $ki, $param['default']))) {
  376. $check = 'checked';
  377. $disabled = '';
  378. $j++;
  379. }
  380. $input = $input_value = '';
  381. if (isset($param['update_input'])) {
  382. if (isset($param['update_input_data']) && isset($param['update_input_data'][$j])) {
  383. $input_value = $param['update_input_data'][$j];
  384. if ($disabled) {
  385. $input_value = '';
  386. }
  387. } else {
  388. $input_value = isset($param['update_input_default']) ? $param['update_input_default'] : '';
  389. }
  390. if ($param['update_input']) {
  391. $input = '[' . $param['update_input'] . ']';
  392. }
  393. $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 . '/>';
  394. }
  395. $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>';
  396. //++$i;
  397. }
  398. $html .= '</ul>';
  399. }
  400. $html .= '<br />';
  401. }
  402. } else {
  403. $js = '';
  404. if (isset($param['control']) && is_string($param['control'])) {
  405. //print_r($param);die;
  406. $js = ' show_id="' . $param['control'] . '" onclick="inputShow($(this), \'' . $param['control'] . '\', \'input\')"';
  407. } elseif (isset($param['bind'])) {
  408. $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
  409. $js = $param['bind'][0] . '="' . $param['bind'][1] . '(\'' . $param['name'] . '\', $(this), ' . $param['bind'][2] . ')" ';
  410. $js .= ' onload="' . $param['bind'][1] . '(\'' . $param['name'] . '\', $(this), ' . $param['bind'][2] . ')" ';
  411. }
  412. $param['parent'] = isset($param['parent']) ? $param['parent'] : '0';
  413. $param['parent'] .= '_' . $param['name'];
  414. if ($param['update'] == 'checkbox' && empty($param['checkall'])) {
  415. $html .= '<input update_type="checked" class="checkbox-checkall ' . $param['name'] . ' update_value" type="' . $param['update'] . '" name="temp_' . $param['name'] . '[]" value="' . $param['parent'] . '"/> 全选 &nbsp;&nbsp;';
  416. }
  417. foreach ($param['option'] as $k => $v) {
  418. $check = '';
  419. if (is_array($v)) {
  420. $value = $v['name'];
  421. isset($v['id']) && $k = $v['id'];
  422. } else {
  423. $value = $v;
  424. }
  425. if (isset($param['bit'][$k])) {
  426. if (isset($param['value']) && ($param['value'] & $k) > 0) {
  427. $check = 'checked';
  428. }
  429. } elseif (isset($param['value'])) {
  430. if (is_string($param['value']) && strpos(',' . $param['value'] . ',', ',' . $k . ',') !== false) {
  431. $check = 'checked';
  432. } elseif (is_array($param['value']) && in_array($k, $param['value'])) {
  433. $check = 'checked';
  434. }
  435. } elseif (isset($param['default'])) {
  436. if (is_string($param['default']) && strpos(',' . $param['default'], ',' . $k) !== false) {
  437. $check = 'checked';
  438. } elseif (is_array($param['default']) && in_array($k, $param['default'])) {
  439. $check = 'checked';
  440. }
  441. }
  442. $cjs = $js;
  443. if (isset($param['control']) && is_string($param['control']) && $param['control'] != $param['name']) {
  444. $cjs = str_replace('update_', '', str_replace($param['control'], $param['name'], $js));
  445. }
  446. $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;';
  447. if (isset($param['bind'])) {
  448. //$html .= '<script>$(document).ready(function(){$(".checkbox-checkall-'.$param['parent'].'").click();})</script>';
  449. }
  450. }
  451. }
  452. }
  453. return '<div class="am-btn-group" >' . $html . '</div>';
  454. }
  455. /**
  456. * group
  457. *
  458. * @return string
  459. */
  460. public static function _group($param, $class = '', $hidden = '', $change = '')
  461. {
  462. $html = $class ? '<div class="' . $class . '">' : '';
  463. $html .= $hidden . '<select class="update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" ' . $change . '>';
  464. if (isset($param['option'])) {
  465. foreach ($param['option'] as $k => $v) {
  466. if ($v['id'] <= 0) {
  467. $html .= '<option value="0" selected>' . $v['name'] . '</option>';
  468. } else {
  469. $html .= '<optgroup label="' . $v['name'] . '">';
  470. if (isset($v['child'])) {
  471. foreach ($v['child'] as $k1 => $v1) {
  472. $selected = '';
  473. if ((isset($param['value']) && $param['value'] == $v1['id']) || (empty($param['value']) && isset($param['default']) && $param['default'] == $v1['id'])) {
  474. $selected = 'selected';
  475. }
  476. $html .= '<option value="' . $v1['id'] . '" ' . $selected . '>' . $v1['name'] . '</option>';
  477. }
  478. }
  479. $html .= '</optgroup>';
  480. }
  481. }
  482. }
  483. $html .= '</select>';
  484. $html .= $class ? '</div>' : '';
  485. return $html;
  486. }
  487. /**
  488. * linkage select 多级联动
  489. *
  490. * @return string
  491. */
  492. public static function _linkage($param, $class = '', $hidden = '', $change = '')
  493. {
  494. $div = 'div';
  495. $w = 'width:20%;';
  496. if ($class == 'span') {
  497. $div = 'span';
  498. $w = '';
  499. }
  500. if (!isset($param['search_state'])) {
  501. $param['search_state'] = false;
  502. }
  503. # 当前级别
  504. $level = 1;
  505. # 传入的参数
  506. $level_param = '';
  507. if (isset($param['linkage'])) {
  508. $level_param = $param['linkage'];
  509. }
  510. $id = 'dever-linkage-' . $param['name'];
  511. $html = '<' . $div . ' class="' . $class . '" id="' . $id . '" >';
  512. # 默认值
  513. if (isset($param['value']) && is_array($param['value'])) {
  514. $param['value'] = implode(',', $param['value']);
  515. }
  516. $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.'")};';
  517. $html .= '$(document).ready(function(){linkage_' . $param['name'] . '(' . $level . ')});</script>';
  518. $html .= '</' . $div . '>';
  519. return $html;
  520. }
  521. /**
  522. * select
  523. *
  524. * @return string
  525. */
  526. public static function _selects($param, $class = '', $hidden = '', $change = '')
  527. {
  528. return self::_select($param, $class, $hidden, $change);
  529. }
  530. /**
  531. * select
  532. *
  533. * @return string
  534. */
  535. public static function _select($param, $class = '', $hidden = '', $change = '')
  536. {
  537. $html = $class ? '<div class="' . $class . '">' : '';
  538. $child_class = '';
  539. if (isset($param['child'])) {
  540. $child_param['name'] = 'update_' . $param['child_name'];
  541. isset($param['value']) && $param['value'] = $param['value'];
  542. isset($param['child_value']) && $child_param['value'] = $param['child_value'];
  543. $change = 'style="width:45%" id="' . $param['name'] . '" data-child="' . $child_param['name'] . '_child" ';
  544. $child_class = ' change';
  545. //$param['name'] .= '_parent';
  546. }
  547. if (isset($param['control']) && is_string($param['control'])) {
  548. //print_r($param);die;
  549. $change = ' show_id="' . $param['control'] . '" onchange="inputShow($(this), \'' . $param['control'] . '\')"';
  550. } elseif (isset($param['bind'])) {
  551. $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
  552. $change = $param['bind'][0] . '="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
  553. $child_class .= ' change';
  554. }
  555. $xm = '';
  556. if ($change) {
  557. $xm = '';
  558. } else {
  559. }
  560. if (!$change && isset($param['update'])) {
  561. $xm = 'xm-select="' . $param['name'] . '" xm-select-skin="normal" xm-select-search="" xm-select-search-type="dl"';
  562. if ($param['update'] != 'selects') {
  563. $xm .= ' xm-select-radio=""';
  564. }
  565. $search_value = '';
  566. if (isset($param['value'])) {
  567. $search_value = $param['value'];
  568. } elseif (isset($param['default'])) {
  569. $search_value = $param['default'];
  570. }
  571. if (isset($param['update_search'])) {
  572. $xm = str_replace('xm-select-search=""', 'xm-select-search="'.Dever::url($param['update_search'] . '&yes='.$search_value.'&json=1').'"', $xm);
  573. }
  574. if (isset($param['update_create'])) {
  575. $xm .= ' xm-select-create=""';
  576. }
  577. if ($param['match'] != 'option') {
  578. $xm .= ' lay-verify="' . $param['name'] . '"';
  579. }
  580. } else {
  581. $xm .= ' xm-select-radio=""';
  582. }
  583. if (isset($param['option']) && isset($param['update']) && $param['update'] == 'select') {
  584. $total = count($param['option']);
  585. if ($total <= 5) {
  586. $xm = '';
  587. }
  588. }
  589. $html .= $hidden . '<select '.$xm.' class="update_value form-control ' . $child_class . ' ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" id="' . $param['name'] . '" ' . $change . '>';
  590. if (isset($param['option'])) {
  591. if (isset($param['lang']) && $param['lang']) {
  592. $html .= '<option value="0" selected>' . $param['lang'] . '</option>';
  593. }
  594. foreach ($param['option'] as $k => $v) {
  595. if (is_array($v)) {
  596. $value = $v['name'];
  597. isset($v['id']) && $k = $v['id'];
  598. } else {
  599. $value = $v;
  600. }
  601. $check = '';
  602. if ((isset($param['value']) && strstr(','. $param['value'] . ',', ',' . $k . ',')) || (isset($param['bit'][$k]) && isset($param['value']) && ($param['value'] & $k) > 0) || (empty($param['value']) && isset($param['default']) && strstr(',' . $param['default'] . ',', ',' . $k . ','))) {
  603. $check = 'selected';
  604. }
  605. $parent = '';
  606. if (isset($param['parent']) && $param['parent'] && isset($v[$param['parent']])) {
  607. $parent = $v[$param['parent']];
  608. }
  609. if (is_array($v)) {
  610. $value = isset($v['name']) ? $v['name'] : $v['lang'];
  611. } else {
  612. $value = $v;
  613. }
  614. $html .= '<option parent="'.$parent.'" value="' . $k . '" ' . $check . '>' . $value . '</option>';
  615. }
  616. }
  617. $html .= '</select>';
  618. if (isset($param['child'])) {
  619. $child = $child_param['name'];
  620. $hidden = self::hidden(array('name' => $child, 'class' => $child . '_child_value'));
  621. foreach ($param['child'] as $k => $v) {
  622. $child_param['name'] = 'child-' . $k;
  623. $child_param['option'] = $v;
  624. $html .= self::select($child_param, $child . '_child ' . $child . '_child_' . $k . '" parent="' . $k . '" style="display:none;margin-top: -35px;margin-left: 47%;"', $hidden);
  625. }
  626. }
  627. $html .= $class ? '</div>' : '';
  628. return $html;
  629. }
  630. /**
  631. * radio
  632. *
  633. * @return string
  634. */
  635. public static function _checkbox($param)
  636. {
  637. return self::radio($param);
  638. }
  639. /**
  640. * text
  641. *
  642. * @return string
  643. */
  644. public static function _text($param, $class = '')
  645. {
  646. if ($class) {
  647. return '<div class="">' . self::text($param, false) . '</div>';
  648. } else {
  649. $auto = $input = '';
  650. $value = (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : ''));
  651. if (isset($param['autocomplete'])) {
  652. if (empty($param['autocomplete'][1])) {
  653. $param['autocomplete'][1] = 'value';
  654. }
  655. if ($param['autocomplete'][1] == 'id') {
  656. $input = self::hidden(array('name' => $param['name'], 'value' => $value));
  657. $input = '<script>var autocomplete_value = {};autocomplete_value[\''.$param['name'].'_value\'] = [];</script>';
  658. if (isset($param['autocomplete'][2]) && $value) {
  659. # 重新定义value
  660. $value = Dever::load($param['autocomplete'][2], $value);
  661. if (is_array($value)) {
  662. $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">';
  663. foreach ($value as $k => $v) {
  664. $link = '';
  665. $attr = '';
  666. $pic = '';
  667. if (isset($v['pic']) && $v['pic']) {
  668. $pic = '<a href="javascript:;"><img src="'.$v['pic'].'" width="100"></a>&nbsp;&nbsp;';
  669. }
  670. if (isset($v['link']) && $v['link']) {
  671. $link = $v['link'];
  672. $attr = ' target="_blank"';
  673. }
  674. $html .= '<tr id="autocomplate_check_'.$param['name'].'_value"><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'].'\', \''.$param['name'].'\')">[删除]</a></td></tr><script>autocomplete_value[\''.$param['name'].'_value\'].push('.$v['id'].');</script>';
  675. }
  676. $html .= '</table></div>';
  677. $input .= $html;
  678. $value = '';
  679. }
  680. }
  681. $param['name'] = $param['name'] . '_temp';
  682. }
  683. $auto = 'complete="' . Dever::url($param['autocomplete'][0]) . '" complete_callback="' . $param['autocomplete'][1] . '" ';
  684. if (isset($param['autocomplete'][3])) {
  685. $auto .= ' complete_cate="' . $param['autocomplete'][3] . '" ';
  686. }
  687. } elseif (isset($param['searchbox'])) {
  688. if (empty($param['searchbox'][1])) {
  689. $param['searchbox'][1] = 'value';
  690. }
  691. if ($param['searchbox'][1] == 'id') {
  692. $input = self::hidden(array('name' => $param['name'], 'value' => $value));
  693. $input = '<script>var searchbox_value = [];searchbox_value[\''.$param['name'].'_value\'] = [];</script>';
  694. if (isset($param['searchbox'][2]) && $value) {
  695. # 重新定义value
  696. $value = Dever::load($param['searchbox'][2], $value);
  697. if (is_array($value)) {
  698. $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">';
  699. foreach ($value as $k => $v) {
  700. $link = '';
  701. $attr = '';
  702. $pic = '';
  703. if (isset($v['pic']) && $v['pic']) {
  704. $pic = '<a href="javascript:;"><img src="'.$v['pic'].'" width="100"></a>&nbsp;&nbsp;';
  705. }
  706. if (isset($v['link']) && $v['link']) {
  707. $link = $v['link'];
  708. $attr = ' target="_blank"';
  709. }
  710. $html .= '<tr id="searchbox_check_'.$param['name'].'_value_'.$v['id'].'"><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="searchbox_del($(this), \''.$param['name'].'_value\', \''.$v['id'].'\', \''.$param['name'].'\')">[删除]</a></td></tr><script>searchbox_value[\''.$param['name'].'_value\'].push('.$v['id'].');</script>';
  711. }
  712. $html .= '</table></div>';
  713. $input .= $html;
  714. $value = '';
  715. }
  716. }
  717. $param['name'] = $param['name'] . '_temp';
  718. }
  719. $auto = 'searchbox="' . Dever::url($param['searchbox'][0]) . '" searchbox_callback="' . $param['searchbox'][1] . '" ';
  720. if (isset($param['searchbox'][3])) {
  721. $auto .= ' searchbox_cate="' . $param['searchbox'][3] . '" ';
  722. }
  723. $search = '';
  724. if (isset($param['searchbox'][4])) {
  725. $temp = explode(',', $param['searchbox'][3]);
  726. $link = explode(',', $param['searchbox'][4]);
  727. $p = array();
  728. $p['option'] = array();
  729. foreach ($temp as $k => $v) {
  730. $p['name'] = $v;
  731. $p['option'] = Dever::load($link[$k]);
  732. $search .= self::_select($p, '', '', ' style="width: 15%;display: inline;margin-left:5px;"');
  733. }
  734. }
  735. $auto .= ' style="display: inline;"';
  736. $input = $search . '<button type="button" onclick="searchbox(\''.$param['name'].'\', $(this))" class="btn btn-primary layui-btn layuiadmin-btn-list" style="margin-left:10px;margin-top: -2px;"><i class="fa fa-save"></i> 搜索</button>' . $input;
  737. }
  738. if (isset($param['bind'])) {
  739. $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
  740. $auto .= $param['bind'][0] . '="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
  741. $auto .= ' onload="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
  742. }
  743. 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;
  744. }
  745. }
  746. /**
  747. * color
  748. *
  749. * @return string
  750. */
  751. public static function _color($param)
  752. {
  753. $param['class'] = 'dever-color form-control';
  754. $param['update'] = 'text';
  755. $param['default'] = '#000000';
  756. return self::text($param, '');
  757. }
  758. /**
  759. * password
  760. *
  761. * @return string
  762. */
  763. public static function _password($param)
  764. {
  765. $param['value'] = '';
  766. return self::text($param);
  767. }
  768. /**
  769. * hidden
  770. *
  771. * @return string
  772. */
  773. public static function _hidden($param)
  774. {
  775. $param['update'] = 'hidden';
  776. return self::text($param, '');
  777. }
  778. /**
  779. * time
  780. *
  781. * @return string
  782. */
  783. public static function _time($param)
  784. {
  785. 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"/>';
  786. }
  787. /**
  788. * date
  789. *
  790. * @return string
  791. */
  792. public static function _date($param)
  793. {
  794. 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"/>';
  795. }
  796. /**
  797. * div
  798. *
  799. * @return string
  800. */
  801. public static function _node($param, $type = 'div')
  802. {
  803. $result = array('', '');
  804. foreach ($param as $k => $v) {
  805. $result[0] .= '<' . $type . ' ' . $v . '>';
  806. $result[1] .= '</' . $type . '>';
  807. }
  808. return $result;
  809. }
  810. }