From be72392b7d3358d27471df340a4036a0d8bf27c7 Mon Sep 17 00:00:00 2001 From: lmj <3407000732@qq.com> Date: Fri, 11 Nov 2022 15:00:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/plus/addQuestion.vue | 110 ++++++++++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 19 deletions(-) diff --git a/pages/plus/addQuestion.vue b/pages/plus/addQuestion.vue index f3180a1..453d767 100644 --- a/pages/plus/addQuestion.vue +++ b/pages/plus/addQuestion.vue @@ -9,18 +9,25 @@ 提交 - + - - + + + + - + @@ -65,6 +72,9 @@ export default { data() { return { + qaimage:false, + editorCtx: '', + formats: {}, fileUrl:this.$config.fileUrl, qa:{ id:'', @@ -76,28 +86,91 @@ } }, methods: { + insertLabel(){ + let $this=this; + this.editorCtx.getContents({ + success(data) { + // 获取编辑器中的文本 + let _html = data.html; + // 去掉文本中默认的标签 + _html = _html.replace('


',''); + // 接去掉文本中最后面的

标签 + _html = _html.substring(0,_html.length-4); + // 重新拼接文本,并在末尾添加

标签 + let html = `${_html} #标签名#

`; + // 给富文本设置内容 + $this.editorCtx.setContents({html}); + } + }) + }, + insertDate() { + const date = new Date() + const formatDate = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}` + this.editorCtx.insertText({ + text: formatDate + }) + }, + insertImage() { + this.qaimage = true + }, + //初始化富文本编辑器 + onEditorReady() { + let $this=this; + /** #ifdef APP-PLUS || H5 ||MP-WEIXIN */ + uni.createSelectorQuery().select('#editor').context((res) => { + //将内容写入编辑器 + $this.editorCtx = res.context; + }).exec(); + /** #endif */ + }, + onStatusChange(e){ + const myFormats = e.detail; + this.formats = myFormats; + }, + undo(){ + this.editorCtx.undo() + }, + redo(){ + this.editorCtx.redo() + }, + clear() { + this.editorCtx.clear({ + success: function(res) { + console.log("clear success") + } + }) + }, toBack(){ uni.navigateBack(); }, goSubmit() { - + let $this=this; let images=[]; this.fileList.forEach(file=>{ images.push(file.path); }) - this.qa.images=images.join(); + $this.qa.images=images.join(); uni.showLoading({title:'提交中...'}) - apiQa.save(this.qa).then(rs=>{ - if(rs.status==200){ - this.$refs.messager.show({message:'提交成功',type:'success'}); - uni.redirectTo({ - url:'/pages/resource/qaDetail?id='+rs.result.id + this.editorCtx.getContents({ + success(res){ + $this.qa.content=res.html; + apiQa.save($this.qa).then((rs)=>{ + setTimeout(function(){uni.hideLoading()},1000); + if(rs.status==200){ + $this.$refs.messager.show({message:'提交成功',type:'success'}); + uni.redirectTo({ + url:'/pages/resource/qaDetail?id='+rs.result.id + }) + }else{ + $this.$refs.messager.show({message:rs.message,type:'error'}); + setTimeout(function(){uni.hideLoading()},1000); + } }) - }else{ - this.$refs.messager.show({message:rs.message,type:'error'}); - setTimeout(function(){uni.hideLoading()},1000); } }) + + + }, change(e) { //console.log('change', e); @@ -140,6 +213,9 @@