|
@@ -27,12 +27,17 @@
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- stringArr: this.string.split(""),
|
|
|
+ // stringArr: this.string.split(""),
|
|
|
obj: {},
|
|
|
arr: [],
|
|
|
keywordIndexArr: []
|
|
|
}
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ stringArr(){
|
|
|
+ return this.string.split("")
|
|
|
+ }
|
|
|
+ },
|
|
|
created() {this.recursiveGetIndex(0)},
|
|
|
mounted() {},
|
|
|
methods: {
|
|
@@ -45,13 +50,25 @@
|
|
|
}
|
|
|
},
|
|
|
recursiveGetIndex(start){ //递归获取满足关键字的索引值
|
|
|
- let index = this.string.indexOf(this.closedStr,start)
|
|
|
+ if (this.closedStr) {
|
|
|
+ let index = this.string.indexOf(this.closedStr,start)
|
|
|
+ if(index != -1){
|
|
|
+ for(let i = 0; i < this.closedStr.length; i++){
|
|
|
+ this.keywordIndexArr.push(index + i)
|
|
|
+ }
|
|
|
+ this.recursiveGetIndex(index + this.closedStr.length)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ aiGetIndex(str){ //递归获取满足ai关键字的索引值
|
|
|
+ let index = this.string.indexOf(str),
|
|
|
+ arr = []
|
|
|
if(index != -1){
|
|
|
- for(let i = 0; i < this.closedStr.length; i++){
|
|
|
- this.keywordIndexArr.push(index + i)
|
|
|
+ for(let i = 0; i < str.length; i++){
|
|
|
+ arr.push(index + i)
|
|
|
}
|
|
|
- this.recursiveGetIndex(index + this.closedStr.length)
|
|
|
}
|
|
|
+ return arr
|
|
|
},
|
|
|
checkItem(item, index) {
|
|
|
if(this.obj.hasOwnProperty(index)){
|
|
@@ -69,25 +86,28 @@
|
|
|
},
|
|
|
clear(str) {
|
|
|
this.obj = {}
|
|
|
- this.stringArr = this.string.split("")
|
|
|
+ // this.stringArr = this.string.split("")
|
|
|
for(let i = 0; i < this.stringArr.length; i++){
|
|
|
- let classList = this.$refs.span[i].getAttribute('class')
|
|
|
- if(classList.indexOf('bg') > -1){
|
|
|
- classList = classList.split('bg')
|
|
|
+ if (this.$refs.span && this.$refs.span[i]) {
|
|
|
+ let classList = this.$refs.span[i].getAttribute('class')
|
|
|
+ if(classList.indexOf('bg') > -1){
|
|
|
+ classList = classList.split('bg')
|
|
|
+ }
|
|
|
+ this.$refs.span[i].setAttribute('class',classList)
|
|
|
}
|
|
|
- this.$refs.span[i].setAttribute('class',classList)
|
|
|
}
|
|
|
if(!!str){
|
|
|
- let strsArr = str.split("")
|
|
|
- strsArr.map((item,index) => {
|
|
|
- for(let j = 0; j < stringArr.length;j++){
|
|
|
- if(item == stringArr[j]){
|
|
|
- this.obj[j] = item
|
|
|
+ let aiIndexArr = this.aiGetIndex(str)
|
|
|
+ // let strsArr = str.split("")
|
|
|
+ // strsArr.map((item,index) => {
|
|
|
+ for(let j = 0; j < this.stringArr.length;j++){
|
|
|
+ if(aiIndexArr.indexOf(j) > -1){
|
|
|
+ this.obj[j] = this.stringArr[j]
|
|
|
let classList = this.$refs.span[j].getAttribute('class') + ' bg'
|
|
|
this.$refs.span[j].setAttribute('class',classList)
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
+ // })
|
|
|
}
|
|
|
},
|
|
|
getData() {
|