From c618c83f9b1bd30b389ac408009d6b7b49729115 Mon Sep 17 00:00:00 2001 From: yi-ge Date: Fri, 17 Jul 2020 10:32:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=84=E8=AE=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/post/_id.vue | 245 +++++++++++++++++++++++---------------------- 1 file changed, 127 insertions(+), 118 deletions(-) diff --git a/pages/post/_id.vue b/pages/post/_id.vue index 3e03fc9..d105df5 100644 --- a/pages/post/_id.vue +++ b/pages/post/_id.vue @@ -135,126 +135,15 @@ export default { window.localStorage.visitorInfo = JSON.stringify(visitorInfo) this.visitorToken = visitorToken this.visitorInfo = visitorInfo + window.editorObj.vditor.options.upload.headers = { + Authorization: 'Bearer ' + this.visitorToken + } + window.editorReplyObj.vditor.options.upload.headers = { + Authorization: 'Bearer ' + this.visitorToken + } } if (!window.editorObj && window.Vditor) { - const upload = { - accept: 'image/*, video/*, audio/*, text/*, application/*, .rar, .zip, .php, .pptx, .ppt, .doc, .docx, .txt, .xls, .xlsx', - url: process.env.baseURL + '/visitor/file/upload', - max: 10485760, // 10 MB - linkToImgUrl: process.env.baseURL + '/visitor/file/fetch', - headers: { - Authorization: 'Bearer ' + window.localStorage.visitorToken - }, - filename: name => encodeURIComponent(name.replace(/[^(a-zA-Z0-9\u4E00-\u9FA5\.)]/g, '') // eslint-disable-line - .replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '') // eslint-disable-line - .replace('/\\s/g', '')), - format (files, responseText) { - return responseText - }, - error: (_) => { - this.$modal.show('dialog', { - title: '提示', - text: '上传失败,请检查网络稍后重试。
允许上传的文件类型:图片、视频、压缩文件、文本文件、Office文件、各类代码文件。' - }) - } - } - window.editorObj = new window.Vditor('editor', { - toolbar: [ - 'emoji', - 'headings', - 'bold', - 'italic', - 'strike', - 'link', - 'list', - 'ordered-list', - 'outdent', - 'indent', - 'quote', - 'line', - 'code', - 'inline-code', - 'upload', - 'table', - 'insert-before', - 'insert-after', - 'undo', - 'redo', - 'fullscreen', - { - name: 'more', - toolbar: [ - 'edit-mode', - 'check', - 'both', - 'code-theme', - 'content-theme', - 'export', - 'outline', - 'preview', - 'format', - 'devtools' - ] - }], - minHeight: 250, - toolbarConfig: { - pin: true - }, - cache: { - enable: true - }, - upload, - placeholder: '我们书写的不是代码,而是人生' - }) - - window.editorReplyObj = new window.Vditor('editor-reply', { - toolbar: [ - 'emoji', - 'headings', - 'bold', - 'italic', - 'strike', - 'link', - 'list', - 'ordered-list', - 'outdent', - 'indent', - 'quote', - 'line', - 'code', - 'inline-code', - 'upload', - 'insert-before', - 'insert-after', - 'undo', - 'redo', - { - name: 'more', - toolbar: [ - 'table', - 'fullscreen', - 'edit-mode', - 'check', - 'both', - 'code-theme', - 'content-theme', - 'export', - 'outline', - 'preview', - 'format', - 'devtools' - ] - }], - minHeight: 220, - toolbarConfig: { - pin: true - }, - cache: { - enable: false - }, - upload, - placeholder: '我们书写的不是代码,而是人生' - }) + this.initEditor() } this.setCommentMap() @@ -337,6 +226,126 @@ export default { } catch (_) { } }, methods: { + initEditor () { + const upload = { + accept: 'image/*, video/*, audio/*, text/*, application/*, .rar, .zip, .php, .pptx, .ppt, .doc, .docx, .txt, .xls, .xlsx', + url: process.env.baseURL + '/visitor/file/upload', + max: 10485760, // 10 MB + linkToImgUrl: process.env.baseURL + '/visitor/file/fetch', + headers: { + Authorization: 'Bearer ' + this.visitorToken + }, + filename: name => encodeURIComponent(name.replace(/[^(a-zA-Z0-9\u4E00-\u9FA5\.)]/g, '') // eslint-disable-line + .replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '') // eslint-disable-line + .replace('/\\s/g', '')), + format (files, responseText) { + return responseText + }, + error: (_) => { + this.$modal.show('dialog', { + title: '提示', + text: '上传失败,请检查网络稍后重试。
允许上传的文件类型:图片、视频、压缩文件、文本文件、Office文件、各类代码文件。' + }) + } + } + window.editorObj = new window.Vditor('editor', { + toolbar: [ + 'emoji', + 'headings', + 'bold', + 'italic', + 'strike', + 'link', + 'list', + 'ordered-list', + 'outdent', + 'indent', + 'quote', + 'line', + 'code', + 'inline-code', + 'upload', + 'table', + 'insert-before', + 'insert-after', + 'undo', + 'redo', + 'fullscreen', + { + name: 'more', + toolbar: [ + 'edit-mode', + 'check', + 'both', + 'code-theme', + 'content-theme', + 'export', + 'outline', + 'preview', + 'format', + 'devtools' + ] + }], + minHeight: 250, + toolbarConfig: { + pin: true + }, + cache: { + enable: true + }, + upload, + placeholder: '我们书写的不是代码,而是人生' + }) + + window.editorReplyObj = new window.Vditor('editor-reply', { + toolbar: [ + 'emoji', + 'headings', + 'bold', + 'italic', + 'strike', + 'link', + 'list', + 'ordered-list', + 'outdent', + 'indent', + 'quote', + 'line', + 'code', + 'inline-code', + 'upload', + 'insert-before', + 'insert-after', + 'undo', + 'redo', + { + name: 'more', + toolbar: [ + 'table', + 'fullscreen', + 'edit-mode', + 'check', + 'both', + 'code-theme', + 'content-theme', + 'export', + 'outline', + 'preview', + 'format', + 'devtools' + ] + }], + minHeight: 220, + toolbarConfig: { + pin: true + }, + cache: { + enable: false + }, + upload, + placeholder: '我们书写的不是代码,而是人生' + }) + }, decodeTitle (name) { try { return this.urldecode(name)