|
@@ -1,6 +1,6 @@
|
|
|
import { MainColorType } from "@/context/themes/color";
|
|
import { MainColorType } from "@/context/themes/color";
|
|
|
import { followUser, getMyFollowers, getMyFollowings, getMyFriends } from "@/services/friend";
|
|
import { followUser, getMyFollowers, getMyFollowings, getMyFriends } from "@/services/friend";
|
|
|
-import { View, Image, Text } from "@tarojs/components";
|
|
|
|
|
|
|
+import { View, Image, Text, ScrollView } from "@tarojs/components";
|
|
|
import { useEffect, useState } from "react";
|
|
import { useEffect, useState } from "react";
|
|
|
import './relation.scss'
|
|
import './relation.scss'
|
|
|
import NewButton, { NewButtonType } from "@/_health/base/new_button";
|
|
import NewButton, { NewButtonType } from "@/_health/base/new_button";
|
|
@@ -8,6 +8,7 @@ import { rpxToPx } from "@/utils/tools";
|
|
|
import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
|
|
import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
|
|
|
import { IconArrow } from "@/components/basic/Icons";
|
|
import { IconArrow } from "@/components/basic/Icons";
|
|
|
import Taro from "@tarojs/taro";
|
|
import Taro from "@tarojs/taro";
|
|
|
|
|
+import NoRecord from "@/_health/components/no_record";
|
|
|
|
|
|
|
|
export default function Relation() {
|
|
export default function Relation() {
|
|
|
const [count, setCount] = useState(0)
|
|
const [count, setCount] = useState(0)
|
|
@@ -18,59 +19,149 @@ export default function Relation() {
|
|
|
const [followings, setFollowings] = useState<any>([])
|
|
const [followings, setFollowings] = useState<any>([])
|
|
|
const [index, setIndex] = useState(0)
|
|
const [index, setIndex] = useState(0)
|
|
|
|
|
|
|
|
|
|
+ const [list, setList] = useState<any>([])
|
|
|
|
|
+ const [loaded, setLoaded] = useState(false)
|
|
|
|
|
+ const [page, setPage] = useState(1)
|
|
|
|
|
+ const [isPulling, setIsPulling] = useState(false)
|
|
|
|
|
+ const [isLoading, setIsLoading] = useState(false)
|
|
|
|
|
+ const [total, setTotal] = useState(-1)
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- getRelation()
|
|
|
|
|
- getFollowers()
|
|
|
|
|
- getFollowings()
|
|
|
|
|
|
|
+ // getRelation()
|
|
|
|
|
+ // getFollowers()
|
|
|
|
|
+ // getFollowings()
|
|
|
|
|
+
|
|
|
|
|
+ Taro.eventCenter.on('followUser', listenFollowUser)
|
|
|
|
|
+ Taro.eventCenter.on('unfollowUser', listenUnfollowUser)
|
|
|
|
|
|
|
|
- Taro.eventCenter.on('followUser',listenFollowUser)
|
|
|
|
|
- Taro.eventCenter.on('unfollowUser',listenUnfollowUser)
|
|
|
|
|
|
|
+ setPage(1)
|
|
|
|
|
+ getList(1)
|
|
|
|
|
|
|
|
- return ()=>{
|
|
|
|
|
|
|
+ return () => {
|
|
|
// Taro.eventCenter.off('followUser')
|
|
// Taro.eventCenter.off('followUser')
|
|
|
// Taro.eventCenter.off('unfollowUser')
|
|
// Taro.eventCenter.off('unfollowUser')
|
|
|
}
|
|
}
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
- function listenFollowUser(e){
|
|
|
|
|
- console.log('follow user',e)
|
|
|
|
|
- getRelation()
|
|
|
|
|
- getFollowers()
|
|
|
|
|
- getFollowings()
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ setPage(1)
|
|
|
|
|
+ getList(1)
|
|
|
|
|
+ }, [index])
|
|
|
|
|
+
|
|
|
|
|
+ function getList(i) {
|
|
|
|
|
+ setPage(i)
|
|
|
|
|
+ if (index == 0) {
|
|
|
|
|
+ getRelation(i)
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (index == 1) {
|
|
|
|
|
+ getFollowings(i)
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ getFollowers(i)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function onRefresh() {
|
|
|
|
|
+ setIsPulling(true)
|
|
|
|
|
+ setPage(1)
|
|
|
|
|
+ getList(1)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function listenUnfollowUser(e){
|
|
|
|
|
- console.log('unfollow user',e)
|
|
|
|
|
- getRelation()
|
|
|
|
|
- getFollowers()
|
|
|
|
|
- getFollowings()
|
|
|
|
|
|
|
+ function more() {
|
|
|
|
|
+ if (isLoading) return
|
|
|
|
|
+ if (total == list.length) return
|
|
|
|
|
+ var i = page + 1
|
|
|
|
|
+ getList(i)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getRelation() {
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ function listenFollowUser(e) {
|
|
|
|
|
+ console.log('follow user', e)
|
|
|
|
|
+ // getRelation()
|
|
|
|
|
+ // getFollowers()
|
|
|
|
|
+ // getFollowings()
|
|
|
|
|
+ getList(1)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function listenUnfollowUser(e) {
|
|
|
|
|
+ console.log('unfollow user', e)
|
|
|
|
|
+ // getRelation()
|
|
|
|
|
+ // getFollowers()
|
|
|
|
|
+ // getFollowings()
|
|
|
|
|
+ getList(1)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function getRelation(i) {
|
|
|
|
|
+ setPage(i)
|
|
|
|
|
+ setIsLoading(true)
|
|
|
getMyFriends({
|
|
getMyFriends({
|
|
|
- page: 1,
|
|
|
|
|
|
|
+ page: i,
|
|
|
limit: 20
|
|
limit: 20
|
|
|
}).then(res => {
|
|
}).then(res => {
|
|
|
|
|
+ setIsLoading(false)
|
|
|
|
|
+ setLoaded(true)
|
|
|
|
|
+ setIsPulling(false)
|
|
|
setCount((res as any).total)
|
|
setCount((res as any).total)
|
|
|
- setFriends((res as any).data)
|
|
|
|
|
|
|
+ // setFriends((res as any).data)
|
|
|
|
|
+ if (i == 1) {
|
|
|
|
|
+ setList((res as any).data)
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ setList([...list, ...(res as any).data])
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(e => {
|
|
|
|
|
+ setIsLoading(false)
|
|
|
|
|
+ setLoaded(true)
|
|
|
|
|
+ setIsPulling(false)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
- function getFollowers() {
|
|
|
|
|
|
|
+ function getFollowers(i) {
|
|
|
|
|
+ setPage(i)
|
|
|
|
|
+ setIsLoading(true)
|
|
|
getMyFollowers({
|
|
getMyFollowers({
|
|
|
- page: 1,
|
|
|
|
|
|
|
+ page: i,
|
|
|
limit: 20
|
|
limit: 20
|
|
|
}).then(res => {
|
|
}).then(res => {
|
|
|
- setCount2((res as any).total)
|
|
|
|
|
- setFollowers((res as any).data)
|
|
|
|
|
|
|
+ setIsLoading(false)
|
|
|
|
|
+ setLoaded(true)
|
|
|
|
|
+ setIsPulling(false)
|
|
|
|
|
+ setCount((res as any).total)
|
|
|
|
|
+ // setFollowers((res as any).data)
|
|
|
|
|
+ if (i == 1) {
|
|
|
|
|
+ setList((res as any).data)
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ setList([...list, ...(res as any).data])
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(e => {
|
|
|
|
|
+ setIsLoading(false)
|
|
|
|
|
+ setLoaded(true)
|
|
|
|
|
+ setIsPulling(false)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
- function getFollowings() {
|
|
|
|
|
|
|
+ function getFollowings(i) {
|
|
|
|
|
+ setPage(i)
|
|
|
|
|
+ setIsLoading(true)
|
|
|
getMyFollowings({
|
|
getMyFollowings({
|
|
|
- page: 1,
|
|
|
|
|
|
|
+ page: i,
|
|
|
limit: 20
|
|
limit: 20
|
|
|
}).then(res => {
|
|
}).then(res => {
|
|
|
- setCount3((res as any).total)
|
|
|
|
|
- setFollowings((res as any).data)
|
|
|
|
|
|
|
+ setIsLoading(false)
|
|
|
|
|
+ setLoaded(true)
|
|
|
|
|
+ setIsPulling(false)
|
|
|
|
|
+ setCount((res as any).total)
|
|
|
|
|
+ // setFollowings((res as any).data)
|
|
|
|
|
+ if (i == 1) {
|
|
|
|
|
+ setList((res as any).data)
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ setList([...list, ...(res as any).data])
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(e => {
|
|
|
|
|
+ setIsLoading(false)
|
|
|
|
|
+ setLoaded(true)
|
|
|
|
|
+ setIsPulling(false)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -107,6 +198,19 @@ export default function Relation() {
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function userList() {
|
|
|
|
|
+ return <View>
|
|
|
|
|
+ {/* <View>我的粉丝{count3}</View> */}
|
|
|
|
|
+ {
|
|
|
|
|
+ list.map((item, index) => {
|
|
|
|
|
+ return followItem(item, index)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
function tapFollow(item) {
|
|
function tapFollow(item) {
|
|
|
var params: any = {
|
|
var params: any = {
|
|
|
follow_origin: 'WECHAT_PRIVATE_CHAT',
|
|
follow_origin: 'WECHAT_PRIVATE_CHAT',
|
|
@@ -121,7 +225,7 @@ export default function Relation() {
|
|
|
|
|
|
|
|
function followItem(item, index) {
|
|
function followItem(item, index) {
|
|
|
return <View key={index} className="relation_item" onClick={() => {
|
|
return <View key={index} className="relation_item" onClick={() => {
|
|
|
- jumpPage('./home?uid='+item.id)
|
|
|
|
|
|
|
+ jumpPage('./home?uid=' + item.id)
|
|
|
}}>
|
|
}}>
|
|
|
<Image src={item.avatar} className="relation_avatar" />
|
|
<Image src={item.avatar} className="relation_avatar" />
|
|
|
<Text className="h34" style={{ color: MainColorType.link, flex: 1 }}>{item.nickname}</Text>
|
|
<Text className="h34" style={{ color: MainColorType.link, flex: 1 }}>{item.nickname}</Text>
|
|
@@ -148,14 +252,38 @@ export default function Relation() {
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return <View style={{ backgroundColor: '#fff', minHeight: '100vh' }}>
|
|
|
|
|
- <View style={{ display: 'flex', flexDirection: 'row', height: 50 }}>
|
|
|
|
|
- <View style={{ flex: 1, color: index == 0 ? '#000' : MainColorType.g02, textAlign: 'center' }} onClick={() => { setIndex(0) }}>搭子</View>
|
|
|
|
|
- <View style={{ flex: 1, color: index == 1 ? '#000' : MainColorType.g02, textAlign: 'center' }} onClick={() => { setIndex(1) }}>关注</View>
|
|
|
|
|
- <View style={{ flex: 1, color: index == 2 ? '#000' : MainColorType.g02, textAlign: 'center' }} onClick={() => { setIndex(2) }}>粉丝</View>
|
|
|
|
|
- </View>
|
|
|
|
|
|
|
+ function onScroll() {
|
|
|
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (loaded && list.length == 0)
|
|
|
|
|
+ return <NoRecord />
|
|
|
|
|
+
|
|
|
|
|
+ return <ScrollView style='height:100vh'
|
|
|
|
|
+ enableBackToTop
|
|
|
|
|
+ scrollY={true}
|
|
|
|
|
+ refresherEnabled={true}
|
|
|
|
|
+ upperThreshold={70}
|
|
|
|
|
+ lowerThreshold={140}
|
|
|
|
|
+ refresherBackground={MainColorType.g05}
|
|
|
|
|
+ onRefresherRefresh={onRefresh}
|
|
|
|
|
+ refresherTriggered={isPulling}
|
|
|
|
|
+ onScroll={onScroll}
|
|
|
|
|
+ onScrollToUpper={() => {
|
|
|
|
|
+
|
|
|
|
|
+ }}
|
|
|
|
|
+ onScrollToLower={more}
|
|
|
|
|
+ ><View >
|
|
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row', height: 50 }}>
|
|
|
|
|
+ <View style={{ flex: 1, color: index == 0 ? '#000' : MainColorType.g02, textAlign: 'center' }} onClick={() => { setIndex(0) }}>搭子</View>
|
|
|
|
|
+ <View style={{ flex: 1, color: index == 1 ? '#000' : MainColorType.g02, textAlign: 'center' }} onClick={() => { setIndex(1) }}>关注</View>
|
|
|
|
|
+ <View style={{ flex: 1, color: index == 2 ? '#000' : MainColorType.g02, textAlign: 'center' }} onClick={() => { setIndex(2) }}>粉丝</View>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ {
|
|
|
|
|
+ userList()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ {/* {
|
|
|
index == 0 && friendsList()
|
|
index == 0 && friendsList()
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
@@ -163,7 +291,8 @@ export default function Relation() {
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
index == 2 && followerList()
|
|
index == 2 && followerList()
|
|
|
- }
|
|
|
|
|
- </View>
|
|
|
|
|
|
|
+ } */}
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </ScrollView>
|
|
|
|
|
|
|
|
}
|
|
}
|