document.addEventListener('DOMContentLoaded', () => { let isLoading = false; let queryData = { cid: -999, start: -999, count: 30 }; let total = -999; $.ajax({ url: Joe.BASE_API, type: 'POST', data: { routeType: 'wallpaper_type' }, success(res) { if (res.code !== 1) return $('.joe_wallpaper__type-list').html('
  • 壁纸抓取失败!请联系作者!
  • '); if (!res.data.length) return $('.joe_wallpaper__type-list').html(`
  • 暂无数据!
  • `); let htmlStr = ''; res.data.forEach(_ => (htmlStr += `
  • ${_.name}
  • `)); $('.joe_wallpaper__type-list').html(htmlStr); $('.joe_wallpaper__type-list .item').first().click(); } }); $('.joe_wallpaper__type-list').on('click', '.item', function () { const cid = $(this).attr('data-cid'); if (queryData.cid === cid || isLoading) return; window.scrollTo({ top: 0, behavior: 'smooth' }); $(this).addClass('active').siblings().removeClass('active'); queryData.cid = cid; queryData.start = 0; renderDom(); }); function renderDom() { $('.joe_wallpaper__list').html(''); isLoading = true; $.ajax({ url: Joe.BASE_API, type: 'POST', data: { routeType: 'wallpaper_list', cid: queryData.cid, start: queryData.start, count: queryData.count }, success(res) { if (res.code !== 1) return; let htmlStr = ''; res.data.forEach(_ => { htmlStr += `壁纸`; }); $('.joe_wallpaper__list').html(htmlStr); new LazyLoad('.wallpaper_lazyload'); total = res.total; initPagination(); }, complete: () => (isLoading = false) }); } function initPagination() { let htmlStr = ''; if (queryData.start / queryData.count !== 0) { htmlStr += `
  • 首页
  • ${Math.ceil(queryData.start / queryData.count)}
  • `; } htmlStr += `
  • ${Math.ceil(queryData.start / queryData.count) + 1}
  • `; if (queryData.start != total - queryData.count) { htmlStr += `
  • ${Math.ceil(queryData.start / queryData.count) + 2}
  • `; } if (queryData.start < total - queryData.count) htmlStr += `
  • 末页
  • `; $('.joe_wallpaper__pagination').html(htmlStr); } $('.joe_wallpaper__pagination').on('click', '.joe_wallpaper__pagination-item', function () { const start = $(this).attr('data-start'); if (!start || isLoading) return; window.scrollTo({ top: 0, behavior: 'smooth' }); queryData.start = Number(start); renderDom(); }); });