1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-10-10 01:35:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

添加分类搜索功能

This commit is contained in:
2022-03-16 00:09:35 +08:00
parent 174d24d5d0
commit 33f8dc4ea4
7 changed files with 144 additions and 30 deletions

View File

@@ -6,11 +6,56 @@
<body>
<%- include("./component/navbar.html"); %>
<main class="main">
<h1><%= title %></h1>
<!-- <h1><%= title %></h1> -->
<div id="container">
<!-- <a href="./book">书本详情页</a> -->
</div>
</main>
<%- include("./component/footer.html"); %>
<!-- 获取参数 -->
<script src="./assets/javascripts/getParams.js"></script>
<script>
var requestParams = getParams();
var searchbox = document.getElementById("searchInput");
var categoryId = Number(requestParams["id"]) ?? "";
if (categoryId === "") {
location.href = "/search";
}
</script>
<script>
getRequest("/category/get", { id: categoryId })
.then(function (response) {
var axiosData = response.data;
var status = axiosData.status;
var data = axiosData.data;
if (status === "success") {
console.log(data)
if (data.description == "")
data.description = "暂无描述";
var topCategory = data.parentId !== 0 ? `<a href="/category?id=${data.parentId}">上级分类</a>` : "";
document.getElementById("container").innerHTML = `
<div class="grid">
<div class="grid-item">
<h1>${data.name}</h1>
<p>分类ID: ${data.id}</p>
<p>${topCategory}</p>
</div>
<div class="grid-item">
<h2>简介</h2>
<p>${data.description}</p>
</div>
</div>`;
// 渲染后重新获取一次字体
fontmin(getPageText());
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
}).catch(function (error) {
console.log(error);
});
</script>
</body>
</html>