Input.php 47 KB

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