|
|
|
@ -1,33 +1,57 @@ |
|
|
|
|
<template> |
|
|
|
|
<div> |
|
|
|
|
<v-contextmenu ref="contextmenu" :disabled="disabled"> |
|
|
|
|
<v-contextmenu-item> |
|
|
|
|
<div > |
|
|
|
|
<v-contextmenu ref="contextmenu"> |
|
|
|
|
<v-contextmenu-item v-if="!disabled"> |
|
|
|
|
<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('read.tip.form.note_title')" prop="note_title"> |
|
|
|
|
<el-input v-model="note_form.note_title" :placeholder="$t('input_please', { keyword: this.$t('read.tip.form.note_title') })"></el-input> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item :label="$t('read.tip.form.note_content')" prop="note_content"> |
|
|
|
|
<el-input type="textarea" v-model="note_form.note_content" :placeholder="$t('input_please', { keyword: this.$t('read.tip.form.note_content') })"></el-input> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item> |
|
|
|
|
<el-button @click="addNote">{{$t('button.add')}}</el-button> |
|
|
|
|
<el-button @click="visible=false">{{$t('button.cancel')}}</el-button> |
|
|
|
|
</el-form-item> |
|
|
|
|
</el-form> |
|
|
|
|
<el-form ref="form" :model="note_form" :rules="rules" label-width="80px"> |
|
|
|
|
<el-form-item :label="$t('note.table.original_text')" > |
|
|
|
|
<el-input autosize type="textarea" v-model="note_form.original_text" disabled></el-input> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item :label="$t('read.form.note_title')" prop="note_title"> |
|
|
|
|
<el-input v-model="note_form.note_title" :placeholder="$t('input_please', { keyword: this.$t('read.form.note_title') })"></el-input> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item :label="$t('read.form.note_content')" prop="note_content"> |
|
|
|
|
<el-input autosize type="textarea" v-model="note_form.note_content" :placeholder="$t('input_please', { keyword: this.$t('read.form.note_content') })"></el-input> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item> |
|
|
|
|
<el-button @click="addNote">{{$t('button.add')}}</el-button> |
|
|
|
|
<el-button @click="visible=false">{{$t('button.cancel')}}</el-button> |
|
|
|
|
</el-form-item> |
|
|
|
|
</el-form> |
|
|
|
|
<el-button slot="reference">{{$t('read.contextmenu.add')}}</el-button> |
|
|
|
|
</el-popover> |
|
|
|
|
</v-contextmenu-item> |
|
|
|
|
<v-contextmenu-item><el-button @click="showSearch=true;queryContent()" class="w-100">{{$t('read.contextmenu.search')}}</el-button></v-contextmenu-item> |
|
|
|
|
</v-contextmenu> |
|
|
|
|
<el-tabs v-model="activeName" type="card" closable @tab-remove="removeTab"> |
|
|
|
|
<el-tab-pane :label="key" :name="key" v-for="(item,key) in openList" :key="key"> |
|
|
|
|
<el-row> |
|
|
|
|
<el-col :span="18"> |
|
|
|
|
<div class="content" v-contextmenu:contextmenu :ref="'edit'+item.title" @mouseup="show" |
|
|
|
|
@contextmenu="selectText" v-html="item.content"/> |
|
|
|
|
<el-form :inline="true" v-if="showSearch"> |
|
|
|
|
<el-form-item :label="$t('read.form.keyword')"> |
|
|
|
|
<el-input @input="queryContent" :placeholder="$t('input_please',{keyword:$t('read.form.keyword')})" v-model="search_form.keyword" |
|
|
|
|
maxlength="10" |
|
|
|
|
show-word-limit> |
|
|
|
|
<i slot="prefix" class="el-input__icon el-icon-search"></i> |
|
|
|
|
</el-input> |
|
|
|
|
</el-form-item> |
|
|
|
|
<template v-if="num>0"> |
|
|
|
|
<el-form-item>{{search_index+1+'/'+num}}</el-form-item> |
|
|
|
|
<el-tooltip :content="$t('read.tip.search_prev')"> |
|
|
|
|
<el-image src="/prev.svg" class="img" @click="search_index>0?search_index--:search_index=num-1;change_search_index()"></el-image> |
|
|
|
|
</el-tooltip> |
|
|
|
|
<el-tooltip :content="$t('read.tip.search_next')"> |
|
|
|
|
<el-image src="/next.svg" class="img" @click="search_index<num-1?search_index++:search_index=0;change_search_index()"></el-image> |
|
|
|
|
</el-tooltip> |
|
|
|
|
</template> |
|
|
|
|
</el-form> |
|
|
|
|
<pre class="content" v-contextmenu:contextmenu :ref="'edit'+item.title" @mouseup="show" |
|
|
|
|
@contextmenu="selectText" v-html="item.content" |
|
|
|
|
/> |
|
|
|
|
</el-col> |
|
|
|
|
<el-col :span="5" class="ml3 note-list"> |
|
|
|
|
<el-row v-for="(item,index) in noteList" :key="index" class="mb2"> |
|
|
|
@ -50,10 +74,10 @@ |
|
|
|
|
@mouseout="reset(item)"> |
|
|
|
|
<transition v-if="item.isEdit" @after-leave="save(item)"> |
|
|
|
|
<el-tooltip class="item" effect="dark" :content="$t('read.tip.auto_save')" v-model="item.isEdit"> |
|
|
|
|
<el-input type="textarea" v-model="item.content"></el-input> |
|
|
|
|
<el-input autosize type="textarea" v-model="item.content"></el-input> |
|
|
|
|
</el-tooltip> |
|
|
|
|
</transition> |
|
|
|
|
<template v-else>{{item.content}}</template> |
|
|
|
|
<template v-else><pre style="background-color: white">{{item.content}}</pre></template> |
|
|
|
|
</div> |
|
|
|
|
</el-card> |
|
|
|
|
<el-alert v-if="item.message" |
|
|
|
@ -97,22 +121,34 @@ |
|
|
|
|
name: 'read', |
|
|
|
|
data() { |
|
|
|
|
return { |
|
|
|
|
//显示搜索框 |
|
|
|
|
showSearch:false, |
|
|
|
|
//显示笔记表单 |
|
|
|
|
visible: false, |
|
|
|
|
//正文搜索 |
|
|
|
|
search_form:{ |
|
|
|
|
keyword:'' |
|
|
|
|
}, |
|
|
|
|
//搜索结果记录数 |
|
|
|
|
num:0, |
|
|
|
|
//搜索结果索引 |
|
|
|
|
search_index:-1, |
|
|
|
|
//笔记表单 |
|
|
|
|
note_form:{ |
|
|
|
|
note_title:'', |
|
|
|
|
note_content:'' |
|
|
|
|
note_content:'', |
|
|
|
|
original_text:'' |
|
|
|
|
}, |
|
|
|
|
//表单校验规则 |
|
|
|
|
rules:{ |
|
|
|
|
note_title:[{ |
|
|
|
|
required: true, |
|
|
|
|
message: this.$t('input_please', { keyword: this.$t('read.tip.form.note_title') }), |
|
|
|
|
message: this.$t('input_please', { keyword: this.$t('read.form.note_title') }), |
|
|
|
|
trigger: 'blur' |
|
|
|
|
}], |
|
|
|
|
note_content:[{ |
|
|
|
|
required: true, |
|
|
|
|
message: this.$t('input_please', { keyword: this.$t('read.tip.form.note_content') }), |
|
|
|
|
message: this.$t('input_please', { keyword: this.$t('read.form.note_content') }), |
|
|
|
|
trigger: 'blur' |
|
|
|
|
}] |
|
|
|
|
}, |
|
|
|
@ -123,7 +159,7 @@ |
|
|
|
|
//禁用右键菜单标志位 |
|
|
|
|
disabled: true, |
|
|
|
|
//替换目标 |
|
|
|
|
replace: [], |
|
|
|
|
replace: {}, |
|
|
|
|
stars: [{ value: 0 }, { value: 0 }, { value: 0 }], |
|
|
|
|
show_star_button: true |
|
|
|
|
} |
|
|
|
@ -138,10 +174,111 @@ |
|
|
|
|
//激活的论文标签 |
|
|
|
|
activeName(newVal) { |
|
|
|
|
this.$store.commit('read/choose', newVal) |
|
|
|
|
}, |
|
|
|
|
showSearch(newVal){ |
|
|
|
|
if(!newVal){ |
|
|
|
|
let pre:HTMLElement=this.$refs['edit'+this.$store.state.read.activeName][0] |
|
|
|
|
this.search_form.keyword='' |
|
|
|
|
this.resetQuery(pre) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
methods: { |
|
|
|
|
//激活选中的搜索结果 |
|
|
|
|
change_search_index(){ |
|
|
|
|
let ele=document.getElementsByClassName('search-light')[this.search_index] |
|
|
|
|
ele.classList.add('choose-search-text') |
|
|
|
|
ele.scrollIntoView({ |
|
|
|
|
block: 'center' |
|
|
|
|
}) |
|
|
|
|
for(let index=0;index<this.num;index++){ |
|
|
|
|
if(index!==this.search_index){ |
|
|
|
|
document.getElementsByClassName('search-light')[index].classList.remove('choose-search-text') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
//重置搜索 |
|
|
|
|
resetQuery(pre:HTMLElement){ |
|
|
|
|
for(let span of pre.querySelectorAll('span[class^=search-light]')){ |
|
|
|
|
let text=document.createTextNode(span.innerText) |
|
|
|
|
span.replaceWith(text) |
|
|
|
|
} |
|
|
|
|
pre.normalize() |
|
|
|
|
this.num=0 |
|
|
|
|
this.search_index=-1 |
|
|
|
|
}, |
|
|
|
|
//正文搜索 |
|
|
|
|
queryContent(){ |
|
|
|
|
let pre:HTMLElement=this.$refs['edit'+this.$store.state.read.activeName][0] |
|
|
|
|
this.resetQuery(pre) |
|
|
|
|
if(this.search_form.keyword.length===0){ |
|
|
|
|
let selection=getSelection() |
|
|
|
|
if(selection&&selection.toString().length>0){ |
|
|
|
|
this.search_form.keyword=selection.toString() |
|
|
|
|
}else{ |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
let replaceObj=[] |
|
|
|
|
for(let node of pre.childNodes) { |
|
|
|
|
let content=node.nodeType===3?node.data:node.innerText |
|
|
|
|
let matchAll = content.matchAll(new RegExp(this.search_form.keyword, 'g')) |
|
|
|
|
let replaceNodes=[] |
|
|
|
|
if(node.nodeType===1&&node.innerText.length===this.search_form.keyword.length) { |
|
|
|
|
node.classList.add('search-light') |
|
|
|
|
}else{ |
|
|
|
|
let length = 0 |
|
|
|
|
let prev |
|
|
|
|
for (let match of matchAll) { |
|
|
|
|
this.num+=1 |
|
|
|
|
let start = document.createTextNode(content.substr(prev ? prev : 0, match.index - length)) |
|
|
|
|
let span = document.createElement('span') |
|
|
|
|
span.classList.add('search-light') |
|
|
|
|
span.innerText = this.search_form.keyword |
|
|
|
|
prev = match.index + this.search_form.keyword.length |
|
|
|
|
replaceNodes.push(start, span) |
|
|
|
|
length += start.data.length + this.search_form.keyword.length |
|
|
|
|
} |
|
|
|
|
if(length>0){ |
|
|
|
|
replaceNodes.push(document.createTextNode(content.substr(prev))) |
|
|
|
|
replaceObj.push({ |
|
|
|
|
source: node, |
|
|
|
|
target: replaceNodes |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(let item of replaceObj){ |
|
|
|
|
let node=item.source |
|
|
|
|
let replaceNodes=item.target |
|
|
|
|
if(replaceNodes.length>0) { |
|
|
|
|
if(node.nodeType===3) { |
|
|
|
|
node.replaceWith(replaceNodes[0]) |
|
|
|
|
for (let index = 1; index < replaceNodes.length; index++) { |
|
|
|
|
replaceNodes[index - 1].after(replaceNodes[index]) |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
node.innerHTML='' |
|
|
|
|
for(let child of replaceNodes){ |
|
|
|
|
node.appendChild(child) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(this.num>0) { |
|
|
|
|
this.search_index=0 |
|
|
|
|
this.change_search_index() |
|
|
|
|
}else{ |
|
|
|
|
this.$message.warning({ |
|
|
|
|
message: this.$t('read.tip.search_zero',{keyword:this.search_form.keyword}).toString(), |
|
|
|
|
showClose: true, |
|
|
|
|
duration: 2000 |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
//编辑笔记 |
|
|
|
|
edit(item: any) { |
|
|
|
|
if ('isEdit' in item) { |
|
|
|
@ -205,31 +342,47 @@ |
|
|
|
|
} |
|
|
|
|
this.activeName = this.$store.state.read.activeName |
|
|
|
|
}, |
|
|
|
|
resetNote(){ |
|
|
|
|
this.replace = {} |
|
|
|
|
this.note_form.note_title='' |
|
|
|
|
this.note_form.note_content='' |
|
|
|
|
this.note_form.original_text='' |
|
|
|
|
}, |
|
|
|
|
//添加笔记 |
|
|
|
|
addNote() { |
|
|
|
|
let that=this |
|
|
|
|
this.$refs.form.validate((valid: boolean)=>{ |
|
|
|
|
if (valid) { |
|
|
|
|
for (let index in this.replace) { |
|
|
|
|
if (this.replace[index].val && this.replace[index].replaceVal) { |
|
|
|
|
this.replace[index].val.replaceWith(this.replace[index].replaceVal) |
|
|
|
|
} |
|
|
|
|
if (valid&&Object.keys(that.replace.replaceVal).length>0) { |
|
|
|
|
let id=new Date().getTime() |
|
|
|
|
let c=document.createElement('span') |
|
|
|
|
c.setAttribute('id',id.toString()) |
|
|
|
|
that.replace.val.replaceWith(that.replace.replaceVal[0]) |
|
|
|
|
for (let index =1;index<that.replace.replaceVal.length;index++) { |
|
|
|
|
that.replace.replaceVal[index-1].after(that.replace.replaceVal[index]) |
|
|
|
|
} |
|
|
|
|
this.noteList.unshift({ |
|
|
|
|
that.noteList.unshift({ |
|
|
|
|
id: `fuck${(Math.random()*10).toFixed()}`, |
|
|
|
|
title: this.note_form.note_title, |
|
|
|
|
content: this.note_form.note_content |
|
|
|
|
}) |
|
|
|
|
this.replace = [] |
|
|
|
|
this.visible=false |
|
|
|
|
this.note_form.note_title='' |
|
|
|
|
this.note_form.note_content='' |
|
|
|
|
that.$message.info({ |
|
|
|
|
message: this.$t('read.tip.add_tip_ok').toString(), |
|
|
|
|
showClose: true, |
|
|
|
|
duration: 1000 |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
that.$message.error({ |
|
|
|
|
message: this.$t('read.tip.add_tip_fail').toString(), |
|
|
|
|
showClose: true, |
|
|
|
|
duration: 1000 |
|
|
|
|
}) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
this.visible=false |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
//显示选中文本 |
|
|
|
|
//获取选中文本 |
|
|
|
|
selectText() { |
|
|
|
|
let selection = getSelection() |
|
|
|
|
console.info(selection) |
|
|
|
@ -244,35 +397,28 @@ |
|
|
|
|
if (range.endOffset - range.startOffset === anchorNode.length) { |
|
|
|
|
console.info(tip + '全选') |
|
|
|
|
bold.innerText = anchorNode.wholeText |
|
|
|
|
this.replace.push({ |
|
|
|
|
this.replace={ |
|
|
|
|
val: anchorNode, |
|
|
|
|
replaceVal: bold |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
replaceVal: [bold] |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
console.info(tip + '选中一部分') |
|
|
|
|
let start = document.createTextNode(anchorNode.substringData(0, range.startOffset)) |
|
|
|
|
let end = document.createTextNode(anchorNode.substringData(range.endOffset, anchorNode.length)) |
|
|
|
|
let span = document.createElement('span') |
|
|
|
|
bold.innerText = anchorNode.substringData(range.startOffset, range.endOffset - range.startOffset) |
|
|
|
|
span.append(start, bold, end) |
|
|
|
|
this.replace.push({ |
|
|
|
|
this.replace={ |
|
|
|
|
val: anchorNode, |
|
|
|
|
replaceVal: span |
|
|
|
|
}) |
|
|
|
|
replaceVal: [start,bold,end] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
this.note_form.original_text=bold.innerText |
|
|
|
|
} else { |
|
|
|
|
let tip = '跨节点' |
|
|
|
|
let startNode = range.startContainer |
|
|
|
|
let endNode = range.endContainer |
|
|
|
|
console.info() |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.$message.error({ |
|
|
|
|
message: this.$t('read.tip.contextmenu_err').toString(), |
|
|
|
|
showClose: true, |
|
|
|
|
duration: 1000 |
|
|
|
|
}) |
|
|
|
|
console.error('无法获取选中文本') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -285,6 +431,18 @@ |
|
|
|
|
content: `内容${n}` |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let that=this |
|
|
|
|
addEventListener('keyup',function(event) { |
|
|
|
|
//监听查找操作 |
|
|
|
|
if(event.shiftKey&&'F'===event.key.toUpperCase()){ |
|
|
|
|
event.preventDefault(); |
|
|
|
|
that.showSearch=!that.showSearch |
|
|
|
|
}else if('ESCAPE'===event.key.toUpperCase()){ |
|
|
|
|
that.showSearch=false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
},true) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
</script> |
|
|
|
@ -294,6 +452,19 @@ |
|
|
|
|
font-size: larger; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.search-light{ |
|
|
|
|
color:blue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.choose-search-text { |
|
|
|
|
animation: changeshadow 1s ease-in infinite ; |
|
|
|
|
} |
|
|
|
|
@keyframes changeshadow { |
|
|
|
|
0%{ text-shadow: 0 0 4px blue} |
|
|
|
|
50%{ text-shadow: 0 0 40px blue} |
|
|
|
|
100%{ text-shadow: 0 0 4px blue} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.choose-note { |
|
|
|
|
cursor: pointer; |
|
|
|
|
} |
|
|
|
@ -337,4 +508,20 @@ |
|
|
|
|
.star-icon i { |
|
|
|
|
font-size: 30px; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.w-100 { |
|
|
|
|
width: 100%; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.el-input.el-input--prefix>input[type='text'] { |
|
|
|
|
height: 40px; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.img{ |
|
|
|
|
height: 30px; |
|
|
|
|
width: 30px; |
|
|
|
|
vertical-align: text-top; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</style> |
|
|
|
|