|
|
|
@ -12,17 +12,18 @@ |
|
|
|
|
<div class="btn-group" role="group" style="margin-bottom: 20px;" aria-label="..."> |
|
|
|
|
<a th:href="@{/admin/write.html}" class="btn btn-success"><i class="fa fa-plus"></i> 新增</a> |
|
|
|
|
</div> |
|
|
|
|
<form class="form-inline" style="float:right;"> |
|
|
|
|
<form id="search-form" class="form-inline" style="float:right;"> |
|
|
|
|
|
|
|
|
|
<div class="form-group"> |
|
|
|
|
<label>分类</label> |
|
|
|
|
<select class="form-control" style="width: 100px;"> |
|
|
|
|
<select id="article-category" class="form-control" style="width: 100px;"> |
|
|
|
|
<option value="">全部</option> |
|
|
|
|
<option th:each="category:${categories}" th:value="${category.id}" th:text="${category.name}"></option> |
|
|
|
|
</select> |
|
|
|
|
</div> |
|
|
|
|
<div class="form-group"> |
|
|
|
|
<label>状态</label> |
|
|
|
|
<select class="form-control" style="width: 100px;"> |
|
|
|
|
<select id="article-status" class="form-control" style="width: 100px;"> |
|
|
|
|
<option value="">全部</option> |
|
|
|
|
<option value="1">发布</option> |
|
|
|
|
<option value="2">草稿</option> |
|
|
|
@ -30,7 +31,7 @@ |
|
|
|
|
</div> |
|
|
|
|
<div class="form-group"> |
|
|
|
|
<label>类型</label> |
|
|
|
|
<select class="form-control" style="width: 100px;"> |
|
|
|
|
<select id="article-types" class="form-control" style="width: 100px;"> |
|
|
|
|
<option value="">全部</option> |
|
|
|
|
<option value="1">文章</option> |
|
|
|
|
<option value="2">页面</option> |
|
|
|
@ -38,8 +39,9 @@ |
|
|
|
|
</div> |
|
|
|
|
<div class="form-group"> |
|
|
|
|
<label>关键字</label> |
|
|
|
|
<input type="text" class="form-control" placeholder="请输入关键字..."> |
|
|
|
|
<input id="article-keywords" type="text" class="form-control" placeholder="请输入关键字..."> |
|
|
|
|
</div> |
|
|
|
|
<button type="reset" class="btn btn-default" id="reset-btn"><i class="fa fa-refresh"></i> 重置</button> |
|
|
|
|
<button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button> |
|
|
|
|
</form> |
|
|
|
|
<table id="data-table" style="user-select: none"></table> |
|
|
|
@ -49,8 +51,29 @@ |
|
|
|
|
<script> |
|
|
|
|
$(function () { |
|
|
|
|
// 显示表单所有文章数据 |
|
|
|
|
// 引入分页和搜索功能 |
|
|
|
|
$('#data-table').bootstrapTable({ |
|
|
|
|
url: "/admin/article/", |
|
|
|
|
url: "/admin/article/search", |
|
|
|
|
pagination: true, // 开启分页 |
|
|
|
|
sidePagination: 'server', // 使用服务端数据 |
|
|
|
|
pageNumber: 1, // 默认页码第一页 |
|
|
|
|
pageSize: 5, // 每页5条数据 |
|
|
|
|
pageList: [5, 10, 15], // 可选页大小 |
|
|
|
|
responseHandler: function (res) { |
|
|
|
|
return res.data |
|
|
|
|
}, |
|
|
|
|
//这个是查询参数,就是bootstrap-table请求后端时携带的参数 |
|
|
|
|
// offset为数据的序号,limit为页大小 |
|
|
|
|
queryParams: function (params) { |
|
|
|
|
return { |
|
|
|
|
pageNum: (params.offset / params.limit) + 1, |
|
|
|
|
pageSize: params.limit, |
|
|
|
|
title: $('#article-keywords').val(), |
|
|
|
|
type: $('#article-types').val(), |
|
|
|
|
status: $('#article-status').val(), |
|
|
|
|
cid: $('#article-category').val(), |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
columns: [ |
|
|
|
|
{ |
|
|
|
|
title: '序号', |
|
|
|
@ -75,7 +98,7 @@ |
|
|
|
|
formatter: value => { |
|
|
|
|
if (value === 1) { |
|
|
|
|
return `<span>已发布</span>` |
|
|
|
|
}else { |
|
|
|
|
} else { |
|
|
|
|
return `<span>草稿</span>` |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -86,7 +109,7 @@ |
|
|
|
|
field: 'category', |
|
|
|
|
align: 'center', |
|
|
|
|
formatter: value => { |
|
|
|
|
return value.name; |
|
|
|
|
return `<a href="javascript:void(0)" data-id="${value.id}" id="selected-category">${value.name}</a>`; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
@ -105,15 +128,19 @@ |
|
|
|
|
align: 'center', |
|
|
|
|
width: 100, |
|
|
|
|
formatter: function (value) { |
|
|
|
|
return `<button type="button" data-id="${value}" class="btn btn-danger btn-sm lw-del-btn"><i class="fa fa-trash"></i> 删除</button>` |
|
|
|
|
return `<button type="button" data-id="${value}" class="btn btn-danger btn-sm article-delete-btn"><i class="fa fa-trash"></i> 删除</button>` |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
responseHandler: function (res) { |
|
|
|
|
return res.data |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 点击搜索按钮,阻止表单自动提交 |
|
|
|
|
$('#search-form').on('submit', function () { |
|
|
|
|
$('#data-table').bootstrapTable('refresh', {silent: true, pageNumber: 1, pageSize: 5}); |
|
|
|
|
return false; |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 删除文章 |
|
|
|
|
$("#data-table").on("click", ".article-delete-btn", function () { |
|
|
|
|
let id = $(this).data('id') |
|
|
|
@ -126,18 +153,24 @@ |
|
|
|
|
dataType: 'json', |
|
|
|
|
success: res => { |
|
|
|
|
if (res.code === 200) { |
|
|
|
|
layer.msg("删除成功", { icon: 1, time: 700 }) |
|
|
|
|
$('#data-table').bootstrapTable('refresh', { silent: true }) |
|
|
|
|
layer.msg("删除成功", {icon: 1, time: 700}) |
|
|
|
|
$('#data-table').bootstrapTable('refresh', {silent: true}) |
|
|
|
|
} else { |
|
|
|
|
layer.msg(res.message, { icon: 2 }) |
|
|
|
|
layer.msg(res.message, {icon: 2}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
layer.close(idx); // 关闭提示框 |
|
|
|
|
}) |
|
|
|
|
}).on('click', '#selected-category', function () { |
|
|
|
|
// 点击文章对分类展示该分类所有文章 |
|
|
|
|
let cid = $(this).data('id'); // 分类id |
|
|
|
|
// 设置搜索条件为查询分类 |
|
|
|
|
$('#reset-btn').click(); |
|
|
|
|
$('#article-category').val(cid); |
|
|
|
|
// 重载查询数据 |
|
|
|
|
$('#data-table').bootstrapTable('refresh', {silent: true,pageNumber: 1, pageSize: 5}); |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
</script> |
|
|
|
|
</body> |
|
|
|
|