142 lines
3.4 KiB
JavaScript
142 lines
3.4 KiB
JavaScript
class Index {
|
|
constructor() {
|
|
this.currentIndex = 0;
|
|
this.classData = []
|
|
this.geIndex();
|
|
this.GetType();
|
|
footer()
|
|
|
|
|
|
lui.scrollToBottom('.swiper-slide-active',function(){
|
|
console.log("11")
|
|
})
|
|
}
|
|
|
|
async GetType() {
|
|
var principal = [], additional = []
|
|
if (localStorage.getItem("principal") == null) {
|
|
let res = await indexServe.type();
|
|
principal = res.principal
|
|
additional = res.additional
|
|
localStorage.setItem("principal", JSON.stringify(principal))
|
|
localStorage.setItem("additional", JSON.stringify(additional))
|
|
|
|
} else {
|
|
principal = get_storage("principal")
|
|
additional = get_storage("additional")
|
|
}
|
|
|
|
var self = this;
|
|
principal.unshift({
|
|
title: '首页',
|
|
id: -1,
|
|
page: 0,
|
|
content: []
|
|
})
|
|
|
|
this.classData = principal
|
|
|
|
principal.forEach((v,i) => {
|
|
$(".header_menu ul").append(`
|
|
<li class="${i == 0 ? 'active': ''}">${v.title}</li>
|
|
`)
|
|
|
|
if (i > 0) {
|
|
$(".page-wrapper").append(`
|
|
<div class="swiper-slide eee list_fa padding_16 top"></div>
|
|
`)
|
|
}
|
|
});
|
|
|
|
|
|
var page = new Swiper ('.page-container', {
|
|
direction: 'horizontal',
|
|
on:{
|
|
slideChange: function (){
|
|
self.currentIndex = this.activeIndex;
|
|
$(".header_menu ul li").eq(this.activeIndex).addClass("active").siblings().removeClass("active")
|
|
self.getClassList();
|
|
},
|
|
},
|
|
})
|
|
|
|
|
|
|
|
$(".header_menu ul li").click(function () {
|
|
self.currentIndex = $(this).index()
|
|
$(this).addClass("active").siblings().removeClass("active")
|
|
page.slideTo($(this).index())
|
|
})
|
|
|
|
}
|
|
|
|
|
|
async getClassList() {
|
|
if (this.classData[this.currentIndex].id != -1) {
|
|
if (this.classData[this.currentIndex].content.length == 0) {
|
|
let res = await indexServe.classList({
|
|
page: this.classData[this.currentIndex].page,
|
|
id: this.classData[this.currentIndex].id
|
|
});
|
|
|
|
this.classData[this.currentIndex].total_page = res.total_page
|
|
this.classData[this.currentIndex].content = [
|
|
...this.classData[this.currentIndex].content,
|
|
...res.data
|
|
]
|
|
|
|
item($(".page-wrapper .eee").eq(this.currentIndex -1),
|
|
this.classData[this.currentIndex].content)
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
async geIndex() {
|
|
let data = await indexServe.index()
|
|
console.log(data)
|
|
|
|
|
|
var modelArr = [ { content: [] }, { content: [] } ]
|
|
|
|
data.model.res.forEach((v,i) => {
|
|
if (i<4) {
|
|
modelArr[0].content.push(v)
|
|
} else {
|
|
modelArr[1].content.push(v)
|
|
}
|
|
})
|
|
|
|
modelArr.forEach(v=> {
|
|
$(".model-wrapper").append(`
|
|
<ul class="swiper-slide">
|
|
${
|
|
v.content.map(item => {
|
|
return ` <li>
|
|
<a href="">
|
|
<div class="top">
|
|
<img src="${item.preview}" alt="">
|
|
<span>${item.total}</span>
|
|
</div>
|
|
<p>${item.title}</p>
|
|
</a>
|
|
</li>`
|
|
}).toString().replaceAll(",","")
|
|
}
|
|
</ul>
|
|
`)
|
|
})
|
|
|
|
item(".news", data.newest.data)
|
|
item(".remm", data.recommended.data)
|
|
|
|
|
|
new Swiper ('.model-container', {
|
|
direction: 'horizontal',
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
new Index() |