陈剑华

feat: 18024 搜索结果-时间轴专题样式卡,显示标题的时间轴卡,标题展示不全,见截图

@@ -27,32 +27,60 @@ export class SearchShowRed { @@ -27,32 +27,60 @@ export class SearchShowRed {
27 res.push(content); 27 res.push(content);
28 } 28 }
29 29
30 - SearchShowRed.formatTitle(html, res, 0, textArr); 30 + console.log('SearchShowRed-res', JSON.stringify(res))
  31 +
  32 + SearchShowRed.formatTitle(
  33 + html.replaceAll('<em>', '').replaceAll('</em>', ''),
  34 + res,
  35 + 0,
  36 + textArr
  37 + );
31 } 38 }
32 39
33 const titleInitRes: titleInitRes = { 40 const titleInitRes: titleInitRes = {
34 titleMarked, 41 titleMarked,
35 textArr 42 textArr
36 } 43 }
  44 + console.log('SearchShowRed-titleInitRes', JSON.stringify(titleInitRes))
37 return titleInitRes 45 return titleInitRes
38 } 46 }
39 47
40 private static formatTitle(textStr: string, matchArr: string[], index: number, textArr: textItem[]) { 48 private static formatTitle(textStr: string, matchArr: string[], index: number, textArr: textItem[]) {
41 const item: string = matchArr[index]; 49 const item: string = matchArr[index];
42 - const arr = textStr.split(item);  
43 - arr.forEach((str: string, ind: number) => { 50 + if (!item) {
  51 + textArr.push({
  52 + content: textStr,
  53 + isRed: false
  54 + })
  55 + return;
  56 + }
  57 + const ind = textStr.indexOf(item);
  58 + const len = item.length;
44 if (ind === 0) { 59 if (ind === 0) {
45 textArr.push({ 60 textArr.push({
46 - content: str.replaceAll('<em>', '').replaceAll('</em>', ''), 61 + content: item,
  62 + isRed: true
  63 + })
  64 + SearchShowRed.formatTitle(textStr.slice(len), matchArr, index + 1, textArr);
  65 + } else if (ind + len === textStr.length) {
  66 + textArr.push({
  67 + content: textStr.slice(0, ind),
47 isRed: false 68 isRed: false
48 - } as textItem) 69 + })
49 textArr.push({ 70 textArr.push({
50 content: item, 71 content: item,
51 isRed: true 72 isRed: true
52 }) 73 })
53 - } else if (ind === 1) {  
54 - SearchShowRed.formatTitle(str, matchArr, index + 1, textArr)  
55 - } 74 + } else {
  75 + textArr.push({
  76 + content: textStr.slice(0, ind),
  77 + isRed: false
56 }) 78 })
  79 + textArr.push({
  80 + content: item,
  81 + isRed: true
  82 + })
  83 + SearchShowRed.formatTitle(textStr.slice(ind + len), matchArr, index + 1, textArr);
  84 + }
57 } 85 }
58 } 86 }