ith5 4 mēneši atpakaļ
vecāks
revīzija
f5262c4983

+ 2 - 1
.env.development

@@ -1 +1,2 @@
-TARO_APP_API="https://192.168.0.187:8181"
+TARO_APP_API="https://192.168.0.187:8181"
+TARO_ACT_HOST="http://localhost:3000"

+ 3 - 1
config/dev.ts

@@ -2,7 +2,9 @@ module.exports = {
   env: {
     NODE_ENV: '"development"',
   },
-  defineConstants: {},
+  defineConstants: {
+    TARO_ACT_HOST: '"http://localhost:3000"',
+  },
   mini: {},
   h5: {
     devServer: {

+ 1 - 0
config/prod.ts

@@ -6,6 +6,7 @@ module.exports = {
   defineConstants: {
     // 生产环境 API 地址
     API_BASE_URL: '"https://api.example.com"',
+    TARO_ACT_HOST: '"https://act.yunfanyouxi.com"',
   },
   mini: {},
   h5: {

+ 1 - 1
src/app.config.ts

@@ -1,7 +1,7 @@
 export default defineAppConfig({
   pages: [
     "pages/index/index",
-    "pages/demo/index",
+    "pages/act/index",
     "pages/message/list/index",
     "pages/message/index",
     "pages/self/index",

+ 6 - 1
src/components/post-list/index.tsx

@@ -175,7 +175,12 @@ const PostList = () => {
                 key={item.id}
                 className="post-list-item  bg-[#fff] p-[10px] mb-[10px]"
               >
-                <View className="flex items-center justify-between">
+                <View
+                  className="flex items-center justify-between"
+                  onClick={() => {
+                    navigateTo({ url: `/pages/self/index?id=${item.user_id}` });
+                  }}
+                >
                   <View className="flex items-center">
                     <View
                       className="w-[40px] h-[40px] rounded-[50%] bg-[#000] overflow-hidden bg-cover bg-center"

+ 48 - 0
src/config/index.ts

@@ -0,0 +1,48 @@
+// 环境配置
+const config = {
+  development: {
+    TARO_ACT_HOST: "http://localhost:3000",
+    API_BASE_URL: "/api",
+  },
+  production: {
+    TARO_ACT_HOST: "https://act.yunfanyouxi.com",
+    API_BASE_URL: "http://127.0.0.1:8181",
+  },
+};
+
+// 获取当前环境
+const getEnv = () => {
+  // 在H5环境中,可以通过location.hostname判断
+  if (typeof window !== "undefined") {
+    const hostname = window.location.hostname;
+    const port = window.location.port;
+
+    // 开发环境判断条件
+    if (
+      hostname === "localhost" ||
+      hostname === "127.0.0.1" ||
+      hostname === "192.168.10.5" ||
+      (hostname === "localhost" && port === "10086")
+    ) {
+      return "development";
+    }
+    return "production";
+  }
+
+  // 在小程序环境中,可以通过Taro.getEnv()判断
+  try {
+    const Taro = require("@tarojs/taro");
+    const env = Taro.getEnv();
+    return env === "h5" ? "development" : "production";
+  } catch (e) {
+    return "development"; // 默认开发环境
+  }
+};
+
+const currentEnv = getEnv();
+
+// 添加调试信息
+console.log("当前环境:", currentEnv);
+console.log("当前配置:", config[currentEnv]);
+
+export default config[currentEnv];

+ 17 - 3
src/http/request.ts

@@ -1,5 +1,6 @@
 import Taro from "@tarojs/taro";
 import { navigateTo } from "@tarojs/taro";
+import config from "../config";
 
 //添加拦截器
 let isRefreshing = true;
@@ -7,8 +8,7 @@ let addSubscriber: any[] = [];
 const request = async (params, callback?: any) => {
   return new Promise(async (resolve) => {
     let { url, data, method, headers, responseType } = params;
-    const BASE_URL =
-      process.env.NODE_ENV === "development" ? "/api" : "http://127.0.0.1:8181";
+    const BASE_URL = config.API_BASE_URL;
     let contentType = "application/json;charset=UTF-8";
     contentType = headers?.contentType || contentType;
 
@@ -25,7 +25,21 @@ const request = async (params, callback?: any) => {
       },
     };
     Taro.showLoading({ title: "加载中", mask: true });
-    const res: any = await Taro.request(option);
+
+    // 添加调试信息
+    console.log("请求配置:", option);
+
+    const res: any = await Taro.request(option).catch((error) => {
+      Taro.hideLoading();
+      console.error("请求失败:", error);
+      Taro.showToast({
+        title: "网络请求失败",
+        icon: "none",
+        duration: 2000,
+      });
+      throw error;
+    });
+
     Taro.hideLoading();
     if (callback) return callback(res.data);
 

+ 6 - 0
src/pages/act/index.scss

@@ -0,0 +1,6 @@
+.act-content {
+  height: calc(100vh - 70px);
+  width: 100%;
+  border: none;
+  padding-top: 40px;
+}

+ 54 - 0
src/pages/act/index.tsx

@@ -0,0 +1,54 @@
+import { NavBar } from "@nutui/nutui-react-taro";
+import { ArrowLeft } from "@nutui/icons-react-taro";
+import { getStorageSync, navigateBack, navigateTo } from "@tarojs/taro";
+import { View } from "@tarojs/components";
+import config from "../../config";
+import { useEffect, useState } from "react";
+import "./index.scss";
+export default function Act() {
+  const [userInfo, setUserInfo] = useState<any>(null);
+  // 监听iframe的emit过来的事件, onMessage
+  useEffect(() => {
+    window.addEventListener("message", (event) => {
+      if (event.type === "message") {
+        console.log("event.data", event.data);
+        switch (event.data) {
+          case "login":
+            navigateTo({ url: "/pages/login/index" });
+            break;
+          default:
+            break;
+        }
+      }
+    });
+  }, []);
+
+  useEffect(() => {
+    setUserInfo(getStorageSync("User"));
+  }, []);
+  return (
+    <>
+      <NavBar
+        back={
+          <>
+            <ArrowLeft />
+            返回
+          </>
+        }
+        fixed
+        onBackClick={(e) => {
+          e.preventDefault();
+          navigateBack({ delta: 1 });
+        }}
+      >
+        活动
+      </NavBar>
+      <View>
+        <iframe
+          className="act-content"
+          src={`${config.TARO_ACT_HOST}/jifen/exchange?vip_code=${userInfo?.vip_code}`}
+        />
+      </View>
+    </>
+  );
+}

+ 0 - 70
src/pages/demo/index.tsx

@@ -1,70 +0,0 @@
-import { Button, Sticky } from "@nutui/nutui-react-taro";
-import { ScrollView, View } from "@tarojs/components";
-import { useEffect, useRef, useState } from "react";
-import { getSystemInfoSync } from "@tarojs/taro";
-
-export default function Demo() {
-  const [scrollHeight, setScrollHeight] = useState<number>(0);
-  const containerTopRef = useRef(null);
-  useEffect(() => {
-    const systemInfo = getSystemInfoSync();
-    // 屏幕高度 - 状态栏 - 导航栏 - 用户信息区域 - 标签栏
-    const height = systemInfo.windowHeight - 44 - 50 - 100;
-    setScrollHeight(height);
-  }, []);
-  return (
-    <View className="bg-[#f8f8f8] h-full w-full">
-      <View>111222</View>
-      <View>111222</View>
-      <View>111222</View>
-      <View>111222</View>
-      <View>111222</View>
-      <ScrollView
-        ref={containerTopRef}
-        style={{ height: `${scrollHeight + 1000}px` }}
-        scrollY
-        className="overflow-hidden"
-      >
-        <Sticky container={containerTopRef} threshold={75}>
-          <Button type="primary">距离顶部75px</Button>
-        </Sticky>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122</View>
-        <View>122ß</View>
-      </ScrollView>
-    </View>
-  );
-}

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

@@ -7,6 +7,7 @@ import "./index.scss";
 import { Image } from "@nutui/nutui-react-taro";
 import { useEffect, useState } from "react";
 import { getCircleInfoApi } from "../../api/circle";
+import config from "../../config";
 
 function Index() {
   const [circleData, setCircleData] = useState<any>(null);
@@ -56,7 +57,10 @@ function Index() {
             <>
               <View
                 className="w-[22%] pt-[10px] mr-[10px] pb-[10px] pl-[5px] border-[1rpx] border-solid border-[#e0e0e0] rounded-[5px] shadow-[0_15px_10px_-16px_rgba(0,0,0,0.3)]"
-                onClick={() => {}}
+                onClick={() => {
+                  // window.location.href = `${config.TARO_ACT_HOST}/jifen/exchange?vip_code=${userInfo?.vip_code}`;
+                  navigateTo({ url: "/pages/act/index" });
+                }}
               >
                 <View className="text-[14px] font-[800] text-[#333]">
                   福利中心
@@ -90,7 +94,7 @@ function Index() {
         <PostList />
         {/* <TabbarCom /> */}
         <View
-          className="fixed bottom-[50px] right-[20px] w-[50px] h-[50px] bg-[#1874d0] rounded-[50%] z-10 justify-center items-center flex "
+          className="fixed bottom-[50px] right-[20px] w-[50px] h-[50px] bg-[#6069d9] rounded-[50%] z-10 justify-center items-center flex "
           onClick={() => {
             navigateTo({ url: "/pages/publish/index" });
           }}

+ 93 - 22
src/pages/self/index.tsx

@@ -9,23 +9,26 @@ import {
 } from "@nutui/icons-react-taro";
 import {
   Badge,
+  Dialog,
   Grid,
   GridItem,
   Image,
   ImagePreview,
   NavBar,
   Tabs,
+  Toast,
 } from "@nutui/nutui-react-taro";
 import {
   navigateTo,
   getSystemInfoSync,
   useDidShow,
   navigateBack,
+  useLoad,
 } from "@tarojs/taro";
 import "./index.scss";
 import { useState, useEffect, useCallback } from "react";
 import { strSlice } from "../../utils";
-import { interactionApi } from "../../api/interaction";
+import { followApi, interactionApi, unfollowApi } from "../../api/interaction";
 import { getUserPostListApi } from "../../api/post";
 import { getUserInfoApi } from "../../api/user";
 const Self = () => {
@@ -47,6 +50,7 @@ const Self = () => {
     count: 0,
     has_more: false,
   });
+  const [userId, setUserId] = useState<any>(null);
 
   // 计算滚动区域高度
   useEffect(() => {
@@ -77,7 +81,9 @@ const Self = () => {
   };
   // 获取用户信息
   const getUserInfo = async () => {
-    const res: any = await getUserInfoApi();
+    const res: any = userId
+      ? await getUserInfoApi(userId)
+      : await getUserInfoApi();
     if (res.code === 200) {
       setUserInfo(res.data);
     }
@@ -106,7 +112,10 @@ const Self = () => {
         page: currentPage,
       };
 
-      const res: any = await getUserPostListApi(null, requestParams);
+      const res: any = await getUserPostListApi(
+        userId ? userId : null,
+        requestParams
+      );
 
       if (res.code === 200) {
         const newData = res.data.list || [];
@@ -142,10 +151,52 @@ const Self = () => {
     }
   };
 
+  // 关注/不关注
+  const handleFollowClick = (followeeId: number, is_followed) => {
+    console.log(followeeId, is_followed);
+    if (is_followed) {
+      Dialog.open("followed_dialog", {
+        title: "提示",
+        content: "确定取消关注吗?",
+        onConfirm: () => {
+          unfollowApi({ followee_id: followeeId }).then(() => {
+            Toast.show("follow_success", {
+              content: "取消关注成功",
+              duration: 2,
+              lockScroll: true,
+            });
+            const data = { ...userInfo, is_followed: false };
+            setUserInfo(data);
+            Dialog.close("followed_dialog");
+          });
+        },
+        onCancel: () => {
+          Dialog.close("followed_dialog");
+        },
+        onClose: () => {
+          Dialog.close("followed_dialog");
+        },
+      });
+    } else {
+      followApi({ followee_id: followeeId }).then(() => {
+        Toast.show("follow_success", {
+          content: "关注成功",
+          duration: 2,
+          lockScroll: true,
+        });
+        const data = { ...userInfo, is_followed: true };
+        setUserInfo(data);
+      });
+    }
+  };
+
   useDidShow(() => {
     getPostList();
     getUserInfo();
   });
+  useLoad((params) => {
+    setUserId(params.id);
+  });
 
   // 加载更多
   const loadMore = useCallback(() => {
@@ -189,22 +240,28 @@ const Self = () => {
               </View>
               <View className="flex-1 ml-[10px]">
                 <View className="text-[16px] font-bold">
-                  {userInfo.nickname || userInfo.username}
+                  {userInfo.username || userInfo.nickname}
                 </View>
               </View>
             </View>
-            <Badge top="2" right="8" value={userInfo.notification_count}>
-              <Notice
-                onClick={() => {
-                  navigateTo({ url: "/pages/message/index" });
-                }}
-              />
-            </Badge>
+            {userId ? (
+              <></>
+            ) : (
+              <Badge top="2" right="8" value={userInfo.notification_count}>
+                <Notice
+                  onClick={() => {
+                    navigateTo({ url: "/pages/message/index" });
+                  }}
+                />
+              </Badge>
+            )}
           </View>
           <View className="flex items-center justify-between text-[14px] mt-[10px]">
             <View className="flex">
               <View className="flex">
-                <Text className="text-[#949494]">关注我</Text>
+                <Text className="text-[#949494]">
+                  {userId ? "粉丝" : "关注我"}
+                </Text>
                 <Text className="ml-[5px]">{userInfo.follow_count}</Text>
               </View>
               <View className="flex ml-[20px]">
@@ -212,16 +269,30 @@ const Self = () => {
                 <Text className="ml-[5px]">{userInfo.interaction_count}</Text>
               </View>
             </View>
-            <View
-              className="bg-[#f7f7f7] w-[70px] h-[30px] rounded-[15px] flex items-center justify-around"
-              onClick={() => {
-                navigateTo({ url: "/pages/publish/index" });
-              }}
-            >
-              <View className="flex items-center">
-                <Plus />
-                <Text>发布</Text>
-              </View>
+            <View className="bg-[#f7f7f7] w-[70px] h-[30px] rounded-[15px] flex items-center justify-around">
+              {userId ? (
+                <>
+                  <View
+                    className="flex items-center justify-center text-[12px] bg-[#f8f8f8] text-[#949494] rounded-[20px] h-[25px] w-[60px] text-center"
+                    onClick={() =>
+                      handleFollowClick(userInfo.id, userInfo.is_followed)
+                    }
+                  >
+                    {userInfo.is_followed ? <></> : <Plus color="#1874d0" />}
+                    <Text>{userInfo.is_followed ? "已关注" : "关注"}</Text>
+                  </View>
+                </>
+              ) : (
+                <View
+                  className="flex items-center justify-center text-[12px] bg-[#6065e0] text-[#fff] rounded-[20px] h-[25px] w-[60px] text-center"
+                  onClick={() => {
+                    navigateTo({ url: "/pages/publish/index" });
+                  }}
+                >
+                  <Plus />
+                  <Text>发布</Text>
+                </View>
+              )}
             </View>
           </View>
         </View>

+ 23 - 12
types/global.d.ts

@@ -1,19 +1,30 @@
 /// <reference types="@tarojs/taro" />
 
-declare module '*.png';
-declare module '*.gif';
-declare module '*.jpg';
-declare module '*.jpeg';
-declare module '*.svg';
-declare module '*.css';
-declare module '*.less';
-declare module '*.scss';
-declare module '*.sass';
-declare module '*.styl';
+declare module "*.png";
+declare module "*.gif";
+declare module "*.jpg";
+declare module "*.jpeg";
+declare module "*.svg";
+declare module "*.css";
+declare module "*.less";
+declare module "*.scss";
+declare module "*.sass";
+declare module "*.styl";
 
 declare namespace NodeJS {
   interface ProcessEnv {
-    TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd'
+    TARO_ENV:
+      | "weapp"
+      | "swan"
+      | "alipay"
+      | "h5"
+      | "rn"
+      | "tt"
+      | "quickapp"
+      | "qq"
+      | "jd";
+    NODE_ENV: "development" | "production";
+    TARO_ACT_HOST: string;
+    API_BASE_URL: string;
   }
 }
-