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
zhenghy
2024-05-25 18:03:34 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
c81f091330425415e9fffb7d82c5c243ad5b6038
c81f0913
2 parents
00d81344
c7f34c0f
Merge remote-tracking branch 'origin/main'
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
12 deletions
sight_harmony/features/wdComponent/src/main/ets/components/cardview/Card2Component.ets
sight_harmony/features/wdComponent/src/main/ets/components/cardview/Card2Component.ets
View file @
c81f091
...
...
@@ -9,8 +9,11 @@ import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick';
const TAG: string = 'Card2Component';
const TAG: string = 'Card2Component'
interface textItem {
content: string,
isRed: boolean
}
/**
* 大图卡:
* compstyle:2
...
...
@@ -27,9 +30,7 @@ export struct Card2Component {
@State clicked: boolean = false;
@ObjectLink compDTO: CompDTO
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
async aboutToAppear(): Promise<void> {
this.clicked = hasClicked(this.contentDTO.objectId)
...
...
@@ -40,12 +41,45 @@ export struct Card2Component {
titleInit() {
if (this.contentDTO.title?.includes('<em>') && this.contentDTO.title?.includes('</em>')) {
this.titleMarked = true;
this.str01 = this.contentDTO.title?.split('<em>')[0] || '';
this.str02 = this.contentDTO.title?.split('<em>')[1].split('</em>')[0] || '';
this.str03 = this.contentDTO.title?.split('<em>')[1].split('</em>')[1] || '';
// this.str01 = this.contentDTO.title?.split('<em>')[0] || '';
// this.str02 = this.contentDTO.title?.split('<em>')[1].split('</em>')[0] || '';
// this.str03 = this.contentDTO.title?.split('<em>')[1].split('</em>')[1] || '';
const html: string = this.contentDTO.title;
const pattern = /<[a-z]+[1-6]?\b[^>]*>(.*?)<\/[a-z]+[1-6]?>/g;
const res: string[] = [];
let match: RegExpExecArray | null;
while ((match = pattern.exec(html)) !== null) {
const content: string = match[1].trim();
res.push(content);
}
let textArr: textItem[] = [];
this.formatTitle(html, res, 0, textArr);
this.textArr = textArr;
}
}
formatTitle(textStr: string, matchArr: string[], index: number, textArr: textItem[]) {
const item: string = matchArr[index];
const arr = textStr.split(item);
arr.forEach((str: string, ind: number) => {
if (ind === 0) {
textArr.push({
content: str.replaceAll('<em>', '').replaceAll('</em>', ''),
isRed: false
} as textItem)
textArr.push({
content: item,
isRed: true
})
} else if (ind === 1) {
this.formatTitle(str, matchArr, index + 1, textArr)
}
})
}
build() {
Column() {
Column() {
...
...
@@ -85,10 +119,18 @@ export struct Card2Component {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
.fontColor(0xED2800)
Span(this.str03)
// Span(this.str01)
// Span(this.str02)
// .fontColor(0xED2800)
// Span(this.str03)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
...
...
Please
register
or
login
to post a comment