Input.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  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. private function uploadHandle($param)
  162. {
  163. $html = $style = '';
  164. $div = array('', '');
  165. $type = 'button';
  166. if (isset($param['upload']) && $param['upload'] == 'qiniu') {
  167. $upload = Dever::load('upload/qiniu.token?key=' . $param['key']);
  168. if (isset($upload['domain'])) {
  169. $domain = $upload['domain'];
  170. $token = $upload['uptoken'];
  171. $host = $upload['host'];
  172. $date = explode('-', date("Y-m-d"));
  173. $path = $param['key'] . '/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
  174. $html = ' m="qiniu" domain="'.$domain.'" path="'.$path.'" host="'.$host.'" token="'.$token.'" ';
  175. }
  176. }
  177. if (isset($param['large']) && $param['large'] && isset($upload['domain'])) {
  178. $html .= ' l="1" ';
  179. $type = 'file';
  180. $div = array('<div class="layui-input" style=" position: relative;
  181. display: inline-block;
  182. border-radius: 2px;
  183. color: black;
  184. text-decoration: none;
  185. text-indent: 0;
  186. line-height: 37px;
  187. height: 37px;
  188. width: 97px;
  189. padding-left: 19px;">', '本地上传</div>');
  190. $style = 'position: absolute;
  191. font-size: 21px;
  192. right: 0;
  193. top: 0;
  194. opacity: 0;';
  195. }
  196. return array($html, $type, $div, $style);
  197. }
  198. /**
  199. * image
  200. *
  201. * @return string
  202. */
  203. public static function _image($param)
  204. {
  205. if (isset($param['value']) && $param['value']) {
  206. $pic = 'src="' . $param['value'] . '"';
  207. } elseif (isset($param['places'])) {
  208. $pic = 'src="http://placehold.it/' . $param['place'] . '"';
  209. } else {
  210. $pic = 'src="" style=display:none;';
  211. }
  212. $class = 'width:100px;display:inline;';
  213. if (layadmin()) {
  214. $class .= 'padding-left:0px;';
  215. }
  216. $upload = self::uploadHandle($param);
  217. $button = $upload[2][0] . '<input type="'.$upload[1].'" style="'.$class.$upload[3].'" class="form-control image_upload" '.$upload[0].' v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="本地上传"/>' . $upload[2][1];
  218. return $button .'
  219. <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="图库"/>
  220. <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">
  221. <div class="layui-progress-bar" lay-percent="0%"></div>
  222. </div>
  223. <div style="margin:10px;">
  224. <img ' . $pic . ' class="update_value" update_type="src" id="show_' . $param['name'] . '_' . $param['index'] . '" width="150" /></div>
  225. <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'] : '')) . '">';
  226. }
  227. /**
  228. * images
  229. *
  230. * @return string
  231. */
  232. public static function _images($param)
  233. {
  234. $pic = '';
  235. if (isset($param['value']) && $param['value']) {
  236. $temp = explode(',', $param['value']);
  237. foreach ($temp as $k => $v) {
  238. $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>';
  239. }
  240. }
  241. $class = 'width:100px;display:inline;';
  242. if (layadmin()) {
  243. $class .= 'padding-left:0px;';
  244. }
  245. $upload = self::uploadHandle($param);
  246. $button = $upload[2][0] . '<input type="'.$upload[1].'" style="'.$class.$upload[3].'" class="form-control image_upload" '.$upload[0].' mul="yes" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="本地上传"/>' . $upload[2][1];
  247. return $button . '
  248. <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="图库"/>
  249. <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">
  250. <div class="layui-progress-bar" lay-percent="0%"></div>
  251. </div>
  252. <div style="margin:10px;" update_type="html" class="update_value ' . $param['name'] . '_' . $param['index'] . '_mul">' . $pic . '</div>
  253. <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'] : '')) . '">';
  254. }
  255. /**
  256. * upload
  257. *
  258. * @return string
  259. */
  260. public static function _upload($param)
  261. {
  262. $class = 'width:100px;display:inline;';
  263. if (layadmin()) {
  264. $class .= 'padding-left:0px;';
  265. }
  266. $upload = self::uploadHandle($param);
  267. $button = $upload[2][0] . '<input type="'.$upload[1].'" style="'.$class.$upload[3].'" class="form-control image_upload" '.$upload[0].' t="file" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="本地上传"/>' . $upload[2][1];
  268. return $button .'
  269. <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="文件库"/>
  270. <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">
  271. <div class="layui-progress-bar" lay-percent="0%"></div>
  272. </div>
  273. <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'] : '')) . '">
  274. </div>';
  275. //return '<input type="file" class="form-control" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '" name="' . $param['name'] . '"/>';
  276. }
  277. /**
  278. * upload
  279. *
  280. * @return string
  281. */
  282. public static function _uploads($param)
  283. {
  284. $file = '';
  285. if (isset($param['value']) && $param['value']) {
  286. $temp = explode(',', $param['value']);
  287. foreach ($temp as $k => $v) {
  288. $upload = Dever::load('upload/file-check', array('option_key' => md5($v)));
  289. $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>';
  290. }
  291. }
  292. $class = 'width:100px;display:inline;';
  293. if (layadmin()) {
  294. $class .= 'padding-left:0px;';
  295. }
  296. $upload = self::uploadHandle($param);
  297. $button = $upload[2][0] . '<input type="'.$upload[1].'" style="'.$class.$upload[3].'" class="form-control image_upload" '.$upload[0].' t="file" mul="yes" v="' . $param['name'] . '_' . $param['index'] . '" id="file_' . $param['name'] . '_' . $param['index'] . '" key="' . $param['key'] . '" value="本地上传"/>' . $upload[2][1];
  298. return $button .'
  299. <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="文件库"/>
  300. <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">
  301. <div class="layui-progress-bar" lay-percent="0%"></div>
  302. </div>
  303. <ul style="margin:10px;" update_type="html" class="update_value ' . $param['name'] . '_' . $param['index'] . '_mul">' . $file . '</ul>
  304. <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'] : '')) . '">';
  305. //return '<input type="file" class="form-control" value="' . (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : '')) . '" name="' . $param['name'] . '"/>';
  306. }
  307. /**
  308. * editor
  309. *
  310. * @return string
  311. */
  312. public static function _editor($param)
  313. {
  314. $width = '100%';
  315. $html = '';
  316. if (isset($param['editor'])) {
  317. $width = '70%';
  318. $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>';
  319. foreach ($param['editor']['button'] as $k => $v) {
  320. if (isset($v['type'])) {
  321. if ($v['type'] == 'image') {
  322. $param['key'] = $v['key'];
  323. } elseif ($v['type'] == 'media') {
  324. $param['media'] = $v['key'];
  325. }
  326. $v['type'] = 'editor_tool" tool="' . $v['type'];
  327. } else {
  328. $v['type'] = 'upload_show_editor';
  329. }
  330. $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'].'">';
  331. }
  332. $html .= '</div></div>';
  333. }
  334. 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>';
  335. }
  336. /**
  337. * markdown
  338. *
  339. * @return string
  340. */
  341. public static function _markdown($param)
  342. {
  343. 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>';
  344. }
  345. /**
  346. * selector
  347. *
  348. * @return string
  349. */
  350. public static function _selector($param, $type = '')
  351. {
  352. $html = '';
  353. if (isset($param['key']) && strpos($param['key'], '.css') !== false) {
  354. $param['key'] = '<link rel="stylesheet" href="' . $param['key'] . '"/>';
  355. }
  356. if (isset($param['option'])) {
  357. foreach ($param['option'] as $k => $v) {
  358. $check = '';
  359. if ((isset($param['value']) && $param['value'] == $k) || (empty($param['value']) && isset($param['default']) && $param['default'] == $k)) {
  360. $check = 'checked';
  361. }
  362. if (is_array($v)) {
  363. $value = $v['name'];
  364. } else {
  365. $value = $v;
  366. }
  367. $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;';
  368. }
  369. $html .= self::hidden($param);
  370. }
  371. return '<div class="am-btn-group" >' . $html . '</div>';
  372. }
  373. /**
  374. * radio
  375. *
  376. * @return string
  377. */
  378. public static function _radio($param, $type = '')
  379. {
  380. $html = '';
  381. if (isset($param['option'])) {
  382. if (isset($param['option']['state']) && $param['option']['state'] >= 1) {
  383. if (isset($param['value'])) {
  384. $param['value'] = explode(',', $param['value']);
  385. } else {
  386. $param['value'] = array();
  387. }
  388. # 处理比较复杂的多维数组
  389. unset($param['option']['state']);
  390. $j = -1;
  391. foreach ($param['option'] as $k => $v) {
  392. $check = '';
  393. if (isset($param['update_parent'])) {
  394. $input_type = $param['update_parent'];
  395. } else {
  396. $input_type = $param['update'];
  397. }
  398. //{check}
  399. $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 />';
  400. $span = array('', '');
  401. if (isset($v['child']) && $v['child']) {
  402. //$i = 1;
  403. $html .= '<ul style="list-style:none;margin:0px;display:;" class="">';
  404. foreach ($v['child'] as $ki => $vi) {
  405. if (!is_array($vi)) {
  406. $temp = $vi;
  407. $vi = array();
  408. $vi['name'] = $temp;
  409. $vi['id'] = $ki;
  410. }
  411. if (isset($v['url'])) {
  412. $span = array('<span class="edit" data-url="' . Dever::url($v['url'] . '?id=' . $vi['id']) . '">', '</span>');
  413. }
  414. $check = '';
  415. $disabled = 'disabled="true"';
  416. if (isset($param['value']) && in_array($ki, $param['value'])) {
  417. $check = 'checked';
  418. $disabled = '';
  419. $j++;
  420. } elseif (isset($param['default']) && is_array($param['default']) && (in_array($k . '_' . $ki, $param['default']))) {
  421. $check = 'checked';
  422. $disabled = '';
  423. $j++;
  424. }
  425. $input = $input_value = '';
  426. if (isset($param['update_input'])) {
  427. if (isset($param['update_input_data']) && isset($param['update_input_data'][$j])) {
  428. $input_value = $param['update_input_data'][$j];
  429. if ($disabled) {
  430. $input_value = '';
  431. }
  432. } else {
  433. $input_value = isset($param['update_input_default']) ? $param['update_input_default'] : '';
  434. }
  435. if ($param['update_input']) {
  436. $input = '[' . $param['update_input'] . ']';
  437. }
  438. $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 . '/>';
  439. }
  440. $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>';
  441. //++$i;
  442. }
  443. $html .= '</ul>';
  444. }
  445. $html .= '<br />';
  446. }
  447. } else {
  448. $js = '';
  449. if (isset($param['control']) && is_string($param['control'])) {
  450. //print_r($param);die;
  451. $js = ' show_id="' . $param['control'] . '" onclick="inputShow($(this), \'' . $param['control'] . '\', \'input\')"';
  452. } elseif (isset($param['bind'])) {
  453. $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
  454. $js = $param['bind'][0] . '="' . $param['bind'][1] . '(\'' . $param['name'] . '\', $(this), ' . $param['bind'][2] . ')" ';
  455. $js .= ' onload="' . $param['bind'][1] . '(\'' . $param['name'] . '\', $(this), ' . $param['bind'][2] . ')" ';
  456. }
  457. $param['parent'] = isset($param['parent']) ? $param['parent'] : '0';
  458. $param['parent'] .= '_' . $param['name'];
  459. if ($param['update'] == 'checkbox' && empty($param['checkall'])) {
  460. $html .= '<input update_type="checked" class="checkbox-checkall ' . $param['name'] . ' update_value" type="' . $param['update'] . '" name="temp_' . $param['name'] . '[]" value="' . $param['parent'] . '"/> 全选 &nbsp;&nbsp;';
  461. }
  462. foreach ($param['option'] as $k => $v) {
  463. $check = '';
  464. if (is_array($v)) {
  465. $value = $v['name'];
  466. isset($v['id']) && $k = $v['id'];
  467. } else {
  468. $value = $v;
  469. }
  470. if (isset($param['bit'][$k])) {
  471. if (isset($param['value']) && ($param['value'] & $k) > 0) {
  472. $check = 'checked';
  473. }
  474. } elseif (isset($param['value'])) {
  475. if (is_string($param['value']) && strpos(',' . $param['value'] . ',', ',' . $k . ',') !== false) {
  476. $check = 'checked';
  477. } elseif (is_array($param['value']) && in_array($k, $param['value'])) {
  478. $check = 'checked';
  479. }
  480. } elseif (isset($param['default'])) {
  481. if (is_string($param['default']) && strpos(',' . $param['default'], ',' . $k) !== false) {
  482. $check = 'checked';
  483. } elseif (is_array($param['default']) && in_array($k, $param['default'])) {
  484. $check = 'checked';
  485. }
  486. }
  487. $cjs = $js;
  488. if (isset($param['control']) && is_string($param['control']) && $param['control'] != $param['name']) {
  489. $cjs = str_replace('update_', '', str_replace($param['control'], $param['name'], $js));
  490. }
  491. $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;';
  492. if (isset($param['bind'])) {
  493. //$html .= '<script>$(document).ready(function(){$(".checkbox-checkall-'.$param['parent'].'").click();})</script>';
  494. }
  495. }
  496. }
  497. }
  498. return '<div class="am-btn-group" >' . $html . '</div>';
  499. }
  500. /**
  501. * group
  502. *
  503. * @return string
  504. */
  505. public static function _group($param, $class = '', $hidden = '', $change = '')
  506. {
  507. $html = $class ? '<div class="' . $class . '">' : '';
  508. $html .= $hidden . '<select class="update_value form-control ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" ' . $change . '>';
  509. if (isset($param['option'])) {
  510. foreach ($param['option'] as $k => $v) {
  511. if ($v['id'] <= 0) {
  512. $html .= '<option value="0" selected>' . $v['name'] . '</option>';
  513. } else {
  514. $html .= '<optgroup label="' . $v['name'] . '">';
  515. if (isset($v['child'])) {
  516. foreach ($v['child'] as $k1 => $v1) {
  517. $selected = '';
  518. if ((isset($param['value']) && $param['value'] == $v1['id']) || (empty($param['value']) && isset($param['default']) && $param['default'] == $v1['id'])) {
  519. $selected = 'selected';
  520. }
  521. $html .= '<option value="' . $v1['id'] . '" ' . $selected . '>' . $v1['name'] . '</option>';
  522. }
  523. }
  524. $html .= '</optgroup>';
  525. }
  526. }
  527. }
  528. $html .= '</select>';
  529. $html .= $class ? '</div>' : '';
  530. return $html;
  531. }
  532. /**
  533. * linkage select 多级联动
  534. *
  535. * @return string
  536. */
  537. public static function _linkage($param, $class = '', $hidden = '', $change = '')
  538. {
  539. $div = 'div';
  540. $w = 'width:20%;';
  541. if ($class == 'span') {
  542. $div = 'span';
  543. $w = '';
  544. }
  545. if (!isset($param['search_state'])) {
  546. $param['search_state'] = false;
  547. }
  548. # 当前级别
  549. $level = 1;
  550. # 传入的参数
  551. $level_param = '';
  552. if (isset($param['linkage'])) {
  553. $level_param = $param['linkage'];
  554. }
  555. $id = 'dever-linkage-' . $param['name'];
  556. $html = '<' . $div . ' class="' . $class . '" id="' . $id . '" >';
  557. # 默认值
  558. if (isset($param['value']) && is_array($param['value'])) {
  559. $param['value'] = implode(',', $param['value']);
  560. }
  561. $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.'")};';
  562. $html .= '$(document).ready(function(){linkage_' . $param['name'] . '(' . $level . ')});</script>';
  563. $html .= '</' . $div . '>';
  564. return $html;
  565. }
  566. /**
  567. * select
  568. *
  569. * @return string
  570. */
  571. public static function _selects($param, $class = '', $hidden = '', $change = '')
  572. {
  573. return self::_select($param, $class, $hidden, $change);
  574. }
  575. /**
  576. * select
  577. *
  578. * @return string
  579. */
  580. public static function _select($param, $class = '', $hidden = '', $change = '')
  581. {
  582. $html = $class ? '<div class="' . $class . '">' : '';
  583. $child_class = '';
  584. if (isset($param['child'])) {
  585. $child_param['name'] = 'update_' . $param['child_name'];
  586. isset($param['value']) && $param['value'] = $param['value'];
  587. isset($param['child_value']) && $child_param['value'] = $param['child_value'];
  588. $change = 'style="width:45%" id="' . $param['name'] . '" data-child="' . $child_param['name'] . '_child" ';
  589. $child_class = ' change';
  590. //$param['name'] .= '_parent';
  591. }
  592. if (isset($param['control']) && is_string($param['control'])) {
  593. //print_r($param);die;
  594. $change = ' show_id="' . $param['control'] . '" onchange="inputShow($(this), \'' . $param['control'] . '\')"';
  595. } elseif (isset($param['bind'])) {
  596. $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
  597. $change = $param['bind'][0] . '="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
  598. $child_class .= ' change';
  599. }
  600. $xm = '';
  601. if ($change) {
  602. $xm = '';
  603. } else {
  604. }
  605. if (!$change && isset($param['update'])) {
  606. $xm = 'xm-select="' . $param['name'] . '" xm-select-skin="normal" xm-select-search="" xm-select-search-type="dl"';
  607. if ($param['update'] != 'selects') {
  608. $xm .= ' xm-select-radio=""';
  609. }
  610. $search_value = '';
  611. if (isset($param['value'])) {
  612. $search_value = $param['value'];
  613. } elseif (isset($param['default'])) {
  614. $search_value = $param['default'];
  615. }
  616. if (isset($param['update_search'])) {
  617. $xm = str_replace('xm-select-search=""', 'xm-select-search="'.Dever::url($param['update_search'] . '&yes='.$search_value.'&json=1').'"', $xm);
  618. }
  619. if (isset($param['update_create'])) {
  620. $xm .= ' xm-select-create=""';
  621. }
  622. if ($param['match'] != 'option') {
  623. $xm .= ' lay-verify="' . $param['name'] . '"';
  624. }
  625. } else {
  626. $xm .= ' xm-select-radio=""';
  627. }
  628. if (isset($param['option']) && isset($param['update']) && $param['update'] == 'select') {
  629. $total = count($param['option']);
  630. if ($total <= 5) {
  631. $xm = '';
  632. }
  633. }
  634. $html .= $hidden . '<select '.$xm.' class="update_value form-control ' . $child_class . ' ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" id="' . $param['name'] . '" ' . $change . '>';
  635. if (isset($param['option'])) {
  636. if (isset($param['lang']) && $param['lang']) {
  637. $html .= '<option value="0" selected>' . $param['lang'] . '</option>';
  638. }
  639. foreach ($param['option'] as $k => $v) {
  640. if (is_array($v)) {
  641. $value = $v['name'];
  642. isset($v['id']) && $k = $v['id'];
  643. } else {
  644. $value = $v;
  645. }
  646. $check = '';
  647. 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 . ','))) {
  648. $check = 'selected';
  649. }
  650. $parent = '';
  651. if (isset($param['parent']) && $param['parent'] && isset($v[$param['parent']])) {
  652. $parent = $v[$param['parent']];
  653. }
  654. if (is_array($v)) {
  655. $value = isset($v['name']) ? $v['name'] : $v['lang'];
  656. } else {
  657. $value = $v;
  658. }
  659. $html .= '<option parent="'.$parent.'" value="' . $k . '" ' . $check . '>' . $value . '</option>';
  660. }
  661. }
  662. $html .= '</select>';
  663. if (isset($param['child'])) {
  664. $child = $child_param['name'];
  665. $hidden = self::hidden(array('name' => $child, 'class' => $child . '_child_value'));
  666. foreach ($param['child'] as $k => $v) {
  667. $child_param['name'] = 'child-' . $k;
  668. $child_param['option'] = $v;
  669. $html .= self::select($child_param, $child . '_child ' . $child . '_child_' . $k . '" parent="' . $k . '" style="display:none;margin-top: -35px;margin-left: 47%;"', $hidden);
  670. }
  671. }
  672. $html .= $class ? '</div>' : '';
  673. return $html;
  674. }
  675. /**
  676. * radio
  677. *
  678. * @return string
  679. */
  680. public static function _checkbox($param)
  681. {
  682. return self::radio($param);
  683. }
  684. /**
  685. * text
  686. *
  687. * @return string
  688. */
  689. public static function _text($param, $class = '')
  690. {
  691. if ($class) {
  692. return '<div class="">' . self::text($param, false) . '</div>';
  693. } else {
  694. $auto = $input = '';
  695. $value = (isset($param['value']) ? $param['value'] : (isset($param['default']) ? $param['default'] : ''));
  696. if (isset($param['autocomplete'])) {
  697. if (empty($param['autocomplete'][1])) {
  698. $param['autocomplete'][1] = 'value';
  699. }
  700. if ($param['autocomplete'][1] == 'id') {
  701. $input = self::hidden(array('name' => $param['name'], 'value' => $value));
  702. $input = '<script>var autocomplete_value = {};autocomplete_value[\''.$param['name'].'_value\'] = [];</script>';
  703. if (isset($param['autocomplete'][2]) && $value) {
  704. # 重新定义value
  705. $value = Dever::load($param['autocomplete'][2], $value);
  706. if (is_array($value)) {
  707. $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">';
  708. foreach ($value as $k => $v) {
  709. $link = '';
  710. $attr = '';
  711. $pic = '';
  712. if (isset($v['pic']) && $v['pic']) {
  713. $pic = '<a href="javascript:;"><img src="'.$v['pic'].'" width="100"></a>&nbsp;&nbsp;';
  714. }
  715. if (isset($v['link']) && $v['link']) {
  716. $link = $v['link'];
  717. $attr = ' target="_blank"';
  718. }
  719. $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>';
  720. }
  721. $html .= '</table></div>';
  722. $input .= $html;
  723. $value = '';
  724. }
  725. }
  726. $param['name'] = $param['name'] . '_temp';
  727. }
  728. $auto = 'complete="' . Dever::url($param['autocomplete'][0]) . '" complete_callback="' . $param['autocomplete'][1] . '" ';
  729. if (isset($param['autocomplete'][3])) {
  730. $auto .= ' complete_cate="' . $param['autocomplete'][3] . '" ';
  731. }
  732. } elseif (isset($param['searchbox'])) {
  733. if (empty($param['searchbox'][1])) {
  734. $param['searchbox'][1] = 'value';
  735. }
  736. if ($param['searchbox'][1] == 'id') {
  737. $input = self::hidden(array('name' => $param['name'], 'value' => $value));
  738. $input = '<script>var searchbox_value = [];searchbox_value[\''.$param['name'].'_value\'] = [];</script>';
  739. if (isset($param['searchbox'][2]) && $value) {
  740. # 重新定义value
  741. $value = Dever::load($param['searchbox'][2], $value);
  742. if (is_array($value)) {
  743. $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">';
  744. foreach ($value as $k => $v) {
  745. $link = '';
  746. $attr = '';
  747. $pic = '';
  748. if (isset($v['pic']) && $v['pic']) {
  749. $pic = '<a href="javascript:;"><img src="'.$v['pic'].'" width="100"></a>&nbsp;&nbsp;';
  750. }
  751. if (isset($v['link']) && $v['link']) {
  752. $link = $v['link'];
  753. $attr = ' target="_blank"';
  754. }
  755. $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>';
  756. }
  757. $html .= '</table></div>';
  758. $input .= $html;
  759. $value = '';
  760. }
  761. }
  762. $param['name'] = $param['name'] . '_temp';
  763. }
  764. $auto = 'searchbox="' . Dever::url($param['searchbox'][0]) . '" searchbox_callback="' . $param['searchbox'][1] . '" ';
  765. if (isset($param['searchbox'][3])) {
  766. $auto .= ' searchbox_cate="' . $param['searchbox'][3] . '" ';
  767. }
  768. $search = '';
  769. if (isset($param['searchbox'][4])) {
  770. $temp = explode(',', $param['searchbox'][3]);
  771. $link = explode(',', $param['searchbox'][4]);
  772. $p = array();
  773. $p['option'] = array();
  774. foreach ($temp as $k => $v) {
  775. $p['name'] = $v;
  776. $p['option'] = Dever::load($link[$k]);
  777. $search .= self::_select($p, '', '', ' style="width: 15%;display: inline;margin-left:5px;"');
  778. }
  779. }
  780. $auto .= ' style="display: inline;"';
  781. $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;
  782. }
  783. if (isset($param['bind'])) {
  784. $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
  785. $auto .= $param['bind'][0] . '="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
  786. $auto .= ' onload="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
  787. }
  788. 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;
  789. }
  790. }
  791. /**
  792. * color
  793. *
  794. * @return string
  795. */
  796. public static function _color($param)
  797. {
  798. $param['class'] = 'dever-color form-control';
  799. $param['update'] = 'text';
  800. $param['default'] = '#000000';
  801. return self::text($param, '');
  802. }
  803. /**
  804. * password
  805. *
  806. * @return string
  807. */
  808. public static function _password($param)
  809. {
  810. $param['value'] = '';
  811. return self::text($param);
  812. }
  813. /**
  814. * hidden
  815. *
  816. * @return string
  817. */
  818. public static function _hidden($param)
  819. {
  820. $param['update'] = 'hidden';
  821. return self::text($param, '');
  822. }
  823. /**
  824. * time
  825. *
  826. * @return string
  827. */
  828. public static function _time($param)
  829. {
  830. 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"/>';
  831. }
  832. /**
  833. * date
  834. *
  835. * @return string
  836. */
  837. public static function _date($param)
  838. {
  839. 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"/>';
  840. }
  841. /**
  842. * div
  843. *
  844. * @return string
  845. */
  846. public static function _node($param, $type = 'div')
  847. {
  848. $result = array('', '');
  849. foreach ($param as $k => $v) {
  850. $result[0] .= '<' . $type . ' ' . $v . '>';
  851. $result[1] .= '</' . $type . '>';
  852. }
  853. return $result;
  854. }
  855. }