Commit 034ad257 authored by KesaubeEire's avatar KesaubeEire

fix: 翻页的各种问题, 真的是屎山...

parent 165eb7f8
...@@ -115,9 +115,10 @@ ...@@ -115,9 +115,10 @@
/**创建请求底层 fetch 函数 /**创建请求底层 fetch 函数
* @param {object} param0 参数对象 * @param {object} param0 参数对象
* @param {function} callback 回调函数 * @param {function} successCallBack 成功回调函数
* @param {function} failCallBack 失败回调函数
*/ */
function createFetch({ url, params, payload }, callback = () => {}) { function createFetch({ url, params, payload }, successCallBack = () => {}, failCallBack = () => {}) {
const msg = { const msg = {
method: params.method, method: params.method,
headers: { headers: {
...@@ -133,6 +134,7 @@ ...@@ -133,6 +134,7 @@
isSearching = false; isSearching = false;
if (!isEnd) toast.push('搜索参数重复捏~'); if (!isEnd) toast.push('搜索参数重复捏~');
if (process.env.APP_ENV === 'dev') console.log(lastSearchURL, url); if (process.env.APP_ENV === 'dev') console.log(lastSearchURL, url);
failCallBack();
return; return;
} }
lastSearchURL = url; lastSearchURL = url;
...@@ -143,12 +145,13 @@ ...@@ -143,12 +145,13 @@
// console.log(data); // console.log(data);
// 处理数据 // 处理数据
callback(data); successCallBack(data);
}) })
.catch(error => { .catch(error => {
// 处理错误 // 处理错误
console.error('网络请求错误:', error); console.error('网络请求错误:', error);
toast.push('网络请求错误'); toast.push('网络请求错误');
failCallBack();
}) })
.finally(() => { .finally(() => {
isSearching = false; isSearching = false;
...@@ -160,8 +163,9 @@ ...@@ -160,8 +163,9 @@
* @param searchParam * @param searchParam
* @param limit * @param limit
* @param page * @param page
* @param {function} failFunction 失败的回调函数
*/ */
function performSearch(searchType, searchParam, limit = 20, page = 1) { function performSearch(searchType, searchParam, limit = 20, page = 1, failFunction = () => {}) {
// 瀑布流请求中不能重复请求 // 瀑布流请求中不能重复请求
if (isSearching) { if (isSearching) {
return; return;
...@@ -195,33 +199,40 @@ ...@@ -195,33 +199,40 @@
if (process.env.APP_ENV === 'dev') console.log(requestType(searchParam)); if (process.env.APP_ENV === 'dev') console.log(requestType(searchParam));
createFetch(requestType(searchParam), data => { createFetch(
if (process.env.APP_ENV === 'dev') console.log(data); requestType(searchParam),
data => {
if (data.length != 0) { if (process.env.APP_ENV === 'dev') console.log(data);
page == 1 ? showList(data) : appendList(data);
} else { if (data.length != 0) {
toast.push('没有搜索到数据捏~'); page == 1 ? showList(data) : appendList(data);
return; } else {
} toast.push('没有搜索到数据捏~');
return;
if (data.length < globalPageLimit) { }
console.log(data.length);
if (data.length < globalPageLimit) {
if (sameSearch) isEnd = true; console.log(data.length);
toast.push('加载完成了捏~');
if (sameSearch) isEnd = true;
return; toast.push('加载完成了捏~');
}
return;
nextPage++; }
// console.log(nextPage);
}); let current = nextPage;
nextPage++;
console.log('current:\t', current, '\t\tnextPage:\t', nextPage);
},
failFunction
);
} }
/**瀑布流: 延续参数继续搜索下一页*/ /**瀑布流: 延续参数继续搜索下一页*/
function continueLastSearch() { function continueLastSearch() {
// console.log(nextPage);
performSearch(lastSearchType, lastSearchParam, globalPageLimit, nextPage); performSearch(lastSearchType, lastSearchParam, globalPageLimit, nextPage);
console.log('--------- TurnPage ---------');
} }
// ----------------------------- // -----------------------------
...@@ -254,7 +265,10 @@ ...@@ -254,7 +265,10 @@
* TODO: 全局内容 30分钟 一次缓存在 localstorage 里 * TODO: 全局内容 30分钟 一次缓存在 localstorage 里
*/ */
export function searchDefault(limit = globalPageLimit, page = 1) { export function searchDefault(limit = globalPageLimit, page = 1) {
performSearch('', '', limit, page); nextPage = 1;
performSearch('', '', limit, page, () => {
nextPage = 2;
});
} }
/**拉取静态资源: Category */ /**拉取静态资源: Category */
...@@ -373,7 +387,7 @@ ...@@ -373,7 +387,7 @@
let pc_debounced = clientHeight > 0 && scrollTop > 0 && scrollTop + clientHeight > scrollHeight - distance; let pc_debounced = clientHeight > 0 && scrollTop > 0 && scrollTop + clientHeight > scrollHeight - distance;
let phone_debounced = window.scrollY + window.innerHeight >= document.documentElement.scrollHeight - distance; let phone_debounced = window.scrollY + window.innerHeight >= document.documentElement.scrollHeight - distance;
if (pc_debounced || phone_debounced) { if ((pc_debounced || phone_debounced) && nextPage != 1 && List.length) {
// toast.push(pc_debounced ? 'pc' : 'phone'); // toast.push(pc_debounced ? 'pc' : 'phone');
debouncedContinue(); debouncedContinue();
} }
......
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