diff --git a/application/admin/controller/api/Plugs.php b/application/admin/controller/api/Plugs.php index 07c89721d..8e32886cf 100644 --- a/application/admin/controller/api/Plugs.php +++ b/application/admin/controller/api/Plugs.php @@ -28,7 +28,7 @@ class Plugs extends Controller { /** - * 系统选择器图标 + * 系统图标选择器 */ public function icon() { @@ -38,12 +38,12 @@ class Plugs extends Controller } /** - * Plupload 插件上传文件 + * 后台通用文件上传 * @return \think\response\Json * @throws \think\Exception * @throws \think\exception\PDOException */ - public function plupload() + public function upload() { if (!NodeService::islogin()) { $this->error('访问授权失败,请重新登录授权再试!'); @@ -83,7 +83,7 @@ class Plugs extends Controller 'exts' => join('|', $exts), 'mime' => File::mine($exts), 'type' => $this->getUploadType(), - 'push' => $this->getUploadPush(), + 'data' => $this->getUploadData(), ]); } @@ -92,14 +92,13 @@ class Plugs extends Controller * @return array * @throws \think\Exception */ - protected function getUploadPush() + private function getUploadData() { - switch ($this->getUploadType()) { - case 'oss': - case 'local': - return ['url' => '?s=admin/api.plugs/plupload', 'token' => uniqid('local_upload_')]; - case 'qiniu': - return ['url' => File::instance('qiniu')->upload(true), 'token' => File::instance('qiniu')->buildUploadToken()]; + if ($this->getUploadType() === 'qiniu') { + $file = File::instance('qiniu'); + return ['url' => $file->upload(true), 'token' => $file->buildUploadToken()]; + } else { + return ['url' => '?s=admin/api.plugs/upload', 'token' => uniqid('local_upload_')]; } } diff --git a/public/static/plugs/jquery/uploader.js b/public/static/plugs/jquery/uploader.js index f4bc0b9f3..f6b7acb1a 100644 --- a/public/static/plugs/jquery/uploader.js +++ b/public/static/plugs/jquery/uploader.js @@ -5,18 +5,18 @@ define(function () { // 检查可以上传的文件后缀 $.form.load('?s=admin/api.plugs/check', {exts: exts, uptype: uptype}, 'post', function (ret, options) { - options = {url: ret.data.push.url, exts: ret.data.exts, acceptMime: ret.data.mime, data: {token: ret.data.push.token}}; + options = {url: ret.data.data.url, exts: ret.data.exts, acceptMime: ret.data.mime, data: ret.data.data}; if (exts.indexOf('*') > -1) delete options.exts, delete options.acceptMime; return renderUploader(options), false; }, false, false, 0); // 初始化上传组件 - function renderUploader(options) { + function renderUploader(options, headers) { this.options = { proindex: 0, elem: element, + headers: headers || {}, multiple: $(element).attr('data-multiple') > 0, - url: '?s=admin/api.plugs/plupload', before: function () { this.proindex = $.msg.loading('上传进度 '); },