Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
rrpgLink_FrontEnd
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kesaubeeire
rrpgLink_FrontEnd
Commits
034ad257
Commit
034ad257
authored
Oct 31, 2023
by
KesaubeEire
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 翻页的各种问题, 真的是屎山...
parent
165eb7f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
28 deletions
+42
-28
src/Content.svelte
src/Content.svelte
+42
-28
No files found.
src/Content.svelte
View file @
034ad257
...
@@ -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 },
callb
ack = () => {}) {
function createFetch({ url, params, payload },
successCallBack = () => {}, failCallB
ack = () => {}) {
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);
// 处理数据
// 处理数据
callb
ack(data);
successCallB
ack(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();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment