zhenghy

Merge remote-tracking branch 'origin/main'

... ... @@ -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)
}
... ...