From 0f8d9e64efc2ffbd63c332a14a99ce4ab2e0d3c5 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Tue, 25 Jan 2022 01:30:55 +0800 Subject: [PATCH] no message --- app/Models/FileContent.php | 27 ++++++++----------- resources/assets/js/components/AceEditor.vue | 10 +++++-- .../pages/manage/components/FileContent.vue | 2 +- .../pages/manage/components/FilePreview.vue | 2 +- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/Models/FileContent.php b/app/Models/FileContent.php index 63b6ae35a..21ce768cf 100644 --- a/app/Models/FileContent.php +++ b/app/Models/FileContent.php @@ -72,23 +72,18 @@ class FileContent extends AbstractModel $content['preview'] = false; if ($file->ext) { $filePath = public_path($content['url']); - switch ($file->type) { - // 支持编辑 - case 'txt': - case 'code': - $content['content'] = file_get_contents($filePath); - break; - + if (in_array($file->type, ['txt', 'code']) && $file->size < 2 * 1024 * 1024) { + // 支持编辑,限制2M内的文件 + $content['content'] = file_get_contents($filePath); + } else { // 支持预览 - default: - if (in_array($file->type, ['picture', 'image', 'tif', 'media'])) { - $url = Base::fillUrl($content['url']); - } else { - $url = 'http://' . env('APP_IPPR') . '.3/' . $content['url']; - } - $content['url'] = base64_encode($url); - $content['preview'] = true; - break; + if (in_array($file->type, ['picture', 'image', 'tif', 'media'])) { + $url = Base::fillUrl($content['url']); + } else { + $url = 'http://' . env('APP_IPPR') . '.3/' . $content['url']; + } + $content['url'] = base64_encode($url); + $content['preview'] = true; } } if ($download) { diff --git a/resources/assets/js/components/AceEditor.vue b/resources/assets/js/components/AceEditor.vue index ec34d4c22..2e627f061 100644 --- a/resources/assets/js/components/AceEditor.vue +++ b/resources/assets/js/components/AceEditor.vue @@ -27,13 +27,19 @@ export default { type: Number || null, default: null }, + wrap: { + type: Boolean, + default: false + }, readOnly: { type: Boolean, default: false }, }, render(createElement) { - return createElement('div') + return createElement('div', { + class: "no-dark-mode" + }) }, data: () => ({ code: '', @@ -187,7 +193,7 @@ export default { // init ace editor this.editor = window.ace.edit(this.$el, { - wrap: true, + wrap: this.wrap, showPrintMargin: false, readOnly: this.readOnly, keyboardHandler: 'vscode', diff --git a/resources/assets/js/pages/manage/components/FileContent.vue b/resources/assets/js/pages/manage/components/FileContent.vue index de1dc5c9c..04c944843 100644 --- a/resources/assets/js/pages/manage/components/FileContent.vue +++ b/resources/assets/js/pages/manage/components/FileContent.vue @@ -53,7 +53,7 @@ - +
diff --git a/resources/assets/js/pages/manage/components/FilePreview.vue b/resources/assets/js/pages/manage/components/FilePreview.vue index 979cc9d23..2d7b90fbf 100644 --- a/resources/assets/js/pages/manage/components/FilePreview.vue +++ b/resources/assets/js/pages/manage/components/FilePreview.vue @@ -30,7 +30,7 @@ - +