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.
 
 
 
 

277 lines
11 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('navigation')"></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-navigation-btn" style="outline: none;" class="btn btn-success"><i class="fa fa-plus"></i>
新增
</button>
<button type="button" id="refresh-ordered-btn" style="outline: none;" class="btn btn-primary"><i class="fa fa-refresh"></i>
保存顺序
</button>
</div>
<table id="data-table" style="user-select: none"></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">&times;</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" required class="form-control"
placeholder="请输入名称...">
</div>
<div class="form-group">
<label>图标</label>
<input type="text" name="icon" class="form-control"
placeholder="请输入图标...">
</div>
<div class="form-group">
<label>跳转链接</label>
<input type="url" name="link" required class="form-control"
placeholder="请输入跳转链接...">
</div>
<div class="form-group">
<label>顺序</label>
<input type="number" min="0" name="ordered" required class="form-control" placeholder="请输入顺序...">
</div>
<div class="form-group">
<label>打开方式</label>
<select required name="linkMode" class="form-control">
<option value="true">在新页面打开</option>
<option value="false">在当前页打开</option>
</select>
</div>
<div class="form-group">
<label>是否启用</label>
<select required name="enable" class="form-control">
<option value="true">启用</option>
<option value="false">禁止</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" style="outline: none;" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="submit" style="outline: none;" class="btn btn-primary">保存</button>
</div>
</form>
</div>
</div>
</div>
<th:block th:include="admin/common::footer"></th:block>
<script>
$(function () {
// 显示表单所有导航条数据
$('#data-table').bootstrapTable({
url: "/admin/navigation/",
responseHandler: function (res) {
return res.data
},
columns: [
{
title: "序号",
width: 50,
align: 'center',
// 生成自增的序号
formatter: function (value, row, index) {
return index + 1
}
},
{
title: "名称",
align: 'center',
field: "name",
formatter: function (value, row) {
return `<a href="${row.link}" target="_blank">${value}</a>`
}
},
{
title: "图标",
align: 'center',
width: 20,
field: "icon",
formatter: value => {
return `<i class="fa fa-${value}"></i>`
}
},
{
title: '顺序',
width: 40,
align: 'center',
field: 'ordered',
formatter: function (value, row) {
return `<input class="form-control sortedBySave" style="width: 60px" type="number" min="0"
data-id="${row.id}" value="${value}">`
}
},
{
title: "跳转方式",
field: "linkMode",
align: 'center',
formatter: value => {
return value ? '新页面打开' : '当前页面打开';
}
},
{
title: "是否启用",
field: "enable",
align: 'center',
formatter: function (value) {
return value ? `<i class="fa fa-check"></i>` : `<i class="fa fa-close"></i>`
}
},
{
field: "id",
title: '操作',
align: "center",
width: 180,
formatter: function (value) {
return `<button style="outline: none;" type="button" data-id="${value}" class="btn btn-info btn-sm navigation-edit-btn" style="margin-right: 10px"><i class="fa fa-edit"></i> 编辑</button>
<button style="outline: none;" type="button" data-id="${value}" class="btn btn-danger btn-sm navigation-delete-btn"><i class="fa fa-trash"></i> 删除</button>`
}
}
]
})
// 编辑对应导航条
$("#data-table").on("click", ".navigation-edit-btn", function () {
let id = $(this).data("id")
$.ajax({
url: "/admin/navigation/" + id,
method: 'GET',
dataType: 'json',
success: res => {
if (res.code === 200) {
res.data['linkMode'] = res.data['linkMode'] + ""
res.data['enable'] = res.data['enable'] + ""
$("#window-title").text('编辑导航条')
$("#data-form").initForm(res.data)
$('#save-window').modal('show')
} else {
layer.msg(res.message, {icon: 2})
}
}
})
})
// 新增导航条
$("#create-navigation-btn").on("click", function () {
$("#window-title").text('新增导航条')
// 清空之前表单的数据
$("#data-form").initForm({
id: "",
name: "",
icon: "",
link: "",
ordered: "",
linkMode: "true",
enable: "true",
})
$('#save-window').modal('show')
})
// 删除导航条
$("#data-table").on("click", ".navigation-delete-btn", function () {
let id = $(this).data('id')
let idx = layer.confirm('是否要删除该数据?', {
btn: ['确认', '取消'] //按钮
}, function () { // 点击确认后删除
$.ajax({
url: '/admin/navigation/' + 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/navigation/",
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; // 阻止表单的提交行为
})
// 实现按照ordered排序
$('#refresh-ordered-btn').on('click', function () {
console.log("id----ordered")
// 返回数据的格式,依次获得所有表格项的id和顺序值并组成下面的格式
// id1----顺序1;id2----顺序2;id3----顺序13
let ids = ""
$('#data-table .sortedBySave').each((index, ele) => ids += $(ele).data('id') + "----" + $(ele).val() + ";")
console.log(ids);
$.ajax({
url: "/admin/navigation/order",
method: "POST",
data: {
ids: ids
},
dataType: "json",
success: res => {
if (res.code === 200) {
layer.msg("保存成功", {icon: 1, time: 600}, function () {
$('#data-table').bootstrapTable('refresh', {silent: true})
});
} else {
layer.msg(res.message, {icon: 2});
}
}
})
})
})
</script>
</body>
</html>