From 0b365562cbe9314b862a4f06c9e1301ed023d6c6 Mon Sep 17 00:00:00 2001 From: PPPSCN <35696959@qq.com> Date: Fri, 5 May 2017 15:42:02 +0800 Subject: [PATCH] 增加清除缓存的功能 --- application/admin/controller/Ajax.php | 22 ++++++++++++++++++++++ application/admin/view/common/header.html | 6 ++++++ public/assets/js/backend/index.js | 16 ++++++++++++++++ 3 files changed, 44 insertions(+), 0 deletions(-) diff --git a/application/admin/controller/Ajax.php b/application/admin/controller/Ajax.php index 68f2070..b9ebaf5 100644 --- a/application/admin/controller/Ajax.php +++ b/application/admin/controller/Ajax.php @@ -9,6 +9,7 @@ use fast\Tree; use think\Config; use think\Db; use think\Lang; +use think\Cache; /** * Ajax异步请求接口 @@ -339,4 +340,25 @@ class Ajax extends Backend } } + /** + * 清空系统缓存 + */ + public function wipeCache() + { + $wipe_cache_type = ['TEMP_PATH', 'LOG_PATH', 'CACHE_PATH']; + foreach ($wipe_cache_type as $item) { + if ($item == 'LOG_PATH') { + $dirs = (array) glob(constant($item) . '*'); + foreach ($dirs as $dir) { + array_map('unlink', (array) glob($dir . DIRECTORY_SEPARATOR . '*.*')); + } + array_map('rmdir', $dirs); + } else { + array_map('unlink', (array) glob(constant($item) . DIRECTORY_SEPARATOR . '*.*')); + } + } + Cache::clear(); + $this->success('清空系统缓存成功!'); + } + } diff --git a/application/admin/view/common/header.html b/application/admin/view/common/header.html index 839fdcc..8e99d6a 100644 --- a/application/admin/view/common/header.html +++ b/application/admin/view/common/header.html @@ -43,6 +43,12 @@ </li> <li> + <a href="javascript:;" data-toggle="wipeCache" title="清空缓存"> + <i class="fa fa-trash"></i> + </a> + </li> + + <li> <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-language"></i></a> <ul class="dropdown-menu"> <li class="{$config['language']=='zh-cn'?'active':''}"> diff --git a/public/assets/js/backend/index.js b/public/assets/js/backend/index.js index f138299..5d44a58 100755 --- a/public/assets/js/backend/index.js +++ b/public/assets/js/backend/index.js @@ -47,6 +47,22 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'adminlte', 'validator'], f e.stopPropagation(); }); + //清除缓存 + $(document).on('click', "[data-toggle='wipeCache']", function () { + $.ajax({ + url: 'ajax/wipeCache', + dataType: 'json', + cache: false, + success: function (ret) { + if (ret.code === 1) { + Backend.api.toastr.success(ret.msg); + } else { + Backend.api.toastr.error('清除系统缓存失败!'); + } + } + }); + }); + //全屏事件 $(document).on('click', "[data-toggle='fullscreen']", function () { var doc = document.documentElement; -- libgit2 0.24.0