fix: 产品搜索关键词高亮

This commit is contained in:
2025-07-01 17:13:24 +08:00
parent 90c1be254b
commit 77706e5bcb
3 changed files with 23 additions and 4 deletions

View File

@@ -299,9 +299,9 @@ class Product extends Common
'query' => request()->param()
])
->each(function ($item) use($keywords) {
$item['spu'] = str_replace($keywords, '<strong class="redpoint">'.$keywords.'</strong>', $item['spu']);
$item['name'] = str_replace($keywords, '<strong class="redpoint">'.$keywords.'</strong>', $item['name']);
$item['short_name'] = str_replace($keywords, '<strong class="redpoint">'.$keywords.'</strong>', $item['short_name']);
$item['spu'] = highlight_keywords($item['spu'], $keywords, ['redpoint']);
$item['name'] = highlight_keywords($item['name'], $keywords, ['redpoint']);
$item['short_name'] = highlight_keywords($item['short_name'], $keywords, ['redpoint']);
return $item;
});
View::assign('products', $products);