Showing
3 changed files
with
69 additions
and
5 deletions
| @@ -4,6 +4,7 @@ import { HttpUtils } from 'wdNetwork/Index' | @@ -4,6 +4,7 @@ import { HttpUtils } from 'wdNetwork/Index' | ||
| 4 | import { WDRouterRule, WDRouterPage } from 'wdRouter/Index' | 4 | import { WDRouterRule, WDRouterPage } from 'wdRouter/Index' |
| 5 | import { TrackConstants, TrackingContent } from 'wdTracking/Index' | 5 | import { TrackConstants, TrackingContent } from 'wdTracking/Index' |
| 6 | import MinePageDatasModel from '../../../model/MinePageDatasModel' | 6 | import MinePageDatasModel from '../../../model/MinePageDatasModel' |
| 7 | +import { SearchShowRed, titleInitRes, textItem } from '../../../utils/searchShowRed' | ||
| 7 | import { FollowListDetailItem } from '../../../viewmodel/FollowListDetailItem' | 8 | import { FollowListDetailItem } from '../../../viewmodel/FollowListDetailItem' |
| 8 | import { FollowOperationRequestItem } from '../../../viewmodel/FollowOperationRequestItem' | 9 | import { FollowOperationRequestItem } from '../../../viewmodel/FollowOperationRequestItem' |
| 9 | 10 | ||
| @@ -14,6 +15,7 @@ export struct FollowChildComponent{ | @@ -14,6 +15,7 @@ export struct FollowChildComponent{ | ||
| 14 | @State columnHeight:number = 202 | 15 | @State columnHeight:number = 202 |
| 15 | 16 | ||
| 16 | @State isLoadingAttention:boolean = false | 17 | @State isLoadingAttention:boolean = false |
| 18 | + @State searchText:string = "" | ||
| 17 | 19 | ||
| 18 | aboutToAppear(): void { | 20 | aboutToAppear(): void { |
| 19 | if(this.type == 0 && StringUtils.isEmpty(this.data.introduction)){ | 21 | if(this.type == 0 && StringUtils.isEmpty(this.data.introduction)){ |
| @@ -190,7 +192,20 @@ export struct FollowChildComponent{ | @@ -190,7 +192,20 @@ export struct FollowChildComponent{ | ||
| 190 | .margin({right: 11}) | 192 | .margin({right: 11}) |
| 191 | 193 | ||
| 192 | Column(){ | 194 | Column(){ |
| 193 | - Text(this.data.cnUserName) | 195 | + Text(){ |
| 196 | + if (StringUtils.isNotEmpty(this.searchText) && this.titleInit(this.data.cnUserName, this.searchText).titleMarked) { | ||
| 197 | + ForEach(this.titleInit(this.data.cnUserName, this.searchText).textArr, (textItem: textItem) => { | ||
| 198 | + if (textItem.isRed) { | ||
| 199 | + Span(textItem.content) | ||
| 200 | + .fontColor("#ED2800") | ||
| 201 | + } else { | ||
| 202 | + Span(textItem.content) | ||
| 203 | + } | ||
| 204 | + }) | ||
| 205 | + } else { | ||
| 206 | + Span(this.data.cnUserName) | ||
| 207 | + } | ||
| 208 | + } | ||
| 194 | .fontWeight(400) | 209 | .fontWeight(400) |
| 195 | .fontSize(18) | 210 | .fontSize(18) |
| 196 | .lineHeight(22) | 211 | .lineHeight(22) |
| @@ -351,4 +366,21 @@ export struct FollowChildComponent{ | @@ -351,4 +366,21 @@ export struct FollowChildComponent{ | ||
| 351 | WDRouterRule.jumpWithPage(WDRouterPage.peopleShipHomePage, params) | 366 | WDRouterRule.jumpWithPage(WDRouterPage.peopleShipHomePage, params) |
| 352 | } | 367 | } |
| 353 | } | 368 | } |
| 369 | + | ||
| 370 | + // 正则过滤检索词 | ||
| 371 | + createCaseInsensitiveRegex(str: string, pattern: string) { | ||
| 372 | + let regex = new RegExp(pattern, 'gi'); | ||
| 373 | + return str.replace(regex, (match) => `<em>${match}</em>`); | ||
| 374 | + } | ||
| 375 | + | ||
| 376 | + checkForPattern(str: string, pattern: string) { | ||
| 377 | + let highlightedStr = this.createCaseInsensitiveRegex(str, pattern); | ||
| 378 | + return highlightedStr; | ||
| 379 | + } | ||
| 380 | + | ||
| 381 | + titleInit(str: string, pattern: string) { | ||
| 382 | + const title = this.checkForPattern(str, pattern) | ||
| 383 | + const titleInitRes:titleInitRes = SearchShowRed.titleInit(title) | ||
| 384 | + return titleInitRes | ||
| 385 | + } | ||
| 354 | } | 386 | } |
| 1 | -import { ToastUtils } from 'wdKit/Index' | 1 | +import { StringUtils, ToastUtils } from 'wdKit/Index' |
| 2 | import { WDRouterRule, WDRouterPage, ProcessUtils } from 'wdRouter/Index' | 2 | import { WDRouterRule, WDRouterPage, ProcessUtils } from 'wdRouter/Index' |
| 3 | +import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed' | ||
| 3 | import { SearchRmhDescription } from '../../viewmodel/SearchResultContentItem' | 4 | import { SearchRmhDescription } from '../../viewmodel/SearchResultContentItem' |
| 4 | 5 | ||
| 5 | @Component | 6 | @Component |
| 6 | export struct SearchCreatorComponent{ | 7 | export struct SearchCreatorComponent{ |
| 7 | @ObjectLink item: SearchRmhDescription | 8 | @ObjectLink item: SearchRmhDescription |
| 8 | userName: string = '' | 9 | userName: string = '' |
| 10 | + @State searchText:string = "" | ||
| 9 | 11 | ||
| 10 | aboutToAppear(): void { | 12 | aboutToAppear(): void { |
| 11 | const userNetName: string = this.item.creatorName; | 13 | const userNetName: string = this.item.creatorName; |
| @@ -38,7 +40,20 @@ export struct SearchCreatorComponent{ | @@ -38,7 +40,20 @@ export struct SearchCreatorComponent{ | ||
| 38 | .height('92lpx') | 40 | .height('92lpx') |
| 39 | .margin({bottom:'15lpx'}) | 41 | .margin({bottom:'15lpx'}) |
| 40 | 42 | ||
| 41 | - Text(this.userName) | 43 | + Text(){ |
| 44 | + if (StringUtils.isNotEmpty(this.searchText) && this.titleInit(this.userName, this.searchText).titleMarked) { | ||
| 45 | + ForEach(this.titleInit(this.userName, this.searchText).textArr, (textItem: textItem) => { | ||
| 46 | + if (textItem.isRed) { | ||
| 47 | + Span(textItem.content) | ||
| 48 | + .fontColor("#ED2800") | ||
| 49 | + } else { | ||
| 50 | + Span(textItem.content) | ||
| 51 | + } | ||
| 52 | + }) | ||
| 53 | + } else { | ||
| 54 | + Span(this.userName) | ||
| 55 | + } | ||
| 56 | + } | ||
| 42 | .fontSize('25lpx') | 57 | .fontSize('25lpx') |
| 43 | .fontWeight('400lpx') | 58 | .fontWeight('400lpx') |
| 44 | .lineHeight('35lpx') | 59 | .lineHeight('35lpx') |
| @@ -62,4 +77,21 @@ export struct SearchCreatorComponent{ | @@ -62,4 +77,21 @@ export struct SearchCreatorComponent{ | ||
| 62 | WDRouterRule.jumpWithPage(WDRouterPage.peopleShipHomePage, params) | 77 | WDRouterRule.jumpWithPage(WDRouterPage.peopleShipHomePage, params) |
| 63 | } | 78 | } |
| 64 | } | 79 | } |
| 80 | + | ||
| 81 | + // 正则过滤检索词 | ||
| 82 | + createCaseInsensitiveRegex(str: string, pattern: string) { | ||
| 83 | + let regex = new RegExp(pattern, 'gi'); | ||
| 84 | + return str.replace(regex, (match) => `<em>${match}</em>`); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + checkForPattern(str: string, pattern: string) { | ||
| 88 | + let highlightedStr = this.createCaseInsensitiveRegex(str, pattern); | ||
| 89 | + return highlightedStr; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + titleInit(str: string, pattern: string) { | ||
| 93 | + const title = this.checkForPattern(str, pattern) | ||
| 94 | + const titleInitRes:titleInitRes = SearchShowRed.titleInit(title) | ||
| 95 | + return titleInitRes | ||
| 96 | + } | ||
| 65 | } | 97 | } |
| @@ -282,7 +282,7 @@ export struct SearchResultContentComponent { | @@ -282,7 +282,7 @@ export struct SearchResultContentComponent { | ||
| 282 | if (this.data_rmh != null && this.data_rmh.length > 0) { | 282 | if (this.data_rmh != null && this.data_rmh.length > 0) { |
| 283 | if (this.data_rmh.length === 1) { | 283 | if (this.data_rmh.length === 1) { |
| 284 | ListItem() { | 284 | ListItem() { |
| 285 | - FollowChildComponent({ data: this.bean, type: 1 }) | 285 | + FollowChildComponent({ data: this.bean, type: 1 ,searchText: decodeURI(this.keywords)}) |
| 286 | }.padding({ left: "31lpx", right: "31lpx" }) | 286 | }.padding({ left: "31lpx", right: "31lpx" }) |
| 287 | } else { | 287 | } else { |
| 288 | ListItem() { | 288 | ListItem() { |
| @@ -356,7 +356,7 @@ export struct SearchResultContentComponent { | @@ -356,7 +356,7 @@ export struct SearchResultContentComponent { | ||
| 356 | ListItemGroup() { | 356 | ListItemGroup() { |
| 357 | ForEach(this.data_rmh, (item: SearchRmhDescription, index: number) => { | 357 | ForEach(this.data_rmh, (item: SearchRmhDescription, index: number) => { |
| 358 | ListItem() { | 358 | ListItem() { |
| 359 | - SearchCreatorComponent({ item: item }) | 359 | + SearchCreatorComponent({ item: item ,searchText: decodeURI(this.keywords)}) |
| 360 | } | 360 | } |
| 361 | .width('150lpx') | 361 | .width('150lpx') |
| 362 | .height('100%') | 362 | .height('100%') |
-
Please register or login to post a comment