yangchenggong1_wd

fix |> 20369 根据关键字搜索号主,搜索结果号主tab,号主的名称里面没有对关键字高亮显示红色

... ... @@ -4,6 +4,7 @@ import { HttpUtils } from 'wdNetwork/Index'
import { WDRouterRule, WDRouterPage } from 'wdRouter/Index'
import { TrackConstants, TrackingContent } from 'wdTracking/Index'
import MinePageDatasModel from '../../../model/MinePageDatasModel'
import { SearchShowRed, titleInitRes, textItem } from '../../../utils/searchShowRed'
import { FollowListDetailItem } from '../../../viewmodel/FollowListDetailItem'
import { FollowOperationRequestItem } from '../../../viewmodel/FollowOperationRequestItem'
... ... @@ -14,6 +15,7 @@ export struct FollowChildComponent{
@State columnHeight:number = 202
@State isLoadingAttention:boolean = false
@State searchText:string = ""
aboutToAppear(): void {
if(this.type == 0 && StringUtils.isEmpty(this.data.introduction)){
... ... @@ -190,7 +192,20 @@ export struct FollowChildComponent{
.margin({right: 11})
Column(){
Text(this.data.cnUserName)
Text(){
if (StringUtils.isNotEmpty(this.searchText) && this.titleInit(this.data.cnUserName, this.searchText).titleMarked) {
ForEach(this.titleInit(this.data.cnUserName, this.searchText).textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor("#ED2800")
} else {
Span(textItem.content)
}
})
} else {
Span(this.data.cnUserName)
}
}
.fontWeight(400)
.fontSize(18)
.lineHeight(22)
... ... @@ -351,4 +366,21 @@ export struct FollowChildComponent{
WDRouterRule.jumpWithPage(WDRouterPage.peopleShipHomePage, params)
}
}
// 正则过滤检索词
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
}
}
\ No newline at end of file
... ...
import { ToastUtils } from 'wdKit/Index'
import { StringUtils, ToastUtils } from 'wdKit/Index'
import { WDRouterRule, WDRouterPage, ProcessUtils } from 'wdRouter/Index'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed'
import { SearchRmhDescription } from '../../viewmodel/SearchResultContentItem'
@Component
export struct SearchCreatorComponent{
@ObjectLink item: SearchRmhDescription
userName: string = ''
@State searchText:string = ""
aboutToAppear(): void {
const userNetName: string = this.item.creatorName;
... ... @@ -38,7 +40,20 @@ export struct SearchCreatorComponent{
.height('92lpx')
.margin({bottom:'15lpx'})
Text(this.userName)
Text(){
if (StringUtils.isNotEmpty(this.searchText) && this.titleInit(this.userName, this.searchText).titleMarked) {
ForEach(this.titleInit(this.userName, this.searchText).textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor("#ED2800")
} else {
Span(textItem.content)
}
})
} else {
Span(this.userName)
}
}
.fontSize('25lpx')
.fontWeight('400lpx')
.lineHeight('35lpx')
... ... @@ -62,4 +77,21 @@ export struct SearchCreatorComponent{
WDRouterRule.jumpWithPage(WDRouterPage.peopleShipHomePage, params)
}
}
// 正则过滤检索词
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
}
}
\ No newline at end of file
... ...
... ... @@ -282,7 +282,7 @@ export struct SearchResultContentComponent {
if (this.data_rmh != null && this.data_rmh.length > 0) {
if (this.data_rmh.length === 1) {
ListItem() {
FollowChildComponent({ data: this.bean, type: 1 })
FollowChildComponent({ data: this.bean, type: 1 ,searchText: decodeURI(this.keywords)})
}.padding({ left: "31lpx", right: "31lpx" })
} else {
ListItem() {
... ... @@ -356,7 +356,7 @@ export struct SearchResultContentComponent {
ListItemGroup() {
ForEach(this.data_rmh, (item: SearchRmhDescription, index: number) => {
ListItem() {
SearchCreatorComponent({ item: item })
SearchCreatorComponent({ item: item ,searchText: decodeURI(this.keywords)})
}
.width('150lpx')
.height('100%')
... ...