|
@@ -61,7 +61,7 @@ export const highlightKeyword = () => {
|
|
|
let keyword = keywordData[i]['keyword'];
|
|
|
for(let j = 0; j < textEleArr.length; j++) {
|
|
|
//todo 遍历 tagData 删除无keyword 的 tag;
|
|
|
-
|
|
|
+ removeTags({ele: textEleArr[j], rowIndex: j});
|
|
|
|
|
|
let txt = textEleArr[j]['innerHTML'];
|
|
|
let startPos = txt.indexOf(keyword), endPos;
|
|
@@ -83,7 +83,7 @@ export const highlightKeyword = () => {
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- removeTag({rowIndex: j, keyword})
|
|
|
+ // removeTag({rowIndex: j, keyword})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -133,6 +133,7 @@ const addRangeDom = (params) => {
|
|
|
|
|
|
const checkHasTag = (params) => {
|
|
|
let hasTag = false;
|
|
|
+ console.log('tagData:checkHasTag start', tagData);
|
|
|
for(let i = 0; i < tagData.length; i++) {
|
|
|
let item = tagData[i];
|
|
|
if(params.rowIndex == item.rowIndex && params.keyword == item.keyword && item.startPos == params.startPos && item.endPos == params.endPos) {
|
|
@@ -144,6 +145,47 @@ const checkHasTag = (params) => {
|
|
|
return hasTag;
|
|
|
}
|
|
|
|
|
|
+const removeTags = (params) => {
|
|
|
+ let {ele} = params;
|
|
|
+ console.log('tagData:removeTags start', tagData);
|
|
|
+ for(let i = 0; i < tagData.length; i++) {
|
|
|
+ let item = tagData[i];
|
|
|
+ let startPos = '', endPos = '';
|
|
|
+ if(params.rowIndex == item.rowIndex) {
|
|
|
+ if(ele) {
|
|
|
+ startPos = ele.innerHTML.indexOf(item.keyword);
|
|
|
+ endPos = startPos + item.keyword.length;
|
|
|
+ if(startPos > -1) {
|
|
|
+ let currentKeyword = ele.innerHTML.substr(item.startPos, item.keyword.length)
|
|
|
+ if(currentKeyword == item.keyword) {
|
|
|
+ } else {
|
|
|
+ removeTagDom(item);
|
|
|
+ tagData.splice(tagData[i], 1);
|
|
|
+ i--;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ removeTagDom(item);
|
|
|
+ tagData.splice(tagData[i], 1);
|
|
|
+ i--;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ removeTagDom(item);
|
|
|
+ tagData.splice(tagData[i], 1);
|
|
|
+ i--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log('tagData:removeTags end', tagData);
|
|
|
+}
|
|
|
+
|
|
|
+const removeTagDom = (params) => {
|
|
|
+ let tagDom = document.getElementById(`denet-keyword-tag-${params.rowIndex}-${params.startPos}`);
|
|
|
+ if(tagDom) {
|
|
|
+ tagDom.remove();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
const removeTag = (params) => {
|
|
|
let tagDom = document.getElementsByClassName(`denet-keyword-tag-${params.rowIndex}`);
|
|
|
tagData = tagData.filter(item => item.rowIndex == params.rowIndex && params.keyword == item.keyword)
|
|
@@ -153,6 +195,7 @@ const removeTag = (params) => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+*/
|
|
|
|
|
|
export const addHighlightEleWrapper = () => {
|
|
|
let ele = document.createElement('div');
|
|
@@ -166,9 +209,13 @@ export const addHighlightEleWrapper = () => {
|
|
|
|
|
|
export const addHighlightDom = (params) => {
|
|
|
let ele = document.createElement('div');
|
|
|
+ let domId = `denet-keyword-tag-${params.rowIndex}-${params.startPos}`;
|
|
|
+ if(document.getElementById(domId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
let defaultCssText = 'position: absolute;border: 1.5px dashed #FCAB40;box-sizing: border-box';
|
|
|
ele.style.cssText = params.cssText + defaultCssText;
|
|
|
- ele.id = `denet-keyword-tag-${params.rowIndex}-${params.keywordIndex}-${params.startPos}`;
|
|
|
+ ele.id = domId;
|
|
|
ele.setAttribute("class", `denet-keyword-tag-${params.rowIndex}`);
|
|
|
let highlightEleWrapper = document.getElementById('denet-keword-highlight-wrapper');
|
|
|
if(highlightEleWrapper) {
|