Index.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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\cache;
  10. use fecadmin\FecadminbaseBlock;
  11. use fecadmin\models\AdminUser;
  12. use fecadmin\models\AdminLog;
  13. use fec\helpers\CUrl;
  14. use fec\helpers\CRequest;
  15. use fec\helpers\CCache;
  16. /**
  17. * @author Terry Zhao <2358269014@qq.com>
  18. * @since 1.0
  19. */
  20. class Index extends FecadminbaseBlock{
  21. public $_obj ;
  22. public $_paramKey = 'id';
  23. public $_defaultDirection = 'asc';
  24. public $_currentUrl;
  25. public function __construct(){
  26. $this->_currentUrl = CUrl::getUrl("fecadmin/cache/index");
  27. $this->_modelName = 'admin_user';
  28. parent::__construct();
  29. }
  30. # 初始化参数
  31. public function initParam(){
  32. # 定义编辑和删除的URL
  33. $this->_editUrl = ''; #CUrl::getUrl("fecadmin/log/indexedit");
  34. $this->_deleteUrl = ''; #CUrl::getUrl("fecadmin/account/indexdelete");
  35. $this->_obj = new AdminLog;
  36. $this->_paramKey = 'id';
  37. /*
  38. # 自定义参数如下:
  39. #排序默认为主键倒序
  40. $this->_orderField = 'created_at';
  41. $this->_sortDirection = 'asc';
  42. # 主键默认为id
  43. $this->_paramKey = 'id';
  44. #第一次打开默认为第一页,一页显示50个
  45. $this->_pageNum = 1;
  46. $this->_numPerPage;
  47. */
  48. parent::initParam();
  49. }
  50. public function getLastData(){
  51. # 返回数据的函数
  52. # 隐藏部分
  53. $pagerForm = $this->getPagerForm();
  54. # 搜索部分
  55. $searchBar = $this->getSearchBar();
  56. # 编辑 删除 按钮部分
  57. $editBar = $this->getEditBar();
  58. # 表头部分
  59. $thead = $this->getTableThead();
  60. # 表内容部分
  61. $tbody = $this->getTableTbody();
  62. # 分页部分
  63. $toolBar = $this->getToolBar($this->_param['numCount'],$this->_param['pageNum'],$this->_param['numPerPage']);
  64. return [
  65. 'pagerForm' => $pagerForm,
  66. 'searchBar' => $searchBar,
  67. 'editBar' => $editBar,
  68. 'thead' => $thead,
  69. 'tbody' => $tbody,
  70. 'toolBar' => $toolBar,
  71. ];
  72. }
  73. # 定义搜索部分字段格式
  74. public function getSearchArr(){
  75. $data = [
  76. [ # 字符串类型
  77. 'type'=>'inputtext',
  78. 'title'=>'账号',
  79. 'name'=>'account' ,
  80. 'columns_type' =>'string'
  81. ],
  82. [ # 时间区间类型搜索
  83. 'type'=>'inputdatefilter',
  84. 'name'=> 'created_at',
  85. 'columns_type' =>'datetime',
  86. 'value'=>[
  87. 'gte'=>'LOG时间开始',
  88. 'lt' =>'LOG时间结束',
  89. ]
  90. ],
  91. ];
  92. return $data;
  93. }
  94. # 定义表格显示部分的配置
  95. public function getTableFieldArr(){
  96. $table_th_bar = [
  97. [
  98. 'orderField' => 'id',
  99. 'label' => 'ID',
  100. 'width' => '110',
  101. 'align' => 'center',
  102. ],
  103. [
  104. 'orderField' => 'account',
  105. 'label' => '账号',
  106. 'width' => '110',
  107. 'align' => 'center',
  108. ],
  109. [
  110. 'orderField' => 'person',
  111. 'label' => '操作人',
  112. 'width' => '110',
  113. 'align' => 'left',
  114. ],
  115. [
  116. 'orderField' => 'url',
  117. 'label' => '操作菜单',
  118. 'width' => '110',
  119. 'align' => 'left',
  120. ],
  121. [
  122. 'orderField' => 'created_at',
  123. 'label' => '创建时间',
  124. 'width' => '190',
  125. 'align' => 'center',
  126. //'convert' => ['datetime' =>'date'], # int date datetime 显示的转换
  127. ],
  128. ];
  129. return $table_th_bar ;
  130. }
  131. public function getEditBar(){
  132. if(!strstr($this->_currentParamUrl,"?")){
  133. $csvUrl = $this->_currentParamUrl."?type=export";
  134. }else{
  135. $csvUrl = $this->_currentParamUrl."&type=export";
  136. }
  137. return '<ul class="toolBar">
  138. <li><a title="确实要刷新?" target="selectedTodo" rel="ids" postType="string" href="'.$this->_currentUrl.'?method=reflush" class="edit"><span>刷新缓存</span></a></li>
  139. <li class="line">line</li>
  140. </ul>';
  141. }
  142. public function getTableThead(){
  143. return '
  144. <thead>
  145. <tr>
  146. <th width="22"><input type="checkbox" group="ids" class="checkboxCtrl"></th>
  147. <th width="40">Cache名称</th>
  148. <th width="110">Cache描述</th>
  149. </tr>
  150. </thead>';
  151. }
  152. public function getTableTbody(){
  153. $str = '';
  154. $str .= '<tr target="sid_user" rel="'.$id.'">
  155. <td><input name="ids" value="all_cache" type="checkbox"></td>
  156. <td>所有缓存</td>
  157. <td>刷新所有的缓存</td>
  158. </tr>
  159. ';
  160. return $str;
  161. }
  162. public function reflush(){
  163. $cacheStr = CRequest::param("ids");
  164. $cacheArr = explode(",",$cacheStr);
  165. foreach($cacheArr as $cacheType){
  166. $cacheType = trim($cacheType);
  167. if($cacheType == all_cache){
  168. CCache::flushAll();
  169. }
  170. }
  171. # 刷新 配置 缓存
  172. \fecadmin\helpers\CConfig::flushCacheConfig();
  173. echo json_encode(array(
  174. "statusCode"=>"200",
  175. "message"=>"reflush cache success",
  176. ));
  177. exit;
  178. }
  179. }