陈剑华

feat: 18020 大图卡组件样式,搜索结果中标题展示不全

Showing 18 changed files with 256 additions and 237 deletions
... ... @@ -6,6 +6,7 @@ import { CardMediaInfo } from '../cardCommon/CardMediaInfo';
import { Notes } from './notes';
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
/**
* 大专题卡--CompStyle: 10
... ... @@ -21,9 +22,7 @@ export struct Card10Component {
@State loadImg: 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.titleInit();
... ... @@ -31,12 +30,9 @@ export struct Card10Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -45,10 +41,14 @@ export struct Card10Component {
if (this.contentDTO.titleShow === 1 && this.contentDTO.newsTitle) {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -7,6 +7,7 @@ import { CardSourceInfo } from '../cardCommon/CardSourceInfo';
import { Notes } from './notes';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG = 'Card11Component';
... ... @@ -21,9 +22,7 @@ export struct Card11Component {
@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.titleInit();
... ... @@ -31,12 +30,9 @@ export struct Card11Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -49,10 +45,14 @@ export struct Card11Component {
}
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -6,6 +6,7 @@ import { ProcessUtils } from 'wdRouter';
import {CarderInteraction} from '../CarderInteraction'
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG = 'Card12Component';
... ... @@ -20,9 +21,7 @@ export struct Card12Component {
@State contentDTO: ContentDTO = new ContentDTO();
@State clicked: boolean = false;
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
aboutToAppear(): void {
this.titleInit();
... ... @@ -30,12 +29,9 @@ export struct Card12Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -48,10 +44,14 @@ export struct Card12Component {
if (this.contentDTO.newsTitle) {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -7,6 +7,7 @@ import {CarderInteraction} from '../CarderInteraction'
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG = 'Card14Component';
... ... @@ -22,9 +23,7 @@ export struct Card14Component {
@State loadImg: boolean = false;
@State clicked: boolean = false;
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
async aboutToAppear(): Promise<void> {
this.titleInit();
... ... @@ -33,12 +32,9 @@ export struct Card14Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -52,10 +48,14 @@ export struct Card14Component {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -7,6 +7,7 @@ import {CarderInteraction} from '../CarderInteraction'
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG: string = 'Card15Component';
... ... @@ -26,9 +27,7 @@ export struct Card15Component {
@State loadImg: boolean = false;
@State clicked: boolean = false;
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
async aboutToAppear(): Promise<void> {
this.titleInit();
... ... @@ -37,12 +36,9 @@ export struct Card15Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -53,10 +49,14 @@ export struct Card15Component {
if (this.contentDTO.newsTitle) {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -7,6 +7,7 @@ import {CarderInteraction} from '../CarderInteraction'
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG = 'Card16Component';
... ... @@ -27,9 +28,7 @@ export struct Card16Component {
@State loadImg: boolean = false;
@State clicked: boolean = false;
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
async aboutToAppear(): Promise<void> {
this.titleInit();
... ... @@ -38,12 +37,9 @@ export struct Card16Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -56,10 +52,14 @@ export struct Card16Component {
if (this.contentDTO.newsTitle) {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -7,6 +7,7 @@ import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { CardMediaInfo } from '../cardCommon/CardMediaInfo';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG = 'Card17Component';
... ... @@ -22,9 +23,7 @@ export struct Card17Component {
@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> {
console.log('Card17Component', JSON.stringify(this.contentDTO))
... ... @@ -34,22 +33,23 @@ export struct Card17Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
Column({ space: 8 }) {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -6,6 +6,7 @@ import { CarderInteraction } from '../CarderInteraction'
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG = 'Card19Component';
... ... @@ -20,9 +21,7 @@ export struct Card19Component {
@State contentDTO: ContentDTO = new ContentDTO()
@State clicked: boolean = false;
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
async aboutToAppear(): Promise<void> {
this.titleInit();
... ... @@ -31,12 +30,9 @@ export struct Card19Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -47,10 +43,14 @@ export struct Card19Component {
if (this.contentDTO.newsTitle) {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle=='null'?"":this.contentDTO.newsTitle)
}
... ...
... ... @@ -7,6 +7,7 @@ import {CarderInteraction} from '../CarderInteraction'
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG = 'Card20Component';
... ... @@ -21,9 +22,7 @@ export struct Card20Component {
@State contentDTO: ContentDTO = new ContentDTO();
@State clicked: boolean = false;
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
aboutToAppear(): void {
this.titleInit();
... ... @@ -31,12 +30,9 @@ export struct Card20Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -48,10 +44,14 @@ export struct Card20Component {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -7,6 +7,7 @@ import {CarderInteraction} from '../CarderInteraction'
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG: string = 'Card6Component-Card13Component';
... ... @@ -22,9 +23,7 @@ export struct Card21Component {
@State loadImg: boolean = false;
@State clicked: boolean = false;
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
async aboutToAppear(): Promise<void> {
this.titleInit();
... ... @@ -33,12 +32,9 @@ export struct Card21Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -50,10 +46,14 @@ export struct Card21Component {
GridItem() {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -8,12 +8,9 @@ import { Notes } from './notes';
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick';
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG: string = 'Card2Component'
interface textItem {
content: string,
isRed: boolean
}
/**
* 大图卡:
* compstyle:2
... ... @@ -33,52 +30,17 @@ export struct Card2Component {
@State textArr: textItem[] = []
async aboutToAppear(): Promise<void> {
this.clicked = hasClicked(this.contentDTO.objectId)
this.titleInit();
this.clicked = hasClicked(this.contentDTO.objectId)
this.loadImg = await onlyWifiLoadImg();
}
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] || '';
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;
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.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() {
... ... @@ -119,10 +81,6 @@ export struct Card2Component {
Text() {
if (this.titleMarked) {
// Span(this.str01)
// Span(this.str02)
// .fontColor(0xED2800)
// Span(this.str03)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
... ...
... ... @@ -5,6 +5,7 @@ import { CardSourceInfo } from '../cardCommon/CardSourceInfo';
import { Notes } from './notes';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
/**
... ... @@ -19,9 +20,7 @@ export struct Card3Component {
@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.titleInit();
... ... @@ -29,12 +28,9 @@ export struct Card3Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -47,10 +43,14 @@ export struct Card3Component {
}
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -7,6 +7,7 @@ import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { Notes } from './notes';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG: string = 'Card4Component';
... ... @@ -25,9 +26,7 @@ export struct Card4Component {
@State loadImg: boolean = false;
@State clicked: boolean = false;
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
@ObjectLink compDTO: CompDTO
async aboutToAppear(): Promise<void> {
... ... @@ -37,12 +36,9 @@ export struct Card4Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -57,10 +53,14 @@ export struct Card4Component {
}
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -5,6 +5,7 @@ import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { Notes } from './notes';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG: string = 'Card5Component';
... ... @@ -22,9 +23,7 @@ export struct Card5Component {
@State loadImg: boolean = false;
@State clicked: boolean = false;
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
async aboutToAppear(): Promise<void> {
console.log('Card2Component', JSON.stringify(this.compDTO))
... ... @@ -35,12 +34,9 @@ export struct Card5Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -69,10 +65,14 @@ export struct Card5Component {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -8,6 +8,7 @@ import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { Logger } from 'wdKit/Index';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG: string = 'Card6Component-Card13Component';
... ... @@ -21,9 +22,7 @@ export struct Card6Component {
@State loadImg: boolean = false;
@State clicked: boolean = false;
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
@ObjectLink compDTO: CompDTO
@State contentDTO: ContentDTO = new ContentDTO();
... ... @@ -33,12 +32,9 @@ export struct Card6Component {
this.clicked = hasClicked(this.contentDTO.objectId)
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -70,10 +66,14 @@ export struct Card6Component {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -7,6 +7,7 @@ import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { TrackConstants, TrackingPageBrowse } from 'wdTracking/Index';
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
/**
* 时间链卡--CompStyle: 09
... ... @@ -22,9 +23,7 @@ export struct Card9Component {
// @State loadImg: boolean = true;
@State clicked: boolean = false;
@State titleMarked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
pageShowTime:number = 0;
pageHideTime:number = 0;
... ... @@ -48,12 +47,9 @@ export struct Card9Component {
}
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] || '';
}
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -62,10 +58,14 @@ export struct Card9Component {
if (this.contentDTO.titleShow === 1 && this.contentDTO.newsTitle) {
Text() {
if (this.titleMarked) {
Span(this.str01)
Span(this.str02)
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
} else {
Span(this.contentDTO.newsTitle)
}
... ...
... ... @@ -5,6 +5,7 @@ import { CardSourceInfo } from '../cardCommon/CardSourceInfo'
import { CardMediaInfo } from '../cardCommon/CardMediaInfo'
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
const TAG: string = 'Card4Component';
... ... @@ -19,9 +20,7 @@ export struct SearchContentComponent {
@State contentDTO: ContentDTO = new ContentDTO();
@State loadImg: boolean = false;
@State clicked: boolean = false;
@State str01: string = '';
@State str02: string = '';
@State str03: string = '';
@State textArr: textItem[] = []
async aboutToAppear(): Promise<void> {
... ... @@ -30,9 +29,9 @@ export struct SearchContentComponent {
}
titleInit() {
this.str01 = this.contentDTO.contentText?.split('<em>')[0] || '';
this.str02 = this.contentDTO.contentText?.split('<em>')[1].split('</em>')[0] || '';
this.str03 = this.contentDTO.contentText?.split('<em>')[1].split('</em>')[1] || '';
const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.title);
// this.titleMarked = titleInitRes.titleMarked;
this.textArr = titleInitRes.textArr;
}
build() {
... ... @@ -47,11 +46,15 @@ export struct SearchContentComponent {
.textOverflow({ overflow: TextOverflow.Ellipsis }) // 超出的部分显示省略号。
// 命中内容
Text(this.contentDTO.contentText) {
Span(this.str01)
Span(this.str02)
Text() {
ForEach(this.textArr, (textItem: textItem) => {
if (textItem.isRed) {
Span(textItem.content)
.fontColor(0xED2800)
Span(this.str03)
} else {
Span(textItem.content)
}
})
}
.fontSize(13)
.width(CommonConstants.FULL_PARENT)
... ...
export interface textItem {
content: string,
isRed: boolean
}
export interface titleInitRes {
titleMarked: boolean,
textArr: textItem[]
}
export class SearchShowRed {
// title: this.contentDTO.title
static titleInit(title: string) {
let titleMarked: boolean = false;
let textArr: textItem[] = [];
if (title?.includes('<em>') && title?.includes('</em>')) {
titleMarked = true;
const html: string = 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);
}
SearchShowRed.formatTitle(html, res, 0, textArr);
}
const titleInitRes: titleInitRes = {
titleMarked,
textArr
}
return titleInitRes
}
private static 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) {
SearchShowRed.formatTitle(str, matchArr, index + 1, textArr)
}
})
}
}
\ No newline at end of file
... ...