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
d73aedd9
Commit
d73aedd9
authored
Oct 22, 2023
by
JoyJ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 瀑布流;整合search
parent
d51c7c48
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
81 deletions
+53
-81
src/Content.svelte
src/Content.svelte
+53
-81
No files found.
src/Content.svelte
View file @
d73aedd9
...
...
@@ -4,10 +4,14 @@
import { _category, _detailWindow, _env, _tagTrans } from './stores';
import { fade } from 'svelte/transition';
function debugMessage(...str) {
if (process.env.APP_ENV === 'dev') console.log(...str);
}
//NextPage指示瀑布流下次应请求的页码数
let nextPage = 1;
//NextPage指示瀑布流下次应请求的limit数
let
l
imit = 20;
let
globalPageL
imit = 20;
//若isEnd(已经没有新的结果了)则滚动到最底不再请求下一页的数据
let isEnd = false;
...
...
@@ -27,19 +31,20 @@
};
/**请求封装头 -> 获取所有资料*/
const getContentsRequest = {
url: `${$_env}/query.php?action=get&limit=${limit}&page=${nextPage}`,
params: { method: 'GET' }
const getContentsRequest = _ => {
return {
url: `${$_env}/query.php?action=get&limit=${globalPageLimit}&page=${nextPage}`,
params: { method: 'GET' }
};
};
/**请求封装头 -> 搜索对应 Tag (函数形式)
* @param {string} tag TAG
* @return {object} 请求封装对象
*/
const searchTagRequest = tag => {
return {
url: `${$_env}/query.php?action=get&limit=${
l
imit}&page=${nextPage}&tag=${encodeURIComponent(tag)}`,
url: `${$_env}/query.php?action=get&limit=${
globalPageL
imit}&page=${nextPage}&tag=${encodeURIComponent(tag)}`,
params: { method: 'GET' }
};
};
...
...
@@ -50,7 +55,7 @@
*/
const searchCategoryRequest = category => {
return {
url: `${$_env}/query.php?action=get&limit=${
l
imit}&page=${nextPage}&category=${category}`,
url: `${$_env}/query.php?action=get&limit=${
globalPageL
imit}&page=${nextPage}&category=${category}`,
params: { method: 'GET' }
};
};
...
...
@@ -61,7 +66,7 @@
*/
const searchTextRequest = text => {
return {
url: `${$_env}/query.php?action=get&limit=${
l
imit}&page=${nextPage}&search=${encodeURIComponent(text)}`,
url: `${$_env}/query.php?action=get&limit=${
globalPageL
imit}&page=${nextPage}&search=${encodeURIComponent(text)}`,
params: { method: 'GET' }
};
};
...
...
@@ -97,7 +102,7 @@
// console.log(data);
if (!data.length) {
isEnd = true;
toast.push('没有
搜索到东西
捏~');
toast.push('没有
更多数据了
捏~');
return;
}
...
...
@@ -138,61 +143,58 @@
}
let lastSearchFunc = null;
let lastSearchType = '';
let lastSearchParam = null;
let isSearching = false;
function continueLastSearch() {
if (lastSearchFunc) {
lastSearchFunc(lastSearchParam, limit, nextPage);
}
performSearch(lastSearchType, lastSearchParam, globalPageLimit, nextPage);
}
/**根据 TAG 搜索游戏
* @param {string} tag TAG
*/
function searchTag(tag, pageLimit = 20, page = 1) {
function performSearch(searchType, searchParam, limit = 20, page = 1) {
if (isSearching) {
return;
}
isSearching = true;
isEnd = false;
limit = pageLimit;
nextPage = page;
lastSearchParam = tag;
if (page > 0) {
nextPage = page;
globalPageLimit = limit;
nextPage = page + 1;
lastSearchType = searchType;
lastSearchParam = searchParam;
let requestType = getContentsRequest;
switch(searchType) {
case 'category':
requestType = searchCategoryRequest;
break;
case 'tag':
requestType = searchTagRequest;
break;
case 'title':
requestType = searchTextRequest;
break;
}
lastSearchFunc = searchTag;
if (process.env.APP_ENV === 'dev') console.log(tag, encodeURIComponent(tag));
createFetch(searchTagRequest(tag), data => {
if (process.env.APP_ENV === 'dev') console.log(data);
createFetch(requestType(searchParam), data => {
debugMessage(data);
page == 1 ? showList(data) : appendList(data);
});
nextPage++;
}
/**根据 TAG 搜索游戏
* @param {string} tag TAG
*/
function searchTag(tag, limit = 20, page = 1) {
performSearch('tag', tag, limit, page);
}
/**根据 category 搜索游戏
* @param {string} category category
*/
function searchCategory(category, pageLimit = 20, page = 1) {
if (isSearching) {
return;
}
isSearching = true;
isEnd = false;
limit = pageLimit;
nextPage = page;
lastSearchParam = category;
if (page > 0) {
nextPage = page;
}
lastSearchFunc = searchCategory;
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++;
function searchCategory(category, limit = 20, page = 1) {
performSearch('category', category, limit, page);
}
/**@var {string} 上次搜索内容*/
...
...
@@ -200,25 +202,8 @@
/**根据 title 搜索游戏
* @param {string} title 名称
*/
export function searchTitle(title, pageLimit = 20, page = 1) {
if (isSearching) {
return;
}
isSearching = true;
isEnd = false;
limit = pageLimit;
nextPage = page;
lastSearchParam = title;
if (page > 0) {
nextPage = page;
}
lastSearchFunc = searchTitle;
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(data);
});
nextPage++;
export function searchTitle(title, limit = 20, page = 1) {
performSearch('title', title, limit, page);
}
window.searchTitle = searchTitle;
...
...
@@ -226,21 +211,8 @@
* 默认搜索 -> 暂时是全部搜索
* TODO: 全局内容 30分钟 一次缓存在 localstorage 里
*/
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(data);
});
nextPage++;
export function searchDefault(_, limit = 20, page = 1) {
performSearch('', '' , limit, page);
}
/**获取封面图
...
...
@@ -262,7 +234,7 @@
/**关闭详情*/
function key_closePanels(event) {
if (event.key === 'Escape') {
console.log
(event);
debugMessage
(event);
// $_iframe_switch = 0;
// $_show_configPanel = false;
$_detailWindow = false;
...
...
@@ -275,7 +247,7 @@
// TODO: 搞个记时, 每天一刷 & 做一个主动更新的按钮
if (!$_category.length) {
createFetch(getLanguageCategory, data => {
if (process.env.APP_ENV === 'dev') console.log
(data);
debugMessage
(data);
$_category = data;
});
}
...
...
@@ -284,7 +256,7 @@
// TODO: 搞个记时, 每天一刷 & 做一个主动更新的按钮
if (!$_tagTrans.length) {
createFetch(getTranslatedTag, data => {
if (process.env.APP_ENV === 'dev') console.log
(data);
debugMessage
(data);
$_tagTrans = data;
});
}
...
...
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