Jony/assets/js/joe.wallpaper.js

87 lines
5.5 KiB
JavaScript
Raw Normal View History

2021-01-28 11:30:39 +00:00
document.addEventListener('DOMContentLoaded', () => {
2021-02-03 06:24:58 +00:00
let isLoading = false;
2021-03-01 14:35:10 +00:00
let queryData = { cid: -999, start: -999, count: 48 };
2021-02-03 06:24:58 +00:00
let total = -999;
$.ajax({
url: Joe.BASE_API,
type: 'POST',
2021-03-26 07:27:06 +00:00
dataType: 'json',
2021-02-03 06:24:58 +00:00
data: { routeType: 'wallpaper_type' },
success(res) {
if (res.code !== 1) return $('.joe_wallpaper__type-list').html('<li class="error">壁纸抓取失败!请联系作者!</li>');
if (!res.data.length) return $('.joe_wallpaper__type-list').html(`<li class="error">暂无数据!</li>`);
let htmlStr = '';
res.data.forEach(_ => (htmlStr += `<li class="item animated swing" data-cid="${_.id}">${_.name}</li>`));
$('.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');
2021-02-04 12:17:05 +00:00
if (isLoading) return;
2021-02-03 06:24:58 +00:00
$(this).addClass('active').siblings().removeClass('active');
queryData.cid = cid;
queryData.start = 0;
renderDom();
});
function renderDom() {
2021-03-01 14:35:10 +00:00
window.scrollTo({ top: 0, behavior: 'smooth' });
2021-02-03 06:24:58 +00:00
$('.joe_wallpaper__list').html('');
isLoading = true;
$.ajax({
url: Joe.BASE_API,
type: 'POST',
2021-03-26 07:27:06 +00:00
dataType: 'json',
2021-02-03 06:24:58 +00:00
data: {
routeType: 'wallpaper_list',
cid: queryData.cid,
start: queryData.start,
count: queryData.count
},
success(res) {
2021-03-01 14:35:10 +00:00
if (res.code !== 1) return (isLoading = false);
isLoading = false;
2021-02-03 06:24:58 +00:00
let htmlStr = '';
res.data.forEach(_ => {
2021-02-10 03:39:20 +00:00
htmlStr += `
<a class="item animated bounceIn" data-fancybox="gallery" href="${_.url}">
2021-04-01 02:19:27 +00:00
<img width="100%" height="100%" class="lazyload" src="${Joe.LAZY_LOAD}" data-src="${_.img_1024_768 || _.url}" onerror="javascript: this.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='" alt="壁纸">
2021-02-10 03:39:20 +00:00
</a>`;
2021-02-03 06:24:58 +00:00
});
$('.joe_wallpaper__list').html(htmlStr);
total = res.total;
initPagination();
2021-03-01 14:35:10 +00:00
}
2021-02-03 06:24:58 +00:00
});
}
function initPagination() {
let htmlStr = '';
if (queryData.start / queryData.count !== 0) {
htmlStr += `
2021-01-30 07:04:20 +00:00
<li class="joe_wallpaper__pagination-item" data-start="0">首页</li>
<li class="joe_wallpaper__pagination-item" data-start="${queryData.start - queryData.count}">
2021-03-01 14:35:10 +00:00
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="12" height="12"><path d="M822.272 146.944l-396.8 396.8c-19.456 19.456-51.2 19.456-70.656 0-18.944-19.456-18.944-51.2 0-70.656l396.8-396.8c19.456-19.456 51.2-19.456 70.656 0 18.944 19.456 18.944 45.056 0 70.656z"/><path d="M745.472 940.544l-396.8-396.8c-19.456-19.456-19.456-51.2 0-70.656 19.456-19.456 51.2-19.456 70.656 0l403.456 390.144c19.456 25.6 19.456 51.2 0 76.8-26.112 19.968-51.712 19.968-77.312.512zm-564.224-63.488c0-3.584 0-7.68.512-11.264h-.512v-714.24h.512c-.512-3.584-.512-7.168-.512-11.264 0-43.008 21.504-78.336 48.128-78.336s48.128 34.816 48.128 78.336c0 3.584 0 7.68-.512 11.264h.512v714.24h-.512c.512 3.584.512 7.168.512 11.264 0 43.008-21.504 78.336-48.128 78.336s-48.128-35.328-48.128-78.336z"/></svg>
2021-01-30 07:04:20 +00:00
</li>
<li class="joe_wallpaper__pagination-item" data-start="${queryData.start - queryData.count}">${Math.ceil(queryData.start / queryData.count)}</li>
2021-02-03 06:24:58 +00:00
`;
}
htmlStr += `<li class="joe_wallpaper__pagination-item active">${Math.ceil(queryData.start / queryData.count) + 1}</li>`;
if (queryData.start != total - queryData.count) {
htmlStr += `
2021-01-30 07:04:20 +00:00
<li class="joe_wallpaper__pagination-item" data-start="${queryData.start + queryData.count}">${Math.ceil(queryData.start / queryData.count) + 2}</li>
<li class="joe_wallpaper__pagination-item" data-start="${queryData.start + queryData.count}">
2021-03-01 14:35:10 +00:00
<svg class="next" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="12" height="12"><path d="M822.272 146.944l-396.8 396.8c-19.456 19.456-51.2 19.456-70.656 0-18.944-19.456-18.944-51.2 0-70.656l396.8-396.8c19.456-19.456 51.2-19.456 70.656 0 18.944 19.456 18.944 45.056 0 70.656z"/><path d="M745.472 940.544l-396.8-396.8c-19.456-19.456-19.456-51.2 0-70.656 19.456-19.456 51.2-19.456 70.656 0l403.456 390.144c19.456 25.6 19.456 51.2 0 76.8-26.112 19.968-51.712 19.968-77.312.512zm-564.224-63.488c0-3.584 0-7.68.512-11.264h-.512v-714.24h.512c-.512-3.584-.512-7.168-.512-11.264 0-43.008 21.504-78.336 48.128-78.336s48.128 34.816 48.128 78.336c0 3.584 0 7.68-.512 11.264h.512v714.24h-.512c.512 3.584.512 7.168.512 11.264 0 43.008-21.504 78.336-48.128 78.336s-48.128-35.328-48.128-78.336z"/></svg>
2021-01-30 07:04:20 +00:00
</li>
2021-02-03 06:24:58 +00:00
`;
}
if (queryData.start < total - queryData.count) htmlStr += `<li class="joe_wallpaper__pagination-item" data-start="${total - queryData.count}">末页</li>`;
$('.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;
queryData.start = Number(start);
renderDom();
});
});