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.
180 lines
6.6 KiB
180 lines
6.6 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('friends')"></th:block> |
|
|
|
<div class="container lw-main lw-banner"> |
|
<div class="btn-group" role="group" style="margin-bottom: 20px" aria-label="..."> |
|
<button type="button" style="outline: none;" id="create-friends-btn" 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="title" class="form-control" |
|
placeholder="请输入友链标题..."> |
|
</div> |
|
|
|
<div class="form-group"> |
|
<label>友链地址</label> |
|
<input type="url" name="link" class="form-control" |
|
placeholder="请输入友链地址..."> |
|
</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/friends/", |
|
columns: [ |
|
{ |
|
title: "序号", |
|
width: 50, |
|
align: 'center', |
|
// 生成自增的序号 |
|
formatter: function (value, row, index) { |
|
return index + 1 |
|
} |
|
}, |
|
|
|
{ |
|
title: "友链标题", |
|
field: "title", |
|
}, |
|
|
|
{ |
|
title: "友链地址", |
|
field: "link", |
|
formatter: value => { |
|
return `<a href="${value}" target="_blank">${value}</a>` |
|
} |
|
}, |
|
|
|
{ |
|
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 friends-edit-btn"><i class="fa fa-edit"></i> 编辑</button> |
|
<button type="button" style="outline: none;" data-id="${value}" class="btn btn-danger btn-sm friends-delete-btn"><i class="fa fa-trash"></i> 删除</button>` |
|
} |
|
} |
|
], |
|
responseHandler: function (res) { |
|
return res.data |
|
} |
|
}) |
|
// 编辑对应友链 |
|
$("#data-table").on("click", ".friends-edit-btn", function () { |
|
let id = $(this).data("id") |
|
$.ajax({ |
|
url: "/admin/friends/" + 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-friends-btn").on("click", function () { |
|
$("#window-title").text('新增友链') |
|
// 清空之前表单的数据 |
|
$("#data-form").initForm({id: "", title: "", link: "",}) |
|
$('#save-window').modal('show') |
|
}) |
|
|
|
|
|
// 删除友链 |
|
$("#data-table").on("click", ".friends-delete-btn", function () { |
|
let id = $(this).data('id') |
|
let idx = layer.confirm('是否要删除该数据?', { |
|
btn: ['确认', '取消'] //按钮 |
|
}, function () { // 点击确认后删除 |
|
$.ajax({ |
|
url: '/admin/friends/' + 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/friends/", |
|
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> |