From ec0eefd16ae9a980141e92bffbc54d40816f2f0e Mon Sep 17 00:00:00 2001 From: Karson Date: Fri, 5 May 2017 18:37:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=B8=8A=E4=BC=A0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9A=84=E5=9B=9E=E4=BC=A0=E6=A0=BC=E5=BC=8F=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=99=84=E4=BB=B6=E9=80=9A=E8=BF=87summernot?= =?UTF-8?q?e=E4=B8=8A=E4=BC=A0=20=E4=BF=AE=E6=AD=A3wipecache=E4=B8=BA?= =?UTF-8?q?=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Ajax.php | 34 ++++++++++++------- application/admin/lang/zh-cn/index.php | 2 ++ application/admin/view/common/header.html | 2 +- .../admin/view/general/attachment/add.html | 9 ++++- application/extra/upload.php | 4 +-- .../assets/js/backend/general/attachment.js | 2 +- public/assets/js/require-upload.js | 25 ++++++++------ 7 files changed, 51 insertions(+), 27 deletions(-) diff --git a/application/admin/controller/Ajax.php b/application/admin/controller/Ajax.php index b9ebaf54..ecbd4623 100644 --- a/application/admin/controller/Ajax.php +++ b/application/admin/controller/Ajax.php @@ -187,10 +187,13 @@ class Ajax extends Backend //判断是否已经存在附件 $sha1 = $file->hash(); - $uploaded = model("attachment")->where('sha1',$sha1)->find(); - if($uploaded){ - $this->code = 200; - $this->data = $uploaded['url']; + $uploaded = model("attachment")->where('sha1', $sha1)->find(); + if ($uploaded) + { + $this->code = 1; + $this->data = [ + 'url' => $uploaded['url'] + ]; return; } @@ -245,8 +248,10 @@ class Ajax extends Backend 'sha1' => $sha1, ); model("attachment")->create(array_filter($params)); - $this->code = 200; - $this->data = $uploadDir . $splInfo->getSaveName(); + $this->code = 1; + $this->data = [ + 'url' => $uploadDir . $splInfo->getSaveName() + ]; } else { @@ -343,22 +348,27 @@ class Ajax extends Backend /** * 清空系统缓存 */ - public function wipeCache() + public function wipecache() { $wipe_cache_type = ['TEMP_PATH', 'LOG_PATH', 'CACHE_PATH']; - foreach ($wipe_cache_type as $item) { - if ($item == 'LOG_PATH') { + foreach ($wipe_cache_type as $item) + { + if ($item == 'LOG_PATH') + { $dirs = (array) glob(constant($item) . '*'); - foreach ($dirs as $dir) { + foreach ($dirs as $dir) + { array_map('unlink', (array) glob($dir . DIRECTORY_SEPARATOR . '*.*')); } array_map('rmdir', $dirs); - } else { + } + else + { array_map('unlink', (array) glob(constant($item) . DIRECTORY_SEPARATOR . '*.*')); } } Cache::clear(); - $this->success('清空系统缓存成功!'); + $this->code = 1; } } diff --git a/application/admin/lang/zh-cn/index.php b/application/admin/lang/zh-cn/index.php index 527d4132..d5b48fab 100644 --- a/application/admin/lang/zh-cn/index.php +++ b/application/admin/lang/zh-cn/index.php @@ -28,4 +28,6 @@ return [ 'Login successful' => '登录成功!', 'Logout successful' => '退出成功!', 'Verification code is incorrect' => '验证码不正确', + 'Wipe cache completed' => '清除缓存成功', + 'Wipe cache failed' => '清除缓存失败', ]; diff --git a/application/admin/view/common/header.html b/application/admin/view/common/header.html index 8e99d6ae..5f26928a 100644 --- a/application/admin/view/common/header.html +++ b/application/admin/view/common/header.html @@ -43,7 +43,7 @@
  • - +
  • diff --git a/application/admin/view/general/attachment/add.html b/application/admin/view/general/attachment/add.html index e74f08ab..65ab5db6 100644 --- a/application/admin/view/general/attachment/add.html +++ b/application/admin/view/general/attachment/add.html @@ -23,7 +23,14 @@
    - + +
    +
    + +
    + +
    +
    diff --git a/application/extra/upload.php b/application/extra/upload.php index ffcfb424..dc06ec68 100644 --- a/application/extra/upload.php +++ b/application/extra/upload.php @@ -3,9 +3,9 @@ //上传配置 return [ /** - * 上传地址,如果不使用又拍云,则可以使用/ajax/upload + * 上传地址,如果不使用又拍云,则可以使用ajax/upload */ - 'uploadurl' => '/admin/ajax/upload', + 'uploadurl' => 'ajax/upload', /** * 又拍云或本机的CDN地址 */ diff --git a/public/assets/js/backend/general/attachment.js b/public/assets/js/backend/general/attachment.js index 13473a31..a9ec03c8 100644 --- a/public/assets/js/backend/general/attachment.js +++ b/public/assets/js/backend/general/attachment.js @@ -56,7 +56,7 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'config'], function ( thumb: function (value, row, index) { //console.log(row); if (row.mimetype.indexOf("image") > -1) { - if (Config.upload.bucket.replace(/^\s+|\s+$/gm,'').length === 0){ + if (Config.upload.bucket.replace(/^\s+|\s+$/gm, '').length === 0) { return ''; } else { return ''; diff --git a/public/assets/js/require-upload.js b/public/assets/js/require-upload.js index 68521456..61622e8f 100755 --- a/public/assets/js/require-upload.js +++ b/public/assets/js/require-upload.js @@ -10,6 +10,7 @@ define(['jquery', 'bootstrap', 'backend', 'config', 'plupload'], function ($, un plupload: function (element, onAfterUpload) { element = typeof element == 'undefined' ? Upload.config.classname : element; $(element, Upload.config.container).each(function () { + var that = this; var id = $(this).prop("id"); var url = $(this).data("url"); var maxsize = $(this).data("maxsize"); @@ -69,17 +70,21 @@ define(['jquery', 'bootstrap', 'backend', 'config', 'plupload'], function ($, un try { var ret = JSON.parse(info.response); if (ret.hasOwnProperty('code')) { - ret.data = ret.code == 200 ? ret.data : ret.data; + ret.data = ret.code == 200 ? ret : ret.data; ret.code = ret.code == 200 ? 1 : ret.code; var data = ret.hasOwnProperty("data") && ret.data != "" ? ret.data : null; var msg = ret.hasOwnProperty("msg") && ret.msg != "" ? ret.msg : ""; - $("input[data-plupload-id='" + id + "-text']").val(data); - var afterUpload = $("#" + id).data("after-upload"); - if (afterUpload && typeof Upload.api.custom[afterUpload] == 'function') { - Upload.api.custom[afterUpload].call(info, id, data); - } - if (typeof onAfterUpload == 'function') { - onAfterUpload.call(info, id, data); + if (ret.code === 1) { + $("input[data-plupload-id='" + id + "-text']").val(data.url); + var afterUpload = $("#" + id).data("after-upload"); + if (afterUpload && typeof Upload.api.custom[afterUpload] == 'function') { + Upload.api.custom[afterUpload].call(that, data); + } + if (typeof onAfterUpload == 'function') { + onAfterUpload.call(that, data); + } + } else { + Toastr.error(msg ? msg : __('Operation failed')); } } else { Toastr.error(e.message + "(code:-2)"); @@ -137,8 +142,8 @@ define(['jquery', 'bootstrap', 'backend', 'config', 'plupload'], function ($, un }, custom: { //自定义上传完成回调 - afteruploadcallback: function (id, response) { - console.log(this, id, response); + afteruploadcallback: function (response) { + console.log(this, response); alert("Custom Callback,Response URL:" + response.url); }, },