|
@@ -6,7 +6,10 @@ import { View, Text, Image, ScrollView, Button } from "@tarojs/components";
|
|
|
import Taro, { useRouter, useShareAppMessage } from "@tarojs/taro";
|
|
import Taro, { useRouter, useShareAppMessage } from "@tarojs/taro";
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
import { useEffect, useState } from "react";
|
|
import { useEffect, useState } from "react";
|
|
|
-import { followUser, getMyFriends } from "@/services/friend";
|
|
|
|
|
|
|
+import { followUser, getFriendDashBoard, getFriendMoments, getMyFriends, getUserHome } from "@/services/friend";
|
|
|
|
|
+import FriendGuide from "./guide";
|
|
|
|
|
+import EmptyContent from "./empty_content";
|
|
|
|
|
+import MomentItem from "./moment_item";
|
|
|
|
|
|
|
|
let useRoute;
|
|
let useRoute;
|
|
|
let useNavigation;
|
|
let useNavigation;
|
|
@@ -15,7 +18,7 @@ if (process.env.TARO_ENV == 'rn') {
|
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+let timer;
|
|
|
export default function Friend() {
|
|
export default function Friend() {
|
|
|
const user = useSelector((state: any) => state.user);
|
|
const user = useSelector((state: any) => state.user);
|
|
|
const launchObj = Taro.getLaunchOptionsSync()
|
|
const launchObj = Taro.getLaunchOptionsSync()
|
|
@@ -25,6 +28,9 @@ export default function Friend() {
|
|
|
const [friends, setFriends] = useState<any>([])
|
|
const [friends, setFriends] = useState<any>([])
|
|
|
const [count, setCount] = useState(0)
|
|
const [count, setCount] = useState(0)
|
|
|
|
|
|
|
|
|
|
+ const systemInfo: any = Taro.getWindowInfo ? Taro.getWindowInfo() : Taro.getSystemInfoSync();
|
|
|
|
|
+ const navigationBarHeight = systemInfo.statusBarHeight + 44;
|
|
|
|
|
+
|
|
|
let router
|
|
let router
|
|
|
let navigation;
|
|
let navigation;
|
|
|
if (useNavigation) {
|
|
if (useNavigation) {
|
|
@@ -38,7 +44,19 @@ export default function Friend() {
|
|
|
router = useRouter()
|
|
router = useRouter()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const [loaded, setLoaded] = useState(false)
|
|
|
|
|
+ const [homeType, setHomeType] = useState('NO_FRIEND')
|
|
|
|
|
+ const [dashBoard, setDashBoard] = useState<any>(null)
|
|
|
|
|
+ const [moments, setMoments] = useState<any>([])
|
|
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ timer = setInterval(() => {
|
|
|
|
|
+ setCount(count => count + 1)
|
|
|
|
|
+ }, 1000)
|
|
|
|
|
+ return () => {
|
|
|
|
|
+ clearInterval(timer)
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
@@ -62,7 +80,10 @@ export default function Friend() {
|
|
|
}, [user.isLogin])
|
|
}, [user.isLogin])
|
|
|
|
|
|
|
|
function myFriends() {
|
|
function myFriends() {
|
|
|
- if (!user.isLogin) return
|
|
|
|
|
|
|
+ if (!user.isLogin) {
|
|
|
|
|
+ setLoaded(true)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
getMyFriends({
|
|
getMyFriends({
|
|
|
page: 1,
|
|
page: 1,
|
|
|
limit: 10
|
|
limit: 10
|
|
@@ -71,6 +92,19 @@ export default function Friend() {
|
|
|
setCount((res as any).total)
|
|
setCount((res as any).total)
|
|
|
setFriends((res as any).data)
|
|
setFriends((res as any).data)
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ getFriendDashBoard().then(res => {
|
|
|
|
|
+ setLoaded(true)
|
|
|
|
|
+ setHomeType((res as any).homepage_type)
|
|
|
|
|
+ setDashBoard(res)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ getFriendMoments({
|
|
|
|
|
+ page: 1,
|
|
|
|
|
+ limit: 50
|
|
|
|
|
+ }).then(res => {
|
|
|
|
|
+ setMoments((res as any).data)
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function updateRelation(obj) {
|
|
function updateRelation(obj) {
|
|
@@ -120,6 +154,9 @@ export default function Friend() {
|
|
|
|
|
|
|
|
useShareAppMessage((e) => {
|
|
useShareAppMessage((e) => {
|
|
|
var sharePath = ``
|
|
var sharePath = ``
|
|
|
|
|
+ if (global.shareData) {
|
|
|
|
|
+ console.log(global.shareData)
|
|
|
|
|
+ }
|
|
|
console.log('share_url', '/pages/friend/friend?type=share&uid=' + user.id)
|
|
console.log('share_url', '/pages/friend/friend?type=share&uid=' + user.id)
|
|
|
return {
|
|
return {
|
|
|
title: 'Friends ',
|
|
title: 'Friends ',
|
|
@@ -129,6 +166,63 @@ export default function Friend() {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function friendGuide() {
|
|
|
|
|
+ return <View>
|
|
|
|
|
+ <View style={{ height: navigationBarHeight, width: rpxToPx(750), backgroundColor: '#fff' }} />
|
|
|
|
|
+ <FriendGuide />
|
|
|
|
|
+ {
|
|
|
|
|
+ process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
|
|
|
|
|
+ }</View>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function empty() {
|
|
|
|
|
+ return <View>
|
|
|
|
|
+ <View style={{ height: navigationBarHeight, width: rpxToPx(750), backgroundColor: '#fff' }} />
|
|
|
|
|
+ <EmptyContent friends={dashBoard.friends} />
|
|
|
|
|
+ {
|
|
|
|
|
+ process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
|
|
|
|
|
+ }
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function content() {
|
|
|
|
|
+ if (!loaded) {
|
|
|
|
|
+ return <View >
|
|
|
|
|
+ {
|
|
|
|
|
+ process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
|
|
|
|
|
+ }
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!user.isLogin) {
|
|
|
|
|
+ return friendGuide()
|
|
|
|
|
+ }
|
|
|
|
|
+ switch (homeType) {
|
|
|
|
|
+ case 'NO_FRIEND':
|
|
|
|
|
+ return friendGuide()
|
|
|
|
|
+ case 'NO_MOMENT':
|
|
|
|
|
+ return empty()
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return <View >
|
|
|
|
|
+ <View style={{ height: navigationBarHeight, width: rpxToPx(750), backgroundColor: '#fff' }} />
|
|
|
|
|
+ <View style={{ backgroundColor: '#fff', minHeight: '100vh' }}>
|
|
|
|
|
+ {
|
|
|
|
|
+ moments.map((item, index) => {
|
|
|
|
|
+ return <View key={index}>
|
|
|
|
|
+ <MomentItem data={item} />
|
|
|
|
|
+ </View>
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ </View>
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
|
|
|
|
|
+ }
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return content()
|
|
|
|
|
+
|
|
|
|
|
|
|
|
return <View>
|
|
return <View>
|
|
|
<ScrollView scrollY style={{ height: '100vh' }}>
|
|
<ScrollView scrollY style={{ height: '100vh' }}>
|