142 lines
5.3 KiB
Plaintext
142 lines
5.3 KiB
Plaintext
<div class="card">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<h5 class="mb-0">友情链接管理</h5>
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addLinkModal">
|
|
<i class="bi bi-plus"></i> 添加链接
|
|
</button>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>排序</th>
|
|
<th>网站名称</th>
|
|
<th>URL</th>
|
|
<th>描述</th>
|
|
<th>操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<% links.forEach(link => { %>
|
|
<tr data-id="<%= link._id %>">
|
|
<td><%= link.order || 0 %></td>
|
|
<td><%= link.name %></td>
|
|
<td><a href="<%= link.url %>" target="_blank"><%= link.url %></a></td>
|
|
<td><%= link.description || '' %></td>
|
|
<td class="action-btns">
|
|
<button class="btn btn-sm btn-primary edit-link-btn" data-id="<%= link._id %>">编辑</button>
|
|
<button class="btn btn-sm btn-danger delete-link-btn" data-id="<%= link._id %>">删除</button>
|
|
</td>
|
|
</tr>
|
|
<% }); %>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- 分页组件 -->
|
|
<%- include('../../components/pagination', {
|
|
currentPage: pagination.currentPage,
|
|
totalPages: pagination.totalPages,
|
|
baseUrl: baseUrl,
|
|
query: query
|
|
}) %>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 添加链接模态框 -->
|
|
<div class="modal fade" id="addLinkModal" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">添加友情链接</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<form id="addLinkForm">
|
|
<div class="modal-body">
|
|
<div class="mb-3">
|
|
<label class="form-label">网站名称</label>
|
|
<input type="text" class="form-control" name="name" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">URL</label>
|
|
<input type="url" class="form-control" name="url" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">描述</label>
|
|
<textarea class="form-control" name="description" rows="3"></textarea>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">排序值</label>
|
|
<input type="number" class="form-control" name="order" value="0">
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
|
<button type="submit" class="btn btn-primary">保存</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// 添加友情链接
|
|
document.getElementById('addLinkForm').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
const formData = new FormData(this);
|
|
const data = {
|
|
name: formData.get('name'),
|
|
url: formData.get('url'),
|
|
description: formData.get('description'),
|
|
order: parseInt(formData.get('order')) || 0
|
|
};
|
|
|
|
fetch('/admin/links', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(data)
|
|
})
|
|
.then(response => response.json())
|
|
.then(result => {
|
|
if (result.success) {
|
|
alert('添加成功!');
|
|
location.reload();
|
|
} else {
|
|
alert('添加失败:' + result.message);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error(error);
|
|
alert('添加失败');
|
|
});
|
|
});
|
|
|
|
// 删除链接
|
|
document.querySelectorAll('.delete-link-btn').forEach(btn => {
|
|
btn.addEventListener('click', function() {
|
|
const linkId = this.getAttribute('data-id');
|
|
if (confirm('确定要删除这个链接吗?')) {
|
|
fetch(`/admin/links/${linkId}`, {
|
|
method: 'DELETE'
|
|
})
|
|
.then(response => response.json())
|
|
.then(result => {
|
|
if (result.success) {
|
|
alert('删除成功!');
|
|
location.reload();
|
|
} else {
|
|
alert('删除失败:' + result.message);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error(error);
|
|
alert('删除失败');
|
|
});
|
|
}
|
|
});
|
|
});
|
|
</script>
|