diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index 6d5fc15f..f7ea77bf 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -11,6 +11,7 @@ use App\Models\WebSocketDialogMsgRead; use App\Models\WebSocketDialogUser; use App\Module\Base; use Request; +use Response; /** * @apiDefine dialog @@ -327,4 +328,36 @@ class DialogController extends AbstractController $read = WebSocketDialogMsgRead::whereMsgId($msg_id)->get(); return Base::retSuccess('success', $read ?: []); } + + /** + * @api {get} api/dialog/msg/download 08. 文件下载 + * + * @apiDescription 需要token身份 + * @apiVersion 1.0.0 + * @apiGroup dialog + * @apiName msg__download + * + * @apiParam {Number} msg_id 消息ID + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + */ + public function msg__download() + { + User::auth(); + // + $msg_id = intval(Request::input('msg_id')); + // + $msg = WebSocketDialogMsg::whereId($msg_id)->first(); + if (empty($msg)) { + abort(403, "This file not exist."); + } + if ($msg->type != 'file') { + abort(403, "This file not support download."); + } + $array = Base::json2array($msg->getRawOriginal('msg')); + // + 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 9776da6e..4f7933eb 100755 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -19,6 +19,7 @@ use App\Module\Base; use Carbon\Carbon; use Illuminate\Support\Arr; use Request; +use Response; /** * @apiDefine project @@ -1082,6 +1083,40 @@ class ProjectController extends AbstractController return Base::retSuccess('success', $file); } + /** + * @api {get} api/project/task/filedown 22. 下载任务文件 + * + * @apiDescription 需要token身份(限:项目、任务负责人) + * @apiVersion 1.0.0 + * @apiGroup project + * @apiName task__filedown + * + * @apiParam {Number} file_id 文件ID + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + */ + public function task__filedown() + { + User::auth(); + // + $file_id = intval(Request::input('file_id')); + // + $file = ProjectTaskFile::find($file_id); + if (empty($file)) { + abort(403, "This file not exist."); + } + // + try { + ProjectTask::userTask($file->task_id, true, true); + } catch (\Exception $e) { + abort(403, $e->getMessage() ?: "This file not support download."); + } + // + return Response::download(public_path($file->getRawOriginal('path')), $file->name); + } + /** * @api {post} api/project/task/add 23. 添加任务 * diff --git a/resources/assets/js/functions/web.js b/resources/assets/js/functions/web.js index c9ed2a54..d15ff778 100755 --- a/resources/assets/js/functions/web.js +++ b/resources/assets/js/functions/web.js @@ -355,6 +355,23 @@ */ dialogCompleted(dialog) { return this.dialogTags(dialog).find(({color}) => color == 'success'); + }, + + /** + * 下载文件 + * @param url + */ + downFile(url) { + if (!url) { + return + } + if ($A.Electron) { + $A.Electron.shell.openExternal(url).catch(() => { + $A.modalError("下载失败"); + }); + } else { + window.open(url) + } } }); diff --git a/resources/assets/js/pages/manage/components/DialogView.vue b/resources/assets/js/pages/manage/components/DialogView.vue index 5bbda206..bef02f70 100644 --- a/resources/assets/js/pages/manage/components/DialogView.vue +++ b/resources/assets/js/pages/manage/components/DialogView.vue @@ -9,7 +9,7 @@