ith5 4 months ago
parent
commit
19a6b1c0c6

+ 15 - 1
config/dev.ts

@@ -4,5 +4,19 @@ module.exports = {
   },
   defineConstants: {},
   mini: {},
-  h5: {},
+  h5: {
+    devServer: {
+      port: 10086,
+      host: "localhost",
+      proxy: {
+        "/api": {
+          target: "http://127.0.0.1:8181",
+          changeOrigin: true,
+          pathRewrite: {
+            "^/api": "",
+          },
+        },
+      },
+    },
+  },
 };

+ 1 - 1
src/components/comment-list/item.tsx

@@ -29,7 +29,7 @@ const CommentListItem = ({ commentData, isChild = false }) => {
                 }}
               >
                 <View className="flex items-center mr-[20rpx]">
-                  <View className="w-[70rpx] h-[70rpx] rounded-[50%] bg-[#000] overflow-hidden bg-[url('https://m.360buyimg.com/mobilecms/s750x366_jfs/t1/26597/30/4870/174583/5c35c5d2Ed55eedc6/50e27870c25e7a82.png')] bg-cover bg-center"></View>
+                  <View className="w-[35px] h-[35px] rounded-[50%] bg-[#000] overflow-hidden bg-[url('https://m.360buyimg.com/mobilecms/s750x366_jfs/t1/26597/30/4870/174583/5c35c5d2Ed55eedc6/50e27870c25e7a82.png')] bg-cover bg-center"></View>
                 </View>
                 <View>
                   <View className="text-[12px] text-[#909090]">

+ 7 - 5
src/components/post-list/index.tsx

@@ -23,8 +23,10 @@ const PostList = () => {
   const [mediaUrl, setMediaUrl] = useState<any[]>([]);
   const getPostList = () => {
     circlePostListApi({ circleId: 1 }).then((res: any) => {
-      setPostList(res.data.list);
-      console.log(res.data.list);
+      if (res.code === 200) {
+        setPostList(res.data.list);
+        console.log(res.data.list);
+      }
     });
   };
   const handleMoreClick = (postIndex: number) => {
@@ -106,8 +108,8 @@ const PostList = () => {
           >
             <View className="flex items-center justify-between">
               <View className="flex items-center">
-                <View className="w-[80rpx] h-[80rpx] rounded-[50%] bg-[#000] overflow-hidden bg-[url('https://m.360buyimg.com/mobilecms/s750x366_jfs/t1/26597/30/4870/174583/5c35c5d2Ed55eedc6/50e27870c25e7a82.png')] bg-cover bg-center"></View>
-                <View className="ml-[10rpx]">
+                <View className="w-[40px] h-[40px] rounded-[50%] bg-[#000] overflow-hidden bg-[url('https://m.360buyimg.com/mobilecms/s750x366_jfs/t1/26597/30/4870/174583/5c35c5d2Ed55eedc6/50e27870c25e7a82.png')] bg-cover bg-center"></View>
+                <View className="ml-[5px]">
                   <View className="text-[14px] font-[800] text-[#9c9dee]">
                     {item.user.nickname || "微信用户"}
                   </View>
@@ -122,7 +124,7 @@ const PostList = () => {
               </View>
               <View className="flex items-center">
                 <View
-                  className="flex items-center justify-center mr-[12px] text-[12px] bg-[#f8f8f8] text-[#949494] rounded-[20px] h-[50rpx] w-[120rpx] text-center"
+                  className="flex items-center justify-center mr-[12px] text-[12px] bg-[#f8f8f8] text-[#949494] rounded-[20px] h-[25px] w-[60px] text-center"
                   onClick={() =>
                     handleFollowClick(item.user_id, item.is_followed)
                   }

+ 2 - 1
src/http/request.ts

@@ -6,7 +6,8 @@ let addSubscriber: any[] = [];
 const request = async (params, callback?: any) => {
   return new Promise(async (resolve) => {
     let { url, data, method, headers, responseType } = params;
-    const BASE_URL = "http://127.0.0.1:8181";
+    const BASE_URL =
+      process.env.NODE_ENV === "development" ? "/api" : "http://127.0.0.1:8181";
     let contentType = "application/json;charset=UTF-8";
     contentType = headers?.contentType || contentType;
 

+ 2 - 2
src/pages/detail/index.tsx

@@ -74,7 +74,7 @@ const Detail = () => {
     <View>
       <View className="p-[10px] flex items-center justify-between">
         <View className="flex items-center">
-          <View className="w-[80rpx] h-[80rpx] rounded-[50%] bg-[#000] overflow-hidden bg-[url('https://m.360buyimg.com/mobilecms/s750x366_jfs/t1/26597/30/4870/174583/5c35c5d2Ed55eedc6/50e27870c25e7a82.png')] bg-cover bg-center"></View>
+          <View className="w-[40px] h-[40px] rounded-[50%] bg-[#000] overflow-hidden bg-[url('https://m.360buyimg.com/mobilecms/s750x366_jfs/t1/26597/30/4870/174583/5c35c5d2Ed55eedc6/50e27870c25e7a82.png')] bg-cover bg-center"></View>
           <View className="ml-[10rpx]">
             <View className="text-[14px] font-[800] text-[#9c9dee]">
               {postData.user.nickname || "微信用户"}
@@ -90,7 +90,7 @@ const Detail = () => {
         </View>
         <View className="flex items-center">
           <View
-            className="flex items-center justify-center mr-[12px] text-[12px] bg-[#f8f8f8] text-[#949494] rounded-[20px] h-[50rpx] w-[120rpx] text-center"
+            className="flex items-center justify-center mr-[12px] text-[12px] bg-[#f8f8f8] text-[#949494] rounded-[20px] h-[25px] w-[60px] text-center"
             onClick={() =>
               handleFollowClick(postData.user_id, postData.is_followed)
             }

+ 4 - 4
src/pages/index/index.tsx

@@ -11,20 +11,20 @@ function Index() {
     <View className="index">
       <View className="p-[10px]  bg-[#fff]">
         <View className="h-25 flex justify-between">
-          <View className="w-[22%] pt-[20rpx] pb-[20rpx] pl-[10rpx] border-[1rpx] border-solid border-[#e0e0e0] rounded-[5px] shadow-[0_35px_60px_-15px_rgba(0,0,0,0.3)]">
+          <View className="w-[22%] pt-[10px] pb-[10px] pl-[5px] border-[1rpx] border-solid border-[#e0e0e0] rounded-[5px] shadow-[0_35px_60px_-15px_rgba(0,0,0,0.3)]">
             <View className="text-[14px] font-[800] text-[#333]">福利中心</View>
             <View className="text-[12px] text-[#949494]">登录领奖</View>
           </View>
-          <View className="w-[22%] pt-[20rpx] pb-[20rpx] pl-[10rpx] border-[1rpx] border-solid border-[#e0e0e0]  rounded-[5px] shadow-[0_35px_60px_-15px_rgba(0,0,0,0.3)]">
+          <View className="w-[22%] pt-[10px] pb-[10px] pl-[5px] border-[1rpx] border-solid border-[#e0e0e0]  rounded-[5px] shadow-[0_35px_60px_-15px_rgba(0,0,0,0.3)]">
             <View className="text-[14px] font-[800] text-[#333]">游戏攻略</View>
             <View className="text-[12px] text-[#949494]">最新资讯</View>
           </View>
-          <View className="w-[22%] pt-[20rpx] pb-[20rpx] pl-[10rpx] border-[1rpx] border-solid border-[#e0e0e0]  rounded-[5px] shadow-[0_35px_60px_-15px_rgba(0,0,0,0.3)]">
+          <View className="w-[22%] pt-[10px] pb-[10px] pl-[5px] border-[1rpx] border-solid border-[#e0e0e0]  rounded-[5px] shadow-[0_35px_60px_-15px_rgba(0,0,0,0.3)]">
             <View className="text-[14px] font-[800] text-[#333]">组队开黑</View>
             <View className="text-[12px] text-[#949494]">寻找队友</View>
           </View>
           <View
-            className="w-[22%] pt-[20rpx] pb-[20rpx] pl-[10rpx] border-[1rpx] border-solid border-[#e0e0e0]  rounded-[5px] shadow-[0_35px_60px_-15px_rgba(0,0,0,0.3)]"
+            className="w-[22%] pt-[10px] pb-[10px] pl-[5px] border-[1rpx] border-solid border-[#e0e0e0]  rounded-[5px] shadow-[0_35px_60px_-15px_rgba(0,0,0,0.3)]"
             onClick={() => {
               navigateTo({ url: "/pages/self/index" });
             }}

+ 116 - 16
src/pages/message/list/index.tsx

@@ -1,4 +1,4 @@
-import { Text, View } from "@tarojs/components";
+import { Text, View, ScrollView } from "@tarojs/components";
 import { useLoad, setNavigationBarTitle, navigateTo } from "@tarojs/taro";
 import { timeFormat } from "../../../utils";
 import { Image } from "@nutui/nutui-react-taro";
@@ -14,10 +14,14 @@ const MessageList = () => {
   const [notificationList, setNotificationList] = useState<any[]>([]);
   const [CommentPostId, setCommentPostId] = useState(0);
   const [CommentParentCommentId, setCommentParentCommentId] = useState(0);
-  const [type, setType] = useState("");
   const [typeId, setTypeId] = useState("0");
+
+  // 分页相关状态
+  const [currentPage, setCurrentPage] = useState(1);
+  const [hasMore, setHasMore] = useState(true);
+  const [loading, setLoading] = useState(false);
+  const [refreshing, setRefreshing] = useState(false);
   useLoad((options) => {
-    setType(options.type);
     switch (options.type) {
       case "like":
         setTypeId("4,5");
@@ -51,24 +55,87 @@ const MessageList = () => {
     markAsReadByTypeApi({ type_id });
   };
 
-  const getNotificationList = async () => {
-    const res: any = await getNotificationListApi({
-      type_id: typeId,
-      page: 1,
-      page_size: 10,
-    });
-    if (res.code === 200) {
-      setNotificationList(res.data.list);
+  const getNotificationList = async (page = 1, isRefresh = false) => {
+    if (loading) return;
+
+    setLoading(true);
+    try {
+      const res: any = await getNotificationListApi({
+        type_id: typeId,
+        page: page,
+        limit: 10,
+      });
+
+      if (res.code === 200) {
+        const { list, has_more } = res.data;
+        console.log("API response:", {
+          page,
+          listLength: list.length,
+          has_more,
+          totalCount: res.data.count,
+        });
+
+        if (isRefresh || page === 1) {
+          // 刷新或首次加载,替换数据
+          setNotificationList(list);
+        } else {
+          // 加载更多,追加数据
+          setNotificationList((prev) => [...prev, ...list]);
+        }
+
+        setCurrentPage(page);
+        setHasMore(has_more);
+        console.log("Updated state:", { currentPage: page, hasMore: has_more });
+      }
+    } catch (error) {
+      console.error("获取通知列表失败:", error);
+    } finally {
+      setLoading(false);
+      setRefreshing(false);
+    }
+  };
+  // 加载更多数据
+  const loadMore = () => {
+    console.log("loadMore triggered:", { hasMore, loading, currentPage });
+    if (hasMore && !loading) {
+      console.log("Loading next page:", currentPage + 1);
+      getNotificationList(currentPage + 1, false);
     }
   };
+
+  // 下拉刷新
+  const onRefresh = () => {
+    setRefreshing(true);
+    setCurrentPage(1);
+    setHasMore(true);
+    getNotificationList(1, true);
+  };
+
   useEffect(() => {
-    getNotificationList();
+    // 重置分页状态
+    setCurrentPage(1);
+    setHasMore(true);
+    setNotificationList([]);
+    getNotificationList(1, true);
   }, [typeId]);
   return (
-    <View className="bg-[#f8f8f8]">
-      {notificationList.map((item) => {
+    <ScrollView
+      className="bg-[#f8f8f8] h-full"
+      scrollY
+      refresherEnabled
+      refresherTriggered={refreshing}
+      onRefresherRefresh={onRefresh}
+      onScrollToLower={loadMore}
+      lowerThreshold={50}
+      enhanced
+      showScrollbar={false}
+    >
+      {notificationList.map((item, index) => {
         return (
-          <View className="p-[10px] text-[14px] flex mb-[2px] bg-[#fff]">
+          <View
+            key={item.id || index}
+            className="p-[10px] text-[14px] flex mb-[2px] bg-[#fff]"
+          >
             <View className="w-[50px] h-[50px] bg-[#000] rounded-[50%] overflow-hidden">
               <Image
                 width={50}
@@ -155,6 +222,39 @@ const MessageList = () => {
         );
       })}
 
+      {/* 加载更多按钮 - 用于测试 */}
+      {hasMore && !loading && (
+        <View className="flex justify-center items-center py-[20px]">
+          <View
+            className="px-[20px] py-[10px] bg-[#007aff] rounded-[20px]"
+            onClick={loadMore}
+          >
+            <Text className="text-[14px] text-white">加载更多</Text>
+          </View>
+        </View>
+      )}
+
+      {/* 加载指示器 */}
+      {loading && (
+        <View className="flex justify-center items-center py-[20px]">
+          <Text className="text-[14px] text-[#999]">加载中...</Text>
+        </View>
+      )}
+
+      {/* 无更多数据提示 */}
+      {!hasMore && notificationList.length > 0 && (
+        <View className="flex justify-center items-center py-[20px]">
+          <Text className="text-[14px] text-[#999]">没有更多数据了</Text>
+        </View>
+      )}
+
+      {/* 空状态 */}
+      {!loading && notificationList.length === 0 && (
+        <View className="flex justify-center items-center py-[100px]">
+          <Text className="text-[14px] text-[#999]">暂无消息</Text>
+        </View>
+      )}
+
       {showCommentInput ? (
         <CommentInput
           postId={CommentPostId}
@@ -166,7 +266,7 @@ const MessageList = () => {
           }}
         />
       ) : null}
-    </View>
+    </ScrollView>
   );
 };