对接后台增删笔记接口

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) {
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

@ -5,7 +5,6 @@
<el-popover
v-model="visible"
trigger="click"
@hide="resetNote"
>
<el-form ref="form" :model="note_form" :rules="rules" label-width="80px">
<el-form-item :label="$t('note.table.original_text')">
@ -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

@ -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
}
}

Loading…
Cancel
Save