Html.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\taglib;
  12. use think\template\TagLib;
  13. /**
  14. * Html标签库驱动
  15. */
  16. class Html extends TagLib
  17. {
  18. // 标签定义
  19. protected $tags = array(
  20. // 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次
  21. 'editor' => array('attr' => 'id,name,style,width,height,type', 'close' => 1),
  22. 'select' => array('attr' => 'name,options,values,output,multiple,id,size,first,change,selected,dblclick', 'close' => 0),
  23. 'grid' => array('attr' => 'id,pk,style,action,actionlist,show,datasource', 'close' => 0),
  24. 'list' => array('attr' => 'id,pk,style,action,actionlist,show,datasource,checkbox', 'close' => 0),
  25. 'imagebtn' => array('attr' => 'id,name,value,type,style,click', 'close' => 0),
  26. 'checkbox' => array('attr' => 'name,checkboxes,checked,separator', 'close' => 0),
  27. 'radio' => array('attr' => 'name,radios,checked,separator', 'close' => 0),
  28. );
  29. /**
  30. * editor标签解析 插入可视化编辑器
  31. * 格式: <html:editor id="editor" name="remark" type="FCKeditor" style="" >{$vo.remark}</html:editor>
  32. * @access public
  33. * @param array $tag 标签属性
  34. * @return string|void
  35. */
  36. public function tagEditor($tag, $content)
  37. {
  38. $id = !empty($tag['id']) ? $tag['id'] : '_editor';
  39. $name = $tag['name'];
  40. $style = !empty($tag['style']) ? $tag['style'] : '';
  41. $width = !empty($tag['width']) ? $tag['width'] : '100%';
  42. $height = !empty($tag['height']) ? $tag['height'] : '320px';
  43. // $content = $tag['content'];
  44. $type = $tag['type'];
  45. switch (strtoupper($type)) {
  46. case 'UEDITOR':
  47. //$parseStr = '<script id="editor" type="text/plain" style="width:1024px;height:500px;"></script><script> var ue = UE.getEditor("editor"); ue.ready(function() { ue.setContent("<p>hello!</p>");});</script> ';
  48. $parseStr = '<script id="' . $id . '" name="' . $name . '" type="text/plain" style="width:1024px;height:500px;">' . $content . '</script><script> var ue = UE.getEditor("'.$id.'"); </script> ';
  49. break;
  50. case 'FCKEDITOR':
  51. $parseStr = '<!-- 编辑器调用开始 --><script type="text/javascript" src="http://public.rrbrr.com/Js/FCKeditor/fckeditor.js"></script><textarea id="' . $id . '" name="' . $name . '">' . $content . '</textarea><script type="text/javascript"> var oFCKeditor = new FCKeditor( "' . $id . '","' . $width . '","' . $height . '" ) ; oFCKeditor.BasePath = "http://public.rrbrr.com/Js/FCKeditor/" ; oFCKeditor.ReplaceTextarea() ;function resetEditor(){setContents("' . $id . '",document.getElementById("' . $id . '").value)}; function saveEditor(){document.getElementById("' . $id . '").value = getContents("' . $id . '");} function InsertHTML(html){ var oEditor = FCKeditorAPI.GetInstance("' . $id . '") ;if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG ){oEditor.InsertHtml(html) ;}else alert( "FCK必须处于WYSIWYG模式!" ) ;}</script> <!-- 编辑器调用结束 -->';
  52. break;
  53. case 'FCKMINI':
  54. $parseStr = '<!-- 编辑器调用开始 --><script type="text/javascript" src="http://public.rrbrr.com/Js/FCKMini/fckeditor.js"></script><textarea id="' . $id . '" name="' . $name . '">' . $content . '</textarea><script type="text/javascript"> var oFCKeditor = new FCKeditor( "' . $id . '","' . $width . '","' . $height . '" ) ; oFCKeditor.BasePath = "http://public.rrbrr.com/Js/FCKMini/" ; oFCKeditor.ReplaceTextarea() ;function resetEditor(){setContents("' . $id . '",document.getElementById("' . $id . '").value)}; function saveEditor(){document.getElementById("' . $id . '").value = getContents("' . $id . '");} function InsertHTML(html){ var oEditor = FCKeditorAPI.GetInstance("' . $id . '") ;if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG ){oEditor.InsertHtml(html) ;}else alert( "FCK必须处于WYSIWYG模式!" ) ;}</script> <!-- 编辑器调用结束 -->';
  55. break;
  56. case 'EWEBEDITOR':
  57. $parseStr = "<!-- 编辑器调用开始 --><script type='text/javascript' src='http://public.rrbrr.com/Js/eWebEditor/js/edit.js'></script><input type='hidden' id='{$id}' name='{$name}' value='{$conent}'><iframe src='http://public.rrbrr.com/Js/eWebEditor/ewebeditor.htm?id={$name}' frameborder=0 scrolling=no width='{$width}' height='{$height}'></iframe><script type='text/javascript'>function saveEditor(){document.getElementById('{$id}').value = getHTML();} </script><!-- 编辑器调用结束 -->";
  58. break;
  59. case 'NETEASE':
  60. $parseStr = '<!-- 编辑器调用开始 --><textarea id="' . $id . '" name="' . $name . '" style="display:none">' . $content . '</textarea><iframe ID="Editor" name="Editor" src="http://public.rrbrr.com/Js/HtmlEditor/index.html?ID=' . $name . '" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" style="height:' . $height . ';width:' . $width . '"></iframe><!-- 编辑器调用结束 -->';
  61. break;
  62. case 'UBB':
  63. $parseStr = '<script type="text/javascript" src="http://public.rrbrr.com/Js/UbbEditor.js"></script><div style="padding:1px;width:' . $width . ';border:1px solid silver;float:left;"><script LANGUAGE="JavaScript"> showTool(); </script></div><div><TEXTAREA id="UBBEditor" name="' . $name . '" style="clear:both;float:none;width:' . $width . ';height:' . $height . '" >' . $content . '</TEXTAREA></div><div style="padding:1px;width:' . $width . ';border:1px solid silver;float:left;"><script LANGUAGE="JavaScript">showEmot(); </script></div>';
  64. break;
  65. /*<script type="text/javascript" src="/Public/Plugin/kindeditor-4.1.7/kindeditor-all-min.js"></script>*/
  66. case 'KINDEDITOR':
  67. $parseStr = '
  68. <script>
  69. KindEditor.ready(function(K) {
  70. window.editor = K.create(\'#'.$id.'\',{
  71. extraFileUploadParams : {
  72. item_id : 1000,
  73. category_id : 1,
  74. "PHPSESSID_KEY": "at8t1gvbs8bq35jqudcuk7381s",
  75. "session_id":"<?= session_id() ?>"
  76. }
  77. });
  78. });
  79. </script>
  80. <textarea id="' . $id . '" style="' . $style . '" name="' . $name . '" >' . $content . '</textarea>';
  81. break;
  82. default:
  83. $parseStr = '<textarea id="' . $id . '" style="' . $style . '" name="' . $name . '" >' . $content . '</textarea>';
  84. }
  85. return $parseStr;
  86. }
  87. /**
  88. * imageBtn标签解析
  89. * 格式: <html:imageBtn type="" value="" />
  90. * @access public
  91. * @param array $tag 标签属性
  92. * @return string|void
  93. */
  94. public function tagImageBtn($tag)
  95. {
  96. $name = $tag['name']; //名称
  97. $value = $tag['value']; //文字
  98. $id = isset($tag['id']) ? $tag['id'] : ''; //ID
  99. $style = isset($tag['style']) ? $tag['style'] : ''; //样式名
  100. $click = isset($tag['click']) ? $tag['click'] : ''; //点击
  101. $type = empty($tag['type']) ? 'button' : $tag['type']; //按钮类型
  102. if (!empty($name)) {
  103. $parseStr = '<div class="' . $style . '" ><input type="' . $type . '" id="' . $id . '" name="' . $name . '" value="' . $value . '" onclick="' . $click . '" class="' . $name . ' imgButton"></div>';
  104. } else {
  105. $parseStr = '<div class="' . $style . '" ><input type="' . $type . '" id="' . $id . '" name="' . $name . '" value="' . $value . '" onclick="' . $click . '" class="button"></div>';
  106. }
  107. return $parseStr;
  108. }
  109. /**
  110. * imageLink标签解析
  111. * 格式: <html:imageLink type="" value="" />
  112. * @access public
  113. * @param array $tag 标签属性
  114. * @return string|void
  115. */
  116. public function tagImgLink($tag)
  117. {
  118. $name = $tag['name']; //名称
  119. $alt = $tag['alt']; //文字
  120. $id = $tag['id']; //ID
  121. $style = $tag['style']; //样式名
  122. $click = $tag['click']; //点击
  123. $type = $tag['type']; //点击
  124. if (empty($type)) {
  125. $type = 'button';
  126. }
  127. $parseStr = '<span class="' . $style . '" ><input title="' . $alt . '" type="' . $type . '" id="' . $id . '" name="' . $name . '" onmouseover="this.style.filter=\'alpha(opacity=100)\'" onmouseout="this.style.filter=\'alpha(opacity=80)\'" onclick="' . $click . '" align="absmiddle" class="' . $name . ' imgLink"></span>';
  128. return $parseStr;
  129. }
  130. /**
  131. * select标签解析
  132. * 格式: <html:select options="name" selected="value" />
  133. * @access public
  134. * @param array $tag 标签属性
  135. * @return string|void
  136. */
  137. public function tagSelect($tag)
  138. {
  139. $name = $tag['name'];
  140. $options = $tag['options'];
  141. $values = $tag['values'];
  142. $output = $tag['output'];
  143. $multiple = $tag['multiple'];
  144. $id = $tag['id'];
  145. $size = $tag['size'];
  146. $first = $tag['first'];
  147. $selected = $tag['selected'];
  148. $style = $tag['style'];
  149. $ondblclick = $tag['dblclick'];
  150. $onchange = $tag['change'];
  151. if (!empty($multiple)) {
  152. $parseStr = '<select autocomplete="off" id="' . $id . '" name="' . $name . '" ondblclick="' . $ondblclick . '" onchange="' . $onchange . '" multiple="multiple" class="' . $style . '" size="' . $size . '" >';
  153. } else {
  154. $parseStr = '<select autocomplete="off" id="' . $id . '" name="' . $name . '" onchange="' . $onchange . '" ondblclick="' . $ondblclick . '" class="' . $style . '" >';
  155. }
  156. if (!empty($first)) {
  157. $parseStr .= '<option value="" >' . $first . '</option>';
  158. }
  159. if (!empty($options)) {
  160. $parseStr .= '<?php foreach($' . $options . ' as $key=>$val) { ?>';
  161. if (!empty($selected)) {
  162. $parseStr .= '<?php if(($' . $selected . ' !== "") && ($' . $selected . ' == $key || in_array($key,$' . $selected . '))) { ?>';
  163. $parseStr .= '<option selected="selected" value="<?php echo $key ?>"><?php echo $val ?></option>';
  164. $parseStr .= '<?php }else { ?><option value="<?php echo $key ?>"><?php echo $val ?></option>';
  165. $parseStr .= '<?php } ?>';
  166. } else {
  167. $parseStr .= '<option value="<?php echo $key ?>"><?php echo $val ?></option>';
  168. }
  169. $parseStr .= '<?php } ?>';
  170. } else if (!empty($values)) {
  171. $parseStr .= '<?php for($i=0;$i<count($' . $values . ');$i++) { ?>';
  172. if (!empty($selected)) {
  173. $parseStr .= '<?php if(($' . $selected . ' !== "") && ((is_string($' . $selected . ') && $' . $selected . ' == $' . $values . '[$i]) || (is_array($' . $selected . ') && in_array($' . $values . '[$i],$' . $selected . ')))) { ?>';
  174. $parseStr .= '<option selected="selected" value="<?php echo $' . $values . '[$i] ?>"><?php echo $' . $output . '[$i] ?></option>';
  175. $parseStr .= '<?php }else { ?><option value="<?php echo $' . $values . '[$i] ?>"><?php echo $' . $output . '[$i] ?></option>';
  176. $parseStr .= '<?php } ?>';
  177. } else {
  178. $parseStr .= '<option value="<?php echo $' . $values . '[$i] ?>"><?php echo $' . $output . '[$i] ?></option>';
  179. }
  180. $parseStr .= '<?php } ?>';
  181. }
  182. $parseStr .= '</select>';
  183. return $parseStr;
  184. }
  185. /**
  186. * checkbox标签解析
  187. * 格式: <html:checkbox checkboxes="" checked="" />
  188. * @access public
  189. * @param array $tag 标签属性
  190. * @return string|void
  191. */
  192. public function tagCheckbox($tag)
  193. {
  194. $name = $tag['name'];
  195. $checkboxes = $tag['checkboxes'];
  196. $checked = $tag['checked'];
  197. $separator = $tag['separator'];
  198. $checkboxes = $this->tpl->get($checkboxes);
  199. $checked = $this->tpl->get($checked) ? $this->tpl->get($checked) : $checked;
  200. $parseStr = '';
  201. foreach ($checkboxes as $key => $val) {
  202. if ($checked == $key || in_array($key, $checked)) {
  203. $parseStr .= '<input type="checkbox" checked="checked" name="' . $name . '[]" value="' . $key . '">' . $val . $separator;
  204. } else {
  205. $parseStr .= '<input type="checkbox" name="' . $name . '[]" value="' . $key . '">' . $val . $separator;
  206. }
  207. }
  208. return $parseStr;
  209. }
  210. /**
  211. * radio标签解析
  212. * 格式: <html:radio radios="name" checked="value" />
  213. * @access public
  214. * @param array $tag 标签属性
  215. * @return string|void
  216. */
  217. public function tagRadio($tag)
  218. {
  219. $name = $tag['name'];
  220. $radios = $tag['radios'];
  221. $checked = $tag['checked'];
  222. $separator = $tag['separator'];
  223. $name_is_array = $tag['name_is_array'];
  224. if(!empty($name_is_array)){
  225. $name = $name.'[]';
  226. }
  227. $radios = $this->tpl->get($radios);
  228. $checked = $this->tpl->get($checked) ? $this->tpl->get($checked) : $checked;
  229. $parseStr = '';
  230. foreach ($radios as $key => $val) {
  231. if ($checked == $key) {
  232. $parseStr .= '<input type="radio" checked="checked" name="' . $name . '" value="' . $key . '">' . $val . $separator;
  233. } else {
  234. $parseStr .= '<input type="radio" name="' . $name . '" value="' . $key . '">' . $val . $separator;
  235. }
  236. }
  237. return $parseStr;
  238. }
  239. /**
  240. * list标签解析
  241. * 格式: <html:grid datasource="" show="vo" />
  242. * @access public
  243. * @param array $tag 标签属性
  244. * @return string
  245. */
  246. public function tagGrid($tag)
  247. {
  248. $id = $tag['id']; //表格ID
  249. $datasource = $tag['datasource']; //列表显示的数据源VoList名称
  250. $pk = empty($tag['pk']) ? 'id' : $tag['pk']; //主键名,默认为id
  251. $style = $tag['style']; //样式名
  252. $name = !empty($tag['name']) ? $tag['name'] : 'vo'; //Vo对象名
  253. $action = !empty($tag['action']) ? $tag['action'] : false; //是否显示功能操作
  254. $key = !empty($tag['key']) ? true : false;
  255. if (isset($tag['actionlist'])) {
  256. $actionlist = explode(',', trim($tag['actionlist'])); //指定功能列表
  257. }
  258. if (substr($tag['show'], 0, 1) == '$') {
  259. $show = $this->tpl->get(substr($tag['show'], 1));
  260. } else {
  261. $show = $tag['show'];
  262. }
  263. $show = explode(',', $show); //列表显示字段列表
  264. //计算表格的列数
  265. $colNum = count($show);
  266. if (!empty($action)) {
  267. $colNum++;
  268. }
  269. if (!empty($key)) {
  270. $colNum++;
  271. }
  272. //显示开始
  273. $parseStr = "<!-- Think 系统列表组件开始 -->\n";
  274. $parseStr .= '<table id="' . $id . '" class="' . $style . '" cellpadding=0 cellspacing=0 >';
  275. $parseStr .= '<tr><td height="5" colspan="' . $colNum . '" class="topTd" ></td></tr>';
  276. $parseStr .= '<tr class="row" >';
  277. //列表需要显示的字段
  278. $fields = array();
  279. foreach ($show as $val) {
  280. $fields[] = explode(':', $val);
  281. }
  282. if (!empty($key)) {
  283. $parseStr .= '<th width="12">No</th>';
  284. }
  285. foreach ($fields as $field) {
  286. //显示指定的字段
  287. $property = explode('|', $field[0]);
  288. $showname = explode('|', $field[1]);
  289. if (isset($showname[1])) {
  290. $parseStr .= '<th width="' . $showname[1] . '">';
  291. } else {
  292. $parseStr .= '<th>';
  293. }
  294. $parseStr .= $showname[0] . '</th>';
  295. }
  296. if (!empty($action)) {
  297. //如果指定显示操作功能列
  298. $parseStr .= '<th >操作</th>';
  299. }
  300. $parseStr .= '</tr>';
  301. $parseStr .= '<volist name="' . $datasource . '" id="' . $name . '" ><tr class="row" >'; //支持鼠标移动单元行颜色变化 具体方法在js中定义
  302. if (!empty($key)) {
  303. $parseStr .= '<td>{$i}</td>';
  304. }
  305. foreach ($fields as $field) {
  306. //显示定义的列表字段
  307. $parseStr .= '<td>';
  308. if (!empty($field[2])) {
  309. // 支持列表字段链接功能 具体方法由JS函数实现
  310. $href = explode('|', $field[2]);
  311. if (count($href) > 1) {
  312. //指定链接传的字段值
  313. // 支持多个字段传递
  314. $array = explode('^', $href[1]);
  315. if (count($array) > 1) {
  316. foreach ($array as $a) {
  317. $temp[] = '\'{$' . $name . '.' . $a . '|addslashes}\'';
  318. }
  319. $parseStr .= '<a href="javascript:' . $href[0] . '(' . implode(',', $temp) . ')">';
  320. } else {
  321. $parseStr .= '<a href="javascript:' . $href[0] . '(\'{$' . $name . '.' . $href[1] . '|addslashes}\')">';
  322. }
  323. } else {
  324. //如果没有指定默认传编号值
  325. $parseStr .= '<a href="javascript:' . $field[2] . '(\'{$' . $name . '.' . $pk . '|addslashes}\')">';
  326. }
  327. }
  328. if (strpos($field[0], '^')) {
  329. $property = explode('^', $field[0]);
  330. foreach ($property as $p) {
  331. $unit = explode('|', $p);
  332. if (count($unit) > 1) {
  333. $parseStr .= '{$' . $name . '.' . $unit[0] . '|' . $unit[1] . '} ';
  334. } else {
  335. $parseStr .= '{$' . $name . '.' . $p . '} ';
  336. }
  337. }
  338. } else {
  339. $property = explode('|', $field[0]);
  340. if (count($property) > 1) {
  341. $parseStr .= '{$' . $name . '.' . $property[0] . '|' . $property[1] . '}';
  342. } else {
  343. $parseStr .= '{$' . $name . '.' . $field[0] . '}';
  344. }
  345. }
  346. if (!empty($field[2])) {
  347. $parseStr .= '</a>';
  348. }
  349. $parseStr .= '</td>';
  350. }
  351. if (!empty($action)) {
  352. //显示功能操作
  353. if (!empty($actionlist[0])) { //显示指定的功能项
  354. $parseStr .= '<td>';
  355. foreach ($actionlist as $val) {
  356. if (strpos($val, ':')) {
  357. $a = explode(':', $val);
  358. if (count($a) > 2) {
  359. $parseStr .= '<a href="javascript:' . $a[0] . '(\'{$' . $name . '.' . $a[2] . '}\')">' . $a[1] . '</a>&nbsp;';
  360. } else {
  361. $parseStr .= '<a href="javascript:' . $a[0] . '(\'{$' . $name . '.' . $pk . '}\')">' . $a[1] . '</a>&nbsp;';
  362. }
  363. } else {
  364. $array = explode('|', $val);
  365. if (count($array) > 2) {
  366. $parseStr .= ' <a href="javascript:' . $array[1] . '(\'{$' . $name . '.' . $array[0] . '}\')">' . $array[2] . '</a>&nbsp;';
  367. } else {
  368. $parseStr .= ' {$' . $name . '.' . $val . '}&nbsp;';
  369. }
  370. }
  371. }
  372. $parseStr .= '</td>';
  373. }
  374. }
  375. $parseStr .= '</tr></volist><tr><td height="5" colspan="' . $colNum . '" class="bottomTd"></td></tr></table>';
  376. $parseStr .= "\n<!-- Think 系统列表组件结束 -->\n";
  377. return $parseStr;
  378. }
  379. /**
  380. * list标签解析
  381. * 格式: <html:list datasource="" show="" />
  382. * @access public
  383. * @param array $tag 标签属性
  384. * @return string
  385. */
  386. public function tagList($tag)
  387. {
  388. $id = $tag['id']; //表格ID
  389. $datasource = $tag['datasource']; //列表显示的数据源VoList名称
  390. $pk = empty($tag['pk']) ? 'id' : $tag['pk']; //主键名,默认为id
  391. $style = $tag['style']; //样式名
  392. $name = !empty($tag['name']) ? $tag['name'] : 'vo'; //Vo对象名
  393. $action = 'true' == $tag['action'] ? true : false; //是否显示功能操作
  394. $key = !empty($tag['key']) ? true : false;
  395. $sort = '' == $tag['sort'] ? 'desc' : 'asc';
  396. $checkbox = $tag['checkbox']; //是否显示Checkbox
  397. if (isset($tag['actionlist'])) {
  398. if (substr($tag['actionlist'], 0, 1) == '$') {
  399. $actionlist = $this->tpl->get(substr($tag['actionlist'], 1));
  400. } else {
  401. $actionlist = $tag['actionlist'];
  402. }
  403. $actionlist = explode(',', trim($actionlist)); //指定功能列表
  404. }
  405. if (substr($tag['show'], 0, 1) == '$') {
  406. $show = $this->tpl->get(substr($tag['show'], 1));
  407. } else {
  408. $show = $tag['show'];
  409. }
  410. $show = explode(',', $show); //列表显示字段列表
  411. //计算表格的列数
  412. $colNum = count($show);
  413. if (!empty($checkbox)) {
  414. $colNum++;
  415. }
  416. if (!empty($action)) {
  417. $colNum++;
  418. }
  419. if (!empty($key)) {
  420. $colNum++;
  421. }
  422. $colNum += 2; //用于bootstrap布局样式里多了befer,after两个伪元素
  423. //显示开始
  424. $parseStr = "<!-- Think 系统列表组件开始 -->\n";
  425. $parseStr .= '<table id="' . $id . '" class="' . $style . '" cellpadding=0 cellspacing=0 >';
  426. $parseStr .= '<tr><td height="5" colspan="' . $colNum . '" class="topTd" ></td></tr>';
  427. $parseStr .= '<tr class="row" >';
  428. //列表需要显示的字段
  429. $fields = array();
  430. foreach ($show as $val) {
  431. $fields[] = explode(':', $val);
  432. }
  433. if (!empty($checkbox) && 'true' == strtolower($checkbox)) {
  434. //如果指定需要显示checkbox列
  435. $parseStr .= '<th width="8"><input type="checkbox" id="check" onclick="CheckAll(\'' . $id . '\')"></th>';
  436. }
  437. if (!empty($key)) {
  438. $parseStr .= '<th width="12">No</th>';
  439. }
  440. foreach ($fields as $field) {
  441. //显示指定的字段
  442. $property = explode('|', $field[0]);
  443. $showname = explode('|', $field[1]);
  444. if (isset($showname[1])) {
  445. $parseStr .= '<th width="' . $showname[1] . '">';
  446. } else {
  447. $parseStr .= '<th>';
  448. }
  449. $showname[2] = isset($showname[2]) ? $showname[2] : $showname[0];
  450. if('sort' == $field[3]){
  451. //if ($sort) {
  452. $parseStr .= '<a href="javascript:sortBy(\'' . $property[0] . '\',\'{$sort}\',\'' . ACTION_NAME . '\')" title="按照' . $showname[2] . '{$sortType} ">' . $showname[0] . '<eq name="order" value="' . $property[0] . '" > <span class="glyphicon {$sortImg}" ></span> <else/> <span class="glyphicon glyphicon-sort" ></span> </eq></a></th>';
  453. } else {
  454. $parseStr .= $showname[0] . '</th>';
  455. }
  456. }
  457. if (!empty($action)) {
  458. //如果指定显示操作功能列
  459. $parseStr .= '<th >操作</th>';
  460. }
  461. $parseStr .= '</tr>';
  462. $parseStr .= '<volist name="' . $datasource . '" id="' . $name . '" ><tr class="row" id="row_{$' . $name . '.' . $pk . '}" '; //支持鼠标移动单元行颜色变化 具体方法在js中定义
  463. if (!empty($checkbox)) {
  464. // $parseStr .= 'onmouseover="over(event)" onmouseout="out(event)" onclick="change(event)" ';
  465. }
  466. $parseStr .= '>';
  467. if (!empty($checkbox)) {
  468. //如果需要显示checkbox 则在每行开头显示checkbox
  469. $parseStr .= '<td><input type="checkbox" name="key" value="{$' . $name . '.' . $pk . '}"></td>';
  470. }
  471. if (!empty($key)) {
  472. $parseStr .= '<td>{$i}</td>';
  473. }
  474. foreach ($fields as $field) {
  475. //显示定义的列表字段
  476. $parseStr .= '<td>';
  477. if (!empty($field[2])) {
  478. // 支持列表字段链接功能 具体方法由JS函数实现
  479. $href = explode('|', $field[2]);
  480. if (count($href) > 1) {
  481. //指定链接传的字段值
  482. // 支持多个字段传递
  483. $array = explode('^', $href[1]);
  484. if (count($array) > 1) {
  485. foreach ($array as $a) {
  486. $temp[] = '\'{$' . $name . '.' . $a . '|addslashes}\'';
  487. }
  488. $parseStr .= '<a href="javascript:' . $href[0] . '(' . implode(',', $temp) . ')">';
  489. } else {
  490. $parseStr .= '<a href="javascript:' . $href[0] . '(\'{$' . $name . '.' . $href[1] . '|addslashes}\')">';
  491. }
  492. } else {
  493. //如果没有指定默认传编号值
  494. $parseStr .= '<a href="javascript:' . $field[2] . '(\'{$' . $name . '.' . $pk . '|addslashes}\')">';
  495. }
  496. }
  497. if (strpos($field[0], '^')) {
  498. $property = explode('^', $field[0]);
  499. foreach ($property as $p) {
  500. $unit = explode('|', $p);
  501. if (count($unit) > 1) {
  502. $parseStr .= '{$' . $name . '.' . $unit[0] . '|' . $unit[1] . '} ';
  503. } else {
  504. $parseStr .= '{$' . $name . '.' . $p . '} ';
  505. }
  506. }
  507. } else {
  508. $property = explode('|', $field[0]);
  509. if (count($property) > 1) {
  510. $parseStr .= '{$' . $name . '.' . $property[0] . '|' . $property[1] . '}';
  511. } else {
  512. $parseStr .= '{$' . $name . '.' . $field[0] . '}';
  513. }
  514. }
  515. if (!empty($field[2])) {
  516. $parseStr .= '</a>';
  517. }
  518. $parseStr .= '</td>';
  519. }
  520. if (!empty($action)) {
  521. //显示功能操作
  522. if (!empty($actionlist[0])) { //显示指定的功能项
  523. $parseStr .= '<td>';
  524. foreach ($actionlist as $val) {
  525. if (strpos($val, ':')) {
  526. $a = explode(':', $val);
  527. if (count($a) > 2) {
  528. $parseStr .= '<a class="btn btn-sm btn-primary" href="javascript:' . $a[0] . '(\'{$' . $name . '.' . $a[2] . '}\')">' . $a[1] . '</a>&nbsp;';
  529. //var_dump('<a class="btn btn-sm btn-primary" href="javascript:' . $a[0] . '(\'{$' . $name . '.' . $a[2] . '}\')">' . $a[1] . '</a>&nbsp;');
  530. } else {
  531. $parseStr .= '<a class="btn btn-sm btn-primary" href="javascript:' . $a[0] . '(\'{$' . $name . '.' . $pk . '}\')">' . $a[1] . '</a>&nbsp;';
  532. }
  533. } else {
  534. $array = explode('|', $val);
  535. if (count($array) > 2) {
  536. $parseStr .= ' <a class="btn btn-sm" href="javascript:' . $array[1] . '(\'{$' . $name . '.' . $array[0] . '}\')">' . $array[2] . '</a>&nbsp;';
  537. } else {
  538. $parseStr .= ' {$' . $name . '.' . $val . '}&nbsp;';
  539. }
  540. }
  541. }
  542. $parseStr .= '</td>';
  543. }
  544. }
  545. $parseStr .= '</tr></volist><tr><td height="5" colspan="' . $colNum . '" class="bottomTd"></td></tr></table>';
  546. $parseStr .= "\n<!-- Think 系统列表组件结束 -->\n";
  547. return $parseStr;
  548. }
  549. }