Leon 1 سال پیش
والد
کامیت
5a5a0004e2

+ 19 - 2
src/_account/pages/ChooseAuth.tsx

@@ -113,7 +113,24 @@ export default function Page() {
 
     async function login(strCode) {
         setBtnDisable(true)
-        wxLogin(strCode).then(res => {
+        var params: any = {}
+        var share_uid = Taro.getStorageSync('share_uid')
+        var share_info = Taro.getStorageSync('share_info')
+        if (share_uid) {
+            params.follow_origin = share_info ? 'WECHAT_GROUP_CHAT' : 'WECHAT_PRIVATE_CHAT'
+            if (share_info) {
+                var groupInfo = JSON.parse(share_info)
+                params.wechat = groupInfo
+                // {
+                //     encryptedData: groupInfo.encryptedData,
+                //     iv: groupInfo.iv
+                // }
+            }
+        }
+
+        console.log(share_uid, share_info, params)
+
+        wxLogin(strCode, params).then(res => {
             console.log(res)
             dispatch(loginSuccess(res));
             setBtnDisable(false)
@@ -121,7 +138,7 @@ export default function Page() {
                 Taro.navigateBack({
                     delta: 1
                 })
-            }else {
+            } else {
                 Taro.setStorage({ key: '149alert', data: true })
             }
 

+ 1 - 1
src/_health/pages/add_moment.tsx

@@ -89,7 +89,7 @@ export default function AddMoment() {
 
 
         if (router.params.edit) {
-            var detail = JSON.parse(router.params.detail)
+            var detail = global.edit_timeline//JSON.parse(router.params.detail)
             setTitle(detail.title)
             var moment = detail.moments[0]
             setDesc(moment.description)

+ 2 - 1
src/_health/pages/timeline_detail.tsx

@@ -522,7 +522,8 @@ export default function TimelineDetail() {
     function edit() {
         if (list.length == 0) return
         var id = list[0].id
-        jumpPage(`./add_moment?edit=1&event_id=${event_id}&id=${id}&detail=${JSON.stringify(detail)}`)
+        global.edit_timeline = detail
+        jumpPage(`./add_moment?edit=1&event_id=${event_id}&id=${id}`)
         // jumpPage('./add_moment?edit=1&event_id='+id+'&detail='+JSON.stringify(detail))
     }
 

+ 140 - 23
src/pages/friend/friend.tsx

@@ -2,35 +2,152 @@
 
 import TabBar from "@/components/navigation/TabBar";
 import { rpxToPx } from "@/utils/tools";
-import { View, Text, Image,ScrollView } from "@tarojs/components";
-import Taro from "@tarojs/taro";
-import { useEffect } from "react";
+import { View, Text, Image, ScrollView, Button } from "@tarojs/components";
+import Taro, { useRouter, useShareAppMessage } from "@tarojs/taro";
+import { useDispatch, useSelector } from "react-redux";
+import { useEffect, useState } from "react";
+import { followUser, getMyFriends } from "@/services/friend";
+
+let useRoute;
+let useNavigation;
+if (process.env.TARO_ENV == 'rn') {
+    useRoute = require("@react-navigation/native").useRoute
+    useNavigation = require("@react-navigation/native").useNavigation
+}
+
+
 export default function Friend() {
-    const observerObjBottom = Taro.createIntersectionObserver().relativeToViewport({bottom:100})
-    useEffect(()=>{
-        observerObjBottom.observe('#a',(res)=>{
-            console.log('a')
-        })
-        observerObjBottom.observe('#b',(res)=>{
-            console.log('b')
+    const user = useSelector((state: any) => state.user);
+    const launchObj = Taro.getLaunchOptionsSync()
+
+    const observerObjBottom = Taro.createIntersectionObserver().relativeToViewport({ bottom: 100 })
+
+    const [friends, setFriends] = useState<any>([])
+    const [count, setCount] = useState(0)
+
+    let router
+    let navigation;
+    if (useNavigation) {
+        navigation = useNavigation()
+    }
+
+    if (process.env.TARO_ENV == 'rn') {
+        router = useRoute()
+    }
+    else {
+        router = useRouter()
+    }
+
+
+
+
+    useEffect(() => {
+        myFriends()
+        if (router.params.type == 'share') {
+            console.log('b', launchObj.shareTicket)
+            if (launchObj.shareTicket) {
+                Taro.getShareInfo({
+                    shareTicket: launchObj.shareTicket,
+                    success(result) {
+                        console.log('share info', result)
+                        updateRelation(result)
+                    },
+                })
+            }
+            else {
+                updateRelation(null)
+            }
+        }
+        console.log('c')
+    }, [user.isLogin])
+
+    function myFriends() {
+        if (!user.isLogin) return
+        getMyFriends({
+            page: 1,
+            limit: 10
+        }).then(res => {
+            console.log(res)
+            setCount((res as any).total)
+            setFriends((res as any).data)
         })
-        observerObjBottom.observe('#c',(res)=>{
-            console.log('c')
+    }
+
+    function updateRelation(obj) {
+        if (!user.isLogin) {
+            Taro.setStorageSync('share_uid', router.params.uid)
+            Taro.setStorageSync('share_info', JSON.stringify(obj))
+            return
+        }
+        console.log('user login')
+        if (user.id != router.params.uid) {
+            var params: any = {
+                follow_origin: obj ? 'WECHAT_GROUP_CHAT' : 'WECHAT_PRIVATE_CHAT'
+            }
+            if (obj) {
+                params.wechat = obj
+            }
+            followUser(router.params.uid, params).then(res => {
+                myFriends()
+            })
+        }
+    }
+
+
+    useEffect(() => {
+        // observerObjBottom.observe('#a', (res) => {
+        //     console.log('a')
+        // })
+        // observerObjBottom.observe('#b', (res) => {
+        //     console.log('b')
+        // })
+        // observerObjBottom.observe('#c', (res) => {
+        //     console.log('c')
+        // })
+        // observerObjBottom.observe('#d', (res) => {
+        //     console.log('d')
+        // })
+        observerObjBottom.observe('#e', (res) => {
+            console.log('e')
         })
-        observerObjBottom.observe('#d',(res)=>{
-            console.log('d')
+    }, [])
+
+    if (process.env.TARO_ENV == 'weapp' /*&& global.allowShare*/) {
+        Taro.updateShareMenu({
+            withShareTicket: true,
+            success() { }
         })
-        observerObjBottom.observe('#e',(res)=>{
-            console.log('e')
+
+        useShareAppMessage((e) => {
+            var sharePath = ``
+            console.log('share_url', '/pages/friend/friend?type=share&uid=' + user.id)
+            return {
+                title: 'Friends ',
+                path: '/pages/friend/friend?type=share&uid=' + user.id,
+                // imageUrl: imageUrl
+            }
         })
-    },[])
+    }
+
+
     return <View>
-        <ScrollView scrollY style={{height:'100vh'}}>
-            <View style={{height:'100vh',backgroundColor:'pink',width:rpxToPx(750)}} id="a"></View>
-            <View style={{height:'100vh',backgroundColor:'blue',width:rpxToPx(750)}} id="b"></View>
-            <View style={{height:'100vh',backgroundColor:'yellow',width:rpxToPx(750)}} id="c"></View>
-            <View style={{height:'100vh',backgroundColor:'green',width:rpxToPx(750)}} id="d"></View>
-            <View style={{height:'100vh',backgroundColor:'red',width:rpxToPx(750)}} id="e"></View>
+        <ScrollView scrollY style={{ height: '100vh' }}>
+            <Button openType="share">分享</Button>
+            <View>好友数量{count}</View>
+            {
+                friends.map((item, index) => {
+                    return <View key={index}>
+                        <Image src={item.avatar} style={{ width: 70, height: 70 }} />
+                        <Text>{item.nickname}</Text>
+                        <Text>{item.relation}</Text>
+                    </View>
+                })
+            }
+            <View style={{ height: '100vh', backgroundColor: 'pink', width: rpxToPx(750) }} id="a"></View>
+            <View style={{ height: '100vh', backgroundColor: 'blue', width: rpxToPx(750) }} id="b"></View>
+            <View style={{ height: '100vh', backgroundColor: 'yellow', width: rpxToPx(750) }} id="c"></View>
+            <View style={{ height: '100vh', backgroundColor: 'green', width: rpxToPx(750) }} id="d"></View>
+            <View style={{ height: '100vh', backgroundColor: 'red', width: rpxToPx(750) }} id="e"></View>
         </ScrollView>
         {
             process.env.TARO_ENV == 'weapp' && <TabBar index={4} />

+ 29 - 0
src/services/friend.tsx

@@ -0,0 +1,29 @@
+import { API_FOLLOW_USER, API_MY_FRIENDS } from "./http/api";
+import { request } from "./http/request";
+
+export const followUser = (id,params) => {
+    return new Promise((resolve, reject) => {
+        request({
+            url: API_FOLLOW_USER+'/'+id+'/followers', method: 'POST', data: {...params}
+        }).then(res => {
+            resolve(res);
+            // dispatch(loginSuccess(res));
+        }).catch(e => {
+            reject(e)
+        })
+    })
+}
+
+export const getMyFriends = (params) => {
+    return new Promise((resolve, reject) => {
+        request({
+            url: API_MY_FRIENDS, method: 'GET', data: {...params}
+        }).then(res => {
+            resolve(res);
+            // dispatch(loginSuccess(res));
+        }).catch(e => {
+            reject(e)
+        })
+    })
+}
+

+ 5 - 1
src/services/http/api.js

@@ -119,4 +119,8 @@ export const API_ME_ALBUMS = `${baseUrl}/api/health/wo/albums`
 export const API_ME_ALBUMS_STAT = `${baseUrl}/api/health/wo/albums-stat`
 export const API_LASTEST_JOURNAL = `${baseUrl}/api/health/journals/latest/generated-info`
 
-export const API_RESET_TESTINFO = `${baseUrl}/api/user/test-resets`
+export const API_RESET_TESTINFO = `${baseUrl}/api/user/test-resets`
+
+//friend
+export const API_FOLLOW_USER = `${baseUrl}/api/users`
+export const API_MY_FRIENDS = `${baseUrl}/api/user/friends`

+ 1 - 0
src/services/http/request.ts

@@ -98,6 +98,7 @@ export async function request<T>(param: RequestParam): Promise<T> {
         if (token.length > 0) {
             header['Authorization'] = `Bearer ${token}`;
         }
+        // header['Authorization'] = `Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmYXN0IiwiYXVkIjoiYWNjb3VudCIsInN1YiI6ImIzNWJmMjFiMjc0ZmVhOWJkN2Y2ZjQzMGUxNDY4ZjQxIiwidHlwIjoiQmVhcmVyIiwic2Vzc2lvbl9zdGF0ZSI6IjFhZWE1M2UxN2ExNWJjZmZkZjc3ZGNhYWI5Zjc4MmNkIiwibmlja25hbWUiOiLnp4B-WGl1IiwiaWF0IjoxNzMzNTY4OTU5LCJleHAiOjIwNDkxMDE3NTl9.QoBTixnIHNx26alD5HKzzO441qOAlWMrmOMzprT99Mg`
 
 
 

+ 2 - 1
src/services/user.tsx

@@ -55,7 +55,7 @@ export const getPerm = () => {
     })
 }
 
-export const wxLogin = (code: string/*, encryptedData: string, iv: string*/) => {
+export const wxLogin = (code: string/*, encryptedData: string, iv: string*/,params) => {
     return new Promise((resolve, reject) => {
         request({
             url: API_OAUTH_LOGIN, method: 'POST',
@@ -65,6 +65,7 @@ export const wxLogin = (code: string/*, encryptedData: string, iv: string*/) =>
                 app_version: '1',
                 client_version: '1',
                 client_type: 'WX_MP',
+                ...params
                 // extra: {
                 //     encryptedData: encryptedData,
                 //     iv: iv