You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
6.4 KiB
170 lines
6.4 KiB
<!DOCTYPE html> |
|
<html xmlns:th="http://www.thymeleaf.org" lang="en"> |
|
<head th:replace="admin/common::header(~{::title},~{},~{})"> |
|
<title>分类管理</title> |
|
</head> |
|
<body> |
|
<th:block th:include="admin/common::nav('category')"></th:block> |
|
|
|
<div class="container lw-main lw-banner"> |
|
<div class="btn-group" role="group" style="margin-bottom: 20px" aria-label="..."> |
|
<button type="button" id="create-category-btn" style="outline: none;" class="btn btn-success"> |
|
<i class="fa fa-plus"></i> 新增</button> |
|
</div> |
|
<table id="data-table"></table> |
|
</div> |
|
<!-- 编辑窗口 --> |
|
<div class="modal fade" id="save-window" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> |
|
<div class="modal-dialog" role="document"> |
|
<div class="modal-content"> |
|
<form id="data-form"> |
|
<input type="hidden" name="id"> |
|
<div class="modal-header"> |
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span |
|
aria-hidden="true">×</span></button> |
|
<h4 class="modal-title" id="window-title">Modal Title</h4> |
|
</div> |
|
<div class="modal-body"> |
|
|
|
<div class="form-group"> |
|
<label>标题</label> |
|
<input type="text" name="name" class="form-control" required placeholder="请输入标题..."> |
|
</div> |
|
|
|
<div class="form-group"> |
|
<label>描述信息</label> |
|
<textarea class="form-control" name="summary" placeholder="请输入描述信息..."></textarea> |
|
</div> |
|
</div> |
|
<div class="modal-footer"> |
|
<button type="button" class="btn btn-default" style="outline: none;" data-dismiss="modal">关闭</button> |
|
<button type="submit" class="btn btn-primary" style="outline: none;">保存</button> |
|
</div> |
|
</form> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
<th:block th:include="admin/common::footer"></th:block> |
|
<script> |
|
$(function () { |
|
// 显示表单所有分类数据 |
|
$('#data-table').bootstrapTable({ |
|
url: "/admin/category/", |
|
columns: [ |
|
{ |
|
title: "序号", |
|
width: 50, |
|
align: 'center', |
|
// 生成自增的序号 |
|
formatter: function (value, row, index) { |
|
return index + 1 |
|
} |
|
} |
|
, |
|
{ |
|
title: "标题", |
|
field: "name", |
|
}, |
|
{ |
|
title: "描述", |
|
field: "summary", |
|
}, |
|
{ |
|
field: "id", |
|
title: '操作', |
|
align: "center", |
|
width: 180, |
|
formatter: function (value) { |
|
return `<button type="button" style="outline: none;" data-id="${value}" class="btn btn-info btn-sm category-edit-btn"><i class="fa fa-edit"></i> 编辑</button> |
|
<button type="button" style="outline: none;" data-id="${value}" class="btn btn-danger btn-sm category-delete-btn"><i class="fa fa-trash"></i> 删除</button>` |
|
} |
|
} |
|
], |
|
responseHandler: function (res) { |
|
return res.data |
|
} |
|
}) |
|
// 编辑对应分类 |
|
$("#data-table").on("click",".category-edit-btn",function () { |
|
let id = $(this).data("id") |
|
$.ajax({ |
|
url: "/admin/category/" + id, |
|
method: 'GET', |
|
dataType: 'json', |
|
success: res => { |
|
if (res.code === 200) { |
|
$("#window-title").text('编辑分类') |
|
$("#data-form").initForm(res.data) |
|
$('#save-window').modal('show') |
|
} |
|
else { |
|
layer.msg(res.message, {icon: 2}) |
|
} |
|
} |
|
|
|
}) |
|
}) |
|
|
|
// 新增分类 |
|
$("#create-category-btn").on("click", function () { |
|
$("#window-title").text('新增分类') |
|
// 清空之前表单的数据 |
|
$("#data-form").initForm({id: "",name:"",summary: ""}) |
|
$('#save-window').modal('show') |
|
}) |
|
|
|
|
|
// 删除分类 |
|
$("#data-table").on("click",".category-delete-btn",function () { |
|
let id = $(this).data('id') |
|
let idx = layer.confirm('是否要删除该数据?', { |
|
btn: ['确认', '取消'] //按钮 |
|
}, function () { // 点击确认后删除 |
|
$.ajax({ |
|
url: '/admin/category/' + id, |
|
method: 'delete', |
|
dataType: 'json', |
|
success: res => { |
|
if (res.code === 200) { |
|
layer.msg("删除成功", {icon: 1, time: 700}) |
|
$('#data-table').bootstrapTable('refresh', {silent: true}) |
|
} else { |
|
layer.msg(res.message, {icon: 2}) |
|
} |
|
} |
|
}) |
|
layer.close(idx); // 关闭提示框 |
|
}) |
|
}) |
|
|
|
// 更新分类数据 |
|
$("#data-form").on("submit",function () { |
|
let data = $(this).serialize(); |
|
$.ajax({ |
|
url:"/admin/category/", |
|
method: "POST", |
|
data: data, |
|
dataType: "json", |
|
success: res => { |
|
if (res.code === 200) { |
|
// 显示成功信息 |
|
layer.msg("保存成功", {icon: 1, time: 600}, function () { |
|
// 关闭模态框 |
|
$('#save-window').modal('hide') |
|
// 重载表格数据 |
|
$('#data-table').bootstrapTable('refresh',{silent: true}) |
|
}) |
|
} |
|
else { |
|
layer.msg(res.message, {icon: 2}) |
|
} |
|
} |
|
}) |
|
return false; // 阻止表单的提交行为 |
|
}) |
|
|
|
}) |
|
</script> |
|
</body> |
|
</html> |