|
|
@@ -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} />
|