完善查询功能
This commit is contained in:
parent
af44459a13
commit
2f9a110931
|
@ -1036,13 +1036,23 @@ class Api
|
|||
$offset = ($data['page'] - 1) * $data['limit'];
|
||||
//$fid = @$data['category_id'];
|
||||
$count = $this->db->count('on_links', '*');
|
||||
|
||||
$keyword = $data['keyword'];
|
||||
error_log("API -->> link_list -->> 转换前的keyword == {$data['keyword']} 转换后的keyword == {$keyword}");
|
||||
//如果成功登录,但token为空,获取所有
|
||||
if ($this->is_login() || (!empty($token) && $this->auth($token))) {
|
||||
$sql = "SELECT *,(SELECT name FROM on_categorys WHERE id = on_links.fid) AS category_name FROM on_links where 1 ";
|
||||
if (!empty($fid) && $fid > 0) {
|
||||
$sql .= " and fid = {$fid}";
|
||||
}
|
||||
if (!empty($keyword)) {
|
||||
$keyword = '%' . $keyword . '%';
|
||||
$sql .= " and (
|
||||
title like '{$keyword}' or
|
||||
url like '{$keyword}' or
|
||||
url_standby like '{$keyword}' or
|
||||
description like '{$keyword}'
|
||||
)";
|
||||
}
|
||||
$sql .= " ORDER BY weight DESC,id DESC";
|
||||
}
|
||||
|
||||
|
@ -1052,7 +1062,16 @@ class Api
|
|||
if (!empty($fid) && $fid > 0) {
|
||||
$sql .= " and fid = {$fid}";
|
||||
}
|
||||
$sql .= "ORDER BY weight DESC,id DESC";
|
||||
if (!empty($keyword)) {
|
||||
$keyword = '%' . $keyword . '%';
|
||||
$sql .= " and (
|
||||
title like '{$keyword}' or
|
||||
url like '{$keyword}' or
|
||||
url_standby like '{$keyword}' or
|
||||
description like '{$keyword}'
|
||||
)";
|
||||
}
|
||||
$sql .= " ORDER BY weight DESC,id DESC";
|
||||
}
|
||||
//如果通过header传递的token验证成功,则获取所有
|
||||
// else if( $this->auth("") === TRUE ) {
|
||||
|
@ -1069,7 +1088,7 @@ class Api
|
|||
if (!empty($limit) && !empty($offset)) {
|
||||
$sql .= " LIMIT {$limit} OFFSET {$offset}";
|
||||
}
|
||||
|
||||
error_log("API -->> link_list -->> sql == {$sql}");
|
||||
//原生查询
|
||||
$datas = $this->db->query($sql)->fetchAll();
|
||||
$datas = [
|
||||
|
|
|
@ -176,7 +176,7 @@ function category_list($api)
|
|||
*/
|
||||
function link_list($api)
|
||||
{
|
||||
error_log("link_list -->> {$_REQUEST['page']} -->> {$_REQUEST['limit']}");
|
||||
error_log("link_list -->> {$_REQUEST['page']} -->> {$_REQUEST['limit']} -->> {$_REQUEST['keyword']}");
|
||||
$page = empty(intval($_REQUEST['page'])) ? null : intval($_REQUEST['page']);
|
||||
$limit = empty(intval($_REQUEST['limit'])) ? null : intval($_REQUEST['limit']);
|
||||
//获取token
|
||||
|
@ -184,12 +184,14 @@ function link_list($api)
|
|||
//获取分类ID
|
||||
$category_id = empty($_POST['category_id']) ? null : intval($_POST['category_id']);
|
||||
$fid = empty(intval($_REQUEST['f_id'])) ? 0 : intval($_REQUEST['f_id']);
|
||||
$keyword = empty($_REQUEST['keyword']) ? null : htmlspecialchars($_REQUEST['keyword'], ENT_QUOTES, 'UTF-8');
|
||||
$data = [
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'token' => $token,
|
||||
'category_id' => $category_id,
|
||||
'fid' => $fid,
|
||||
'keyword' => $keyword,
|
||||
];
|
||||
$api->link_list($data);
|
||||
}
|
||||
|
|
|
@ -2,50 +2,63 @@
|
|||
<?php include_once('left.php'); ?>
|
||||
|
||||
<div class="layui-body">
|
||||
<!-- 内容主体区域 -->
|
||||
<div class="layui-row content-body place-holder">
|
||||
<!-- 内容主体区域 -->
|
||||
<div class="layui-row content-body place-holder">
|
||||
|
||||
<!-- 说明提示框 -->
|
||||
<div class="layui-col-lg12">
|
||||
<blockquote class="layui-elem-quote">
|
||||
<p>1. 分类的私有属性优先级高于链接的私有属性</p>
|
||||
<p>2. 权重数字越大,排序越靠前</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
<!-- 说明提示框END -->
|
||||
<!-- 内容主题区域 -->
|
||||
<div class="layui-col-md12 layui-col-lg12">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-md2 layui-col-lg2">
|
||||
<!-- 树节点 -->
|
||||
<div id="category_tree"></div>
|
||||
</div>
|
||||
<div class="layui-col-md10 layui-col-lg10">
|
||||
<!-- 表格数据 -->
|
||||
<table id="link_list_table" lay-filter="link_list_table_filter" lay-data="{id: 'mylink_reload'}"></table>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 开启表格头部工具栏 -->
|
||||
<script type="text/html" id="linktool">
|
||||
<div class="layui-btn-container">
|
||||
<button class="layui-btn layui-btn-sm" lay-event="add_link">新增链接</button>
|
||||
<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckData">删除选中</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="readmoredata">批量修改分类</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="set_private">设为私有</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="set_public">设为公有</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="reset_query">重置查询</button>
|
||||
<!-- <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button> -->
|
||||
</div>
|
||||
</script>
|
||||
<!-- 开启表格头部工具栏END -->
|
||||
</div>
|
||||
<script type="text/html" id="link_operate">
|
||||
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
|
||||
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="">删除</a>
|
||||
</script>
|
||||
</div>
|
||||
<!-- 内容主题区域END -->
|
||||
<!-- 说明提示框 -->
|
||||
<div class="layui-col-lg12">
|
||||
<blockquote class="layui-elem-quote">
|
||||
<p>1. 分类的私有属性优先级高于链接的私有属性</p>
|
||||
<p>2. 权重数字越大,排序越靠前</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="layui-btn-container">
|
||||
</div>
|
||||
<!-- 说明提示框END -->
|
||||
<!-- 内容主题区域 -->
|
||||
<div class="layui-col-md12 layui-col-lg12">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-md2 layui-col-lg2">
|
||||
<!-- 树节点 -->
|
||||
<div id="category_tree"></div>
|
||||
</div>
|
||||
<div class="layui-col-md10 layui-col-lg10">
|
||||
<!-- 表格数据 -->
|
||||
<table id="link_list_table" lay-filter="link_list_table_filter" lay-data="{id: 'mylink_reload'}"></table>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 开启表格头部工具栏 -->
|
||||
<script type="text/html" id="linktool">
|
||||
<div class="layui-btn-container">
|
||||
<div class="layui-input-group">
|
||||
<div class="layui-input-split layui-input-prefix" style="cursor: pointer;">
|
||||
<i class="layui-icon layui-icon-search" lay-event="search_query"></i>
|
||||
</div>
|
||||
<input type="text" placeholder="搜索…" class="layui-input" id="search_query">
|
||||
</div>
|
||||
<!-- <input type="text" lay-affix="search" lay-filter="search_query"
|
||||
lay-options="{split: true}" placeholder="搜索…"
|
||||
class="layui-input"
|
||||
lay-event="search_query" id="search_query"> -->
|
||||
<div style="height: 10px;"></div>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="reset_query">重置查询</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="add_link">新增链接</button>
|
||||
<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckData">删除选中</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="readmoredata">批量修改分类</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="set_private">设为私有</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="set_public">设为公有</button>
|
||||
<!-- <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
|
||||
<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button> -->
|
||||
</div>
|
||||
</script>
|
||||
<!-- 开启表格头部工具栏END -->
|
||||
</div>
|
||||
<script type="text/html" id="link_operate">
|
||||
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
|
||||
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="">删除</a>
|
||||
</script>
|
||||
</div>
|
||||
<!-- 内容主题区域END -->
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
|
|
@ -206,9 +206,24 @@ layui.use(["table", "layer", "form", "tree", "util"], function () {
|
|||
// 设为公开,0
|
||||
set_cat_batch(ids, 0);
|
||||
break;
|
||||
case "search_query":
|
||||
console.log("点击了 search_query --》》");
|
||||
value = $("#search_query").val();
|
||||
if (value.trim() === '') {
|
||||
break;
|
||||
}
|
||||
console.log("keyword== " + value);
|
||||
table.reloadData("link_list_table", {
|
||||
where: {
|
||||
keyword: value,
|
||||
},
|
||||
scrollPos: "fixed",
|
||||
});
|
||||
break;
|
||||
case "reset_query":
|
||||
// 重置查询
|
||||
console.log("reset_query");
|
||||
$("#search_query").val("");
|
||||
table.reloadData("link_list_table", {
|
||||
where: {
|
||||
f_id: 0,
|
||||
|
|
Loading…
Reference in New Issue