Skip to content

Let's use AI to Earn!

加分页组件 观察组件 下拉最低加载更多

DESKTOP-ZTS2NQJNA4557d95a7e86
diff --git a/electron/main/plat/platforms/xhs/index.ts b/electron/main/plat/platforms/xhs/index.ts
index 0749403b..f4a5ed82 100644
--- a/electron/main/plat/platforms/xhs/index.ts
+++ b/electron/main/plat/platforms/xhs/index.ts
@@ -142,8 +142,9 @@ export class Xhs extends PlatformBase {
* @returns
*/
async getsearchNodeList(account: AccountModel, qe?: string,pageInfo?:any) {
+ console.log('------ getsearchNodeList xhs pageInfo---', pageInfo);
const pageNo = pageInfo ? Number.parseInt(pageInfo.pcursor) : 0;
-
+ console.log('------ getsearchNodeList xhs pageNo---', pageNo);
const pageSize = 20;
const cookie: CookiesType = JSON.parse(account.loginCookie);
diff --git a/electron/plat/xiaohongshu/index.ts b/electron/plat/xiaohongshu/index.ts
index 64c74814..0d8dbeee 100644
--- a/electron/plat/xiaohongshu/index.ts
+++ b/electron/plat/xiaohongshu/index.ts
@@ -1379,9 +1379,10 @@ export class XiaohongshuService {
// 获取作品列表
async getSearchNodeList(cookie: string, qe: string, page: number = 0) {
const url = `/api/sns/web/v1/search/notes`;
+ console.log('------ getSearchNodeList --- asdadsda::', qe, page);
const body =
{"keyword":"猫咪",
- "page":1,
+ "page": page,
"page_size":20,
"search_id":"2em3pesjyckq6kdr2n6mt",
"sort":"general","note_type":0,"ext_flags":[],"geo":"",
diff --git a/package.json b/package.json
index 664ab560..4d9ccee4 100644
--- a/package.json
+++ b/package.json
@@ -61,6 +61,7 @@
"p-queue": "^8.1.0",
"path": "^0.12.7",
"qs": "^6.14.0",
+ "react-intersection-observer": "^9.16.0",
"react-masonry-css": "^1.0.16",
"react-router-dom": "6",
"react-sortablejs": "^6.1.4",
diff --git a/src/views/replyother/index.tsx b/src/views/replyother/index.tsx
index 7a976657..13b1cf43 100644
--- a/src/views/replyother/index.tsx
+++ b/src/views/replyother/index.tsx
@@ -34,6 +34,7 @@ import {
InputNumber,
Radio,
Tooltip,
+ Spin,
} from 'antd';
import { useCallback, useRef, useState, useEffect } from 'react';
import AccountSidebar from '../account/components/AccountSidebar/AccountSidebar';
@@ -59,6 +60,7 @@ import {
import Masonry from 'react-masonry-css';
import { AccountModel } from '../../../electron/db/models/account';
import WebView from '../../components/WebView';
+import { useInView } from 'react-intersection-observer';
export default function Page() {
const [wordList, setWordList] = useState<WorkData[]>([]);
@@ -81,10 +83,11 @@ export default function Page() {
const [pageInfo, setPageInfo] = useState<{
count: number;
hasMore: boolean;
- pcursor?: string;
+ pcursor?: any;
}>({
count: 0,
hasMore: false,
+ pcursor: 1,
});
// 创建 webview 的引用
@@ -138,6 +141,34 @@ export default function Page() {
// 添加任务弹窗状态
const [taskModalVisible, setTaskModalVisible] = useState(false);
+ // 添加加载状态
+ const [isLoadingMore, setIsLoadingMore] = useState(false);
+
+ // 使用 react-intersection-observer 创建一个观察器
+ const { ref: loadMoreRef, inView } = useInView({
+ threshold: 0.5, // 当元素50%可见时触发
+ triggerOnce: false // 允许多次触发
+ });
+
+ // 监听 inView 变化,当元素可见时加载更多
+ useEffect(() => {
+ if (inView && pageInfo.hasMore && !isLoadingMore) {
+ loadMorePosts();
+ }
+ }, [inView, pageInfo.hasMore, isLoadingMore]);
+
+ // 加载更多帖子
+ const loadMorePosts = async () => {
+ if (!pageInfo.hasMore || isLoadingMore) return;
+
+ setIsLoadingMore(true);
+ try {
+ await getSearchListFunc(activeAccountId, undefined);
+ } finally {
+ setIsLoadingMore(false);
+ }
+ };
+
// 提交任务
const submitTask = (values: any) => {
console.log('任务参数:', values);
@@ -196,14 +227,26 @@ export default function Page() {
// 搜索列表 - 平台自己搜索
- async function getSearchListFunc(thisid:any, qe?:any,pageInfo?:any) {
- setPostList([])
- const res = await getCommentSearchNotes(thisid,qe,pageInfo)
- console.log('------ getSearchListFunc', res)
- if(res.list.length){
- setPostList(res.list)
+ async function getSearchListFunc(thisid:any, qe?:any,) {
+ // 如果不是加载更多(没有传入 pageInfo),则清空现有列表
+ if (!pageInfo) {
+ setPostList([]);
}
+ console.log('------ getSearchListFunc pageInfo---@@: 1', pageInfo);
+ const res = await getCommentSearchNotes(thisid, qe, pageInfo);
+ console.log('------ getSearchListFunc', res);
+ if (res.list?.length) {
+ // 如果是加载更多,则追加到现有列表
+ setPostList(prev => pageInfo ? [...prev, ...res.list] : res.list);
+
+ // 更新分页信息
+ setPageInfo({
+ count: res.pageInfo.count || 0,
+ hasMore: res.pageInfo.hasMore || false,
+ pcursor: res.pageInfo.pcursor || ''
+ });
+ }
}
async function getFwqCreatorList() {
@@ -591,7 +634,7 @@ export default function Page() {
</div>
}
actions={[
- <Space onClick={() => likePost(item)}>
+ <Space key="like" onClick={() => likePost(item)}>
<LikeOutlined
style={{
color: likedPosts[item.noteId]
@@ -604,15 +647,15 @@ export default function Page() {
/>
<span>{item.likeCount || 0}</span>
</Space>,
- <Space onClick={() => showCommentModal(item)}>
+ <Space key="comment-list" onClick={() => showCommentModal(item)}>
<UnorderedListOutlined />
<span>{item.commentCount || 0}</span>
</Space>,
- <Space onClick={() => openReplyWorks(item)}>
+ <Space key="reply" onClick={() => openReplyWorks(item)}>
<CommentOutlined />
<span>评论</span>
</Space>,
- <Space onClick={() => collectPost(item)}>
+ <Space key="collect" onClick={() => collectPost(item)}>
<StarOutlined
style={{
color: collectedPosts[item.noteId]
@@ -649,6 +692,25 @@ export default function Page() {
</div>
))}
</Masonry>
+
+ {/* 替换原来的加载更多按钮为自动加载区域 */}
+ <div
+ ref={loadMoreRef}
+ className={styles.loadMoreArea}
+ >
+ {isLoadingMore && (
+ <div className={styles.loadingMore}>
+ <Spin size="small" />
+ <span style={{ marginLeft: 8 }}>加载中...</span>
+ </div>
+ )}
+
+ {!pageInfo.hasMore && postList.length > 0 && (
+ <div className={styles.noMoreData}>
+ <Divider plain>没有更多内容了</Divider>
+ </div>
+ )}
+ </div>
</div>
{/* </Col> */}
</div>
diff --git a/src/views/replyother/reply.module.scss b/src/views/replyother/reply.module.scss
index a357da5b..44958927 100644
--- a/src/views/replyother/reply.module.scss
+++ b/src/views/replyother/reply.module.scss
@@ -164,4 +164,32 @@
margin-bottom: 0;
}
}
+
+ // 添加自动加载区域样式
+ .loadMoreArea {
+ width: 100%;
+ padding: 16px 0;
+ min-height: 60px;
+ }
+
+ .loadingMore {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ color: #999;
+ font-size: 14px;
+ }
+
+ .noMoreData {
+ color: #999;
+ font-size: 14px;
+ text-align: center;
+
+ :global {
+ .ant-divider {
+ color: #999;
+ font-size: 14px;
+ }
+ }
+ }
}
\ No newline at end of file