2022-11-29 18:27:14 +08:00
|
|
|
<template>
|
2025-01-02 15:30:44 +08:00
|
|
|
<section class="AiHighlight" :class="{bold}" v-html="html"/>
|
2022-11-29 18:27:14 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
name: "AiHighlight",
|
|
|
|
|
props: {
|
|
|
|
|
value: {default: ""},
|
|
|
|
|
content: {default: ""},
|
|
|
|
|
keywords: {default: () => []},
|
|
|
|
|
color: {default: ""},
|
|
|
|
|
bold: Boolean
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
words: v => [v.keywords].flat(),
|
|
|
|
|
html() {
|
|
|
|
|
let {content, words, value} = this
|
|
|
|
|
const reg = new RegExp(`(${words.join("|")})`, 'g')
|
|
|
|
|
content = content?.replace(/(@v)/g, this.keywordRender(value))
|
|
|
|
|
return !!words.join("|") ? content?.replace(reg, this.keywordRender('$1')) : content
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
keywordRender(word) {
|
|
|
|
|
const {color} = this
|
|
|
|
|
return `<p class="keyword" style="color:${color}">${word}</p>`
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2025-01-02 15:30:44 +08:00
|
|
|
.AiHighlight {
|
2022-11-29 18:27:14 +08:00
|
|
|
display: flex;
|
|
|
|
|
align-items: baseline;
|
|
|
|
|
|
|
|
|
|
.keyword {
|
|
|
|
|
display: block;
|
|
|
|
|
width: auto;
|
|
|
|
|
color: $primaryColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&.bold {
|
|
|
|
|
.keyword {
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|