Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
王士厅
2024-09-11 16:57:52 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6925c8a351434e9703f8dd63cb1db828d2f0f217
6925c8a3
1 parent
892f2131
fix: 搜索页-联想词展示问题
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
1 deletions
sight_harmony/features/wdComponent/src/main/ets/components/search/SearchComponent.ets
sight_harmony/features/wdComponent/src/main/ets/components/search/SearchRelatedComponent.ets
sight_harmony/features/wdComponent/src/main/ets/components/search/SearchComponent.ets
View file @
6925c8a
...
...
@@ -114,6 +114,7 @@ export struct SearchComponent {
console.log(TAG, JSON.stringify(err))
})
}
// console.log(TAG, 'this.relatedSearchContentsData', JSON.stringify(this.relatedSearchContentsData))
}
getSearchHint() {
...
...
sight_harmony/features/wdComponent/src/main/ets/components/search/SearchRelatedComponent.ets
View file @
6925c8a
import { SearchRelatedItem } from '../../viewmodel/SearchRelatedItem'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG = "SearchRelatedComponent"
...
...
@@ -12,6 +13,23 @@ export struct SearchRelatedComponent {
@Prop searchText: string
@Prop percent:number = 1
// 正则过滤检索词
createCaseInsensitiveRegex(str: string, pattern: string) {
let regex = new RegExp(pattern, 'gi');
return str.replace(regex, (match) => `<em>${match}</em>`);
}
checkForPattern(str: string, pattern: string) {
let highlightedStr = this.createCaseInsensitiveRegex(str, pattern);
return highlightedStr;
}
titleInit(str: string, pattern: string) {
const title = this.checkForPattern(str, pattern)
const titleInitRes:titleInitRes = SearchShowRed.titleInit(title)
return titleInitRes
}
build() {
Column() {
List() {
...
...
@@ -28,11 +46,29 @@ export struct SearchRelatedComponent {
Text(){
ForEach(item.data_arr,(item:string)=>{
if (this.titleInit(item, this.searchText).titleMarked) {
ForEach(this.titleInit(item, this.searchText).textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor($r('app.color.color_ED2800'))
.fontSize(`${this.calcHeight(31)}lpx`)
.fontWeight(400)
.lineHeight(`${this.calcHeight(50)}lpx`)
} else {
Span(textItem.content)
.fontColor($r('app.color.color_000000'))
.fontSize(`${this.calcHeight(31)}lpx`)
.fontWeight(400)
.lineHeight(`${this.calcHeight(50)}lpx`)
}
})
} else {
Span(item)
.fontColor(item===this.searchText?$r('app.color.color_ED2800'):
$r('app.color.color_000000'))
.fontColor(
$r('app.color.color_000000'))
.fontSize(`${this.calcHeight(31)}lpx`)
.fontWeight(400)
.lineHeight(`${this.calcHeight(50)}lpx`)
}
})
}
.maxLines(1)
...
...
Please
register
or
login
to post a comment