/**
* 查找字符串
* @param content 需要查询关键字的内容
* @param key 查找的关键字
* @param result 不用管
* @returns {*[]} 返回一个数组 type=1 是匹配到关键字的字符串
*/
getHighlightStrArray (content, key, result) {
if (result === undefined) {
result = []
}
key = key.toUpperCase()
const keyLen = key.length
const tmp = content.toUpperCase()
if (tmp.length >= keyLen && keyLen > 0) {
let index = -1
index = tmp.indexOf(key)
if (index !== -1) {
const text = content.substring(0, index)
result.push({
type: 2,
text: text
})
const keyText = content.substring(index, index + keyLen)
result.push({
type: 1,
text: keyText
})
content = content.substring(index + keyLen, content.length)
this.getHighlightStrArray(content, key, result)
} else {
result.push({
type: 2,
text: content
})
}
} else {
result.push({
type: 2,
text: content
})
}
return result
}
console