🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 9. 模板搜索页 ## 搜索页 HkCms有提供基础搜索页,在默认模板下的index目录下**search.html**文件有演示案例。 ## 使用方法 1. 调用方式 复制以下表单放置任意位置即可,定义`model_id`,以查询不同的副表模型数据。 ``` <pre class="calibre16">``` <span class="token"><</span>form class<span class="token">=</span><span class="token4">"d-flex"</span> action<span class="token">=</span><span class="token4">"{:url('/search/index')}"</span> method<span class="token">=</span><span class="token4">"get"</span><span class="token">></span> <span class="token"><</span><span class="token">!</span><span class="token">--</span> model_id的value值为空时,无法获取副表的字段。 <span class="token">--</span><span class="token">></span> <span class="token"><</span>input type<span class="token">=</span><span class="token4">"hidden"</span> name<span class="token">=</span><span class="token4">"model_id"</span> value<span class="token">=</span><span class="token4">""</span><span class="token">></span> <span class="token"><</span>input class<span class="token">=</span><span class="token4">"form-control"</span> type<span class="token">=</span><span class="token4">"search"</span> name<span class="token">=</span><span class="token4">"keyword"</span> placeholder<span class="token">=</span><span class="token4">"关键字"</span> aria<span class="token">-</span>label<span class="token">=</span><span class="token4">"Search"</span><span class="token">></span> <span class="token"><</span>button class<span class="token">=</span><span class="token4">"btn btn-primary"</span><span class="token">></span>搜索<span class="token"><</span><span class="token">/</span>button<span class="token">></span> <span class="token"><</span><span class="token">/</span>form<span class="token">></span> ``` ``` 2. 搜索结果页 结果页放到index目录下,并命名search.html - 结果页变量 ``` <pre class="calibre16">``` $__param__ <span class="token5">// 查询(搜索)参数</span> $__modelInfo__ <span class="token5">// 所有模型信息</span> $__SDATA__ <span class="token5">// 搜索到的列表结果</span> $__SPAGE__ <span class="token5">// 分页数据</span> ``` ``` ## 变量说明 - $\_\_param\_\_ 搜索参数数组,里面包含:keyword(用户搜索的关键字)、model\_id(模型ID) 、category\_id(模型ID) 、orderby(排序字段)、ordermode(排序类型,asc=升序,desc=降序) ``` <pre class="calibre16">``` <span class="token1">{</span>$__param__<span class="token1">[</span><span class="token4">'keyword'</span><span class="token1">]</span><span class="token1">}</span> <span class="token5">// 搜索的关键字</span> <span class="token1">{</span>$__param__<span class="token1">[</span><span class="token4">'category_id'</span><span class="token1">]</span><span class="token1">}</span> <span class="token5">// 筛选的栏目ID</span> <span class="token1">{</span>$__param__<span class="token1">[</span><span class="token4">'model_id'</span><span class="token1">]</span><span class="token1">}</span> <span class="token5">// 筛选的模型ID</span> ``` ``` - $\_\_modelInfo\_\_ 模型信息,使用volist输出 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"__modelInfo__"</span><span class="token1">}</span> 模型别名:<span class="token1">{</span>$item<span class="token1">.</span>alias<span class="token1">}</span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span> ``` ``` - $\_\_SDATA\_\_ 结果列表 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"__SDATA__"</span><span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span>、更多字段前往后台字段管理里面查看 <span class="token1">{</span>hkcms<span class="token1">:</span>color name<span class="token">=</span><span class="token4">"$item.title"</span><span class="token1">}</span> <span class="token5">// 搜索结果文字高亮</span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span> ``` ``` 搜索文字高亮使用(v2.2.3.220920+)下面的标签: {hkcms:color name="$item.title"} ,默认是红色,如果想改成蓝色并加粗如下: ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>color name<span class="token">=</span><span class="token4">"$item.title"</span> style<span class="token">=</span><span class="token4">"color:blue;font-weight:bold"</span><span class="token1">}</span> ``` ``` 高亮效果图 ![](https://img.kancloud.cn/4b/a2/4ba206107e85b16a800c0138fa91aa9f_468x186.png) - $\_\_SPAGE\_\_ 分页对象,使用contentpage分页标签,了解更多前往内容列表分页标签查看 ``` <pre class="calibre20">``` <span class="token1">{</span>hkcms<span class="token1">:</span>contentpage name<span class="token">=</span><span class="token4">"__SPAGE__"</span> item<span class="token">=</span><span class="token4">"home,pre,pageno,next,last,info"</span> mobile_item<span class="token">=</span><span class="token4">"pre,pageno,next"</span> pre<span class="token">=</span><span class="token4">"&laquo;"</span> next<span class="token">=</span><span class="token4">"&raquo;"</span> <span class="token">/</span><span class="token1">}</span> ``` ```