diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index d2d4bd9cb..ea20062db 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api; use App\Models\File; +use App\Models\FileContent; use App\Models\ProjectTask; use App\Models\ProjectTaskFile; use App\Models\User; @@ -13,6 +14,7 @@ use App\Models\WebSocketDialogUser; use App\Module\Base; use Carbon\Carbon; use DB; +use Redirect; use Request; use Response; @@ -531,7 +533,10 @@ class DialogController extends AbstractController * @apiGroup dialog * @apiName msg__download * - * @apiParam {Number} msg_id 消息ID + * @apiParam {Number} msg_id 消息ID + * @apiParam {String} down 直接下载 + * - yes: 下载(默认) + * - preview: 转预览地址 * * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -542,6 +547,7 @@ class DialogController extends AbstractController User::auth(); // $msg_id = intval(Request::input('msg_id')); + $down = Request::input('down', 'yes'); // $msg = WebSocketDialogMsg::whereId($msg_id)->first(); if (empty($msg)) { @@ -552,6 +558,10 @@ class DialogController extends AbstractController } $array = Base::json2array($msg->getRawOriginal('msg')); // + if ($down === 'preview') { + return Redirect::to(FileContent::toPreviewUrl($array)); + } + // return Response::download(public_path($array['path']), $array['name']); } diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php index 1399edd93..ce0b3f792 100755 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api; use App\Exceptions\ApiException; use App\Models\AbstractModel; use App\Models\File; +use App\Models\FileContent; use App\Models\Project; use App\Models\ProjectColumn; use App\Models\ProjectFlow; @@ -22,6 +23,7 @@ use App\Module\BillExport; use Carbon\Carbon; use Illuminate\Support\Arr; use Madzipper; +use Redirect; use Request; use Response; use Session; @@ -1306,6 +1308,9 @@ class ProjectController extends AbstractController * @apiName task__filedown * * @apiParam {Number} file_id 文件ID + * @apiParam {String} down 直接下载 + * - yes: 下载(默认) + * - preview: 转预览地址 * * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -1316,6 +1321,7 @@ class ProjectController extends AbstractController User::auth(); // $file_id = intval(Request::input('file_id')); + $down = Request::input('down', 'yes'); // $file = ProjectTaskFile::find($file_id); if (empty($file)) { @@ -1328,6 +1334,14 @@ class ProjectController extends AbstractController abort(403, $e->getMessage() ?: "This file not support download."); } // + if ($down === 'preview') { + return Redirect::to(FileContent::toPreviewUrl([ + 'ext' => $file->ext, + 'name' => $file->name, + 'path' => $file->getRawOriginal('path'), + ])); + } + // return Response::download(public_path($file->getRawOriginal('path')), $file->name); } diff --git a/app/Models/FileContent.php b/app/Models/FileContent.php index ef374f452..8a3e20b80 100644 --- a/app/Models/FileContent.php +++ b/app/Models/FileContent.php @@ -42,22 +42,14 @@ class FileContent extends AbstractModel /** * 转预览地址 - * @param File $file - * @param $content + * @param array $array * @return string */ - public static function formatPreview($file, $content) + public static function toPreviewUrl($array) { - $content = Base::json2array($content ?: []); - $filePath = $content['url']; - if (in_array($file->type, ['word', 'excel', 'ppt'])) { - if (empty($content)) { - $filePath = 'assets/office/empty.' . str_replace(['word', 'excel', 'ppt'], ['docx', 'xlsx', 'pptx'], $file->type); - } - } - $fileExt = $file->ext; - $fileName = $file->name; - $fileSize = $file->size; + $fileExt = $array['ext']; + $fileName = $array['name']; + $filePath = $array['path']; if (in_array($fileExt, File::localExt)) { $url = Base::fillUrl($filePath); } else { @@ -73,6 +65,28 @@ class FileContent extends AbstractModel return Base::fillUrl("fileview/onlinePreview?url=" . urlencode(base64_encode($url))); } + /** + * 转预览地址 + * @param File $file + * @param $content + * @return string + */ + public static function formatPreview($file, $content) + { + $content = Base::json2array($content ?: []); + $filePath = $content['url']; + if (in_array($file->type, ['word', 'excel', 'ppt'])) { + if (empty($content)) { + $filePath = 'assets/office/empty.' . str_replace(['word', 'excel', 'ppt'], ['docx', 'xlsx', 'pptx'], $file->type); + } + } + return self::toPreviewUrl([ + 'ext' => $file->ext, + 'name' => $file->name, + 'path' => $filePath, + ]); + } + /** * 获取格式内容(或下载) * @param File $file diff --git a/resources/assets/js/components/OnlyOffice.vue b/resources/assets/js/components/OnlyOffice.vue index 448764f1c..30c9d5b6a 100644 --- a/resources/assets/js/components/OnlyOffice.vue +++ b/resources/assets/js/components/OnlyOffice.vue @@ -124,10 +124,17 @@ export default { }, fileUrl() { - const codeId = this.code || this.value.id; - let fileUrl = `file/content/?id=${codeId}&token=${this.userToken}`; - if (this.historyId > 0) { - fileUrl += `&history_id=${this.historyId}` + let codeId = this.code || this.value.id; + let fileUrl + if ($A.leftExists(codeId, "msgFile_")) { + fileUrl = `dialog/msg/download/?msg_id=${$A.leftDelete(codeId, "msgFile_")}&token=${this.userToken}`; + } else if ($A.leftExists(codeId, "taskFile_")) { + fileUrl = `project/task/filedown/?file_id=${$A.leftDelete(codeId, "taskFile_")}&token=${this.userToken}`; + } else { + fileUrl = `file/content/?id=${codeId}&token=${this.userToken}`; + if (this.historyId > 0) { + fileUrl += `&history_id=${this.historyId}` + } } return fileUrl; }, @@ -251,11 +258,6 @@ export default { if (/\/hideenOfficeTitle\//.test(window.navigator.userAgent)) { config.document.title = " "; } - if ($A.leftExists(codeId, "msgFile_")) { - config.document.url = `http://nginx/api/dialog/msg/download/?msg_id=${$A.leftDelete(codeId, "msgFile_")}&token=${this.userToken}`; - } else if ($A.leftExists(codeId, "taskFile_")) { - config.document.url = `http://nginx/api/project/task/filedown/?file_id=${$A.leftDelete(codeId, "taskFile_")}&token=${this.userToken}`; - } if (this.readOnly || this.historyId > 0) { config.editorConfig.mode = "view"; config.editorConfig.callbackUrl = null; diff --git a/resources/assets/js/pages/single/fileMsg.vue b/resources/assets/js/pages/single/fileMsg.vue index 6774aa162..26440a5a7 100644 --- a/resources/assets/js/pages/single/fileMsg.vue +++ b/resources/assets/js/pages/single/fileMsg.vue @@ -12,13 +12,13 @@ -