[更新]修改文件上传

This commit is contained in:
Anyon 2019-09-11 10:50:27 +08:00
parent fdf0464c64
commit b54f5a12e5
2 changed files with 13 additions and 14 deletions

View File

@ -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_')];
}
}

View File

@ -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('上传进度 <span data-upload-progress></span>');
},