Manager.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fecadmin\block\systemlog;
  10. use fecadmin\FecadminbaseBlock;
  11. use fecadmin\models\SystemLog;
  12. use fec\helpers\CUrl;
  13. /**
  14. * @author Terry Zhao <2358269014@qq.com>
  15. * @since 1.0
  16. */
  17. class Manager extends FecadminbaseBlock{
  18. public $_obj ;
  19. public $_paramKey = 'id';
  20. public $_defaultDirection = 'asc';
  21. # 初始化参数
  22. public function initParam(){
  23. # 定义编辑和删除的URL
  24. $this->_editUrl = CUrl::getUrl("fecadmin/systemLog/manageredit");
  25. $this->_deleteUrl = CUrl::getUrl("fecadmin/systemLog/managerdelete");
  26. $this->_obj = new SystemLog;
  27. $this->_paramKey = 'id';
  28. /*
  29. # 自定义参数如下:
  30. #排序默认为主键倒序
  31. $this->_orderField = 'created_at';
  32. $this->_sortDirection = 'asc';
  33. # 主键默认为id
  34. $this->_paramKey = 'id';
  35. #第一次打开默认为第一页,一页显示50个
  36. $this->_pageNum = 1;
  37. $this->_numPerPage;
  38. */
  39. parent::initParam();
  40. }
  41. public function getLastData(){
  42. # 返回数据的函数
  43. # 隐藏部分
  44. $pagerForm = $this->getPagerForm();
  45. # 搜索部分
  46. $searchBar = $this->getSearchBar();
  47. # 编辑 删除 按钮部分
  48. $editBar = $this->getEditBar();
  49. # 表头部分
  50. $thead = $this->getTableThead();
  51. # 表内容部分
  52. $tbody = $this->getTableTbody();
  53. # 分页部分
  54. $toolBar = $this->getToolBar($this->_param['numCount'],$this->_param['pageNum'],$this->_param['numPerPage']);
  55. return [
  56. 'pagerForm' => $pagerForm,
  57. 'searchBar' => $searchBar,
  58. 'editBar' => $editBar,
  59. 'thead' => $thead,
  60. 'tbody' => $tbody,
  61. 'toolBar' => $toolBar,
  62. ];
  63. }
  64. # 定义搜索部分字段格式
  65. public function getSearchArr(){
  66. $data = [
  67. [ # 字符串类型
  68. 'type'=>'inputtext',
  69. 'title'=>'类别',
  70. 'name'=>'category' ,
  71. 'columns_type' =>'string'
  72. ],
  73. ];
  74. return $data;
  75. }
  76. # 定义表格显示部分的配置
  77. public function getTableFieldArr(){
  78. $table_th_bar = [
  79. [
  80. 'orderField' => 'id',
  81. 'label' => 'ID',
  82. 'width' => '10',
  83. 'align' => 'left',
  84. ],
  85. [
  86. 'orderField' => 'level',
  87. 'label' => 'level',
  88. 'width' => '10',
  89. 'align' => 'left',
  90. ],
  91. [
  92. 'orderField' => 'category',
  93. 'label' => 'category',
  94. 'width' => '30',
  95. 'align' => 'left',
  96. ],
  97. [
  98. 'orderField' => 'log_time',
  99. 'label' => 'log_time',
  100. 'width' => '40',
  101. 'align' => 'left',
  102. 'convert' => ['int' => 'datetime']
  103. ],
  104. [
  105. 'orderField' => 'prefix',
  106. 'label' => 'prefix',
  107. 'width' => '40',
  108. 'align' => 'left',
  109. ],
  110. [
  111. 'orderField' => 'message',
  112. 'label' => 'message',
  113. 'width' => '200',
  114. 'align' => 'left',
  115. ],
  116. ];
  117. return $table_th_bar ;
  118. }
  119. # table 表 标题 1
  120. public function getTableTheadHtml($table_th_bar){
  121. $table_th_bar = $this->getTableTheadArrInit($table_th_bar);
  122. $this->_param['orderField'] = $this->_param['orderField'] ? $this->_param['orderField'] : $this->_paramKey;
  123. $this->_param['orderDirection'] = $this->_param['orderDirection'] ? $this->_param['orderDirection'] : $this->_defaultDirection;
  124. foreach($table_th_bar as $k => $field){
  125. if($field['orderField'] == $this->_param['orderField']){
  126. $table_th_bar[$k]['class'] = $this->_param['orderDirection'];
  127. }
  128. }
  129. $str = '<thead><tr>';
  130. //$str .= '<th width="22"><input type="checkbox" group="'.$this->_paramKey.'s" class="checkboxCtrl"></th>';
  131. foreach($table_th_bar as $b){
  132. $width = $b['width'];
  133. $label = $b['label'];
  134. $orderField = $b['orderField'];
  135. $class = isset($b['class']) ? $b['class'] : '';
  136. $align = isset($b['align']) ? 'align="'.$b['align'].'"' : '';
  137. $str .= '<th width="'.$width.'" '.$align.' orderField="'.$orderField.'" class="'.$class.'">'.$label.'</th>';
  138. }
  139. $str .= '</tr></thead>';
  140. return $str;
  141. }
  142. # table 内容部分
  143. public function getTableTbodyHtml($data){
  144. $fileds = $this->getTableFieldArr();
  145. $str .= '';
  146. $csrfString = \fec\helpers\CRequest::getCsrfString();
  147. foreach($data as $one){
  148. $str .= '<tr target="sid_user" rel="'.$one[$this->_paramKey].'">';
  149. foreach($fileds as $field){
  150. $orderField = $field['orderField'];
  151. $display = $field['display'];
  152. $val = $one[$orderField];
  153. if($val){
  154. if(isset($field['display']) && !empty($field['display'])){
  155. $display = $field['display'];
  156. $val = $display[$val] ? $display[$val] : $val;
  157. }
  158. if(isset($field['convert']) && !empty($field['convert'])){
  159. $convert = $field['convert'];
  160. foreach($convert as $origin =>$to){
  161. if(strstr($origin,'mongodate')){
  162. if(isset($val->sec)){
  163. $timestramp = $val->sec;
  164. if($to == 'date'){
  165. $val = date('Y-m-d',$timestramp);
  166. }else if($to == 'datetime'){
  167. $val = date('Y-m-d H:i:s',$timestramp);
  168. }else if($to == 'int'){
  169. $val = $timestramp;
  170. }
  171. }
  172. }else if(strstr($origin,'date')){
  173. if($to == 'date'){
  174. $val = date('Y-m-d',strtotime($val));
  175. }else if($to == 'datetime'){
  176. $val = date('Y-m-d H:i:s',strtotime($val));
  177. }else if($to == 'int'){
  178. $val = strtotime($val);
  179. }
  180. }else if($origin == 'int'){
  181. if($to == 'date'){
  182. $val = date('Y-m-d',$val);
  183. }else if($to == 'datetime'){
  184. $val = date('Y-m-d H:i:s',$val);
  185. }else if($to == 'int'){
  186. $val = $val;
  187. }
  188. }else if($origin == 'string'){
  189. if($to == 'img'){
  190. $t_width = isset($field['img_width']) ? $field['img_width'] : '100';
  191. $t_height = isset($field['img_height']) ? $field['img_height'] : '100';
  192. $val = '<img style="width:'.$t_width.'px;height:'.$t_height.'px" src="'.$val.'" />';;
  193. }
  194. }
  195. }
  196. }
  197. }
  198. $str .= '<td>'.$val.'</td>';
  199. }
  200. $str .= '</tr>';
  201. }
  202. return $str ;
  203. }
  204. }