Commit 93961d3d authored by JoyJ's avatar JoyJ

fix: 瀑布流

parent 7d6208e6
......@@ -83,10 +83,12 @@
if (params.method == 'POST') msg.body = payload;
if (params.headers) msg.headers = params.headers;
/*
if (lastSearchURL == url) {
toast.push('搜索参数重复捏~');
return;
}
*/
lastSearchURL = url;
fetch(url, msg)
......@@ -132,13 +134,7 @@
* @param data JSON数据
*/
function appendList(data) {
// List = [...List, ...data];
List = [];
// <!-- FIXME: 暂时以这种略微丑陋的方式做切换动画, 可能这就是唯一方案了 -->
setTimeout(() => {
List = [...List, ...data];
isSearching = false;
}, 400);
showList([...List, ...data]);
}
let lastSearchFunc = null;
......@@ -146,8 +142,10 @@
let isSearching = false;
function continueLastSearch() {
console.log("continueLastSearch");
console.log("lastSearchFunc=" + lastSearchFunc.toString());
if (lastSearchFunc) {
lastSearchFunc(lastSearchParam);
lastSearchFunc(lastSearchParam, limit, nextPage);
}
}
......@@ -170,10 +168,7 @@
if (process.env.APP_ENV === 'dev') console.log(tag, encodeURIComponent(tag));
createFetch(searchTagRequest(tag), data => {
if (process.env.APP_ENV === 'dev') console.log(data);
if (page == 1) {
showList(data);
}
isSearching = false;
page == 1 ? showList(data) : appendList(data);
});
nextPage++;
}
......@@ -194,7 +189,11 @@
nextPage = page;
}
lastSearchFunc = searchCategory;
if (process.env.APP_ENV === 'dev') console.log(category);
if (process.env.APP_ENV === 'dev') console.log('执行搜索:\t', category);
createFetch(searchCategoryRequest(title), data => {
if (process.env.APP_ENV === 'dev') console.log(data);
page == 1 ? showList(data) : appendList(data);
});
nextPage++;
}
......@@ -219,7 +218,7 @@
if (process.env.APP_ENV === 'dev') console.log('执行搜索:\t', title);
createFetch(searchTextRequest(title), data => {
if (process.env.APP_ENV === 'dev') console.log(data);
page == 1 ? showList(data) : appendList();
page == 1 ? showList(data) : appendList(data);
});
nextPage++;
}
......@@ -229,15 +228,19 @@
* 默认搜索 -> 暂时是全部搜索
* TODO: 全局内容 30分钟 一次缓存在 localstorage 里
*/
export function searchDefault(_,pageLimit = 20, page = 1) {
export function searchDefault(_, pageLimit = 20, page = 1) {
if (isSearching) {
return;
}
isSearching = true;
isEnd = false;
limit = pageLimit;
nextPage = page;
lastSearchFunc = searchDefault;
lastSearchParam = "";
createFetch(getContentsRequest, data => {
if (process.env.APP_ENV === 'dev') console.log(data);
page == 1 ? showList(data) : appendList();
page == 1 ? showList(data) : appendList(data);
});
nextPage++;
}
......@@ -289,11 +292,17 @@
}
//拉动到页面底部则更新数据
window.scroll(function () {
//滚动到底部时
if (window.scrollTop() + window.height() > document.height() - 1.0 && !isSearching) {
window.addEventListener("scroll",() => {
let scrollTop =document.documentElement.scrollTop ||document.body.scrollTop
let clientHeight =document.documentElement.clientHeight ||document.body.clientHeight
let scrollHeight =document.documentElement.scrollHeight ||document.body.scrollHeight
console.log('scrolled, top=' + scrollTop.toString());
console.log('scrolled, ch=' + clientHeight.toString());
console.log('scrolled, top+ch=' + (scrollTop +clientHeight).toString());
console.log('scrolled, sh=' + scrollHeight.toString());
if ((clientHeight >0 &&scrollTop >0) && (scrollTop +clientHeight > scrollHeight - 10.0)) {
//page+1重复上次搜索
continueLastSearch();
//具体数据操作
}
});
// 初始化请求 -> 拉取全部条目
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment