mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]修改文件上传
This commit is contained in:
parent
fdf0464c64
commit
b54f5a12e5
@ -28,7 +28,7 @@ class Plugs extends Controller
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统选择器图标
|
* 系统图标选择器
|
||||||
*/
|
*/
|
||||||
public function icon()
|
public function icon()
|
||||||
{
|
{
|
||||||
@ -38,12 +38,12 @@ class Plugs extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plupload 插件上传文件
|
* 后台通用文件上传
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
* @throws \think\Exception
|
* @throws \think\Exception
|
||||||
* @throws \think\exception\PDOException
|
* @throws \think\exception\PDOException
|
||||||
*/
|
*/
|
||||||
public function plupload()
|
public function upload()
|
||||||
{
|
{
|
||||||
if (!NodeService::islogin()) {
|
if (!NodeService::islogin()) {
|
||||||
$this->error('访问授权失败,请重新登录授权再试!');
|
$this->error('访问授权失败,请重新登录授权再试!');
|
||||||
@ -83,7 +83,7 @@ class Plugs extends Controller
|
|||||||
'exts' => join('|', $exts),
|
'exts' => join('|', $exts),
|
||||||
'mime' => File::mine($exts),
|
'mime' => File::mine($exts),
|
||||||
'type' => $this->getUploadType(),
|
'type' => $this->getUploadType(),
|
||||||
'push' => $this->getUploadPush(),
|
'data' => $this->getUploadData(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,14 +92,13 @@ class Plugs extends Controller
|
|||||||
* @return array
|
* @return array
|
||||||
* @throws \think\Exception
|
* @throws \think\Exception
|
||||||
*/
|
*/
|
||||||
protected function getUploadPush()
|
private function getUploadData()
|
||||||
{
|
{
|
||||||
switch ($this->getUploadType()) {
|
if ($this->getUploadType() === 'qiniu') {
|
||||||
case 'oss':
|
$file = File::instance('qiniu');
|
||||||
case 'local':
|
return ['url' => $file->upload(true), 'token' => $file->buildUploadToken()];
|
||||||
return ['url' => '?s=admin/api.plugs/plupload', 'token' => uniqid('local_upload_')];
|
} else {
|
||||||
case 'qiniu':
|
return ['url' => '?s=admin/api.plugs/upload', 'token' => uniqid('local_upload_')];
|
||||||
return ['url' => File::instance('qiniu')->upload(true), 'token' => File::instance('qiniu')->buildUploadToken()];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
public/static/plugs/jquery/uploader.js
vendored
6
public/static/plugs/jquery/uploader.js
vendored
@ -5,18 +5,18 @@ define(function () {
|
|||||||
|
|
||||||
// 检查可以上传的文件后缀
|
// 检查可以上传的文件后缀
|
||||||
$.form.load('?s=admin/api.plugs/check', {exts: exts, uptype: uptype}, 'post', function (ret, options) {
|
$.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;
|
if (exts.indexOf('*') > -1) delete options.exts, delete options.acceptMime;
|
||||||
return renderUploader(options), false;
|
return renderUploader(options), false;
|
||||||
}, false, false, 0);
|
}, false, false, 0);
|
||||||
|
|
||||||
// 初始化上传组件
|
// 初始化上传组件
|
||||||
function renderUploader(options) {
|
function renderUploader(options, headers) {
|
||||||
this.options = {
|
this.options = {
|
||||||
proindex: 0,
|
proindex: 0,
|
||||||
elem: element,
|
elem: element,
|
||||||
|
headers: headers || {},
|
||||||
multiple: $(element).attr('data-multiple') > 0,
|
multiple: $(element).attr('data-multiple') > 0,
|
||||||
url: '?s=admin/api.plugs/plupload',
|
|
||||||
before: function () {
|
before: function () {
|
||||||
this.proindex = $.msg.loading('上传进度 <span data-upload-progress></span>');
|
this.proindex = $.msg.loading('上传进度 <span data-upload-progress></span>');
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user