From 464421c2a3012befe8306d45fb8cddcd6a4adfbc Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Fri, 31 Jul 2020 18:50:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E5=90=8E=E5=8F=B0=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E7=AC=94=E8=AE=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/document.vue | 5 ++- pages/index/read.vue | 88 ++++++++++++++++++++++++++++++++-------- store/read.js | 4 ++ 3 files changed, 78 insertions(+), 19 deletions(-) diff --git a/pages/index/document.vue b/pages/index/document.vue index 87e0876..a2843de 100644 --- a/pages/index/document.vue +++ b/pages/index/document.vue @@ -131,7 +131,10 @@ read(item: any) { let loadingInstance =Loading.service({}); let that=this - this.GLOBAL.fetchGet(`/v1/api/file/find/${item.fileId}`,{},function(res) { + this.GLOBAL.fetchGet("/v1/api/file/find",{ + paperId:item.id, + fileId:item.fileId + },function(res) { if(res.code==='200'){ fetch(`${that.GLOBAL.server_address}${res.msg}`).then(res=>res.text()).then(res=>{ item.content=res diff --git a/pages/index/read.vue b/pages/index/read.vue index 2f1f088..371b827 100644 --- a/pages/index/read.vue +++ b/pages/index/read.vue @@ -5,7 +5,6 @@ @@ -375,9 +374,28 @@ }, //删除笔记 del(item: any, index: number) { - this.$set(item, 'type', 'success') - this.$set(item, 'message', '删除成功') - this.noteList.splice(index, 1) + let that=this + let span=document.getElementById(item.id) + if(span) { + let text = document.createTextNode(span.innerText) + span.replaceWith(text) + that.pre.normalize() + this.GLOBAL.fetchJSON('/v1/api/notes/remove', 'DELETE', { + noteId: item.id, + paperId: that.activeContent.id, + content: that.pre.innerHTML + }, function(res) { + if (res.code === '200') { + that.noteList.splice(index, 1) + that.$store.commit('read/updateContent',that.pre.innerHTML) + } else { + that.$message.error(that.$t('error_500').toString()) + } + }) + }else{ + that.$message.error(that.$t('error_500').toString()) + } + }, //提交评分 submitRating() { @@ -458,22 +476,36 @@ for (let index = 1; index < that.replace.replaceVal.length; index++) { that.replace.replaceVal[index - 1].after(that.replace.replaceVal[index]) } - that.noteList.unshift({ - id: this.note_form.note_id, - title: this.note_form.note_title, - content: this.note_form.note_content - }) - that.$message.info({ - message: this.$t('read.tip.add_tip_ok').toString(), - showClose: true, - duration: 1000 + + that.GLOBAL.fetchJSON('/v1/api/notes/add','POST',{ + noteId: this.note_form.note_id, + noteTitle: this.note_form.note_title, + noteContent: this.note_form.note_content, + paperId: that.activeContent.id, + fileId: that.activeContent.fileId, + content: that.pre.innerHTML + },function(res) { + if(res.code==='200'){ + that.$message.info({ + message: that.$t('read.tip.add_tip_ok').toString(), + showClose: true, + duration: 1000, + onClose:function() { + that.$store.commit('read/updateContent',that.pre.innerHTML) + that.noteList.unshift({ + id: that.note_form.note_id, + title: that.note_form.note_title, + content: that.note_form.note_content + }) + that.resetNote() + } + }) + }else{ + that.$message.error(that.$t('error_500').toString()) + } }) } else { - that.$message.error({ - message: this.$t('read.tip.add_tip_fail').toString(), - showClose: true, - duration: 1000 - }) + that.$message.error(that.$t('read.tip.add_tip_fail').toString()) return false } this.visible = false @@ -520,6 +552,24 @@ } else { console.error('无法获取选中文本') } + }, + //查找笔记 + findNote(){ + let that=this + this.GLOBAL.fetchGet(`/v1/api/notes/list/${this.activeContent.id}`,{},function(res) { + if(res.code==='200'){ + that.noteList=[] + res.data.data.forEach(item=>{ + that.noteList.push({ + id: item.noteId, + title: item.noteTitle, + content: item.noteContent + }) + }) + }else{ + that.$message.error(that.$t('error_500').toString()) + } + }) } }, mounted() { @@ -527,7 +577,9 @@ this.$nextTick(() => { if(this.activeContent) { that.queryRating() + that.findNote() } + }) this.activeName = this.$store.state.read.activeName diff --git a/store/read.js b/store/read.js index c2456fa..c22c5ad 100644 --- a/store/read.js +++ b/store/read.js @@ -37,5 +37,9 @@ export const mutations = { //查找状态 find(state,item){ state.read[state.activeName].find=item + }, + //更新正文 + updateContent(state,content){ + state.read[state.activeName].content=content } }