151 lines
3.3 KiB
HTML
151 lines
3.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
<style>
|
|
body,
|
|
ul,
|
|
li {
|
|
margin: 0;
|
|
padding: 0;
|
|
list-style: none;
|
|
}
|
|
|
|
.title {
|
|
display: flex;
|
|
height: 40px;
|
|
align-items: center;
|
|
padding: 0 15px;
|
|
border-bottom: 1px solid #efefef;
|
|
}
|
|
|
|
.title li {
|
|
margin-right: 10px;
|
|
}
|
|
|
|
.title .active {
|
|
color: red;
|
|
}
|
|
|
|
.content ul {
|
|
display: none;
|
|
}
|
|
|
|
.content .active {
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<ul class="title">
|
|
|
|
</ul>
|
|
|
|
<div class="content">
|
|
|
|
</div>
|
|
|
|
</body>
|
|
<script src="./ajax.js"></script>
|
|
<script>
|
|
var index = 0;
|
|
var title = [
|
|
{ type: 1, title: '推荐', page: 1, total_page: 0, content: [] },
|
|
{ type: 2, title: '时令', page: 1, total_page: 0, content: [] },
|
|
{ type: 3, title: '食肉', page: 1, total_page: 0, content: [] },
|
|
{ type: 4, title: '素食', page: 1, total_page: 0, content: [] },
|
|
{ type: 5, title: '烘焙', page: 1, total_page: 0, content: [] },
|
|
];
|
|
|
|
|
|
// 渲染tabs切换的标题
|
|
function renderTitle() {
|
|
title.forEach((v, i) => {
|
|
$(".title").innerHTML += `
|
|
<li class="${i == 0 ? 'active' : ''}">${v.title}</li>
|
|
`;
|
|
|
|
$(".content").innerHTML += `
|
|
<ul class="${i == 0 ? 'active' : ''}">
|
|
|
|
</ul>
|
|
`
|
|
});
|
|
|
|
_(".title li").forEach((v, i) => {
|
|
v.onclick = () => {
|
|
_(".title li").forEach((item, index) => {
|
|
item.classList.remove("active");
|
|
_(".content ul")[index].classList.remove("active")
|
|
})
|
|
|
|
v.classList.add("active")
|
|
_(".content ul")[i].classList.add("active")
|
|
|
|
index = i;
|
|
getList();
|
|
}
|
|
});
|
|
|
|
// 默认调用接口获取 推荐 的数据
|
|
getList();
|
|
|
|
}
|
|
|
|
|
|
function getList() {
|
|
if (title[index].content.length == 0) {
|
|
http.get({
|
|
url: '/index/class',
|
|
data: {
|
|
type: title[index].type,
|
|
page: title[index].page
|
|
},
|
|
success: (res) => {
|
|
var data = res.result;
|
|
title[index].total_page = data.total_page;
|
|
title[index].content = title[index].content.concat(data.items);
|
|
();
|
|
},
|
|
error: (err) => { }
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
function renderContentLi() {
|
|
title[index].content.forEach((v, i) => {
|
|
_(".content ul")[index].innerHTML += `
|
|
<li>
|
|
<p>${v.title}</p>
|
|
</li>
|
|
`
|
|
})
|
|
}
|
|
|
|
|
|
renderTitle();
|
|
|
|
|
|
|
|
|
|
// 获取单个标签
|
|
function $(className) {
|
|
return document.querySelector(className)
|
|
}
|
|
|
|
// 获取多个标签
|
|
function _(className) {
|
|
return document.querySelectorAll(className)
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
</html> |