From bce123243672f290f4417a65a015917f1fcff30e Mon Sep 17 00:00:00 2001 From: zyh Date: Tue, 27 Sep 2022 09:41:24 +0800 Subject: [PATCH] =?UTF-8?q?NEZ-2227=20feat=EF=BC=9Atext=20chart=20?= =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E7=BC=96=E8=BE=91=E5=99=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8F=92=E5=85=A5=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/chart/richTextEditor.vue | 45 ++++++++++++++++++- .../rightBox/chart/otherChartConfig.vue | 13 +++--- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/nezha-fronted/src/components/chart/richTextEditor.vue b/nezha-fronted/src/components/chart/richTextEditor.vue index 041ea332b..5d2aefd87 100644 --- a/nezha-fronted/src/components/chart/richTextEditor.vue +++ b/nezha-fronted/src/components/chart/richTextEditor.vue @@ -2,6 +2,15 @@
{{$t('validate.tooLong')}}
+ +
@@ -26,7 +35,8 @@ export default { ['link', 'code-block'], [{ list: 'ordered' }, { list: 'bullet' }], [{ color: [] }, { background: [] }], - [{ align: [] }] + [{ align: [] }], + ['image'] // 上传图片 ] } }, @@ -41,6 +51,16 @@ export default { const $self = this if (!this.quill) { this.quill = new Quill(this.$refs.editor, this.options) + // 覆盖默认上传图片 + const toolbar = this.quill.getModule('toolbar') + toolbar.addHandler('image', (value) => { + this.uploadType = 'image' + if (value) { + this.$refs.upload.$children[0].$refs.input.click() + } else { + this.quill.format('image', false) + } + }) this.quill.on('selection-change', function (range, oldRange, source) { const tooltip = $self.$el.querySelector('.ql-tooltip') if (tooltip) { @@ -83,6 +103,29 @@ export default { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1) } return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4()) + }, + // 上传图片 + async uploadChange (file) { + const isLt4M = (file.size / 1024 / 1024) < 4 + if (isLt4M) { + console.log(this.$axios.defaults.baseURL + 'file/download/') + const form = new FormData() + form.append('file', file.raw) + const res = await this.$post('/file/upload', form, { 'Content-Type': 'multipart/form-data' }) + if (res.code === 200) { + // 获取光标所在位置 + const currentIndex = this.quill.getSelection().index + // 插入图片 + const uploadUrl = this.$axios.defaults.baseURL + 'file/download/' + this.quill.insertEmbed(currentIndex, 'image', `${uploadUrl}${res.data.uuid}`) + // 调整光标到最后 + this.quill.setSelection(currentIndex + 1) + } else { + this.$message.error(res.msg) + } + } else { + this.$message.error(this.$t('tip.imgSize')) + } } }, mounted () { diff --git a/nezha-fronted/src/components/common/rightBox/chart/otherChartConfig.vue b/nezha-fronted/src/components/common/rightBox/chart/otherChartConfig.vue index 70c00e82a..9d585f7fa 100644 --- a/nezha-fronted/src/components/common/rightBox/chart/otherChartConfig.vue +++ b/nezha-fronted/src/components/common/rightBox/chart/otherChartConfig.vue @@ -39,12 +39,13 @@ - +