Commit 93961d3d authored by JoyJ's avatar JoyJ

fix: 瀑布流

parent 7d6208e6
...@@ -83,10 +83,12 @@ ...@@ -83,10 +83,12 @@
if (params.method == 'POST') msg.body = payload; if (params.method == 'POST') msg.body = payload;
if (params.headers) msg.headers = params.headers; if (params.headers) msg.headers = params.headers;
/*
if (lastSearchURL == url) { if (lastSearchURL == url) {
toast.push('搜索参数重复捏~'); toast.push('搜索参数重复捏~');
return; return;
} }
*/
lastSearchURL = url; lastSearchURL = url;
fetch(url, msg) fetch(url, msg)
...@@ -132,13 +134,7 @@ ...@@ -132,13 +134,7 @@
* @param data JSON数据 * @param data JSON数据
*/ */
function appendList(data) { function appendList(data) {
// List = [...List, ...data]; showList([...List, ...data]);
List = [];
// <!-- FIXME: 暂时以这种略微丑陋的方式做切换动画, 可能这就是唯一方案了 -->
setTimeout(() => {
List = [...List, ...data];
isSearching = false;
}, 400);
} }
let lastSearchFunc = null; let lastSearchFunc = null;
...@@ -146,8 +142,10 @@ ...@@ -146,8 +142,10 @@
let isSearching = false; let isSearching = false;
function continueLastSearch() { function continueLastSearch() {
console.log("continueLastSearch");
console.log("lastSearchFunc=" + lastSearchFunc.toString());
if (lastSearchFunc) { if (lastSearchFunc) {
lastSearchFunc(lastSearchParam); lastSearchFunc(lastSearchParam, limit, nextPage);
} }
} }
...@@ -170,10 +168,7 @@ ...@@ -170,10 +168,7 @@
if (process.env.APP_ENV === 'dev') console.log(tag, encodeURIComponent(tag)); if (process.env.APP_ENV === 'dev') console.log(tag, encodeURIComponent(tag));
createFetch(searchTagRequest(tag), data => { createFetch(searchTagRequest(tag), data => {
if (process.env.APP_ENV === 'dev') console.log(data); if (process.env.APP_ENV === 'dev') console.log(data);
if (page == 1) { page == 1 ? showList(data) : appendList(data);
showList(data);
}
isSearching = false;
}); });
nextPage++; nextPage++;
} }
...@@ -194,7 +189,11 @@ ...@@ -194,7 +189,11 @@
nextPage = page; nextPage = page;
} }
lastSearchFunc = searchCategory; 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++; nextPage++;
} }
...@@ -219,7 +218,7 @@ ...@@ -219,7 +218,7 @@
if (process.env.APP_ENV === 'dev') console.log('执行搜索:\t', title); if (process.env.APP_ENV === 'dev') console.log('执行搜索:\t', title);
createFetch(searchTextRequest(title), data => { createFetch(searchTextRequest(title), data => {
if (process.env.APP_ENV === 'dev') console.log(data); if (process.env.APP_ENV === 'dev') console.log(data);
page == 1 ? showList(data) : appendList(); page == 1 ? showList(data) : appendList(data);
}); });
nextPage++; nextPage++;
} }
...@@ -229,15 +228,19 @@ ...@@ -229,15 +228,19 @@
* 默认搜索 -> 暂时是全部搜索 * 默认搜索 -> 暂时是全部搜索
* TODO: 全局内容 30分钟 一次缓存在 localstorage 里 * TODO: 全局内容 30分钟 一次缓存在 localstorage 里
*/ */
export function searchDefault(_,pageLimit = 20, page = 1) { export function searchDefault(_, pageLimit = 20, page = 1) {
if (isSearching) {
return;
}
isSearching = true; isSearching = true;
isEnd = false; isEnd = false;
limit = pageLimit; limit = pageLimit;
nextPage = page; nextPage = page;
lastSearchFunc = searchDefault;
lastSearchParam = ""; lastSearchParam = "";
createFetch(getContentsRequest, data => { createFetch(getContentsRequest, data => {
if (process.env.APP_ENV === 'dev') console.log(data); if (process.env.APP_ENV === 'dev') console.log(data);
page == 1 ? showList(data) : appendList(); page == 1 ? showList(data) : appendList(data);
}); });
nextPage++; nextPage++;
} }
...@@ -289,11 +292,17 @@ ...@@ -289,11 +292,17 @@
} }
//拉动到页面底部则更新数据 //拉动到页面底部则更新数据
window.scroll(function () { window.addEventListener("scroll",() => {
//滚动到底部时 let scrollTop =document.documentElement.scrollTop ||document.body.scrollTop
if (window.scrollTop() + window.height() > document.height() - 1.0 && !isSearching) { 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(); 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