class Home { constructor() { this.TabsDatas = []; this.list = []; this.PageSwiper = null; this.CurrentPage = 0; // 点击搜索进入搜索页面 document.querySelector(".search").onclick = () => { location.href = "./search.html" } // 通过在本地保存一个变量 homeIndex,记录用户在首页当前浏览到哪个分类, // 然后从其他页面回首页,那么根据本地变量 homeIndex 的数值,再回到上次浏览的分类 if (localStorage.getItem("homeIndex") != null) { this.CurrentPage = localStorage.getItem("homeIndex") } this.GetTypeData().then(() => this.GetIndexData()) } // 获取分类的数据,并渲染页面 async GetTypeData() { if (localStorage.getItem("typeList") == null) { // 获取分类数据 this.list = (await homeService.type({})).principal; localStorage.setItem("typeList", JSON.stringify(this.list)) } else { this.list = JSON.parse(localStorage.getItem("typeList")) } console.log("this.list ============== :", this.list); // 根据分类的数组长度遍历生成与分类对应的内容 this.list.forEach((v, i) => { this.TabsDatas.push({ id: v.id, title: v.title, page: 0, TotalPage: 0, content: [] }) document.querySelector(".s-wrapper").innerHTML += `
` }); // 为每一个内容绑定滚动事件 var slide = document.querySelectorAll(".s-wrapper .s-slide"); var self = this; slide.forEach((v, i) => { if (i > 0) { v.addEventListener('scroll', function () { if (Math.ceil(this.scrollHeight - this.scrollTop) == this.clientHeight) { self.TabsDatas[i - 1].page += 1; if (self.TabsDatas[i - 1].page <= self.TabsDatas[i - 1].TotalPage) { self.GetTypeInfoData(i) } } }) } }) // 向数据中追加首页 this.list.unshift({ id: -1, title: '首页' }); // 根据数据生成横向菜单 var MenuList = document.querySelector(".menu_list"); this.list.forEach((v, i) => { MenuList.innerHTML += `