瀏覽代碼

增加清除缓存的功能

PPPSCN 8 年之前
父節點
當前提交
0b365562cb
共有 3 個文件被更改,包括 44 次插入0 次删除
  1. 22 0
      application/admin/controller/Ajax.php
  2. 6 0
      application/admin/view/common/header.html
  3. 16 0
      public/assets/js/backend/index.js

+ 22 - 0
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('清空系统缓存成功!');
+    }
+
 }

+ 6 - 0
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':''}">

+ 16 - 0
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;