This commit is contained in:
2025-07-04 17:17:41 +08:00
10 changed files with 63 additions and 54 deletions

View File

@@ -226,18 +226,18 @@ if (!function_exists('get_platform')) {
if (!function_exists('highlight_keywords')) {
/**
* 高亮关键词
* @param string $item
* @param string $keywords
* @param array $class
* @param string $text // 要处理的文本
* @param string $keyword // 关键词
* @param string|callable $repalce // 替换函数或字符串
* @return string
*/
function highlight_keywords(string $text, string $keywords, array $class=[]): string
function highlight_keywords(string $text, string $keyword, string|callable $replace): string
{
return preg_replace_callback('/' . preg_quote($keywords, '/') . '+/i', function($match) use($text, $class) {
if (empty($match)) {
return $text;
}
return '<strong class="' . implode(' ', $class) . '">' . $match[0] . '</strong>';
return preg_replace_callback('/' . preg_quote($keyword, '/') . '+/i', function($match) use($text, $replace) {
if (empty($match)) return $text;
if (is_string($replace)) return '<strong>' . $match[0] . '</strong>';
if (is_callable($replace)) return $replace($match[0]);
return $match[0];
}, $text);
}
}

View File

@@ -170,9 +170,9 @@ class Article extends Common
]);
$ret = ArticleLeaveMessageModel::create($data);
if ($ret->isEmpty()) {
return error(lang('留言提交失败'));
return error(lang('信息提交失败'));
}
return success(lang('留言提交成功'));
return success(lang('信息已成功提交!'));
}
}

View File

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

View File

@@ -37,6 +37,13 @@
<img src="{$photo}" alt="" />
</div>
{/volist}
{if condition="!empty($product.video_img) && !empty($product.video_url) && $idx == 1"}
<div class="swiper-slide">
<video poster="{$product.video_img}" autoplay="autoplay" muted="muted" loop="loop" id="video" controls>
<source src="{$product.video_url}" type="video/mp4"/>
</video>
</div>
{/if}
</div>
<!-- 如果需要分页器 -->
<div class="swiper-pagination"></div>

View File

@@ -15,19 +15,6 @@
</div>
<!-- 顶部菜单-->
<div class="top-menu">
<div class="it-ct">
<div class="it-1"><a href="/">{:lang_i18n('首页')}</a></div>
</div>
<div class="it-ct">
<div class="it-1">
<div class="it-1-more">{:lang_i18n('产品列表')}<i class="icon-arrow"></i></div>
{notempty name="header_categorys"}
{volist name="header_categorys" id="ca"}
<div class="it-1-2"><a href="{:url('product/category', ['id' => $ca.id])}">{$ca.name}</a></div>
{/volist}
{/notempty}
</div>
</div>
{notempty name="header_navigation"}
{volist name="header_navigation" id="nav"}
<div class="it-ct">

View File

@@ -37,13 +37,13 @@
<!-- 小图片预览 -->
<div id="imageMenu">
<ul class="image_list">
{volist name="sku.photo_album" id="photo"}
<li id="onlickImg"><img src="{:thumb($photo)}" data-url="{$photo}" /></li>
{/volist}
{if condition="!empty($product.video_img) && !empty($product.video_url) && $idx == 1"}
<!-- 产品视频 -->
<li id="onlickImg"><img src="{:thumb($product.video_img)}" data-url="{$product.video_url}" /></li>
{/if}
{volist name="sku.photo_album" id="photo"}
<li id="onlickImg"><img src="{:thumb($photo)}" data-url="{$photo}" /></li>
{/volist}
</ul>
</div>
<!-- 右边切换按钮 -->
@@ -52,16 +52,9 @@
<!-- 产品大图 -->
<div class="bigImg" id="vertical">
<!-- 主图 -->
{if condition="!empty($product.video_img) && !empty($product.video_url) && $idx == 1"}
<!-- 如果有视频情况下默认先显示视频 -->
<video poster="{$product.video_img}" autoplay="autoplay" muted="muted" loop="loop" id="video" controls style="width: 510px;height: 510px; position: relative;z-index: 998;">
<source src="{$product.video_url}" type="video/mp4"/>
</video>
{else/}
{notempty name="sku.photo_album[0]"}
<img src="{$sku.photo_album[0]}" id="midimg" />
{/notempty}
{/if}
</div>
</div>
{/volist}
@@ -225,7 +218,7 @@
<textarea name="message" id="message"></textarea>
</div>
</div>
<button type="button" id="send" class="submit-btn">{:lang_i18n('提交')}</button>
<button type="submit" class="submit-btn">{:lang_i18n('提交')}</button>
</form>
</div>
</div>
@@ -273,21 +266,12 @@
// 处理表单提交
modal.find("form").submit(function(e) {
e.preventDefault();
var form = $(this)
var formData = $(this).serialize();
// 这里可以添加代码将formData发送到服务器
// 例如通过AJAX
console.log("提交的数据: " + formData);
// 提交成功后可以选择关闭模态框
modal.hide();
});
// 提交询盘
$('#send').click(function() {
var form = $(this).parents('form');
$.ajax({
url: "{:url('product/inquiry')}",
type: 'POST',
data: form.serialize(),
data: formData,
success: function(r) {
if (r.code == 0) {
form[0].reset(); // 重置表单
@@ -297,6 +281,7 @@
},
error: function(e) {
console.error(e);
modal.hide();
}
})
});

View File

@@ -14,6 +14,7 @@
</div>
</form>
<!-- 搜索结果列表-->
{notempty name="products"}
<ul class="seul">
{volist name="products" id="pro"}
<a href="{:url('product/detail', ['id' => $pro['id']])}">
@@ -32,6 +33,10 @@
</a>
{/volist}
</ul>
<div>{$page|raw}</div>
{else/}
<div style="text-align: center; padding: 10%;">暂无数据</div>
{/notempty}
</div>
</div>
{/block}

View File

@@ -17,9 +17,10 @@
<script type="text/javascript">
$(function() {
$('.headnav .navitem').each(function(idx, item) {
$(item).removeClass('hover');
if (compareUrls(location.href, item.href)) {
$(item).addClass('hover').siblings();
var _item = $(item);
_item.removeClass('hover');
if (_item.attr('href') && compareUrls(location.href, _item.get(0).href)) {
_item.addClass('hover').siblings();
}
});

View File

@@ -12,6 +12,7 @@ class Product
*/
public function list()
{
$params = request()->get([
'category_id',
'language' => 'zh-cn',
@@ -47,8 +48,8 @@ class Product
->order(['sort' => 'asc', 'id' => 'desc'])
->hidden(['category_id'])
->paginate([
'list_row' => $params['size'],
'page' => $params['page']
'list_rows' => $params['size'],
'page' => $params['page']
])
->each(function($item) {
if (!empty($item['cover_image']) && !str_starts_with($item['cover_image'], 'http')) {

View File

@@ -103,3 +103,25 @@
.orico_Page_search .searchMain ::placeholder {
color: #737373;
}
.orico_Page_search .searchMain .pagination {
zoom: 1;
text-align: center;
color: #555;
clear: both;
padding-bottom: 2rem;
}
.orico_Page_search .searchMain .pagination span {
padding: 0px 0px;
display: inline-block;
}
.orico_Page_search .searchMain .pagination li {
display: inline-block;
width: 34px;
height: 22px;
line-height: 22px;
font-size: 16px;
}
.orico_Page_search .searchMain .pagination li.active {
background-color: #444444;
color: #ffffff;
}