对接后台增删笔记接口

master
pan 4 years ago
parent f342e408b8
commit 464421c2a3
  1. 5
      pages/index/document.vue
  2. 88
      pages/index/read.vue
  3. 4
      store/read.js

@ -131,7 +131,10 @@
read(item: any) { read(item: any) {
let loadingInstance =Loading.service({}); let loadingInstance =Loading.service({});
let that=this 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'){ if(res.code==='200'){
fetch(`${that.GLOBAL.server_address}${res.msg}`).then(res=>res.text()).then(res=>{ fetch(`${that.GLOBAL.server_address}${res.msg}`).then(res=>res.text()).then(res=>{
item.content=res item.content=res

@ -5,7 +5,6 @@
<el-popover <el-popover
v-model="visible" v-model="visible"
trigger="click" trigger="click"
@hide="resetNote"
> >
<el-form ref="form" :model="note_form" :rules="rules" label-width="80px"> <el-form ref="form" :model="note_form" :rules="rules" label-width="80px">
<el-form-item :label="$t('note.table.original_text')"> <el-form-item :label="$t('note.table.original_text')">
@ -375,9 +374,28 @@
}, },
// //
del(item: any, index: number) { del(item: any, index: number) {
this.$set(item, 'type', 'success') let that=this
this.$set(item, 'message', '删除成功') let span=document.getElementById(item.id)
this.noteList.splice(index, 1) 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() { submitRating() {
@ -458,22 +476,36 @@
for (let index = 1; index < that.replace.replaceVal.length; index++) { for (let index = 1; index < that.replace.replaceVal.length; index++) {
that.replace.replaceVal[index - 1].after(that.replace.replaceVal[index]) that.replace.replaceVal[index - 1].after(that.replace.replaceVal[index])
} }
that.noteList.unshift({
id: this.note_form.note_id, that.GLOBAL.fetchJSON('/v1/api/notes/add','POST',{
title: this.note_form.note_title, noteId: this.note_form.note_id,
content: this.note_form.note_content noteTitle: this.note_form.note_title,
}) noteContent: this.note_form.note_content,
that.$message.info({ paperId: that.activeContent.id,
message: this.$t('read.tip.add_tip_ok').toString(), fileId: that.activeContent.fileId,
showClose: true, content: that.pre.innerHTML
duration: 1000 },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 { } else {
that.$message.error({ that.$message.error(that.$t('read.tip.add_tip_fail').toString())
message: this.$t('read.tip.add_tip_fail').toString(),
showClose: true,
duration: 1000
})
return false return false
} }
this.visible = false this.visible = false
@ -520,6 +552,24 @@
} else { } else {
console.error('无法获取选中文本') 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() { mounted() {
@ -527,7 +577,9 @@
this.$nextTick(() => { this.$nextTick(() => {
if(this.activeContent) { if(this.activeContent) {
that.queryRating() that.queryRating()
that.findNote()
} }
}) })
this.activeName = this.$store.state.read.activeName this.activeName = this.$store.state.read.activeName

@ -37,5 +37,9 @@ export const mutations = {
//查找状态 //查找状态
find(state,item){ find(state,item){
state.read[state.activeName].find=item state.read[state.activeName].find=item
},
//更新正文
updateContent(state,content){
state.read[state.activeName].content=content
} }
} }

Loading…
Cancel
Save