From 96580e228458059b2541c0c8e7132f079e94ddb4 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 10 Feb 2022 20:12:17 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=AF=A5=E6=96=87=E4=BB=B6=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=B7=B2=E7=BB=8F=E6=94=B9=E5=8F=98=E4=BA=86=E3=80=82?= =?UTF-8?q?=E8=AF=A5=E9=A1=B5=E9=9D=A2=E5=B0=86=E8=A2=AB=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/DialogController.php | 13 +++++++++ app/Http/Controllers/Api/FileController.php | 16 ++++++++-- .../Controllers/Api/ProjectController.php | 14 ++++++++- resources/assets/js/components/OnlyOffice.vue | 20 ++++++++----- .../pages/manage/components/FileContent.vue | 18 +++++++++++- .../pages/manage/components/FilePreview.vue | 18 +++++++++++- resources/assets/js/pages/single/fileMsg.vue | 27 +++++++++++++---- resources/assets/js/pages/single/fileTask.vue | 29 +++++++++++++++---- 8 files changed, 131 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index a2cadfe63..6824a0c13 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -9,6 +9,7 @@ use App\Models\WebSocketDialog; use App\Models\WebSocketDialogMsg; use App\Models\WebSocketDialogMsgRead; use App\Module\Base; +use Carbon\Carbon; use Request; use Response; @@ -349,6 +350,9 @@ class DialogController extends AbstractController * @apiName msg__detail * * @apiParam {Number} msg_id 消息ID + * @apiParam {String} only_update_at 仅获取update_at字段 + * - no (默认) + * - yes * * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -359,11 +363,20 @@ class DialogController extends AbstractController User::auth(); // $msg_id = intval(Request::input('msg_id')); + $only_update_at = Request::input('only_update_at', 'no'); // $dialogMsg = WebSocketDialogMsg::whereId($msg_id)->first(); if (empty($dialogMsg)) { return Base::retError("文件不存在"); } + // + if ($only_update_at == 'yes') { + return Base::retSuccess('success', [ + 'id' => $dialogMsg->id, + 'update_at' => Carbon::parse($dialogMsg->updated_at)->toDateTimeString() + ]); + } + // $data = $dialogMsg->toArray(); // if ($data['type'] == 'file') { diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index 05ee13379..edc340824 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -9,12 +9,11 @@ use App\Models\FileContent; use App\Models\FileLink; use App\Models\FileUser; use App\Models\User; -use App\Models\WebSocketDialogMsg; use App\Module\Base; use App\Module\Ihttp; +use Carbon\Carbon; use Illuminate\Support\Facades\DB; use Request; -use Response; /** * @apiDefine file @@ -383,7 +382,10 @@ class FileController extends AbstractController * @apiParam {Number|String} id * - Number: 文件ID(需要登录) * - String: 链接码(不需要登录,用于预览) - * @apiParam {String} down 直接下载 + * @apiParam {String} only_update_at 仅获取update_at字段 + * - no (默认) + * - yes + * @apiParam {String} down 直接下载 * - no: 浏览(默认) * - yes: 下载(office文件直接下载) * @@ -395,6 +397,7 @@ class FileController extends AbstractController { $id = Request::input('id'); $down = Request::input('down', 'no'); + $only_update_at = Request::input('only_update_at', 'no'); // if (Base::isNumber($id)) { User::auth(); @@ -409,6 +412,13 @@ class FileController extends AbstractController return Base::retError('参数错误'); } // + if ($only_update_at == 'yes') { + return Base::retSuccess('success', [ + 'id' => $file->id, + 'update_at' => Carbon::parse($file->updated_at)->toDateTimeString() + ]); + } + // $content = FileContent::whereFid($file->id)->orderByDesc('id')->first(); return FileContent::formatContent($file, $content?->content, $down == 'yes'); } diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php index 2515486d7..28892a35d 100755 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -1099,7 +1099,10 @@ class ProjectController extends AbstractController * @apiGroup project * @apiName task__filedetail * - * @apiParam {Number} file_id 文件ID + * @apiParam {Number} file_id 文件ID + * @apiParam {String} only_update_at 仅获取update_at字段 + * - no (默认) + * - yes * * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -1110,11 +1113,20 @@ class ProjectController extends AbstractController User::auth(); // $file_id = intval(Request::input('file_id')); + $only_update_at = Request::input('only_update_at', 'no'); // $file = ProjectTaskFile::find($file_id); if (empty($file)) { return Base::retError("文件不存在"); } + // + if ($only_update_at == 'yes') { + return Base::retSuccess('success', [ + 'id' => $file->id, + 'update_at' => Carbon::parse($file->updated_at)->toDateTimeString() + ]); + } + // $data = $file->toArray(); $data['path'] = $file->getRawOriginal('path'); // diff --git a/resources/assets/js/components/OnlyOffice.vue b/resources/assets/js/components/OnlyOffice.vue index e43ad89a1..9dc2f2e81 100644 --- a/resources/assets/js/components/OnlyOffice.vue +++ b/resources/assets/js/components/OnlyOffice.vue @@ -60,6 +60,7 @@ export default { type: Boolean, default: false }, + documentKey: Function }, data() { @@ -91,10 +92,6 @@ export default { fileName() { return this.value.name; }, - - fileUpdatedAt() { - return this.value.updated_at ? $A.Date(this.value.updated_at, true) : ''; - } }, watch: { @@ -108,8 +105,17 @@ export default { this.loadIng--; if (e !== null) { $A.modalAlert("组件加载失败!"); + return; + } + if (!this.documentKey) { + this.handleClose(); + return + } + const documentKey = this.documentKey(); + if (documentKey && documentKey.then) { + documentKey.then(this.loadFile); } else { - this.loadFile() + this.loadFile(); } }) }, @@ -130,7 +136,7 @@ export default { return type; }, - loadFile() { + loadFile(keyAppend = '') { if (this.docEditor !== null) { this.docEditor.destroyEditor(); this.docEditor = null; @@ -152,7 +158,7 @@ export default { const config = { "document": { "fileType": this.fileType, - "key": `${this.fileType}-${fileKey}-${this.fileUpdatedAt}`, + "key": `${this.fileType}-${fileKey}-${keyAppend}`, "title": fileName, "url": `http://nginx/api/file/content/?id=${fileKey}&token=${this.userToken}`, }, diff --git a/resources/assets/js/pages/manage/components/FileContent.vue b/resources/assets/js/pages/manage/components/FileContent.vue index d3878abc7..618385703 100644 --- a/resources/assets/js/pages/manage/components/FileContent.vue +++ b/resources/assets/js/pages/manage/components/FileContent.vue @@ -52,7 +52,7 @@ - + @@ -330,6 +330,22 @@ export default { this.unsaveTip = false; }, + documentKey() { + return new Promise(resolve => { + this.$store.dispatch("call", { + url: 'file/content', + data: { + id: this.fileId, + only_update_at: 'yes' + }, + }).then(({data}) => { + resolve($A.Date(data.update_at, true)) + }).catch(() => { + resolve(0) + }); + }) + }, + formatName(file) { let {name, ext} = file; if (ext != '') { diff --git a/resources/assets/js/pages/manage/components/FilePreview.vue b/resources/assets/js/pages/manage/components/FilePreview.vue index 2d7b90fbf..061e1900f 100644 --- a/resources/assets/js/pages/manage/components/FilePreview.vue +++ b/resources/assets/js/pages/manage/components/FilePreview.vue @@ -29,7 +29,7 @@ - + @@ -144,6 +144,22 @@ export default { }) }, + documentKey() { + return new Promise(resolve => { + this.$store.dispatch("call", { + url: 'file/content', + data: { + id: this.code || this.file.id, + only_update_at: 'yes' + }, + }).then(({data}) => { + resolve($A.Date(data.update_at, true)) + }).catch(() => { + resolve(0) + }); + }) + }, + exportMenu(act) { switch (this.file.type) { case 'mind': diff --git a/resources/assets/js/pages/single/fileMsg.vue b/resources/assets/js/pages/single/fileMsg.vue index 1dc61a3a2..19ae4f052 100644 --- a/resources/assets/js/pages/single/fileMsg.vue +++ b/resources/assets/js/pages/single/fileMsg.vue @@ -4,7 +4,7 @@